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

Deprecate DataModule properties: train_transforms, val_transforms, test_transforms, dims, and size #8851

Merged
merged 12 commits into from
Aug 11, 2021

Conversation

Tshimanga
Copy link
Contributor

@Tshimanga Tshimanga commented Aug 11, 2021

Deprecate DataModule properties: train_transforms, val_transforms, test_transforms, dums, and size

What does this PR do?

added deprecation warnings to Datamodule methods: train_transforms, val_transforms, test_transforms, dums, and size.

as per the approach outlined in the ticket based on #7301 where the deprecation warning goes out next release and then is removed two releases later. I did not find any tests that need to be moved.

Fixes #8728

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 🙃

…tamodule methods: train_transforms, val_transforms, test_transforms, dums, and size
@codecov
Copy link

codecov bot commented Aug 11, 2021

Codecov Report

Merging #8851 (da9363b) into master (cb2a8ed) will decrease coverage by 4%.
The diff coverage is 82%.

@@           Coverage Diff           @@
##           master   #8851    +/-   ##
=======================================
- Coverage      93%     89%    -4%     
=======================================
  Files         169     169            
  Lines       14073   14090    +17     
=======================================
- Hits        13045   12486   -559     
- Misses       1028    1604   +576     

@ananthsub ananthsub changed the title as part of ticket #8728; added deprecation warnings to Datamodule met… Deprecate DataModule properties: train_transforms, val_transforms, test_transforms, dums, and size Aug 11, 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.

thanks for working on this @Tshimanga !

CHANGELOG.md Outdated Show resolved Hide resolved
@ananthsub ananthsub changed the title Deprecate DataModule properties: train_transforms, val_transforms, test_transforms, dums, and size Deprecate DataModule properties: train_transforms, val_transforms, test_transforms, dims, and size Aug 11, 2021
@ananthsub ananthsub added this to the v1.5 milestone Aug 11, 2021
@ananthsub ananthsub added the data handling Generic data-related topic label Aug 11, 2021
@pep8speaks
Copy link

pep8speaks commented Aug 11, 2021

Hello @Tshimanga! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

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

Comment last updated at 2021-08-11 03:15:21 UTC

@carmocca
Copy link
Contributor

These are some occurrences found by grepping the project which should be addressed/updated/removed

tests/helpers/boring_model.py:163:            self.dims = self.random_train[0].shape
tests/helpers/boring_model.py:170:            self.dims = getattr(self, "dims", self.random_test[0].shape)
tests/helpers/boring_model.py:174:            self.dims = getattr(self, "dims", self.random_predict[0].shape)
tests/helpers/datamodules.py:43:        # self.dims is returned when you call dm.size()
tests/helpers/datamodules.py:44:        # Setting default dims here because we know them.
tests/helpers/datamodules.py:46:        self.dims = (1, 28, 28)
docs/source/extensions/datamodules.rst:130:            # self.dims is returned when you call dm.size()
docs/source/extensions/datamodules.rst:131:            # Setting default dims here because we know them.
docs/source/extensions/datamodules.rst:133:            self.dims = (1, 28, 28)
docs/source/extensions/datamodules.rst:148:                # self.dims = tuple(self.mnist_train[0][0].shape)
docs/source/extensions/datamodules.rst:155:                # self.dims = tuple(self.mnist_test[0][0].shape)
docs/source/extensions/datamodules.rst:224:                self.dims = self.mnist_train[0][0].shape
docs/source/extensions/datamodules.rst:229:                self.dims = getattr(self, "dims", self.mnist_test[0][0].shape)
pl_examples/basic_examples/mnist_datamodule.py:82:        self.dims = (1, 28, 28)
pl_examples/domain_templates/generative_adversarial_net.py:230:        self.dims = (1, 28, 28)

docs/source/extensions/datamodules.rst:366:        def __init__(self, train_transforms, val_transforms, test_transforms):
docs/source/extensions/datamodules.rst:368:            self.train_transforms = train_transforms
docs/source/extensions/datamodules.rst:369:            self.val_transforms = val_transforms
docs/source/extensions/datamodules.rst:370:            self.test_transforms = test_transforms
docs/source/starter/introduction_guide.rst:1121:    train_transforms = ...
docs/source/starter/introduction_guide.rst:1122:    val_transforms = ...
docs/source/starter/introduction_guide.rst:1123:    test_transforms = ...
pl_examples/basic_examples/mnist_datamodule.py:91:        self.test_transforms = self.default_transforms
pl_examples/basic_examples/mnist_datamodule.py:135:        extra = dict(transform=self.test_transforms) if self.test_transforms else {}

@Tshimanga
Copy link
Contributor Author

Tshimanga commented Aug 11, 2021

@carmocca so I didn't remove those occurrences because they seemed to be implementation details of those specific datamodules, and I don't believe determining what other datamodules may or may not implement their own additional properties is in scope of this ticket, just cleaning up the LightningDataModule interface itself.

train_transforms, val_transforms, test_transforms, dims, and size are entirely optional to use, yet they’re on the DataModule interface. The Trainer does not rely on these, nor is the user forced to implement them. In reality, these are internal implementation details of individual datamodules. As a result, we ought to deprecate these off the DataModule interface.

Of course, users retain the ability to implement these properties in their LightningModules if they find these abstractions helpful.

That said, if the goal is actually to purge these properties from any classes implementing the LightningDataModule interface then I can go ahead and do so. Thoughts? @ananthsub

@Tshimanga
Copy link
Contributor Author

By the way, thanks for the attentiveness guys! @carmocca @ananthsub Really appreciate the rapid feedback :)

@ananthsub
Copy link
Contributor

ananthsub commented Aug 11, 2021

That said, if the goal is actually to purge these properties from any classes implementing the LightningDataModule interface then I can go ahead and do so. Thoughts? @ananthsub

I don't think we need to purge these properties from all classes. If modules want to implement dims or train_transforms independently, that is their prerogative, as they are implementation details of the module. we just shouldn't expect all modules to have them defined.

@Tshimanga you could go through the docs to ensure those references to ensure that no arguments are based to the base DataModule constructor.

@mergify mergify bot added the ready PRs ready to be merged label Aug 11, 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 !

@ananthsub ananthsub merged commit 24f0124 into Lightning-AI:master Aug 11, 2021
@carmocca
Copy link
Contributor

@Tshimanga you could go through the docs to ensure those references to ensure that no arguments are based to the base DataModule constructor.

This is important as it's not nice to have the docs using deprecated functionality.

@Tshimanga
Copy link
Contributor Author

@carmocca Good morning, and yeah definitely. I guess I'll open a follow up PR for that after work. Didn't realize this branch would be merged for me. 👍🏽

@ananthsub
Copy link
Contributor

This is important as it's not nice to have the docs using deprecated functionality.
Didn't realize this branch would be merged for me.

I was premature with the merge! My apologies @Tshimanga @carmocca . @Tshimanga a follow up PR would be hugely appreciated!

four4fish pushed a commit to four4fish/pytorch-lightning that referenced this pull request Aug 16, 2021
…st_transforms, dims, and size (Lightning-AI#8851)

* Deprecate DataModule properties: train_transforms, val_transforms, test_transforms, dims, and size
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 ready PRs ready to be merged refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate {train/val/test}_transforms, dims, and size from the DataModule
6 participants