-
Notifications
You must be signed in to change notification settings - Fork 3.6k
load_from_checkpoint support for LightningCLI when using dependency injection
#18105
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
load_from_checkpoint support for LightningCLI when using dependency injection
#18105
Conversation
0bda3b7 to
6075f6f
Compare
Borda
left a comment
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 we have this as optional so that still allow users to use an older version of jsonargparse and not have a too narrow version range...
carmocca
left a comment
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.
Interesting solution. But I think we should iterate on the UX for this first
load_from_checkpoint support for LightningCLI when using dependency injection
da5a248 to
f007077
Compare
f007077 to
ae8aa65
Compare
ae8aa65 to
78667fa
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #18105 +/- ##
==========================================
- Coverage 84% 48% -35%
==========================================
Files 450 442 -8
Lines 38154 38050 -104
==========================================
- Hits 31893 18430 -13463
- Misses 6261 19620 +13359 |
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 you have changes requested for this PR. Can you check it again please?
save_hyperparameters consistent for CLI and hardcoded training for custom python objects
#20432
What does this PR do?
For now this pull request is intended to start the discussion on how to add full support for
load_from_checkpointfor models trained usingLightningCLI.LightningCLIis designed to allow the use of dependency injection, which is a good programming pattern. Since this means that class instances are given to the module's__init__, the current implementation ofsave_hyperparametersis not enough because there is no reliable way to know how the objects were instantiated. And this preventsload_from_checkpointfrom working correctly.The main idea is that
LightningCLIprovides tosave_hyperparameters, through a context variable, the actual parameters used for instantiation. These get saved as normal in thehparams.yamlfile. Thenload_from_checkpointuses a custom instantiator that makes use of jsonargparse to support the configuration of subclasses (class_pathandinit_args) in configs.The issue #15427 asks for a way to instantiate a model from a config file. However,
load_from_checkpointdoes both instantiation and loading of weights. Is there really a need to only instantiate from config? Like having aload_from_configwhich would get the path to thehparams.yamlfile?Also #15427 asks about dataloaders. From what I understand
save_hyperparameterscan also be used for data modules. However, I don't know how that is intended to work.Fixes #15427
Fixes #13279
Before submitting
PR review
Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:
Reviewer checklist