-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
fix missing call to untoggle_optimizer when accumulating gradients #8284
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8284 +/- ##
=======================================
- Coverage 93% 88% -5%
=======================================
Files 212 212
Lines 13716 13729 +13
=======================================
- Hits 12747 12075 -672
- Misses 969 1654 +685 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the milestone correct? Is this also an issue in the bug-fix branch or just after the loop refactor?
edit: nvm saw the original reported issue is for 1.3.7
I know this is closed, but I just pulled master, and tried testing w/3 optimizers instead of 2 (this problem is fixed when I only have 2) and the issue persists. Check this out: #8365 |
@@ -185,20 +185,17 @@ def _run_optimization( | |||
else: | |||
if self.trainer.lightning_module.automatic_optimization: | |||
self._optimizer_step(optimizer, opt_idx, batch_idx, closure) | |||
if len(self.trainer.optimizers) > 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes len() == 2, consider 3 optimizers - it should be a cyclic toggle instead of boolean
What does this PR do?
Fixes #8281
The training loop toggles the optimizers in case there are mutliple, and untoggles after the optimizer step is completed.
However, the untoggle is missing during the accumulation phase, and it is certainly necessary.
Every
toggle_optimizer()
call needs a matchinguntoggle_optimizer()
call.Test fails on master
Before submitting
PR review
Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:
Did you have fun?
I made sure I had fun coding 🙃