1、完整报错

RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 4.00 GiB total capacity; 2.41 GiB already allocated; 5.70 MiB free; 2.56 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

2、原因

batch_size过大,导致内存容量撑不住了。

通过打开任务管理器,我们很清楚的发现,原因就是内存容量不足,导致报错。

PyTorch——报错解决:RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 3.94 GiB total c_gpu

3、解决方法

减小batch_size

正常运行:

PyTorch——报错解决:RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 3.94 GiB total c_深度学习_02


任务管理器检测情况:

PyTorch——报错解决:RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 3.94 GiB total c_深度学习_03

参考文章

  1. ​深度学习中的batch的大小对学习效果有何影响?​