我认为这是一个对于GPU内存较低的PyTorch用户来说非常普遍的信息:
RuntimeError: CUDA out of memory. Tried to allocate X MiB (GPU X; X GiB total capacity; X GiB already allocated; X MiB free; X cached)
我尝试通过将每个图层加载到GPU上并再次加载回来来处理图像:
for m in self.children():
m.cuda()
x = m(x)
m.cpu()
torch.cuda.empty_cache()
但似乎并不是非常有效。我在想是否有什么技巧可以在使用较少GPU内存的情况下训练大型深度学习模型。
torch.cuda.empty_cache()
没有起作用。相反,我首先禁用了 GPU,然后重新启动内核,并重新激活了 GPU。这对我起了作用。 - multitudes