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

Hash values in LightningEnum instead of name. #8421

Merged
merged 11 commits into from
Jul 19, 2021

Conversation

ramonemiliani93
Copy link
Contributor

@ramonemiliani93 ramonemiliani93 commented Jul 14, 2021

What does this PR do?

Fixes enums hash by name and not by value. For example:

TrainerFn.FITTING in (None, "fit") # True
TrainerFn.FITTING in {None, "fit"} # False

Both should have the same result.

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 update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)
  • Did you list all the breaking changes introduced by this pull request?

PR review

Anyone in the community is free to review the PR once the tests have passed.
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 🙃

@codecov
Copy link

codecov bot commented Jul 14, 2021

Codecov Report

Merging #8421 (20320a3) into master (adaa32f) will decrease coverage by 5%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #8421    +/-   ##
=======================================
- Coverage      93%     88%    -5%     
=======================================
  Files         217     217            
  Lines       14225   14225            
=======================================
- Hits        13199   12536   -663     
- Misses       1026    1689   +663     

Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

Can you add a test for this?

You can do so with a doctest for DeviceType in line 85

    >>> # which is case invariant
    >>> DeviceType.TPU in ('tpu', 'CPU')
    True
+   >>> DeviceType.TPU in {'tpu', 'CPU'}
+   True

pytorch_lightning/utilities/enums.py Outdated Show resolved Hide resolved
@carmocca carmocca added the bug Something isn't working label Jul 14, 2021
@carmocca carmocca added this to the v1.3.x milestone Jul 14, 2021
@ramonemiliani93
Copy link
Contributor Author

Done! Let me know if everything is fine 🙌

@carmocca
Copy link
Contributor

Oh and one last thing, needs an entry in the "Fixed" section of https://github.com/PyTorchLightning/pytorch-lightning/blob/master/CHANGELOG.md

pytorch_lightning/utilities/enums.py Outdated Show resolved Hide resolved
@Borda Borda added the ready PRs ready to be merged label Jul 15, 2021
@mergify mergify bot requested a review from a team July 15, 2021 09:15
tests/utilities/test_enums.py Outdated Show resolved Hide resolved
@carmocca carmocca enabled auto-merge (squash) July 15, 2021 11:40
auto-merge was automatically disabled July 15, 2021 13:30

Head branch was pushed to by a user without write access

@tchaton
Copy link
Contributor

tchaton commented Jul 19, 2021

Dear @ramonemiliani93,

Weird, enum doesn't play nice with Set. Might be worth to replace it with list and get this merge.

Best,
T.C

@carmocca carmocca enabled auto-merge (squash) July 19, 2021 12:27
@carmocca carmocca merged commit c9eb7e4 into Lightning-AI:master Jul 19, 2021
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.

8 participants