Skip to content

Commit 22847fc

Browse files
committed
fix(ezpz): xpu-aware set_pg_timeouts workaround for xccl
Upstream torch.distributed.distributed_c10d._set_pg_timeout has no xpu branch — only cpu (gloo) and cuda (nccl / gloo / torchcomms). On xccl PGs the loop adds no backends, emits the warning "Set timeout is now only supported for either nccl or gloo.", and never calls _set_default_timeout. Result: CommConfig.train_timeout_seconds silently no-ops on every Intel XPU run we've ever done — including the moe_debugmodel_ep step-41 incident where a 100s configured timeout watched a 985s silence go by without firing. ProcessGroupXCCL itself has set_timeout and abort methods; the dispatch upstream just doesn't route to them. Until that's fixed upstream, _set_pg_timeouts_xpu_aware calls upstream first (covers cpu/cuda backends + the safety barrier) then walks each PG and calls ProcessGroupXCCL.set_timeout directly on any xccl-backed group, logging the count of patched groups. Verified on 2N Sunspot (alloc 12467180): moe_debugmodel_ep clean 10 steps, exit 0, log line "Applied train timeout 0:01:40 to 6 xccl ProcessGroup(s)" fires alongside the still-present upstream warning. Note: this only fixes the Python dispatch. Empirical work in the follow-up commit shows the xccl C++ runtime still doesn't enforce the per-collective timeout, so a hung xccl collective will still not abort. See docs/upstream-issues/train_timeout_xpu_silent_noop.md.
1 parent 2e71e14 commit 22847fc

1 file changed

Lines changed: 53 additions & 1 deletion

File tree

‎torchtitan/experiments/ezpz/trainer.py‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,58 @@
3232
from torchtitan.trainer import Trainer
3333

3434

35+
def _set_pg_timeouts_xpu_aware(
36+
timeout: timedelta,
37+
parallel_dims: ParallelDims,
38+
) -> None:
39+
"""Apply ``timeout`` to every PG in the mesh, with explicit XPU support.
40+
41+
Upstream ``dist_utils.set_pg_timeouts`` delegates to
42+
``torch.distributed.distributed_c10d._set_pg_timeout``, whose device
43+
dispatch only knows about cpu (gloo) and cuda (nccl / gloo /
44+
torchcomms). On XPU the loop adds no backends, emits the warning
45+
``"Set timeout is now only supported for either nccl or gloo."``,
46+
and never calls ``_set_default_timeout``. Result: ``train_timeout_seconds``
47+
silently no-ops and a hung collective burns the full PBS walltime
48+
instead of aborting (see
49+
``docs/upstream-issues/train_timeout_xpu_silent_noop.md``).
50+
51+
Workaround: invoke the upstream helper first (covers cpu/cuda
52+
backends + the safety barrier), then walk each PG ourselves and
53+
call ``ProcessGroupXCCL.set_timeout`` on any xccl-backed groups.
54+
Remove once PyTorch's ``_set_pg_timeout`` learns about XPU.
55+
"""
56+
dist_utils.set_pg_timeouts(timeout=timeout, parallel_dims=parallel_dims)
57+
58+
xpu_device = torch.device("xpu")
59+
if not (
60+
torch.distributed.is_xccl_available() and torch.xpu.is_available()
61+
):
62+
return
63+
64+
from torch._C._distributed_c10d import ProcessGroupXCCL
65+
66+
groups: list[torch.distributed.ProcessGroup | None] = [
67+
mesh.get_group()
68+
for mesh in parallel_dims.get_all_one_dimensional_meshes().values()
69+
] + [None]
70+
patched = 0
71+
for group in groups:
72+
if group is None:
73+
group = torch.distributed.distributed_c10d._get_default_group()
74+
if xpu_device not in group._device_types:
75+
continue
76+
backend = group._get_backend(xpu_device)
77+
if isinstance(backend, ProcessGroupXCCL):
78+
backend.set_timeout(timeout)
79+
patched += 1
80+
if patched:
81+
logger.info(
82+
f"Applied train timeout {timeout} to {patched} xccl ProcessGroup(s) "
83+
"(upstream _set_pg_timeout has no xpu branch)."
84+
)
85+
86+
3587
class FaultTolerantTrainer(Trainer):
3688
@dataclass(kw_only=True, slots=True)
3789
class Config(Trainer.Config):
@@ -621,7 +673,7 @@ def train(self):
621673
# reduce timeout after first train step for faster signal
622674
# (assuming lazy init and compilation are finished)
623675
if self.step == 1:
624-
dist_utils.set_pg_timeouts(
676+
_set_pg_timeouts_xpu_aware(
625677
timeout=timedelta(seconds=config.comm.train_timeout_seconds),
626678
parallel_dims=self.parallel_dims,
627679
)

0 commit comments

Comments
 (0)