Pytorch RuntimeError:CUDA 内存不足,可用内存量很大
pytorch 3527
原文标题 :Pytorch RuntimeError: CUDA out of memory with a huge amount of free memory
在训练模型时,我遇到了以下问题:
RuntimeError: CUDA out of memory. Tried to allocate 304.00 MiB (GPU 0; 8.00 GiB total capacity; 142.76 MiB already allocated; 6.32 GiB free; 158.00 MiB 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
正如我们所见,尝试分配 304 MiB 内存时发生错误,而 6.32 GiB 是空闲的!问题是什么?正如我所看到的,建议的选项是设置 max_split_size_mb 以避免碎片。它会有所帮助以及如何正确地做到这一点?
这是我的 PyTorch 版本:
火炬==1.10.2+cu113
火炬视觉==0.11.3+cu113
torchaudio===0.10.2+cu113