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

Enables reload of dataloaders on every n epochs from every epoch #5043

Merged
merged 87 commits into from
Jul 7, 2021

Conversation

sidhantls
Copy link
Contributor

@sidhantls sidhantls commented Dec 9, 2020

What does this PR do?

This PR extends the logic of reloading dataloaders on every epoch allowing DLs to be reloaded every n epochs. It changes the argument from reload_dataloaders_every_epoch to reload_dataloaders_every_n_epochs . The parameter accepts an int>= 0. The default value is 0

Fixes #5001

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • 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? Otherwise, we ask you to create a separate PR for every change.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

Anyone in the community is free to review the PR once the tests have passed.
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; Bugfixes should be including in bug-fix release milestones (m.f.X) and features should be included in (m.X.b) releases.

Did you have fun?

Make sure you had fun coding 🙃

@rohitgr7
Copy link
Contributor

rohitgr7 commented Dec 9, 2020

you need to deprecate reload_dataloaders_every_epoch, assign its value to reload_dataloaders_every_n_epoch and raise a deprecation warning if it's set.

Also maybe rename reload_dataloaders_every_n_epoch to reload_dataloaders_every_n_epochs??

And ofcourse pls add a test too.

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 ! Minor changes and a test.

pytorch_lightning/trainer/evaluation_loop.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/connectors/data_connector.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/training_loop.py Outdated Show resolved Hide resolved
tests/trainer/test_dataloaders.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Dec 9, 2020

Codecov Report

Merging #5043 (e173cee) into master (bca5adf) will decrease coverage by 5%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #5043    +/-   ##
=======================================
- Coverage      92%     88%    -5%     
=======================================
  Files         213     213            
  Lines       13798   13809    +11     
=======================================
- Hits        12744   12132   -612     
- Misses       1054    1677   +623     

@sidhantls
Copy link
Contributor Author

@rohitgr7 after looking at check_val_every_n_epoch I just went with reload_dataloaders_every_n_epoch. but sure, I can rename it to reload_dataloaders_every_n_epochs

@rohitgr7
Copy link
Contributor

rohitgr7 commented Dec 9, 2020

@rohitgr7 after looking at check_val_every_n_epoch I just went with reload_dataloaders_every_n_epoch. but sure, I can rename it to reload_dataloaders_every_n_epochs

ah.. I was just looking at these two arguments so though epochs might be better. https://github.com/PyTorchLightning/pytorch-lightning/blob/05f25f3a543dd06382feb7f19761e452af572288/pytorch_lightning/trainer/trainer.py#L111-L112

@pep8speaks
Copy link

pep8speaks commented Dec 11, 2020

Hello @sid-sundrani! Thanks for updating this PR.

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

Comment last updated at 2021-07-07 01:18:59 UTC

pytorch_lightning/trainer/connectors/data_connector.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 Outdated Show resolved Hide resolved
tests/trainer/test_dataloaders.py Outdated Show resolved Hide resolved
@sidhantls
Copy link
Contributor Author

you need to deprecate reload_dataloaders_every_epoch, assign its value to reload_dataloaders_every_n_epoch and raise a deprecation warning if it's set.

@rohitgr7 the warning doesn't print for some reason if I use DeprecationWarning with rank_zero_warn

from pytorch_lightning.utilities import rank_zero_warn
# works, prints 
rank_zero_warn("Deprecation message..")
# doesnt print. there are a few examples of this usage 
rank_zero_warn("Deprecation message..", DeprecationWarning)

should I do the former?

@rohitgr7
Copy link
Contributor

you need to deprecate reload_dataloaders_every_epoch, assign its value to reload_dataloaders_every_n_epoch and raise a deprecation warning if it's set.

@rohitgr7 the warning doesn't print for some reason if I use DeprecationWarning with rank_zero_warn

from pytorch_lightning.utilities import rank_zero_warn
# works, prints 
rank_zero_warn("Deprecation message..")
# doesnt print. there are a few examples of this usage 
rank_zero_warn("Deprecation message..", DeprecationWarning)

should I do the former?

Can you add the warning at the correct place where it should be and a failing test? Will check it. @sid-sundrani

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.

Let's make it an int only, no bool. Default to 0. since other similar parameters check_val_every_n_epoch, log_every_n_steps, ... doesn't accept a bool value.

pytorch_lightning/trainer/connectors/data_connector.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/connectors/data_connector.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/connectors/data_connector.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/connectors/data_connector.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/trainer.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/training_loop.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/training_loop.py Outdated Show resolved Hide resolved
@tchaton tchaton added this to the 1.2 milestone Dec 14, 2020
@tchaton tchaton added design Includes a design discussion data handling Generic data-related topic labels Dec 14, 2020
@sidhantls sidhantls requested a review from rohitgr7 December 14, 2020 14:34
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.

pytorch_lightning/trainer/connectors/data_connector.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/properties.py Outdated Show resolved Hide resolved
@Borda Borda changed the base branch from master to release/1.2-dev December 14, 2020 17:32
CHANGELOG.md Outdated Show resolved Hide resolved
pytorch_lightning/trainer/properties.py Outdated Show resolved Hide resolved
tests/deprecated_api/test_remove_1-4.py Outdated Show resolved Hide resolved
tests/deprecated_api/test_remove_1-4.py Outdated Show resolved Hide resolved
tests/trainer/test_dataloaders.py Outdated Show resolved Hide resolved
@sidhantls sidhantls requested a review from carmocca December 16, 2020 16:27
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.

LGTM. I'm just wondering if someone sets limit_train/val/test_batches=0 should it even load the dataloaders at all??

docs/source/trainer.rst Outdated Show resolved Hide resolved
pytorch_lightning/core/hooks.py Outdated Show resolved Hide resolved
pytorch_lightning/core/hooks.py Outdated Show resolved Hide resolved
pytorch_lightning/core/hooks.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/connectors/data_connector.py Outdated Show resolved Hide resolved
docs/source/trainer.rst Outdated Show resolved Hide resolved
@rohitgr7
Copy link
Contributor

@sid-sundrani pls mark it as ready for review if it's ready.

@sidhantls sidhantls marked this pull request as ready for review December 19, 2020 15:13
@akihironitta akihironitta requested review from carmocca and removed request for teddykoker June 24, 2021 02:54
@carmocca carmocca added the ready PRs ready to be merged label Jun 24, 2021
@mergify mergify bot removed the has conflicts label Jun 24, 2021
CHANGELOG.md Outdated Show resolved Hide resolved
pytorch_lightning/trainer/trainer.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/connectors/data_connector.py Outdated Show resolved Hide resolved
@mergify mergify bot added the has conflicts label Jul 1, 2021
@edenlightning
Copy link
Contributor

@sid-sundrani any chance you can rebase and address final comments? we would love to finally merge!

pytorch_lightning/trainer/connectors/data_connector.py Outdated Show resolved Hide resolved
tests/deprecated_api/test_remove_1-6.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/trainer.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/trainer.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/connectors/data_connector.py Outdated Show resolved Hide resolved
@mergify mergify bot removed the has conflicts label Jul 6, 2021
@carmocca carmocca requested a review from awaelchli July 7, 2021 01:11
@awaelchli awaelchli enabled auto-merge (squash) July 7, 2021 01:17
@awaelchli awaelchli closed this Jul 7, 2021
auto-merge was automatically disabled July 7, 2021 01:18

Pull request was closed

@awaelchli awaelchli reopened this Jul 7, 2021
@awaelchli awaelchli enabled auto-merge (squash) July 7, 2021 01:19
@kaushikb11 kaushikb11 disabled auto-merge July 7, 2021 10:46
@kaushikb11 kaushikb11 changed the title Enables reload of dataloaders on every n epochs from every epoch Enables reload of dataloaders on every n epochs from every epoch Jul 7, 2021
@kaushikb11 kaushikb11 enabled auto-merge (squash) July 7, 2021 10:48
@carmocca carmocca merged commit 20df24d into Lightning-AI:master Jul 7, 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 design Includes a design discussion ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhance] Update reload_dataloaders_every_epoch to reload_dataloaders_every_n_epoch