InplaceABN Backward Error

近日在对一个包含InplaceABN模块的网络进行魔改的时候,遇到了如下报错:

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [64, 256, 7, 7]], which is output 0 of InPlaceABNBackward, is at version 3; expected version 1 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!

之前应用InplaceABN的时候,并没有研读过paper和代码,所以在解决这个问题的时候,花费了数小时,像无头苍蝇一样试错,虽然知道是连续的inplace操作引发的问题,但是没有定位到具体引发问题是在哪个block的哪块代码,居然一直在错误地方尝试clone()来解决。次日常看github的issue,才将问题原因真正搞清楚。

1. InplaceABN提供的block

ABN is standard BN + activation (no memory savings).
InPlaceABN is BN+activation done inplace (with memory savings).
InPlaceABNSyncis BN+activation done inplace (with memory savings) + computation of BN (fwd+bwd) with data from all the gpus.

2. Inplace shortcut

out += residual to out = out + residual

+=和add_()是Inplace操作

我遇到的问题其实是,在ResidualBlock中,有InplaceABN和add_两个连续的inplce操作。

3. 解决方案

 

reference:

https://github.com/mapillary/inplace_abn/issues/6

inplace_abn/resnet.py at main · mapillary/inplace_abn · GitHub

inplace_abn/residual.py at main · mapillary/inplace_abn · GitHub

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

EnjoyCodingAndGame

愿我的知识,成为您的财富!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值