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

Why the optimizer.step() write twice? #8

Closed
San-ctuary opened this issue May 21, 2022 · 3 comments
Closed

Why the optimizer.step() write twice? #8

San-ctuary opened this issue May 21, 2022 · 3 comments

Comments

@San-ctuary
Copy link

loss1.backward(retain_graph=True)
self.optimizer.step()
loss2.backward()
self.optimizer.step()

When the first optimizer.step() execute all the gradient relate to loss1 will update,but some variable in loss2 are common in loss1.So this maybe cause some problem.

@xuchunyu123
Copy link

你好,我能问下你这个问题最后是怎么解决的吗,我也是在这里报错

@San-ctuary
Copy link
Author

作者已经在别的issue里面回答了,应该是pytorch版本问题,如果不降低版本的话直接把第一个.step注释掉就行

@deepConnectionism
Copy link

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [512, 25]], 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).

通过楼上的方案解决了 感谢

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

3 participants