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

Adds Sampler Wrappers for custom samplers in distributed environment #12959

Merged
merged 24 commits into from
Jun 22, 2022

Conversation

otaj
Copy link
Contributor

@otaj otaj commented May 3, 2022

What does this PR do?

Fixes #9883
Closes #12866, #12413

Adds a DistributedSamplerWrapper and UnrepeatedDistributedSamplerWrapper in order to wrap custom samplers in distributed environment.

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

None

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 minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the 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 🙃

cc @Borda @awaelchli @rohitgr7 @akihironitta @justusschock @ninginthecloud @otaj

@otaj otaj added feature Is an improvement or enhancement distributed Generic distributed-related topic data handling Generic data-related topic labels May 3, 2022
@otaj otaj added this to the 1.7 milestone May 3, 2022
@otaj otaj self-assigned this May 3, 2022
@mergify mergify bot removed the has conflicts label May 4, 2022
@mergify mergify bot removed the ready PRs ready to be merged label May 6, 2022
@otaj
Copy link
Contributor Author

otaj commented May 9, 2022

could we clarify how close are we to the original code?

@Borda Where would you like us to clarify more? In documentation, in docstrings, in changelog?

pytorch_lightning/overrides/distributed.py Outdated Show resolved Hide resolved
pytorch_lightning/overrides/distributed.py Outdated Show resolved Hide resolved
pytorch_lightning/overrides/distributed.py Outdated Show resolved Hide resolved
@Borda
Copy link
Member

Borda commented May 9, 2022

could we clarify how close are we to the original code?

@Borda Where would you like us to clarify more? In documentation, in docstrings, in changelog?

probably in the same comment, you mention that it was inspired from...

@mergify mergify bot added the ready PRs ready to be merged label May 9, 2022
@mergify mergify bot added has conflicts and removed ready PRs ready to be merged labels Jun 14, 2022
@mergify mergify bot added ready PRs ready to be merged and removed has conflicts ready PRs ready to be merged labels Jun 21, 2022
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.

LGTM!

CHANGELOG.md Outdated Show resolved Hide resolved
src/pytorch_lightning/overrides/distributed.py Outdated Show resolved Hide resolved
@otaj
Copy link
Contributor Author

otaj commented Jun 22, 2022

At this moment, I believe the PR is ready to go. We decided to move from Catalyst's implementation.

Currently, there is _DatasetSamplerWrapper which whole purpose is to wrap Sampler into a class with Dataset-like features (i.e. inheritance from Dataset and meaningful methods __getitem__ and __len__) and DistributedSamplerWrapper, which is very much just DistributedSampler which takes as a first argument Sampler instead of Dataset. Under the hood, we create _DatasetSamplerWrapper from the Sampler and just call the machinery of DistributedSampler

@carmocca , can you merge please if the final pass of review still looks good to you? Thanks!

@carmocca carmocca merged commit 33bd270 into master Jun 22, 2022
@carmocca carmocca deleted the feature/distributed_sampler branch June 22, 2022 10:17
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 distributed Generic distributed-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.

Weighted Random Sampler for ddp Make custom samplers distributed automatically
6 participants