admin管理员组文章数量:1611534
torch遇到错误:RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 23.65 GiB total capacity; 20.53 GiB already allocated; 9.56 MiB free; 20.94 GiB reserved in total by PyTorch)
原因:应该是我使用的图数据集太大了,而且是一开始就全部怼到了cuda上,所以就内存不够了
解决方法:
参考链接
将批次迭代地发送到 CUDA,并制作小批量,不要一开始就一次将所有数据发送到 CUDA。
for e in range(epochs):
for images, labels in train_loader:
if torch.cuda.is_available():
images, labels = images.cuda(), labels.cuda()
# blablabla
另外,在evaluate或者test时候,注意使用torch.autograd.no_grad()
阻止梯度更新。
with torch.autograd.no_grad():
# blabla
本文标签: allocateMIBRuntimeErrorCUDAMemory
版权声明:本文标题:RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 23.65 GiB total capacity; 20.5 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1728620919a1166349.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论