【规避内存不足问题】DefaultCPUAllocator: not enough memory: you tried to allocate 8000000 bytes. Buy new RAM

Source

【错误描述】

pytorch训练深度模型,往往报内存不足,但是本人自己的电脑很low,经常将dataloader中多线程num_workers置为0和将batch_size减小。但是在一次训练中将batch_size设置成1还是报错,最后采用修改源代码中统计字节参数,规避了内存不足的报错。

builtins.RuntimeError: [enforce fail at ..\c10\core\CPUAllocator.cpp:73] data. DefaultCPUAllocator: not enough memory: you tried to allocate 80000000000 bytes. Buy new RAM!

规避方式:找到采样器中的__iter__方法,将n的参数设置小,最终规避报错。参考路径。D:\autosoftware\anaconda3\Lib\site-packages\torch\utils\data\sampler.py
在这里插入图片描述