RuntimeError: CUDA out of memory. Tried to allocate 14.00 MiB (GPU 0; 6.00 G)的解决【实测成功】

仅作为记录,大佬请跳过。

仅需减小batchsize

展示:

在这里插入图片描述

即可运行。


博主的这个程序减小batchsize就行了,可能不同的博友们的程序不一样,也有的大佬博主使用不计算梯度释放内存的方式

不计算梯度——传送门

with torch.no_grad()

释放内存——传送门

if hasattr(torch.cuda, 'empty_cache'):
	torch.cuda.empty_cache()

RuntimeError: CUDA out of memory. Tried to allocate 14.00 MiB (GPU 0; 6.00 G)的解决【实测成功】_第1张图片

你可能感兴趣的:(python)