RuntimeError: CUDA out of memory. Tried to allocate 2.15 GiB (GPU 0; 12.00 GiB total capacity; 520.39 MiB already allocated; 8.51 GiB free; 1.30 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
只是为啥了,8.5G空闲GPU用不了
你先nvidia-smi查看一下gpu占用情况,把没正常退出的程序kill掉
先清除占用的内存
import torch, gc
gc.collect()
torch.cuda.empty_cache()
找出CUDA耗尽内存的原因,并重新启动内核以避免错误再次发生
torch.cuda.memory_summary(device=None, abbreviated=False)
降低工人数量num_workers
这是显存不够了,建议把batch size调小一点,若是调到1还是这样,那就只能换台更好的电脑跑这个模型了。
在任务管理器找到榨干GPU的罪魁祸首?
就是ctrl+alt+del,选任务管理器,点击性能
可以参考一下这个帖子
https://blog.csdn.net/xiaoyifeishuang1/article/details/121266541
kill已有的进程,或者把batchisize调小一些,甚至epoch调小都可以
前两天刚遇到同样的问题,极有可能是你的其他进程再用,但是你没有关闭,先用nvidia-smi查询一下有那些进程在用GPU,没有释放。
kill掉相应的进程就可以啦
杀死没有用或者没必要运行的内存试试,关闭一些自启动进程