1_2 pytorch 调试相关问题

1、inplace operation问题

 RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [1, 128, 60, 116]], which is output 0 of ReluBackward0, is at version 1; expected version 0 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

我也在往常查找了一些解决办法,例如:变量名不能用一样的,不行,pass梯度更新放在最后面,optimizer.step(),但是这个训练代码训练其他的googlenet等网络都没有问题,pass由于网络里连用两个nn.ReLU(inplace = True),由于是inplace操作,所以不产生中间变量,导致backward的时候,缺失这部分需要的变量,测试了将 inplace = False,不行,pass变量赋值时出现错误,就是不能使用 += 等符号,将其拆开写,测试了下,成功。

feat += layer()变成  feat = feat + layer()

2、cuda out of memory

可能是gpu中的显存被占用没有清空;

通过nvidia-smi查看显存占用,通过fuser -v /dev/nvidia*进行nvidia的进程,

kill -9 pid进行进程杀死。

3、

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值