ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memor

在Docker容器中利用Pytorch训练模型的时候,出现了题目中的错误:

ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memory (shm).
ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memory (shm).
……
RuntimeError: unable to write to file </torch_265_3416587874_1>: No space left on device (28)

看错误提示应该是共享内存不够了。

在容器红执行df -h查看磁盘使用情况:

可见容器默认的shared memory只有64MB。但训练程序中,data_loader设置的workers数目比较多,该程序中为8,这些workers通过共享内存进行协作,导致默认的共享内存不够用。

Please note that PyTorch uses shared memory to share data between processes, so if torch multiprocessing is used (e.g. for multithreaded data loaders) the default shared memory segment size that container runs with is not enough, and you should increase shared memory size either with –ipc=host or –shm-size command line options to nvidia-docker run.

基于以上原因,解决方法可从两个方面入手:

1. 将workers数量降低,例如设置num_workers=0;

2. 将容器的共享内存加大,由上面英文提示,可通过–ipc=host或–shm-size进行设置。 

这里,我选择的是第二种方式,加大容器的共享内存:

docker run ... --shm-size 8G ...

重启容器后,再次通过df -h查看磁盘使用情况,发现共享内存已经变成8G:

再次运行训练程序,成功! 

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
乘风的头像乘风管理团队
上一篇 2023年4月5日
下一篇 2023年4月5日

相关推荐