本文主要是介绍pytorch报错:RuntimeError: one of the variables needed for gradient computation has been modified by an,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
修改网络时
pytroch报错:
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [1600, 16, 256]], which is output 0 of CudnnConvolutionBackward, is at version 1; expected version 0 instead
解决方案一:
检查被报错的那个tensor的所有操作,如果出现了x += m
,x=x+m
的加法或者减法运算,全部改为以下格式:
x = x.clone() + m
这篇关于pytorch报错:RuntimeError: one of the variables needed for gradient computation has been modified by an的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!