Skip to content

[distributed] Route _set_pg_timeout to ProcessGroupXCCL on xpu PGs - #184767

Closed
saforem2 wants to merge 2 commits into
pytorch:mainfrom
saforem2:xccl-set-pg-timeout-dispatch
Closed

saforem2 wants to merge 2 commits into
pytorch:mainfrom
saforem2:xccl-set-pg-timeout-dispatch

Conversation

@saforem2

Copy link
Copy Markdown

[distributed] Route _set_pg_timeout to ProcessGroupXCCL on xpu PGs

Summary

torch.distributed.distributed_c10d._set_pg_timeout currently has
device-conditional branches for cpu (gloo) and cuda
(nccl/gloo/torchcomms) — but no torch.device("xpu") branch. On
an xccl-backed process group the existing loop adds no backends,
emits the warning

UserWarning: Set timeout is now only supported for either nccl or gloo.

and _set_default_timeout is never called. The per-PG timeout
(e.g. CommConfig.train_timeout_seconds in torchtitan, or any user
who later wants to call _set_pg_timeout directly) silently no-ops on
every Intel XPU run.

ProcessGroupXCCL already exposes the public Backend.set_timeout
method; the only gap is the Python dispatch. This PR adds an xpu
branch that mirrors the existing cuda branch and routes xccl PGs
through backend.set_timeout(timeout). (XCCL doesn't expose
_set_default_timeout the way ProcessGroupNCCL does, so it can't
share the existing backends set, which is drained via
_set_default_timeout at the end of the function.)

After this patch, calling _set_pg_timeout on an xccl PG:

  • does not emit the "only supported for nccl or gloo" warning;
  • routes through ProcessGroupXCCL.set_timeout(timeout);
  • updates backend.options._timeout (the same field
    test_gloo_set_pg_timeout_api
    asserts on for gloo).

Diff

@@ inside _set_pg_timeout, after the cuda branch @@
+    # XCCL exposes the public Backend API method ``set_timeout`` rather
+    # than the private ``_set_default_timeout`` alias NCCL uses, so it
+    # cannot share the ``backends`` set above (which is drained via
+    # ``_set_default_timeout``). Route xpu PGs through ``set_timeout``
+    # directly.
+    xccl_backends: set[Backend] = set()
+    if torch.device("xpu") in devices and is_xccl_available():
+        backend = group._get_backend(torch.device("xpu"))
+        if isinstance(backend, ProcessGroupXCCL):
+            xccl_backends.add(backend)
-    if len(backends) == 0:
+    if len(backends) == 0 and len(xccl_backends) == 0:
         warnings.warn(
             "Set timeout is now only supported for either nccl or gloo.", stacklevel=2
         )
     for backend in backends:
         backend._set_default_timeout(timeout)
+    for backend in xccl_backends:
+        backend.set_timeout(timeout)

Test plan

Adds test/distributed/test_c10d_xccl.py::ProcessGroupXCCLTest::test_xccl_set_pg_timeout_api,
modeled on the existing test_gloo_set_pg_timeout_api. The new test:

  1. Initialises a single-rank xccl PG with timeout=timedelta(seconds=50).
  2. Asserts backend.options._timeout == timedelta(seconds=50).
  3. Calls c10d.distributed_c10d._set_pg_timeout(timedelta(milliseconds=1), pg)
    inside warnings.catch_warnings(record=True).
  4. Asserts no "Set timeout is now only supported..." warning fired.
  5. Asserts backend.options._timeout == timedelta(milliseconds=1).

The test gates on @requires_accelerator_dist_backend(["xccl"]) and
skips when XPU is not available, matching the convention used by
other xccl tests under test/distributed/.

Empirical verification (out-of-tree)

Verified on 12 ranks of an Intel XPU (Sunspot, 1 node × 12 tiles) with
torch 2.13.0.dev from the same distributed_c10d.py, patched and
unpatched:

State Warning fires ProcessGroupXCCL.set_timeout called options._timeout after
Unpatched yes no unchanged
Patched no yes (recorded via monkey-patched class-method spy) updated to new value

Side observation: xccl's C++ set_timeout does propagate the
value into options._timeout. Whether that timeout is then
enforced by a watchdog (and ccl_abort-equivalent fires when
collectives exceed the deadline) is a separate question and is out
of scope for this PR
. This PR only fixes the Python dispatch gap so
the value actually reaches the backend; an enforcement PR — which
needs to land changes in ProcessGroupXCCL.{hpp,cpp} and likely a
watchdog thread analogous to NCCL's — would follow.

Risk

Minimal. Behavior for cpu / cuda / torchcomms users is unchanged. For
xccl users, the previous behavior was a no-op + warning; the new
behavior calls backend.set_timeout and suppresses the warning. The
only failure mode is if ProcessGroupXCCL.set_timeout itself raises —
in which case the user would have been getting the warning today and
the timeout would have been silently ignored, so this surfaces an
otherwise-hidden error.

Related

This is a prerequisite for proper per-collective timeout handling on
Intel XPU. Downstream context (a hung MoE training run that consumed
its full PBS walltime instead of aborting at the configured 100s
deadline, because _set_pg_timeout had silently no-op'd) is described
in this writeup.
The downstream torchtitan workaround in
saforem2/torchtitan@22847fcb
walks each PG and calls ProcessGroupXCCL.set_timeout directly; this
PR makes that workaround unnecessary.

cc @gujinghui @fengyuan14 @jbschlosser

torch.distributed.distributed_c10d._set_pg_timeout had device-conditional
branches for cpu (gloo) and cuda (nccl/gloo/torchcomms) but no
torch.device("xpu") branch. On an xccl-backed process group, the loop
adds no backends, emits the warning "Set timeout is now only supported
for either nccl or gloo.", and _set_default_timeout is never called.
The per-PG timeout silently no-ops on every Intel XPU run.

ProcessGroupXCCL exposes the public Backend API method set_timeout
(rather than the private _set_default_timeout alias NCCL uses), so it
cannot share the existing `backends` set, which is drained via
_set_default_timeout. This change adds an xpu/xccl-aware branch that
mirrors the cuda branch and dispatches to backend.set_timeout(timeout)
directly.

Adds test/distributed/test_c10d_xccl.py with
test_xccl_set_pg_timeout_api, modeled on the existing
test_gloo_set_pg_timeout_api. It verifies that calling
_set_pg_timeout on an xccl PG:
- does NOT emit the "only supported for nccl or gloo" warning;
- updates backend.options._timeout to the new value.

Whether xccl's C++ runtime then *enforces* the new timeout via a
watchdog + abort is out of scope for this PR (the value reaches the
backend; enforcement is a separate fix in ProcessGroupXCCL.{hpp,cpp}).
Copilot AI review requested due to automatic review settings May 21, 2026 17:41
@pytorch-bot pytorch-bot Bot added ciflow/torchtitan Run TorchTitan integration tests release notes: distributed (c10d) release notes category labels May 21, 2026
@pytorch-bot

pytorch-bot Bot commented May 21, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/184767

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@linux-foundation-easycla

linux-foundation-easycla Bot commented May 21, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: saforem2 / name: Sam Foreman (37af153)

@pytorch-bot

pytorch-bot Bot commented May 21, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/torchtitan

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates distributed process-group timeout handling to support the XCCL backend on XPU devices, and adds a regression test to ensure the timeout is propagated without emitting the “unsupported” warning.

Changes:

  • Add XCCL/XPU handling to _set_pg_timeout by calling ProcessGroupXCCL.set_timeout(...).
  • Update the “no supported backend found” condition to account for XCCL backends.
  • Add a new distributed test validating _set_pg_timeout behavior for XCCL.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
torch/distributed/distributed_c10d.py Routes XCCL/XPU process groups through set_timeout and avoids the unsupported-backend warning for XCCL.
test/distributed/test_c10d_xccl.py Adds a regression test ensuring _set_pg_timeout reaches ProcessGroupXCCL.set_timeout and emits no unsupported warning.

Comment thread torch/distributed/distributed_c10d.py Resolved
Comment thread torch/distributed/distributed_c10d.py Resolved
Comment thread torch/distributed/distributed_c10d.py Resolved
Comment thread test/distributed/test_c10d_xccl.py Resolved
Comment thread test/distributed/test_c10d_xccl.py Resolved
Comment thread torch/distributed/distributed_c10d.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37af153700

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread test/distributed/test_c10d_xccl.py Resolved
Per copilot + codex review on pytorch#184767:

- xccl_backends: set[Backend] -> xccl_backend: ProcessGroupXCCL | None
  Backend in this module is the str-backed backend-name wrapper, not
  a ProcessGroup, so set[Backend] was a type error. Also: an xpu PG
  resolves to exactly one xccl backend, so a single optional binding
  is cleaner than a set + for-loop.
- Updated the "Set timeout is now only supported..." warning to
  include xccl; the previous text was outdated once xccl was routed.
- Test now uses torch.testing._internal.common_utils.find_free_port
  + the @retry_on_connect_failures decorator instead of a bespoke
  bind-and-release helper. Removes the documented race between
  closing the probe socket and init_process_group binding the port.

Verified locally (Sunspot, 1N, torch 2.13.0.dev xpu, alloc 12467231)
that the simplified single-binding form still passes the same
contract: warning suppressed, ProcessGroupXCCL.set_timeout reached,
backend.options._timeout updates.
@saforem2

Copy link
Copy Markdown
Author

All 7 inline review threads from copilot and codex are addressed and resolved as of 8ceedc7:

  • xccl_backends: set[Backend] → xccl_backend: ProcessGroupXCCL | None (the original Backend annotation was wrong — Backend is the str-backed backend-name wrapper, not a ProcessGroup)
  • collapsed to a single optional binding (XPU resolves to exactly one xccl backend, unlike the cuda block's genuinely multi-element set)
  • updated the "Set timeout is now only supported..." warning to read "nccl, gloo, and xccl" (was outdated post-patch)
  • swapped the bespoke _free_port for torch.testing._internal.common_utils.find_free_port + @retry_on_connect_failures to handle the documented bind-release race

Locally re-verified against the in-repo .venv torch 2.13 on Sunspot (1 XPU node, 12 ranks): warning suppressed, ProcessGroupXCCL.set_timeout is reached, backend.options._timeout updates from the init value to the new value.

Could I get a review from a c10d maintainer? Tagging @kwen2501 as CODEOWNER for torch/csrc/distributed/c10d/Backend.*, and @guangyey + @frost-intel for xccl-side eyes (you both shipped #184331 / #181646 recently).

@frost-intel

Copy link
Copy Markdown
Collaborator

@saforem2 There's a draft PR #183625 to take care of this case. We're also adding test_c10d_xccl.py although we might break some of that into pieces.

saforem2 added a commit to saforem2/torchtitan that referenced this pull request May 22, 2026
Adds docs/summaries/2026-05-08_to_2026-05-22.md (51 commits over
~2 weeks, organized by theme):

- Upstream PyTorch PR for xccl _set_pg_timeout dispatch
  (pytorch/pytorch#184767, under review)
- 4 upstream torchtitan syncs (34th–37th), two with non-trivial
  replays (PR pytorch#3159 Full DTensor signature change, PR pytorch#3386 MoE
  refactor)
- 80B bad-node failover wrapper for production training; the
  e216a25 silent-hang detection fix closes the 8479579 incident
  class where the wrapper saw shell exit 0 while the inner trainer
  had died
- agpt_{2b,20b,80b}_real configs with cos_sin RoPE for v1 lm-eval
  alignment
- Sunspot 2N smoke campaigns post-resync
- MoE EP=2 step-41 hang investigation (reclassified transient on
  retry; surfaced the xccl-timeout-never-fires gap that kicked off
  the upstream PR thread)
- TPC26 MAPE talk prep (outline + §9 engineer-hours data)
- Docs hygiene (TREE.md, Date columns on production tables,
  unstaled "Last updated" markers, lychee link fixes)

Adds the corresponding row to docs/summaries/README.md and a journal
entry for today summarizing the PR filing + this writeup.
@saforem2

Copy link
Copy Markdown
Author

oh wow, even better then! thanks

@saforem2 saforem2 closed this May 22, 2026
saforem2 added a commit to saforem2/torchtitan that referenced this pull request May 29, 2026
~80 commits across 8 days. Organized by 7 themes:

- 2 upstream PRs filed: pytorch/pytorch#184767 (xccl _set_pg_timeout
  dispatch, closed in deference to #183625) and pytorch#3436
  (histc -> bincount/scatter, open and likely superseded by draft
  pytorch#3450).
- 5 upstream syncs absorbed (39th-42nd plus a 41st-sync catch-up the
  42nd-sync smoke surfaced). Lesson logged: always smoke moe_2b_ep
  after a sync that touches GroupedExperts.
- Production v2 training: 20B 512N HSn 0.579 -> 0.635 in 1100 steps;
  2B 256N + 512N stepping through 28K-54K with the keep_latest_k=10
  ckpt-purge root cause closed.
- Failover wrapper hardening: ANSI exit-code parsing fix, silent-hang
  watchdog via --timeout, preflight smoke + env overrides, fixture-
  based test harness.
- Scaling sweep infrastructure: 2B {4..4096}N sweep, walltime right-
  sized, venv pinned to project .venv.
- Chart/plotting hardening across 6+ scripts (palette consistency,
  ambivalent style fixes, dual SVG+PNG output).
- Docs hygiene: production READMEs refreshed across 4 stale pages,
  TREE.md unstaled.

Includes the corresponding row in docs/summaries/README.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/torchtitan Run TorchTitan integration tests open source release notes: distributed (c10d) release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants