DistributedSampler(num_replicas=0) raises a rank error instead of rejecting num_replicas
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- python
- Domain
- distributed-systems
Research direction
Start at the DistributedSampler constructor in torch.utils.data.distributed and reproduce the reported call with num_replicas=0. Review the constructor checks and verify that invalid num_replicas values are rejected directly rather than reported as an invalid rank. Done means the reported input produces a ValueError identifying num_replicas, without reaching division by zero.
Written by the indexing model from the issue text.
Description
I confirmed this on current pytorch main. num_replicas <= 0 is blamed on rank. Drafted with AI assistance; I reviewed the constructor checks.
🐛 Describe the bug
DistributedSampler(..., num_replicas=0, rank=0)raises aValueErroraboutrank, notnum_replicas.import torch from torch.utils.data.distributed import DistributedSampler DistributedSampler(range(10), num_replicas=0, rank=0) # ValueError: Invalid rank 0, rank should be in the interval [0, -1]The constructor only checks
rank >= num_replicas or rank < 0. Whennum_replicasis 0 or negative, that interval is meaningless and a validrank=0is reported as invalid. Laterlen(dataset) / num_replicaswould divide by zero if the rank check were reordered.Versions
pytorch
main.
cc @andrewkho @divyanshk @SsnL @VitalyFedyunin @dzhulgakov @scotts @malfet
- Dominant language
- Python
- Stars
- 103k
- Forks
- 29.9k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pytorch/pytorch
-
bot-triaged module: docs triaged
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
bot-triaged module: rocm module: tests module: windows triaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bot-triaged module: inductor oncall: pt2 release triage triaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bot-triaged module: cpu module: inductor module: windows oncall: pt2 release triage triaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bot-triaged oncall: cpu inductor oncall: pt2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100