Loading old checkpoints with new hparam keys #8917
Unanswered
codezakh
asked this question in
Lightning Trainer API: Trainer, LightningModule, LightningDataModule
Replies: 1 comment
-
@codezakh, The I initiated a feature request #8631 (@tchaton agreed on the idea) few days back which is a slightly different use case but requires pretty much similar fix. Not sure if it has any drawbacks though. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Define a
LightningModule
with an__init__
like this....where
cfg
is say,and then save the model with
trainer.save_checkpoint()
tomodel.ckpt
. Then at a later time, we make a small change toLitModel
and gate it behind a new key, so it is now:and we attempt to load our saved
model.ckpt
withLitModel.load_from_checkpoint('model.ckpt', new_key=True)
to test how the new behavior affects the performance of the old saved model.The current behavior is to throw
omegaconf.errors.ConfigKeyError: Key 'new_key' is not in struct
because of this_line, which is part of the following block:TLDR: Once a model has been saved with a
DictConfig
as its hyperparameter storage, it is seems impossible (please correct me if I'm wrong) to load it with future code that adds more hparams, even if they are compatible with the architecture.What is the recommended way to handle this use case, because it is natural over the course of R&D to add new flags and want to load old weights with them. My current solution is to override
load_from_checkpoint
and addOmegaConf.set_struct(..., False)
beforecheckpoint[cls.CHECKPOINT_HYPER_PARAMS_KEY].update(kwargs)
or use theomegaconf.open_dict(...)
context manager before the.update()
call.It feels as if lightning should do this, because the
hparams
object on an instantiatedLightningModule
does not seem to have thestruct=True
flag set on it.Beta Was this translation helpful? Give feedback.
All reactions