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

Added strict=False for load_from_checkpoint #2819

Merged
merged 23 commits into from
Aug 13, 2020
Merged

Added strict=False for load_from_checkpoint #2819

merged 23 commits into from
Aug 13, 2020

Conversation

shijianjian
Copy link
Contributor

What does this PR do?

Enabled functionality as

 model = system.load_from_checkpoint(ckpt_path, hparams_file=vars(hparams), strict=False)

Fixes #2629

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together? Otherwise, we ask you to create a separate PR for every change.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@mergify mergify bot requested a review from a team August 4, 2020 10:10
@codecov
Copy link

codecov bot commented Aug 4, 2020

Codecov Report

Merging #2819 into master will increase coverage by 0%.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #2819   +/-   ##
======================================
  Coverage      90%     90%           
======================================
  Files          81      81           
  Lines        7553    7553           
======================================
+ Hits         6796    6797    +1     
+ Misses        757     756    -1     

@Borda Borda added the feature Is an improvement or enhancement label Aug 4, 2020
Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls rebase on master and do not add removed/deprecated API

@mergify mergify bot requested a review from a team August 4, 2020 10:42
@williamFalcon
Copy link
Contributor

@shijianjian can you add a test for this?

pytorch_lightning/core/saving.py Outdated Show resolved Hide resolved
@mergify mergify bot requested a review from a team August 4, 2020 15:01
@mergify mergify bot requested a review from a team August 4, 2020 16:08
@pep8speaks
Copy link

pep8speaks commented Aug 4, 2020

Hello @shijianjian! Thanks for updating this PR.

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-08-13 19:51:47 UTC

@awaelchli
Copy link
Contributor

Do I understand correctly, this PR also adds unrelated to strict kwarg the possibility to have hparams_file a dict? Why do we need that? Isn't it the same as passing the dict as kwargs?

@shijianjian
Copy link
Contributor Author

Do I understand correctly, this PR also adds unrelated to strict kwarg the possibility to have hparams_file a dict? Why do we need that? Isn't it the same as passing the dict as kwargs?

@awaelchli The only reason that I included that is because of the hparams modification by hparams['on_gpu'] = False. I will remove those code if anyone can confirm that this specific modification is not needed.

@awaelchli
Copy link
Contributor

Not sure why we override the on_gpu=False, I guess it is assumed we always load the checkpoint to CPU, which is probably not necessary. But I think that requires a different solution. The reason why I am not so convinced with the hprams file as a dict is:

  1. Now there are two different ways to do the same thing, which in my opinion is not a great design. Will the user know that there is no difference?
  2. Two ways of doing the same thing will require also twice the amounts of tests, essentially duplicated, and twice the amount of maintenance effort.
  3. The meaning of the argname "hparams_file" is now misleading if it can be a dict

@shijianjian
Copy link
Contributor Author

@awaelchli I have no objections to remove it since it is only used for my own project, as long as you confirmed that the hparams['on_gpu'] = False is not needed here.

I will remove the corresponding code soon.

Thank you.

@shijianjian shijianjian requested review from rohitgr7, Borda and justusschock and removed request for a team August 6, 2020 17:19
@shijianjian
Copy link
Contributor Author

Should be able to be merged.

@mergify mergify bot requested a review from a team August 6, 2020 17:20
@Borda Borda added the design Includes a design discussion label Aug 6, 2020
tests/trainer/test_trainer.py Outdated Show resolved Hide resolved
tests/trainer/test_trainer.py Outdated Show resolved Hide resolved
@mergify mergify bot requested a review from a team August 6, 2020 18:03
@Borda Borda added the ready PRs ready to be merged label Aug 6, 2020
@mergify
Copy link
Contributor

mergify bot commented Aug 6, 2020

This pull request is now in conflict... :(

@mergify mergify bot requested a review from a team August 6, 2020 18:26
@Borda Borda modified the milestones: 1.0.0, 0.9.x Aug 13, 2020
@rohitgr7
Copy link
Contributor

still, some pep8 issues are there.

tests/models/test_restore.py Outdated Show resolved Hide resolved
@mergify mergify bot requested a review from a team August 13, 2020 19:46
@ananyahjha93 ananyahjha93 added the ready PRs ready to be merged label Aug 13, 2020
@ananyahjha93 ananyahjha93 dismissed stale reviews from awaelchli and justusschock August 13, 2020 20:24

outdated

@ananyahjha93 ananyahjha93 merged commit 53f855c into Lightning-AI:master Aug 13, 2020
ameliatqy pushed a commit to ameliatqy/pytorch-lightning that referenced this pull request Aug 17, 2020
* Added strict=False and hparams_file accepcts dict

* Apply suggestions from code review

Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>

* Type check fix

* Added tests

* Linting & test fix

* Removed redundant code & test

* Added strict=False and hparams_file accepcts dict

* Apply suggestions from code review

Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>

* Type check fix

* Added tests

* Linting & test fix

* Removed redundant code & test

* Apply suggestions from code review

* tests

* tests

* chlog

* Update tests/models/test_restore.py

Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com>

* update test comments

* Added docstring for the strict attribute

* Added supplementary tests

* Update saving.py

* Apply suggestions from code review

Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com>

* pep8, removed extra func

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
Co-authored-by: Jirka Borovec <jirka@pytorchlightning.ai>
Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com>
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
Co-authored-by: ananyahjha93 <ananya@pytorchlightning.ai>
@Borda Borda modified the milestones: 0.9.x, 0.9.0 Aug 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Includes a design discussion feature Is an improvement or enhancement ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose load_state_dict strict=False
8 participants