解决RuntimeError: CUDA out of memory. Tried to allocate 14.00 MiB (GPU 0; 7.43 GiB total capacity; 6.3

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()

你可能感兴趣的:(python小工具封装,机器学习,深度学习实战讲解与分析)