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 frozen dataclass instance error in apply_to_collection #10927

Merged
merged 13 commits into from
Jan 5, 2022

Conversation

abhi-rf
Copy link
Contributor

@abhi-rf abhi-rf commented Dec 3, 2021

What does this PR do?

changed the set_attribute function in in the apply_to_collection for recursively applying a function to all elements of a certain dtype in utilities/apply_func.py to Work with frozen dataclass Also now.

Fixes #10873

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

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? Yes

Make sure you had fun coding 🙃

Copy link
Member

@justusschock justusschock left a comment

Choose a reason for hiding this comment

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

Sorry, but I feel I need to block this for now. I think this violates the core idea of a python frozen dataclass (which is being immutable) and therefore it should not be hacked around this. Let's discuss in #10873 .

If I'm outvoted I will happily open this PR again. Just want to prevent merging until a common decision was made

pytorch_lightning/utilities/apply_func.py Outdated Show resolved Hide resolved
@abhi-rf
Copy link
Contributor Author

abhi-rf commented Dec 4, 2021

Sorry, but I feel I need to block this for now. I think this violates the core idea of a python frozen dataclass (which is being immutable) and therefore it should not be hacked around this. Let's discuss in #10873 .

If I'm outvoted I will happily open this PR again. Just want to prevent merging until a common decision was made

Sure, makes sense. I did not think of it as a way to prevent python from doing its job.

Copy link
Contributor Author

@abhi-rf abhi-rf left a comment

Choose a reason for hiding this comment

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

Raised error instead of forcing the apply

Copy link
Member

@justusschock justusschock left a comment

Choose a reason for hiding this comment

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

@abhi-rf Would you mind to also add a test case for this?

@abhi-rf
Copy link
Contributor Author

abhi-rf commented Dec 10, 2021

@abhi-rf Would you mind to also add a test case for this?

Sure, I can surely give it a try!!

@carmocca
Copy link
Contributor

@abhi-rf You can find its existing tests in tests/utilities/test_apply_func.py

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 !

pytorch_lightning/utilities/apply_func.py Outdated Show resolved Hide resolved
@stale
Copy link

stale bot commented Jan 5, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you need further help see our docs: https://pytorch-lightning.readthedocs.io/en/latest/generated/CONTRIBUTING.html#pull-request or ask the assistance of a core contributor here or on Slack. Thank you for your contributions.

@stale stale bot added the won't fix This will not be worked on label Jan 5, 2022
@stale stale bot removed the won't fix This will not be worked on label Jan 5, 2022
@carmocca carmocca self-assigned this Jan 5, 2022
@carmocca carmocca added data handling Generic data-related topic feature Is an improvement or enhancement labels Jan 5, 2022
@carmocca carmocca added this to the 1.6 milestone Jan 5, 2022
@mergify mergify bot added the has conflicts label Jan 5, 2022
@carmocca carmocca enabled auto-merge (squash) January 5, 2022 21:09
@mergify mergify bot removed the has conflicts label Jan 5, 2022
@carmocca carmocca changed the title Fix frozen dataclass instance error in apply_to_collection function Fix frozen dataclass instance error in apply_to_collection Jan 5, 2022
@carmocca carmocca dismissed justusschock’s stale review January 5, 2022 21:10

The blocking review is outdated. The original error is respected

@carmocca carmocca requested a review from justusschock January 5, 2022 21:10
@mergify mergify bot added the ready PRs ready to be merged label Jan 5, 2022
@carmocca carmocca merged commit 43c140c into Lightning-AI:master Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data handling Generic data-related topic 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.

Frozen Dataclasses as samples produce an error in 1.5+
5 participants