-
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
Why are hparams mandatory in the LightningModule definition? #599
Comments
hparams are not required. we could also expand support to passing in a dictionary or something |
Yes, they are not mandatory as such. But the saved weights in the checkpoint cannot be loaded. Is there a workaround for that? |
It's just the If you don't want to follow the standard convention, you should be able to create your model manually, then restore your weights just as you would a standard Torch model. model = MyModel(whatever, args, you, want)
checkpoint = torch.load(checkpoint_path, map_location=lambda storage, loc: storage)
model.load_state_dict(checkpoint['state_dict']) This is a little bit error-prone in cases where your model has variable layer sizes. If you don't create the model with the same layers as the model that the checkpoint was saved from, this will fail. You can also let the trainer restore the weights by doing e.g. trainer = Trainer(..., restore_from_checkpoint=checkpoint_path)
trainer.test() Do either of these solutions meet your needs? Perhaps we could take a look at providing a convenience method for this? Or maybe even change the signature of
Then if we get |
@neggert |
BTW, we shall include these usecases in tests... |
I'm very for this. For my usecase, we use a completely separate configuration system outside of lightning's for our model construction.
@akshaykvnit I believe it's |
@jeffling No |
@shijianjian @jeffling @neggert @williamFalcon @Borda There is a |
Seems to have been implemented in #516. At a glance the implementation looks reasonable, but I haven't tested it. |
When I don't pass hparams in the LightningModule, it doesn't allow me to load a previously saved model using a checkpoint. Particularly, hparams can't be passed in Jupyter Notebook/Lab, so how to use it in such a usecase (for testing, etc.)?
I am able to train a model, checkpoint it, but I can't load it when I restart the kernel.
The text was updated successfully, but these errors were encountered: