Support both Namespace and dict for hyperparameter saving/loading. #943
Labels
feature
Is an improvement or enhancement
good first issue
Good for newcomers
help wanted
Open to be worked on
Milestone
🚀 Feature
Let the user pass a dict to
LightningModule
so that after model saving it can be restored usingload_from_checkpoint
orload_from_metrics
.Motivation
Currently, there is nothing that prevents the user from passing in hyperparameters to
LightningModule
via dictionary (or even somthing else). However, the model loading/saving assumes it is always aargparse.Namespace
. This could potentially be an issue whenload_from_checkpoint
restores the module with a Namespace passed in instead of dict.Pitch
The model saving currently converts Namespace to dict and the model loading converts it back to Namespace.
Pitch 1: Also save the type inside the checkpoint, e.g.,
and when restoring we instantiate with the appropriate type.
Pitch 2: Dump the whole hparams object (Namespace, dict, ...) into checkpoint without converting it to dict first and let pickle take care of the rest. Most flexible option but could give problems when loading from checkpoint.
Alternatives
Somehow restrict the user to only use argparse.
Additional context
The idea was suggested by @williamFalcon in PR #919.
The text was updated successfully, but these errors were encountered: