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

Do not prefetch when possible #12101

Merged
merged 14 commits into from
Feb 28, 2022
Merged

Do not prefetch when possible #12101

merged 14 commits into from
Feb 28, 2022

Conversation

carmocca
Copy link
Contributor

@carmocca carmocca commented Feb 24, 2022

What does this PR do?

Only prefetch unless we require it. That is when:

  • Iterable datasets are used, where we need to know when it will be exhausted to run validation.
  • Interbatch parallelism is used, where no prefetching would be silly.

This is good for FFCV because they already do prefetching internally.

We no longer error on 0-length map-style datasets as this is inconsistent with iterable datasets.

Part of #11538
Follow-up to #11606
Reverts #1280

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

None knowingly

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?
  • [n/a] 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

  • 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

cc @Borda @justusschock @awaelchli @ninginthecloud @akihironitta

@carmocca carmocca added the feature Is an improvement or enhancement label Feb 24, 2022
@carmocca carmocca added this to the 1.6 milestone Feb 24, 2022
@carmocca carmocca self-assigned this Feb 24, 2022
@carmocca carmocca added data handling Generic data-related topic performance labels Feb 24, 2022
pytorch_lightning/utilities/fetching.py Show resolved Hide resolved
tests/loops/test_loops.py Show resolved Hide resolved
tests/loops/test_loops.py Show resolved Hide resolved
tests/utilities/test_fetching.py Show resolved Hide resolved
tests/utilities/test_fetching.py 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 ! Some comments.

pytorch_lightning/loops/dataloader/evaluation_loop.py Outdated Show resolved Hide resolved
pytorch_lightning/loops/dataloader/evaluation_loop.py Outdated Show resolved Hide resolved
pytorch_lightning/loops/fit_loop.py Outdated Show resolved Hide resolved
pytorch_lightning/utilities/fetching.py Show resolved Hide resolved
pytorch_lightning/utilities/fetching.py Show resolved Hide resolved
@carmocca carmocca enabled auto-merge (squash) February 28, 2022 12:49
@mergify mergify bot added the ready PRs ready to be merged label Feb 28, 2022
Copy link
Contributor

@rohitgr7 rohitgr7 left a comment

Choose a reason for hiding this comment

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

small comments.

@@ -393,6 +393,9 @@ option when using sequential data.
to ``limit_{mode}_batches``, if it is set to 1.0 it will run for the whole dataset, otherwise it will throw an exception.
Here ``mode`` can be train/val/test/predict.

When iterable datasets are used, Lightning will pre-fetch 1 batch (in addition to the current batch) so it can detect
when the training will stop and run validation if necessary.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
when the training will stop and run validation if necessary.
when the training epoch will end and run validation if necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

while the comment here is not wrong, the real reason we have the prefetching is actually to avoid starting a new epoch that doesn't have any batches left in the dataloader. Relying on a StopIteration check is not possible for this reason.

pytorch_lightning/utilities/data.py Outdated Show resolved Hide resolved
pytorch_lightning/utilities/data.py Show resolved Hide resolved
pytorch_lightning/utilities/data.py Show resolved Hide resolved
pytorch_lightning/utilities/data.py Show resolved Hide resolved
Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com>
@carmocca carmocca merged commit 6309a59 into master Feb 28, 2022
@carmocca carmocca deleted the feat/no-prefetch-default branch February 28, 2022 18:31
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 performance ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants