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 _should_reload_dl_epoch causing inconsistent validation dataloader reloading #11036

Merged

Conversation

adamviola
Copy link
Contributor

@adamviola adamviola commented Dec 11, 2021

What does this PR do?

Fixes #10948

When the flag reload_dataloaders_every_n_epochs is set, PyTorch Lightning reloads dataloaders on epochs that are multiples of reload_dataloaders_every_n_epochs. This causes inconsistent validation dataloader reloading when the flagscheck_val_every_n_epoch or val_check_interval are set.

This PR now has the trainer store the epoch of the last reload of the train and validation dataloaders. Each dataloader is now eligible to reload when current_epoch - dl_last_reload_epoch >= reload_dataloaders_every_n_epochs.

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

No

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?

Actually yes

@adamviola adamviola force-pushed the bugfix/inconsistent-dl-reloading branch 3 times, most recently from 95ac137 to 123984d Compare December 11, 2021 20:39
@adamviola adamviola marked this pull request as ready for review December 11, 2021 21:17
@adamviola adamviola changed the title Fix _should_reload_dl_epoch causing inconsistent validation dataloa… Fix _should_reload_dl_epoch causing inconsistent validation dataloader reloading Dec 11, 2021
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.

Great work!

tests/trainer/test_dataloaders.py Show resolved Hide resolved
@carmocca carmocca added this to the 1.5.x milestone Dec 13, 2021
@carmocca carmocca added bug Something isn't working data handling Generic data-related topic labels Dec 13, 2021
@adamviola adamviola force-pushed the bugfix/inconsistent-dl-reloading branch from 0300720 to 1df1282 Compare December 20, 2021 19:27
@mergify mergify bot removed the has conflicts label Dec 20, 2021
tests/trainer/test_dataloaders.py Outdated Show resolved Hide resolved
tests/trainer/test_dataloaders.py Outdated Show resolved Hide resolved
tests/trainer/test_dataloaders.py Outdated Show resolved Hide resolved
tests/trainer/test_dataloaders.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.

Really nice contribution!

pytorch_lightning/trainer/data_loading.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/data_loading.py Outdated Show resolved Hide resolved
tests/trainer/test_dataloaders.py Show resolved Hide resolved
tests/trainer/test_dataloaders.py Outdated Show resolved Hide resolved
@mergify mergify bot added the ready PRs ready to be merged label Dec 21, 2021
@awaelchli awaelchli enabled auto-merge (squash) December 28, 2021 00:30
@awaelchli awaelchli merged commit 1fc046c into Lightning-AI:master Dec 28, 2021
awaelchli added a commit that referenced this pull request Jan 4, 2022
…der reloading (#11036)

Co-authored-by: Adam Viola <@adamviola>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: thomas chaton <[email protected]>
Co-authored-by: Adrian Wälchli <[email protected]>
awaelchli added a commit that referenced this pull request Jan 4, 2022
…der reloading (#11036)

Co-authored-by: Adam Viola <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: thomas chaton <[email protected]>
Co-authored-by: Adrian Wälchli <[email protected]>
awaelchli added a commit that referenced this pull request Jan 5, 2022
…der reloading (#11036)

Co-authored-by: Adam Viola <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: thomas chaton <[email protected]>
Co-authored-by: Adrian Wälchli <[email protected]>
awaelchli added a commit that referenced this pull request Jan 5, 2022
…der reloading (#11036)

Co-authored-by: Adam Viola <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: thomas chaton <[email protected]>
Co-authored-by: Adrian Wälchli <[email protected]>
awaelchli added a commit that referenced this pull request Jan 5, 2022
…der reloading (#11036)

Co-authored-by: Adam Viola <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: thomas chaton <[email protected]>
Co-authored-by: Adrian Wälchli <[email protected]>
lexierule pushed a commit that referenced this pull request Jan 5, 2022
…der reloading (#11036)

Co-authored-by: Adam Viola <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: thomas chaton <[email protected]>
Co-authored-by: Adrian Wälchli <[email protected]>
@rohitgr7 rohitgr7 mentioned this pull request Feb 7, 2022
12 tasks
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
5 participants