参考于https://blog.csdn.net/qq_41963227/article/details/119391566
记录一下!!
- caffe2线程泄露
问题描述:在使用pytorch1.9的dataloader时,如果设置num_workers>0或者pin_memory=True时,出现caffe2线程泄露的warning,数量等于num_workers的数量。
[W pthreadpool-cpp.cc:90] Warning: Leaking Caffe2 thread-pool after fork. (function pthreadpool)
比如nuw_work =4
j那么这句话就会输出4次!
不影响正常使用,如果设置num_workers数目为0和pin_memory=False会影响训练速度
官方说在pytorch1.10会修改这个warning,之后就不会有这个问题了,如果不想看它一直输出可以使用下面的解决方法。
解决方法:pytorchGitHub项目问题讨论
使用GitHub源文件安装的方式安装pytorch,并在安装前删除caffe2/utils/threadpool/pthreadpool-cpp.cc 文件中的警告程序删除,即下方代码块的第四行。
auto num_threads = leaked->get_thread_count();
// NOLINTNEXTLINE(modernize-make-unique)
threadpool.reset(new PThreadPool(num_threads));
TORCH_WARN(“Leaking Caffe2 thread-pool after fork.”);
不会影响程序运行。
2 容器exit code