代码运行报这个错误:
RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 4.93 GiB total capacity; 94.84 MiB already allocated; 21.00 MiB free; 108.00 MiB reserved in total by PyTorch)
import torch, gc
gc.collect()
torch.cuda.empty_cache()
加入以上代码解决了,记录下。
本文介绍了一种常见的PyTorch CUDA内存溢出错误及其解决方案。通过使用Python的垃圾回收模块gc和PyTorch的cuda缓存清空功能,可以有效地解决此问题。
7053

被折叠的 条评论
为什么被折叠?



