Skip to content

Give an option to either provide dataset or dataset_size in distributed sampler #1479

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ramanishsingh
Copy link
Contributor

Currently the StatefulDistributedSampler takes the dataset as an argument, but only uses the length/size of the dataset.
Adding an option to provide size of the dataset instead, for more flexibility.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 29, 2025
Copy link

pytorch-bot bot commented Apr 29, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/data/1479

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 Cancelled Job

As of commit 1116f96 with merge base aef2409 (image):

CANCELLED JOB - The following job was cancelled. Please retry:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@ramanishsingh ramanishsingh marked this pull request as ready for review April 29, 2025 17:33
@@ -179,19 +182,66 @@ def __iter__(self):
)


class StatefulDistributedSampler(torch.utils.data.distributed.DistributedSampler):
class StatefulDistributedSampler(Sampler[int]):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should continue subclassing DistributedSampler for StatefulDistributedSampler - it is easy to udnerstand that by just the naming and we might trigger many type checking issues in downstream code which uses StatefulDistributedSampler and expects a variant of DistributedSampler.

Since DistributedSampler is a common utility in PyTorch, StatefulDistributedSampler should be expected to be an extension of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to fork it instead of subclassing because I do not want to upstream these changes in torch.utils.data.distributed.DistributedSampler as it might break other users' code.
Nevertheless, it is redundant to have Dataset as an arg when we just need the length of it.

Copy link
Contributor

@divyanshk divyanshk left a comment

Choose a reason for hiding this comment

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

Lets sync if there is a better way to do this - maybe create a new sampler?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants