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

Support re-instantiation for custom DataLoader in Lightning #10680

Merged
merged 55 commits into from Nov 24, 2021

Conversation

awaelchli
Copy link
Member

@awaelchli awaelchli commented Nov 22, 2021

What does this PR do?

Part of #10329

Adds support for re-instantiating custom DataLoaders in Lightning, a feature that was recently added to Lite first in #10279.

  • The utilities in Lite were moved to general data utilities
  • The place in Lightning where we call *_dataloader on the LightningModule or DataModule gets wrapped with a context manager.

Limitations:
The patching will only work if the DataLoader gets instantiated inside the *_dataloader methods.
The custom DataLoader needs to be compatible with the patching, i.e., it needs to allow Lightning to write the arguments to it's dict.

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 update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

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

Did you have fun?

I made sure I had fun coding 🙃

Part of #1 (it's a lie, this is just here to avoid noisy GitHub bot)

cc @Borda @justusschock @awaelchli @ninginthecloud

awaelchli and others added 30 commits November 1, 2021 23:21
@awaelchli awaelchli added data handling Generic data-related topic feature Is an improvement or enhancement labels Nov 23, 2021
@awaelchli awaelchli added this to the 1.6 milestone Nov 23, 2021
@awaelchli awaelchli marked this pull request as ready for review November 23, 2021 16:22
tests/utilities/test_data.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 !

pytorch_lightning/trainer/data_loading.py Show resolved Hide resolved
@mergify mergify bot added the ready PRs ready to be merged label Nov 24, 2021
@mergify mergify bot removed the has conflicts label Nov 24, 2021
@awaelchli awaelchli enabled auto-merge (squash) November 24, 2021 14:29
@awaelchli awaelchli merged commit 30ec481 into master Nov 24, 2021
@awaelchli awaelchli deleted the feature/patch-dataloader-init branch November 24, 2021 14:58
@rusty1s
Copy link
Contributor

rusty1s commented Mar 31, 2022

@awaelchli This is really cool. This comes in handy with our custom data loaders in PyG. Thank you!

One issue I ran into is the use of "nested inheritance" of data loaders:

torch.utils.data.DataLoader
       |
MyBaseDataLoader
       |
MyFinalLoader

This seems to do some weird things in the _replace_dataloader_init_method context manager since we overwrite the __init__ function of both data loader classes. I can try to set up a reproducible example later.

@carmocca
Copy link
Member

Hi @rusty1s! Glad that you find it useful, we actually worked on this with PyG as a motivation.

Happy to take a look once you define what those "weird things" are. You can find existing tests here if you are interested in poking at it yourself:

https://github.com/PyTorchLightning/pytorch-lightning/blob/1acb0dcbf4720b49b3de557d75f57a06c7276083/tests/utilities/test_data.py#L153-L176

Also, it would be better if you can open a new issue once you have a repro. Thank you!

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.

None yet

5 participants