-
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
Optimizer Frequencies logic, and new configure_optimizers #1269
Conversation
and returns optimizer_frequencies. optimizer_frequencies was added as a member of Trainer.
Description added to configure_optimizers in LightningModule
Hello @asafmanor! Thanks for updating this PR.
Comment last updated at 2020-03-31 13:40:10 UTC |
Codecov Report
@@ Coverage Diff @@
## master #1269 +/- ##
======================================
- Coverage 92% 92% -0%
======================================
Files 62 62
Lines 3210 3235 +25
======================================
+ Hits 2949 2968 +19
- Misses 261 267 +6 |
@PyTorchLightning/core-contributors ^^ pls check... |
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.
pls, could you check my questions?
just now it turned out there is another PR refactoring optimizers, see #1279 |
@ethanwharris pls be aware also of this work and decide which shall be merged first to reduce conflicts... if you agree we can change the destination branch, so this can be merged to yours #1279 or that one to here... |
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.
Co-Authored-By: Asaf Manor <32155911+asafmanor@users.noreply.github.com>
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.
nice work on this. i like the added option of returning dicts, makes the code more explicit when reading 👍
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 🚀
@asafmanor GREAT work, may you pls just add a note to changelog so it can go... |
This pull request is now in conflict... :( |
This pull request is now in conflict... :( |
Great job! =) |
n_critic = 5 | ||
return ( | ||
{'optimizer': dis_opt, 'frequency': n_critic}, | ||
{'optimizer': gen_opt, 'frequency': 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.
shouldn't this also have an example for scheduler?
{'optimizer': dis_opt, 'frequency': n_critic, 'lr_scheduler': Scheduler()}
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.
@Borda @asafmanor?
Also, amazing job :)
@asafmanor what about saving/loading checkpoints? did we handle storing this information for resuming training? |
I use |
We can do followup PR if needed but now it was blocking others so we needed to get it done... |
…AI#1269) * init_optimizers accepts Dict, Sequence[Dict] and returns optimizer_frequencies. optimizer_frequencies was added as a member of Trainer. * Optimizer frequencies logic implemented in training_loop. Description added to configure_optimizers in LightningModule * optimizer frequencies tests added to test_gpu * Fixed formatting for merging PR Lightning-AI#1269 * Apply suggestions from code review * Apply suggestions from code review Co-Authored-By: Asaf Manor <32155911+asafmanor@users.noreply.github.com> * Update trainer.py * Moving get_optimizers_iterable() outside. * Update note * Apply suggestions from code review * formatting * formatting * Update CHANGELOG.md * formatting * Update CHANGELOG.md Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Before submitting
What does this PR do?
Fixes #594
Description
This PR implements "optimizer_frequencies" logic, where every optimizer can be used several steps in a row as the number of its associated frequency before the next optimizer is called.
This is a highly needed feature for the optimization of networks, e.g. Wasserstein GANs.
The API follows @williamFalcon suggested API, and allows LightningModule.configure_optimizers()
to return a dictionary or multiple dictionaries, containing the new
frequency
key.Backward compatibility is obviously maintained.
Documentation:
Tests:
TODO:
I've started implementing such a test in test_optimizers but ran into questions regarding the method.
On a single_gpu training in a private project of mine, this has proven to work flawlessly.
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
Did you have fun?
Yep 🥇