-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Update LR schedulers only when their corresponding Optimizer is being… #4868
Conversation
Hello @hemildesai! Thanks for updating this PR.
Comment last updated at 2021-05-04 00:57:35 UTC |
1229ca7
to
51dc3d1
Compare
Codecov Report
@@ Coverage Diff @@
## master #4868 +/- ##
=======================================
- Coverage 91% 85% -6%
=======================================
Files 200 200
Lines 12894 13252 +358
=======================================
- Hits 11783 11312 -471
- Misses 1111 1940 +829 |
what if I set: def configure_optimizer(self):
optimizer1 = {'optimizer': SGD, 'frequency': 10}
optimizer2 = {'optimizer': ADAM, 'frequency': 10}
scheduler1 = scheduler(optimizer1)
scheduler2 = scheduler(optimizer2)
return [optimizer1, optimizer2], [scheduler1, scheduler2] the fix won't work, right? |
@rohitgr7 It mentions in the docs at https://pytorch-lightning.readthedocs.io/en/stable/lightning_module.html#configure-optimizers that if multiple optimizers are passed in a list, all of them will run at each optimization step. So I assumed that we don't want to change that behavior. |
I did pass them in a dictionary within a list with a specified |
@rohitgr7 I think the example will error out in the current version as well because when two lists are passed, it assumes that each element of the first list is an optimizer from torch.optim. Although there's no explicit check for it. |
True. not a valid configuration. Can you add a condition here: https://github.com/PyTorchLightning/pytorch-lightning/blob/204a0a2d03ce7dfb014e347f1d34a49ef5e86902/pytorch_lightning/trainer/optimizers.py#L44 |
40d7801
to
18865e2
Compare
… used. In the case when optimizer frequencies are specified, the LR scheduler corresponding to a particular optimizer is updated only when that optimizer is being used in the training loop or epoch.
28f1cdf
to
a46cbca
Compare
""" Verify that learning rate scheduling is working """ | ||
|
||
hparams = EvalModelTemplate.get_default_hparams() | ||
model = EvalModelTemplate(**hparams) |
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.
Can you replace this with BoringModel
?
@carmocca mind help getting this merged? |
hparams = EvalModelTemplate.get_default_hparams() | ||
model = EvalModelTemplate(**hparams) | ||
model.configure_optimizers = model.configure_optimizers__multiple_schedulers |
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 there an issue for converting all of the old test utilities to boring model / boring datamodule equivalents? Maybe something we can guarantee for v1.4 to simplify testing?
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.
We don't have an issue for it. Just doing it little by little and making sure all new code uses BoringModel
Maybe something we can guarantee for v1.4 to simplify testing?
The benefit is a considerable speedup, more than simplification
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.
lgtm
thanks for the fix.
the pr could have avoided the refactors in the tests. IMO should have been done in a separate pr for a more careful review.
… used.
In the case when optimizer frequencies are specified,
the LR scheduler corresponding to a particular optimizer is updated
only when that optimizer is being used in the training loop or epoch.
What does this PR do?
Fixes #4815
Also updates several old tests to use
BoringModel
Before submitting
PR review