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

Automatically check DataModule.has_{setup,teardown,prepare_data} [2/2] #7238

Merged
merged 16 commits into from
May 11, 2021

Conversation

carmocca
Copy link
Contributor

@carmocca carmocca commented Apr 27, 2021

What does this PR do?

This PR automates checking whether the appropriate setup/teardown/prepare_data has been called. The check was only performed by the Trainer. Now it is done by the DataModule itself.

This has implications for the users if they were manually calling these functions themselves, as they will now be a no-op if they had been called already.

# user code:
dm.setup('fit')
...
dm.setup('fit')  # before this PR setup would get called it again, now it is a no-op

Fixes:

Fixes the check when the stage is None. Before it wasn't checking each attribute (has_setup_{fit,validate,test}) but has_setup_None which is not defined.

This PR does NOT fix_ #7286 because to properly resolve it, we need to avoid stage becoming None in the first place.

Note

The changes in this PR are the opposite of those discussed in #7301.

This PR attempts to fix the current design implementation. Not saying we should not change the design itself in the future.

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)

PR review

  • 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

@carmocca carmocca added the bug Something isn't working label Apr 27, 2021
@carmocca carmocca added this to the v1.3 milestone Apr 27, 2021
@carmocca carmocca self-assigned this Apr 27, 2021
@codecov
Copy link

codecov bot commented Apr 27, 2021

Codecov Report

Merging #7238 (fe91797) into master (3ec5420) will decrease coverage by 0%.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #7238   +/-   ##
======================================
- Coverage      92%     92%   -0%     
======================================
  Files         199     199           
  Lines       13030   13034    +4     
======================================
- Hits        11967   11955   -12     
- Misses       1063    1079   +16     

@carmocca carmocca changed the title Automatically check DataModule.has_{setup,teardown,prepare_data} [WIP] Automatically check DataModule.has_{setup,teardown,prepare_data} Apr 28, 2021
@carmocca carmocca added the data handling Generic data-related topic label Apr 30, 2021
@carmocca carmocca changed the title [WIP] Automatically check DataModule.has_{setup,teardown,prepare_data} [WIP][Blocked by #7289] Automatically check DataModule.has_{setup,teardown,prepare_data} Apr 30, 2021
@carmocca carmocca changed the title [WIP][Blocked by #7289] Automatically check DataModule.has_{setup,teardown,prepare_data} [Blocked by #7289] Automatically check DataModule.has_{setup,teardown,prepare_data} Apr 30, 2021
@carmocca carmocca changed the title [Blocked by #7289] Automatically check DataModule.has_{setup,teardown,prepare_data} [Blocked by #7289] Automatically check DataModule.has_{setup,teardown,prepare_data} [2/2] Apr 30, 2021
@carmocca carmocca modified the milestones: v1.3, v1.4 May 3, 2021
@carmocca carmocca changed the title [Blocked by #7289] Automatically check DataModule.has_{setup,teardown,prepare_data} [2/2] Automatically check DataModule.has_{setup,teardown,prepare_data} [2/2] May 4, 2021
@carmocca carmocca marked this pull request as ready for review May 4, 2021 10:50
@mergify mergify bot removed the has conflicts label May 4, 2021
Copy link
Contributor

@ananthsub ananthsub left a comment

Choose a reason for hiding this comment

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

Agreed with the fix for now but I'm in favor of simplifying/deprecating these properties in v1.4

@mergify mergify bot added the has conflicts label May 6, 2021
pytorch_lightning/core/datamodule.py Outdated Show resolved Hide resolved
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 ! @ananthsub I think this is an important feature as preparing a dataset can be costly and shouldn't be done several times.

How do you propose to solve this problem if we remove those properties ?

@mergify mergify bot removed the has conflicts label May 10, 2021
@carmocca carmocca modified the milestones: v1.4, v1.3.x May 10, 2021
@carmocca carmocca added the ready PRs ready to be merged label May 10, 2021
@Borda Borda merged commit b65ae79 into master May 11, 2021
@Borda Borda deleted the check-has-setup-teardown-dm branch May 11, 2021 08:53
@carmocca carmocca mentioned this pull request May 17, 2021
edgarriba pushed a commit that referenced this pull request May 18, 2021
…/2] (#7238)

* Automatically check `DataModule.has_{setup,teardown,prepare_data}`

* Use variable

* Spacing

* Docs

* Update CHANGELOG

* Remove `_DataModuleWrapper`

* Add test

* Update docs/source/extensions/datamodules.rst

* Bad merge

* add test for invalid name

* Remove ValueError

Co-authored-by: Adrian Wälchli <[email protected]>
lexierule pushed a commit that referenced this pull request May 19, 2021
…/2] (#7238)

* Automatically check `DataModule.has_{setup,teardown,prepare_data}`

* Use variable

* Spacing

* Docs

* Update CHANGELOG

* Remove `_DataModuleWrapper`

* Add test

* Update docs/source/extensions/datamodules.rst

* Bad merge

* add test for invalid name

* Remove ValueError

Co-authored-by: Adrian Wälchli <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working data handling Generic data-related topic ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants