-
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
Add support for optimizers and learning rate schedulers to LightningCLI #8093
Add support for optimizers and learning rate schedulers to LightningCLI #8093
Conversation
Hello @mauvilsa! Thanks for updating this PR. There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-06-30 20:45:35 UTC |
for more information, see https://pre-commit.ci
Codecov Report
@@ Coverage Diff @@
## master #8093 +/- ##
=======================================
- Coverage 93% 88% -5%
=======================================
Files 212 212
Lines 13595 13665 +70
=======================================
- Hits 12635 12024 -611
- Misses 960 1641 +681 |
- Change manual configure_optimizers example to return dict.
for more information, see https://pre-commit.ci
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.
cc @jlperla for his thoughts
It all sounds great! I couldn't quite tell what the CLI would look for for choosing an which optimizer and which lr schedulers (and arguments) and how the default ones and values are set... but maybe I just can't read the diffs correctly. The only other thing I would say is that whatever that way is, I would doublecheck that it works fine on the grid CLI with escaping characters/etc. Since trying different permutations of optimizers, LR schedulers, and hyperparameters for them is a key use-case. If grid has trouble with the escaping I think it is important to know early. |
- Changed instantiate_class so that it does not depend on jsonargparse. - Added yaml snippets for more clarity.
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.
your docs are always 100% super nice
Given the comments above, I am worried that this has a terminal design flaw that makes it unusable in practice. This sounds like there is no way to set reasonable defaults that are problem specific. And hence in practice an entire dictionary needs to be passed in each time. That is verbose. And "users" need to know what the reasonable problem dependent defaults are for those all as well. At that point I should be using a json file rather than the cli If that is the design and I am not misunderstanding it, and there is no way to change the defaults in my code, I just dont think I can use this feature. Creating my own subclasses for all optimizers /etc is not a solution. Isn't there a design or tweak that can make it more like the nice, hierarchical CLI that come up in the rest of this package? |
@jlperla I believe that you have some expectations for the cli that I don't think are justified. What makes something a cli is being able to run something from the command line. It is not that every minute detail should be Luckily the optimizer example is perfect to illustrate why this should be done via a config file instead of individual command line arguments. Imagine that for some task you want to try different optimizers. Each optimizer has its own parameters that could be varied. Even if multiple optimizers have a parameter with the same name, e.g. I have no good idea how the example above could be easily done using individual command line arguments. But with a config file this can be defined quite clearly, for example: optimizer:
sweep:
- class_path: torch.optim.SGD
init_args:
lr:
sweep: [0.00001, 0.0001, 0.001, 0.01, 0.1, 1.0]
momentum:
sweep: [0, 0.1]
- class_path: torch.optim.Adam
init_args:
lr:
sweep: [0.001, 0.01]
amsgrad:
sweep: [True, False]
- class_path: torch.optim.RMSprop This would be for some hypothetical sweeper that would take care of trying out all the combinations defined in the config file. The cli itself would not be aware of the sweeping and only get a config file with individual values without any |
- Changed link_optimizers_and_lr_schedulers to reduce on indentation level.
Co-authored-by: Adrian Wälchli <[email protected]>
for more information, see https://pre-commit.ci
To me, that is really the only reason I want to use the CLI. If I can't make it sweepable with grid and then see the results in the grid webview then I need to use a different system. And just to be clear, this is not narrowly for JUST grid. I would be doing the identical thing on a cluster myself. Come up with the cartesian product of these things, run a whole bunch of aruments with CLI, etc. Not modify individual config files). So this isn't any sort of "lets change PL to be more grid-friendly" as you would want the same thing even if you weren't on grid. I should also point out that this is the only sane way to work with debugging in PL. In vscode, you set the CLI arugments you want to work with in a new "launch" type and then hit F5.
I don't see a limitation of grid. Except that with grid I hope to one day be able to execute these things programmatically instead of literally calling from a shell - but for that you would need just as much control over default values for execution. I see a limitation of the CLI. If the config files are the first and foremost goal, then I missed things (and I think it should be renamed as the name LightningCLI suggests otherwise). What is the point then vs. Hydra, which does an amazing job of handling config files?
Exactly! That is why you need to find the value for your problem and then set it. This shows why managing default values is so essential.
If that is the assumption and the starting point, then that is fine - but it means that the feature is useful for people like me, and most low-tech users of grid.
Exactly, that is why you need to be able to change the defaults for when you choose that parameters.
I think this is the problem. It hasn't been designed for the CLI. And just to be clear, for this, there is absolutetly nothing specific to my problem. Every single project has the same need for choosing optimizers/learning rate schedulers... tinnkering arorund until you find a nice default... baking them in... and then moving onto the other parts of the project. I have discussed this with @tchaton and @zippeurfou at various points and they might have some insights on this general topic, but I think the core of the problem is that (for me at least), I want the LightningCLI as a very simple CLI solution for simple projects. I want to be able to write a bunch of calls tot he function in either grid on on my cluster etc. without manually messing around with YAML files. If I wanted a more complciated config file solution, I would look to hydra. But I don't. |
Being able to provide init arguments of a subclass as independent command line arguments (that is avoiding the need to provide a json) is a general feature that would be implemented in jsonargparse. Regarding the defaults for subclasses, again this is a new feature for jsonargparse and probably with a small change in LightningArgumentParser to be able to specify them. I don't think these are difficult to do. Neither of these features are specific to optimizers and learning rate schedulers which is the purpose of this pull request. And what is currently implemented here is not incompatible with these additional features. For me it is fine if this pull request does not close #7576 and it is closed only when the rest is ready. But I don't see any more comments that require changes for this pull request |
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 PR is good to go as it is and already large enough. Some recap notes:
- Does not close Easier way to configure optimizers and schedulers in the CLI #7576
Further improvements to the docs will be done in a separate PR to clarify the usage without config files. Add support for optimizers and learning rate schedulers to LightningCLI #8093 (comment)edit: done in LightningCLI documentation improvements #8303- Will explore whether we can simplify the optimizer instantiation further. Add support for optimizers and learning rate schedulers to LightningCLI #8093 (comment)
Add mapping for. edit: done in LightningCLI documentation improvements #8303--optimizer.class_path
and--optimizer.init_args.*
Add support for optimizers and learning rate schedulers to LightningCLI #8093 (comment)
What does this PR do?
New feature for LightningCLI to make optimizers and learning rate schedulers easily configurable. It implements the proposal mentioned in #7576 (comment) except for minor differences required during development. How it should be used is explained in lightning_cli.rst.
This PR does not close #7576.
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?
Make sure you had fun coding 🙃