pytorch錯誤:RuntimeError: received 0 items of ancdata解決

詳情見鏈接

RuntimeError: received 0 items of
ancdata錯誤是在dataloader加載數據時出現的錯誤,原因是pytorch多線程共享tensor是通過打開文件的方式實現的,而打開文件的數量是有限制的,通過

ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 128088
max locked memory       (kbytes, -l) 16384
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 128088
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

可查看,當需共享的tensor超過open files限制時,即會出現該錯誤。

解決辦法有2種:

  • 1、增加open files的限制數量:

不能用sudo ulimit -n命令,而需執行:

sudo sh -c "ulimit -n 65535 && exec su $LOGNAME"
  • 2、修改多線程的tensor方式爲file_system(默認方式爲file_descriptor,受限於open files數量):
 torch.multiprocessing.set_sharing_strategy('file_system')
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章