Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loss2.backward():runtime error #1

Closed
MindsetFather opened this issue Apr 25, 2022 · 2 comments
Closed

loss2.backward():runtime error #1

MindsetFather opened this issue Apr 25, 2022 · 2 comments

Comments

@MindsetFather
Copy link

MindsetFather commented Apr 25, 2022

Thanks for the open source code! And there is a problem confuing me.
When i running the code with [python main.py],there is a Pytorch error:
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [512, 38]], which is output 0 of AsStridedBackward0, 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).

Code error is located in solver.py,line 188
//Minimax strategy
loss1.backward(retain_graph=True)
self.optimizer.step()
loss2.backward()
self.optimizer.step()

when i change the code to
loss1.backward(retain_graph=True)
//self.optimizer.step()
loss2.backward()
self.optimizer.step()

It worked!
I wonder if the first [self.optimizer.step()] should be annotated,if not, how to resolve the error.
Thank you.

@wuhaixu2016
Copy link
Collaborator

Hi, I think both versions are fine.

But, to solve the error that you come across at first (keep the first backward), you should change the pytorch version as 1.4.0

@MindsetFather
Copy link
Author

thank you ,it worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants