Reliability of _class_path in Lightning checkpoints when using instantiate_module
#21474
Replies: 2 comments 2 replies
-
|
Note: I understand that Lightning provides the standard way to load checkpoints via LightningModule.load_from_checkpoint(...) However, that approach requires the model class to be known explicitly at load time. In my use case, all model and datamodule classes are already available in the environment, and the checkpoint itself contains the corresponding This makes the loading process fully config- and checkpoint-driven, which is why the presence and stability of |
Beta Was this translation helpful? Give feedback.
-
|
To answer some of my own questions:
After inspecting the lightning code and some minor analysis, I came to conclusion that
python my_cli_script.py --model=model.yaml --data=data.yamlwhere model.yaml: classpath: base.MyModeldata.yaml: classpath: database.MyDataClass |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Lightning team ,
I have a question regarding the reliability and long-term guarantees of relying on
_class_pathstored inside Lightning checkpoints, specifically when usinginstantiate_modulefromlightning.pytorch.clito instantiate the model class and data module class.Context
In my project, I load a Lightning checkpoint and re-instantiate both the model and datamodule using:
This approach is entirely based on the assumption that the saved checkpoint contains a
_class_pathentry for:hyper_parameters)datamodule_hyper_parameters)These class paths are then consumed by
instantiate_moduleto reconstruct the objects.Below is a simplified version of what I currently do:
This works well with recent Lightning versions, and is very convenient for fully config-driven workflows.
Questions
Is it guaranteed that Lightning checkpoints will always contain the
_class_pathkey for:hyper_parameters)datamodule_hyper_parameters)?Is
_class_path:From which Lightning version did checkpoints start reliably including
_class_path?Is relying on
instantiate_modulefor checkpoint restoration considered a supported and future-proof pattern, or is it more of an internal/CLI-specific mechanism?Can users expect this behavior to remain stable in future Lightning releases?
Beta Was this translation helpful? Give feedback.
All reactions