RuntimeError:one of the variables needed for gradient computation has been modified by an inplace...

调试过程出现如下错误:

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

参考博客

由于新版本的pytorch把Varible和Tensor融合为一个Tensor,inplace操作,之前对Varible能用,但现在对Tensor,就会出错了。

res += x # 报错
res = x + res # right

 

你可能感兴趣的:(知识点)