Skip to content

Add support for len(datamodule) #9895

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

Merged
merged 11 commits into from
Oct 15, 2021
Merged

Add support for len(datamodule) #9895

merged 11 commits into from
Oct 15, 2021

Conversation

kingyiusuen
Copy link
Contributor

@kingyiusuen kingyiusuen commented Oct 11, 2021

What does this PR do?

Fixes #5965

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?

Make sure you had fun coding 🙃

@kingyiusuen
Copy link
Contributor Author

The two truth value tests in test_define_as_dataclass failed:

assert BoringDataModule1(batch_size=32)
assert BoringDataModule2(batch_size=32)

I think it is because no *_dataloader method is implemented in BoringDataModule1 and BoringDataModule2. As a result, the newly introduced __len__ method returns 0, and the two datamodules are considered as False.

Let me know how I should fix this.

@kingyiusuen kingyiusuen marked this pull request as ready for review October 11, 2021 17:28
@awaelchli awaelchli added data handling Generic data-related topic feature Is an improvement or enhancement labels Oct 11, 2021
@awaelchli awaelchli added this to the v1.6 milestone Oct 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.

LGMT !

@codecov
Copy link

codecov bot commented Oct 12, 2021

Codecov Report

Merging #9895 (1f581eb) into master (f915a8a) will decrease coverage by 4%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #9895    +/-   ##
=======================================
- Coverage      93%     89%    -4%     
=======================================
  Files         178     179     +1     
  Lines       15642   15826   +184     
=======================================
- Hits        14486   14048   -438     
- Misses       1156    1778   +622     


def get_num_batches(dataloader: DataLoader) -> None:
nonlocal num_batches
L = len(dataloader)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As @carmocca said in #5965, the dataloaders might not have __len__ defined. Shouldn't we try to catch this?

Copy link
Contributor

Choose a reason for hiding this comment

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

let's use descriptive, lowercase variable names :)

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.

Looks great!

@carmocca carmocca changed the title Add support for len(datamodule) Add support for len(datamodule) Oct 14, 2021
@carmocca carmocca requested a review from SkafteNicki October 14, 2021 14:39
@mergify mergify bot added the ready PRs ready to be merged label Oct 15, 2021
@carmocca carmocca merged commit 6429de8 into Lightning-AI:master Oct 15, 2021

def get_num_batches(dataloader: DataLoader) -> None:
nonlocal num_batches
L = len(dataloader)
Copy link
Contributor

Choose a reason for hiding this comment

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

let's use descriptive, lowercase variable names :)

rohitgr7 pushed a commit to Tshimanga/pytorch-lightning that referenced this pull request Oct 18, 2021
@kingyiusuen kingyiusuen deleted the feature/5965-support-len-datamodule branch October 19, 2021 13:18
@ninginthecloud ninginthecloud mentioned this pull request Oct 21, 2021
12 tasks
ninginthecloud added a commit to ninginthecloud/pytorch-lightning that referenced this pull request Oct 27, 2021
ninginthecloud added a commit to ninginthecloud/pytorch-lightning that referenced this pull request Oct 27, 2021
ninginthecloud added a commit to ninginthecloud/pytorch-lightning that referenced this pull request Oct 28, 2021
carmocca pushed a commit that referenced this pull request Oct 29, 2021
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.

support len(datamodule)
6 participants