Skip to content
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

Expose load_state_dict strict=False #2629

Closed
shijianjian opened this issue Jul 17, 2020 · 3 comments · Fixed by #2819
Closed

Expose load_state_dict strict=False #2629

shijianjian opened this issue Jul 17, 2020 · 3 comments · Fixed by #2819
Labels
feature Is an improvement or enhancement help wanted Open to be worked on

Comments

@shijianjian
Copy link
Contributor

🚀 Feature

In contrastive learning, we normally train a representation learning backbone then adding the classifier. Sometimes, I wish to play with different classifiers. It would be best to have strict=False exposed to make the model still load with a user's permission.

model = TransferLearningModel.load_from_checkpoint(ckpt_path, strict=False)

The implementation is intuitive but an extremely useful feature in my case. Thank you!

@shijianjian shijianjian added feature Is an improvement or enhancement help wanted Open to be worked on labels Jul 17, 2020
@hbredin
Copy link
Contributor

hbredin commented Jul 20, 2020

This feature would also be very useful for LightningModule instances that add a bunch of layers at setup time (as load_from_checkpoint does not seem to call setup).

See related conversation in PytorchLightning Slack.

I'd be happy to try and contribute this (easy, I guess) change if this seems like a good idea.

@s-rog
Copy link
Contributor

s-rog commented Jul 20, 2020

yeah seems pretty straight forward. Add a strict arg with default True to load_from_checkpoint that gets passed into _load_model_state and into model.load_state_dict here

unless there are other concerns?

@hbredin
Copy link
Contributor

hbredin commented Jul 20, 2020

I don't foresee any other concern but would like to hear from maintainers before spending some time on such a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement help wanted Open to be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants