Lin-Yijie / Graph-Matching-Networks

PyTorch implementation of Graph Matching Networks, e.g., Graph Matching with Bi-level Noisy Correspondence (COMMON, ICCV 2023), Graph Matching Networks for Learning the Similarity of Graph Structured Objects (GMN, ICML 2019).
Other
271 stars 55 forks source link

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

Open zztian007 opened 5 months ago

zztian007 commented 5 months ago

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).

Lin-Yijie commented 5 months ago

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

zztian007 commented 5 months ago

The pytorch version is 1.13. The python version is 3.8.11

Lin-Yijie commented 5 months ago

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 commented 5 months ago

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

This might work