Skip to content

Commit 13cb21a

Browse files
newtdmsguangyey
authored andcommitted
Enable split_group API when TorchComms is used as a backend for TorchTitan on XPU (pytorch#178236)
When TP>1 is enabled for TorchTitan models using TorchComms backend, the execution hangs on XPU (new_comms creation times out). Investigation shows that split_group API is being enabled only for cuda device for the same model configuration. This PR makes the calls generic using the accelerator API, and makes TP>1 cases functional on XPU. Pull Request resolved: pytorch#178236 Approved by: https://github.com/d4l3k, https://github.com/guangyey Co-authored-by: Yu, Guangye <guangye.yu@intel.com>
1 parent 20f1bde commit 13cb21a

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

torch/distributed/device_mesh.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,12 @@ def _init_one_process_group(
549549
getattr(default_group, "bound_device_id", None) is not None
550550
or dist_config.use_torchcomms
551551
)
552-
and torch.cuda.is_available()
552+
and torch.accelerator.is_available()
553553
and (
554554
backend is None
555-
or default_group._get_backend(torch.device("cuda")).name()
555+
or default_group._get_backend(
556+
torch.accelerator.current_accelerator() # pyrefly: ignore[bad-argument-type]
557+
).name()
556558
== backend
557559
)
558560
):

torch/distributed/distributed_c10d.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5453,10 +5453,18 @@ def split_group(
54535453
)
54545454

54555455
parent_group_rank = parent_global_to_group_ranks[global_rank]
5456-
parent_backend = parent_pg._get_backend(torch.device("cuda"))
5456+
5457+
if torch.accelerator.is_available():
5458+
parent_backend = parent_pg._get_backend(
5459+
torch.accelerator.current_accelerator() # pyrefly: ignore[bad-argument-type]
5460+
)
5461+
else:
5462+
raise RuntimeError(
5463+
"No backend for the parent process group or its backend does not support splitting"
5464+
)
54575465

54585466
# if the parent backend does not support splitting, raise error
5459-
# currently this API only support NCCL backend
5467+
# currently this API only support NCCL and XCCL backend
54605468
if (
54615469
not parent_backend or not parent_backend.supports_splitting
54625470
) and not _use_torchcomms_enabled():
@@ -5522,7 +5530,16 @@ def split_group(
55225530

55235531
global_ranks_in_my_group = [parent_group_to_global_ranks[rank] for rank in my_group]
55245532
split_pg.bound_device_id = device_id # type: ignore[union-attr]
5525-
split_backend_class = split_pg._get_backend(torch.device("cuda"))
5533+
5534+
if torch.accelerator.is_available():
5535+
split_backend_class = split_pg._get_backend(
5536+
torch.accelerator.current_accelerator() # pyrefly: ignore[bad-argument-type]
5537+
)
5538+
else:
5539+
raise RuntimeError(
5540+
"No backend for the parent process group or its backend does not support splitting"
5541+
)
5542+
55265543
if not _use_torchcomms_enabled():
55275544
split_backend_class._set_sequence_number_for_group()
55285545
if split_pg.group_name != group_name:

0 commit comments

Comments
 (0)