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

Change lightning module params to dict when loading #1639

Merged
merged 3 commits into from
May 2, 2020

Conversation

cmpute
Copy link
Contributor

@cmpute cmpute commented Apr 27, 2020

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 to update the docs?
  • Did you write any new necessary tests?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

This is a relatively small issue so I directly create a PR without issue.

What does this PR do?

When the checkpoint file is loaded, if lightning module has hparams as an argument for __init__, the hparams in checkpoint file will be fed. However it's fed as a positional argument, which means if hparams is not the first parameter for __init__, it will be loaded in an incorrect way. So this PR changes positional argument to a key-value pair based.

@pep8speaks
Copy link

pep8speaks commented Apr 27, 2020

Hello @cmpute! Thanks for updating this PR.

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

Comment last updated at 2020-04-29 16:36:06 UTC

@mergify mergify bot requested a review from a team April 27, 2020 15:37
@mergify mergify bot requested a review from a team April 29, 2020 00:04
@Borda Borda added the feature Is an improvement or enhancement label Apr 29, 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.

LGTM 🦝

@Borda Borda requested review from awaelchli and a team April 29, 2020 11:38
@Borda Borda added this to the 0.7.6 milestone Apr 29, 2020
@Borda Borda added the ready PRs ready to be merged label Apr 29, 2020
Copy link
Contributor

@tullie tullie left a comment

Choose a reason for hiding this comment

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

The tests need to be fixed.

@Borda Borda removed the ready PRs ready to be merged label Apr 29, 2020
@mergify mergify bot requested a review from a team April 29, 2020 14:38
@cmpute
Copy link
Contributor Author

cmpute commented Apr 29, 2020

It seems that a lot of the test are not running on the latest commit, how can I request the CI again?

@Borda
Copy link
Member

Borda commented Apr 29, 2020

It seems that a lot of the test are not running on the latest commit, how can I request the CI again?

I have restarted it but it is still failing, see

FAILED tests/models/test_restore.py::test_load_model_with_missing_hparams - T...
====== 1 failed, 243 passed, 27 skipped, 239 warnings in 82.34s (0:01:22) ======

@awaelchli
Copy link
Contributor

Look at the error message:

  # load the state_dict on the model automatically
        kwargs.update(hparams=hparams)
>       model = cls(*args, **kwargs)
E       TypeError: __init__() got an unexpected keyword argument 'hparams'

It's running an old code, that's weird.
Maybe try force push again ?

@cmpute
Copy link
Contributor Author

cmpute commented Apr 29, 2020

        # load the state_dict on the model automatically
        kwargs.update(hparams=hparams)
>       model = cls(*args, **kwargs)
E       TypeError: __init__() got an unexpected keyword argument 'hparams'

pytorch_lightning/core/lightning.py:1552: TypeError

In the CI test, this is the error reported, however in my branch, the code is actually

if hparams:
    kwargs.update(hparams=hparams)            
model = cls(*args, **kwargs)
model.load_state_dict(checkpoint['state_dict'])

Do I have to commit something to make this change take effect? :0

@cmpute
Copy link
Contributor Author

cmpute commented Apr 29, 2020

I added another commit

@awaelchli
Copy link
Contributor

seems to work now :) just the formatting now

@mergify mergify bot requested a review from a team April 29, 2020 16:35
@Borda Borda requested a review from tullie April 29, 2020 16:37
@Borda Borda added the ready PRs ready to be merged label Apr 30, 2020
@williamFalcon williamFalcon merged commit 4dc77b5 into Lightning-AI:master May 2, 2020
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 ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants