Graph-Matching-Networks icon indicating copy to clipboard operation
Graph-Matching-Networks copied to clipboard

A runtime error reported when executing the loss.backward(torch.ones_like(loss)) line

Open zztian007 opened this issue 1 year ago • 6 comments

When I run train.py in the GMD , it reports the following runtime error. Do I need modify any code of the python files as you provided? How to fix it?

Traceback (most recent call last): File "E:\Projects\PythonProjects\XFVD\Models\GMN\train.py", line 97, in <module> loss.backward(torch.ones_like(loss)) # File "D:\WorkSpace\Anaconda3\envs\python38-tf2\lib\site-packages\torch\_tensor.py", line 487, in backward torch.autograd.backward( File "D:\WorkSpace\Anaconda3\envs\python38-tf2\lib\site-packages\torch\autograd\__init__.py", line 197, in backward Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [20]], which is output 0 of ReluBackward0, is at version 1; expected version 0 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

zztian007 avatar Jan 26 '24 13:01 zztian007

What is the version of your pytorch? This issue appears to be unprecedented.

Lin-Yijie avatar Jan 27 '24 01:01 Lin-Yijie

The pytorch version is 1.13. The python version is 3.8.11

zztian007 avatar Jan 27 '24 02:01 zztian007

The code was tested with torch = 1.2.0. Could you consider downgrading your PyTorch installation to version 1.2.0 or a version close to it?

Lin-Yijie avatar Jan 27 '24 03:01 Lin-Yijie

or you could change the line loss.backward(torch.ones_like(loss)) to loss = torch.sum(loss) loss.backward()

This might work

Lin-Yijie avatar Jan 27 '24 03:01 Lin-Yijie