pytorch出现nan不影响训练_pytorch报cuda显存不足

pytorch出现nan不影响训练_pytorch报cuda显存不足无论batch-size设置多小也是会出现这个问题的,我的原因是我将pytorch升级到了1.0.1,然后出现了这个问题RuntimeError:CUDAoutofmemory.Triedt

pytorch出现nan不影响训练_pytorch报cuda显存不足"

无论batch-size设置多小也是会出现这个问题的,我的原因是我将pytorch升级到了1.0.1,然后出现了这个问题

RuntimeError: CUDA out of memory. Tried to allocate 823.88 MiB (GPU 0; 7.93 GiB total capacity; 6.96 GiB already allocated; 189.31 MiB free; 10.26 MiB cached)

你可以监控一下之GPU的使用情况 ,使用下面的命令

watch -n 0.1 nvidia-smi

在期间会出现GPU的使用率达到99%,估计是没有释放GPU内存吧。

解决方法

我出现问题的代码,在输入到网络里面 ,如下:

output = net(input,inputcoord)

将这个代码做如下修改,其中torch.no_grad()是禁用梯度计算的上下文管理器,一般是在validate或者test会使用,只需要计算网络的输出,而无需计算梯度了

with torch.no_grad():
    output = net(input,inputcoord)

附带

在调试低版本的pytorch源程序的时候也会出现警告

 UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.

 也可以在前面添加下面的解决这个问题

with torch.no_grad():

 

参考

pytorch出现RuntimeError: CUDA out of memory.

https://pytorch.org/docs/stable/generated/torch.no_grad.html?highlight=torch%20no_grad#torch.no_grad

今天的文章pytorch出现nan不影响训练_pytorch报cuda显存不足分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/78463.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注