当前位置:   article > 正文

PyTorch出现”RuntimeError: CUDA out of memory“的解决方法_outofmemoryerror: cuda out of memory. tried to all

outofmemoryerror: cuda out of memory. tried to allocate 7.12 gib (gpu 0; 24.

问题描述

在运行以下代码时遇到了内存不足的问题。

  1. # 代码
  2. x = self.conv(x)
  3. # 出现以下问题
  4. RuntimeError: CUDA out of memory. Tried to allocate 66.00 MiB (GPU 0; 2.00 GiB total capacity; 1.21 GiB already allocated; 19.68 MiB free; 1.23 GiB reserved in total by PyTorch)

 

解决方法

参考链接:https://blog.csdn.net/pursuit_zhangyu/article/details/88717635no_grad

将以上代码进行修改,禁止梯度计算来减少内存消耗

  1. with torch.no_grad():
  2. x = self.conv(x)

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/88941
推荐阅读
相关标签
  

闽ICP备14008679号