RuntimeError: CUDA out of memory. Tried to allocate 22.00 MiB (GPU 0; 10.76 GiB total capacity; 9.61

RuntimeError: CUDA out of memory. Tried to allocate 22.00 MiB (GPU 0; 10.76 GiB total capacity; 9.61 GiB already allocated; 4.50 MiB free; 332.12 MiB cached)

有时遇到这种情况,怎么改batchsize都还是会报内存溢出错误,nVidia-smi时发现gpu很多空闲,这时出现的原因极可能就是中间变量数据导致的,这时可以检查loss,acc,pred等中间计算数据后面是否加了.item(),如果没加,给加上,就会解决错误。

猜你喜欢

转载自blog.csdn.net/snow_maple521/article/details/115427827