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

Fix inspection of unspecified args for container hparams #9125

Merged
merged 20 commits into from
Sep 6, 2021

Conversation

s-rog
Copy link
Contributor

@s-rog s-rog commented Aug 26, 2021

What does this PR do?

Fixes #8948

Does your PR introduce any breaking changes? If yes, please list them.

The internal logic for qualifying containers has been changed from not isinstance(str) to specific types (Namespace, dict, omegaconf if available). May break undocumented edge case uses.

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • 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?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

Todo:

  • omegaconf
  • tests

the tests only test for functionality, not sure how I would test for "non-inspection" besides passing in a type that breaks the parsing which is not ideal.

@s-rog s-rog added the bug Something isn't working label Aug 26, 2021
@s-rog s-rog added this to the v1.4.x milestone Aug 26, 2021
@s-rog s-rog self-assigned this Aug 26, 2021
@s-rog s-rog requested a review from awaelchli August 26, 2021 06:05
@s-rog s-rog marked this pull request as ready for review August 31, 2021 06:50
@codecov
Copy link

codecov bot commented Aug 31, 2021

Codecov Report

Merging #9125 (87880c7) into master (cf1a589) will increase coverage by 0%.
The diff coverage is 89%.

@@          Coverage Diff           @@
##           master   #9125   +/-   ##
======================================
  Coverage      92%     92%           
======================================
  Files         178     178           
  Lines       14858   14875   +17     
======================================
+ Hits        13709   13726   +17     
  Misses       1149    1149           

Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

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

Hey @s-rog. Mind putting more comments on the code. This part of the code might be complex for new contributors or reviewers.

@mergify mergify bot added the has conflicts label Sep 2, 2021
@mergify mergify bot removed the has conflicts label Sep 3, 2021
Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

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

LGTM !

@mergify mergify bot added ready PRs ready to be merged has conflicts labels Sep 3, 2021
@mergify mergify bot removed the has conflicts label Sep 5, 2021
@s-rog s-rog enabled auto-merge (squash) September 6, 2021 09:37
@s-rog s-rog merged commit 904dde7 into master Sep 6, 2021
@s-rog s-rog deleted the bug/hparams-parsing branch September 6, 2021 09:48
justusschock added a commit that referenced this pull request Sep 7, 2021
* Update parsing.py

* add todo (for single arg)

* unblock non container single arg

* init test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update CHANGELOG.md

* pep8 line length

* Update pytorch_lightning/utilities/parsing.py

* remove dict namespace conversion

* add omegaconf support

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add dict test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add omegaconf test

* Update CHANGELOG.md

* Update pytorch_lightning/utilities/parsing.py

Co-authored-by: Jirka Borovec <[email protected]>

* Update pytorch_lightning/utilities/parsing.py

Co-authored-by: Jirka Borovec <[email protected]>

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>
justusschock added a commit that referenced this pull request Sep 7, 2021
* Update parsing.py

* add todo (for single arg)

* unblock non container single arg

* init test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update CHANGELOG.md

* pep8 line length

* Update pytorch_lightning/utilities/parsing.py

* remove dict namespace conversion

* add omegaconf support

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add dict test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add omegaconf test

* Update CHANGELOG.md

* Update pytorch_lightning/utilities/parsing.py

Co-authored-by: Jirka Borovec <[email protected]>

* Update pytorch_lightning/utilities/parsing.py

Co-authored-by: Jirka Borovec <[email protected]>

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>
awaelchli pushed a commit that referenced this pull request Sep 7, 2021
* Update parsing.py

* add todo (for single arg)

* unblock non container single arg

* init test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update CHANGELOG.md

* pep8 line length

* Update pytorch_lightning/utilities/parsing.py

* remove dict namespace conversion

* add omegaconf support

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add dict test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add omegaconf test

* Update CHANGELOG.md

* Update pytorch_lightning/utilities/parsing.py

Co-authored-by: Jirka Borovec <[email protected]>

* Update pytorch_lightning/utilities/parsing.py

Co-authored-by: Jirka Borovec <[email protected]>

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>
lexierule pushed a commit that referenced this pull request Sep 10, 2021
* Update parsing.py

* add todo (for single arg)

* unblock non container single arg

* init test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update CHANGELOG.md

* pep8 line length

* Update pytorch_lightning/utilities/parsing.py

* remove dict namespace conversion

* add omegaconf support

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add dict test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add omegaconf test

* Update CHANGELOG.md

* Update pytorch_lightning/utilities/parsing.py

Co-authored-by: Jirka Borovec <[email protected]>

* Update pytorch_lightning/utilities/parsing.py

Co-authored-by: Jirka Borovec <[email protected]>

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>
@awaelchli
Copy link
Contributor

@s-rog we may have missed a detail here regarding the _hparams_name, see #9631. Let's see if we can cover this edge case.

# container
elif len(args) == 1 and isinstance(args[0], tuple(hparams_container_types)):
hp = args[0]
obj._hparams_name = "hparams"
Copy link
Contributor

Choose a reason for hiding this comment

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

here it is immediately assume that the name of the arg was "hparams". previously, the logic below was checking for matching argument names in the signature.

While this old way of passing in hyperparameters is not our recommended way, we have not officially dropped backward compatibility for this and therefore this was an unwanted breaking change imo.

Copy link
Contributor

Choose a reason for hiding this comment

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

See #9631 for an example of what was working previously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

save_hyperparameters attempts to parse unspecified args when a namespace is specified
4 participants