小白记录用,大佬可跳过 完整报错:
RuntimeError: CUDA error: out of memory
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
出错的地方:
if torch.cuda.is_available():
dadao=dadao.cuda()
我是使用学校服务器来运行的,之前在自己的设备上运行是没有问题的,尝试过网上各种方法,排除了显存不足的原因,但都没有成功。
后来发现错误的原因是因为服务器有多个GPU,我没有指定具体哪一个
所以在加上一行下面的代码
torch.cuda.set_device(1)
就成功运行了