当前位置: 代码迷 >> 综合 >> pytorch报错:RuntimeError: one of the variables needed for gradient computation has been modified by an
  详细解决方案

pytorch报错:RuntimeError: one of the variables needed for gradient computation has been modified by an

热度:84   发布时间:2024-01-04 03:13:03.0

修改网络时
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 += mx=x+m的加法或者减法运算,全部改为以下格式:

x = x.clone() + m
  相关解决方案