我在跑pytorch的时候,显存的报错如下(真的是GPU显存全部占用完了):
RuntimeError: CUDA out of memory. Tried to allocate 24.00 MiB (GPU 0; 11.92 GiB total capacity; 11.01 GiB already allocated; 7.63 MiB free; 11.22 GiB reserved in total by PyTorch)
可能的原因是:
① 在循环训练中累积历史记录
具体请点击这里查看(https://ptorch.com/news/160.html)
② 如果测试时爆显存,有可能是忘记设置no_grad了
即在测试代码前加一行with torch.no_grad():
即可。
具体请点击这里查看(https://blog.csdn.net/xiaoxifei/article/details/84377204)