pytorch 训练
问题RuntimeError: CUDA out of memory.
RuntimeError: CUDA out of memory. Tried to allocate 26.00 MiB (GPU 0; 7.43 GiB total capacity; 5.46 GiB already allocated; 18.44 MiB free; 6.83 GiB reserved in total by PyTorch)
解决办法
在报错哪一行前面加上下面两行:释放无关的内存
if hasattr(torch.cuda, 'empty_cache'):
torch.cuda.empty_cache()