Skip to content

Commit 237ab81

Browse files
committed
distributed_test: Map rank to GPU accordingly
If world_size is lesser than or equal to number of GPU's available then the rank can be directly mapped to corresponding GPU. This fixes the issue referenced in pytorch#45435 and pytorch#47629 For world_size = 3 and number of GPU's = 8, the rank to GPU mapping will be 0,2,4. This is due to the introduction of barrier, (refer pytorch#45181) the tensors in barrier is mapped to cuda0,1,2 and the tensors in the actual test cases are mapped to cuda0,2,4 resulting in different streams and leading to timeout. This issue is specific to default process group. Issue is not observed in new process group since the streams are created again after the initial barrier call. This patch maps the rank to corresponding GPU's when the world_size is less than or equal to the number of GPU's, in this case 0,1,2 Note: The barrier function in distributed_c10d.py should include new parameter to specify the tensor or rank to GPU mapping. In that case, this patch will be redundant but harmless since the tests can specify the tensors with appropriate GPU rankings.
1 parent 8ff0b6f commit 237ab81

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

torch/testing/_internal/distributed/distributed_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,12 @@ def _init_multigpu_helper(self):
364364
if BACKEND == "nccl":
365365
apply_hack_for_nccl()
366366

367-
nGPUs_per_process = nGPUs // world_size
367+
""" If rank is lesser than or equal to number of available GPU's
368+
then each rank can be mapped to corresponding GPU.
369+
"""
370+
nGPUs_per_process = 1
371+
if world_size > nGPUs:
372+
nGPUs_per_process = nGPUs // world_size
368373
rank_to_GPU = {
369374
i: list(
370375
visible_devices[i * nGPUs_per_process: (i + 1) * nGPUs_per_process]

0 commit comments

Comments
 (0)