错误处理:one of the variables needed for gradient computation has been modified by inplace operation
生活随笔
收集整理的這篇文章主要介紹了
错误处理:one of the variables needed for gradient computation has been modified by inplace operation
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [1, 100]], which is output 0 of UnsqueezeBackward0, is at version 5040; expected version 5039 instead.
錯誤分析:
由于pytorch升級到pytorch0.4之后,與之前pytorch0.3的用法發(fā)生來了一些變化,比如最重要的在pytorch0.4中將Tensor與Variance都組合成了同一個(gè)東西,pytorch0.4不再支持inplace操作。
解決方法:
1.把所有的inplace=True改成inplace=False
2.將loss+=new_loss這樣所有的+=操作,改成loss=loss+new_loss
3.將pytorch版本回退到0.3,或者添加一個(gè)pytorch0.3的環(huán)境。
?
總結(jié)
以上是生活随笔為你收集整理的错误处理:one of the variables needed for gradient computation has been modified by inplace operation的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TRMF 辅助论文:最小二乘法复现TRM
- 下一篇: MAS 714总复习