[Solved] pytorc Error: RuntimeError: one of the variables needed for gradient computation has been modified by an

Error reported by
pytroch when modifying the network:

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

 

Solution 1:

Check all operations of the tensor that is reported as an error. If there is an addition or subtraction operation of x + = m, x = x + m, all operations shall be changed to the following format:

x = x.clone() + m

Read More: