-
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
load_from_checkpoint
support for LightningCLI when using dependency injection
#18105
load_from_checkpoint
support for LightningCLI when using dependency injection
#18105
Conversation
0bda3b7
to
6075f6f
Compare
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...
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
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.
Overall looks fine. Given the complexity and the lack of docs I don't expect users to try this yet. Will you add those later?
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?
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_checkpoint
for models trained usingLightningCLI
.LightningCLI
is 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_hyperparameters
is not enough because there is no reliable way to know how the objects were instantiated. And this preventsload_from_checkpoint
from working correctly.The main idea is that
LightningCLI
provides tosave_hyperparameters
, through a context variable, the actual parameters used for instantiation. These get saved as normal in thehparams.yaml
file. Thenload_from_checkpoint
uses a custom instantiator that makes use of jsonargparse to support the configuration of subclasses (class_path
andinit_args
) in configs.The issue #15427 asks for a way to instantiate a model from a config file. However,
load_from_checkpoint
does both instantiation and loading of weights. Is there really a need to only instantiate from config? Like having aload_from_config
which would get the path to thehparams.yaml
file?Also #15427 asks about dataloaders. From what I understand
save_hyperparameters
can 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