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

Output Contains Duplicate Keys When Using DistributedSampler in Distributed Inference #13

Open
yfyeung opened this issue Nov 5, 2024 · 1 comment

Comments

@yfyeung
Copy link
Contributor

yfyeung commented Nov 5, 2024

When using s3tokenizer with PyTorch's DistributedSampler in a distributed inference setup, the output files contain duplicate keys, and the total number of keys is always a multiple of world_size.

This issue arises because DistributedSampler in PyTorch, by default, pads the dataset by repeating samples if drop_last=False, to ensure the total dataset size is divisible by world_size. This behavior is implemented in the DistributedSampler source code, where extra samples are added if len(indices) % num_replicas != 0, causing certain samples to appear multiple times across different ranks.

        if not self.drop_last:
            # add extra samples to make it evenly divisible
            padding_size = self.total_size - len(indices)
            if padding_size <= len(indices):
                indices += indices[:padding_size]
            else:
                indices += (indices * math.ceil(padding_size / len(indices)))[
                    :padding_size
                ]
@xingchensong
Copy link
Owner

welcome for pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants