错误处理:one of the variables needed for gradient computation has been modified by inplace operation(代码片

Posted UQI-LIUWJ

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了错误处理:one of the variables needed for gradient computation has been modified by inplace operation(代码片相关的知识,希望对你有一定的参考价值。

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的用法发生来了一些变化,比如最重要的在pytorch0.4中将Tensor与Variance都组合成了同一个东西,pytorch0.4不再支持inplace操作。

解决方法:


1.把所有的inplace=True改成inplace=False
2.将loss+=new_loss这样所有的+=操作,改成loss=loss+new_loss
3.将pytorch版本回退到0.3,或者添加一个pytorch0.3的环境。
 

以上是关于错误处理:one of the variables needed for gradient computation has been modified by inplace operation(代码片的主要内容,如果未能解决你的问题,请参考以下文章

Neither the JAVA_HOME nor the JRE_HOME environment variable is definedAt least one of these environ

完美解决RuntimeError: one of the variables needed for gradient computation has been modified by an inp

VMware启动Centos时出现错误Cannot open the disk 'xxxxxxx.vmdk' or one of the snapshot disks it depen

DatastageDatastage在win10上安装报错:This Application requires one of the following versions of the .NET

Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by se

The story of one latency spike