imgclsmob icon indicating copy to clipboard operation
imgclsmob copied to clipboard

Inplace RunError when testing backward of RevNet with PyTorch 1.11.0

Open taokz opened this issue 2 years ago • 1 comments

Hi, thank you for your good code, recently I've tried to reproduce RevNet with PyTorch 1.11.0, and I use your code. However, I got a RunError as follows:

File ~\Documents\RevNet\revnet.py:71, in ReversibleBlockFunction.backward(ctx, grad_y)
     68 gm = ctx.gm
     70 with torch.autograd.set_detect_anomaly(True):
---> 71     x, y = ctx.saved_variables
     72 # x, y = ctx.saved_tensors
     73 y1, y2 = torch.chunk(y, chunks=2, dim=1)

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [0]], which is output 0 of ReversibleBlockFunctionBackward, is at version 3; expected version 2 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!

I've searched potential solution on the Internet but I still can not solve it. One solution is to downgrade the pytorch version to 1.4.0 but this version does not support the GPU I use. Could you provide some suggestions for me? I appreciate your help. Thanks!

taokz avatar Aug 09 '22 21:08 taokz

Hi, I addressed the issue by modifying line 94 to: x = torch.cat((x1, x2), dim=1).data.contiguous() and by removing line 124: x.data.set_() However, I'm not entirely certain about the ramifications of these changes.

Unqua avatar Nov 04 '23 09:11 Unqua