donydchen / causal_emotion

☯︎[ACMMM'22] Official PyTorch Implementation of Towards Unbiased Visual Emotion Recognition via Causal Intervention
https://github.com/donydchen/causal_emotion
MIT License
17 stars 3 forks source link

gradient updating error #2

Closed xml94 closed 1 week ago

xml94 commented 1 month ago

Thank you for your wonderful work.

I got an gradient updating error as follows, could you please help me to figure it out?

Traceback (most recent call last): File "train.py", line 96, in model.optimize_parameters() # calculate loss functions, get gradients, update network weights File "/home/oem/Mingle/casual_emotion/models/iern_model.py", line 166, in optimize_parameters self.backward_Cls() File "/home/oem/Mingle/casual_emotion/models/iern_model.py", line 146, in backward_Cls self.loss_Cls.backward() File "/home/oem/anaconda3/envs/Mingle/lib/python3.8/site-packages/torch/_tensor.py", line 488, in backward torch.autograd.backward( File "/home/oem/anaconda3/envs/Mingle/lib/python3.8/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.cuda.FloatTensor [512]] is at version 2; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

xml94 commented 1 month ago

I found the non-error by changing a line of code in iern_model.py as follows: image

donydchen commented 1 week ago

Hi, @xml94. Thanks for your interest in this project.

I feel the issue might be caused by the PyTorch version. As mentioned in the README, this project worked fine on PyTorch version 1.4 when it was built, but it might have some issues when working with the current, newer version.