Skip to content

[Fix] [AMD] distributed: Fix custom AR capture for DSA DP dual graphs - #36088

Merged
kevin-mii merged 11 commits into
sgl-project:mainfrom
tanth47:codex/fix-amd-dsa-dense-dp-graph
Nov 19, 2026
Merged

kevin-mii merged 11 commits into
sgl-project:mainfrom
tanth47:codex/fix-amd-dsa-dense-dp-graph

Conversation

@tanth47

@tanth47 tanth47 commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Fixes #36071.

On ROCm, DSA with DP attention allows different DP lanes to replay different
decode graphs concurrently. Custom all-reduce direct graph-input registration
assumes something stronger: every rank in the communicator replays the same
captured graph and custom-AR call ordinal in lockstep.

During capture, each custom-AR call embeds a RankData slot. Registration then
fills that slot with peer pointers belonging to the same captured-call ordinal.
At replay there is no runtime graph-id handshake. If TP2 lane pairs select
different graphs, each pair reads graph-local buffers that are inactive on the
other ranks. The resulting all-reduce is incomplete and can turn GLM-5.2 logits
into NaN, followed by repeated token ID 0.

This supersedes the earlier shared-memory-pool address-collision hypothesis.
Instrumentation found no pointer-registration ordering, IPC-handle, offset, or
capture-to-registration drift.

Modifications

  • Use the communicator's stable pre-registered copy-in buffer during graph
    capture when DSA DP attention is enabled.
  • Apply the policy to both AITER and legacy SGLang custom all-reduce.
  • Preserve direct graph-input registration for non-DP DSA and other attention
    backends.
  • Add unit coverage for the graph-capture policy.

This retains custom-AR itself. Only its graph input staging changes.

Minimal causal proof

Hardware: 8 x AMD MI350X, ROCm 7.2.4, AITER
c16d44b93a528b2a4bfd6d8d3409116d465872a9.

A standalone distributed reproducer captures four same-shape BF16 graphs. Each
graph contributes a distinct constant, making stale peer-buffer selection
numerically observable.

Input registration Replay pattern Failed rank-results Result
direct all eight ranks replay the same graph 0/32 exact
direct DP4/TP2 skew: rank pairs replay g0/g1/g2/g3 8/8 incorrect
copy-in the same DP4/TP2 skew 0/8 exact

The expected skewed global sum is BF16 2080 on every rank. Direct mode
returns 206, 414, 624, and 832 for the four rank pairs. These are
exactly the contributions from each active TP2 pair, proving that the other
graphs' peer buffers were not supplying the current inputs. Copy-in returns
2080 on all eight ranks.

A stronger release/acquire system-scope barrier did not help (8/8 full-model
requests still corrupt), excluding a simple memory-visibility issue.

Full-model accuracy tests

Model/configuration: GLM-5.2-MXFP4, BF16 KV, TP8/DP4/EP8 with DP attention,
TileLang DSA prefill/decode, full decode graphs.

Graph collective Result
AITER custom AR, direct registration 4/4 hard corrupt
SGLang custom AR, direct registration 4/4 hard corrupt
Plain NCCL 0/4 hard corrupt
AITER custom AR, copy-in 0/4 hard corrupt

Extended copy-in soak:

  • no MTP: sequential 32/32 clean; concurrent c8 x 4 OSL64 32/32 clean;
  • AITER prefill + TileLang decode + MTP + overlap: sequential 32/32 clean;
    concurrent c8 x 4 OSL64 32/32 clean;
  • six policy/dispatch unit tests pass in the ROCm image.

Performance

Three matching rounds with AITER prefill + MTP, c4, 4,096 cached + 1,024
fresh, OSL512:

Capture input path Mean TPOT Mean token/s/user
direct registration 11.753 ms 85.14
copy-in 11.889 ms 84.80

Observed throughput delta: -0.40%, within run-to-run variance from MTP
acceptance length.

Design scope

The patch is the smallest safe production fix. A zero-copy replacement would
require a new runtime protocol that advertises each rank's active graph slot,
or allocator integration that makes every graph produce directly into one
stable registered address. Static same-ordinal peer registration cannot safely
support independently selected graphs.

Checklist

  • Format code according to project style.
  • Add unit tests.
  • Provide accuracy and speed benchmark results.
  • Follow the SGLang code style guidance.

CI States

Latest PR Test (Base): ✅ Run #43779232638
Latest PR Test (Extra): ❌ Run #43779232598
Latest PR Test (AMD ROCm 10): ❌ Run #43779232614

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@tanth47

tanth47 commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor Author

@HaiShaw, could you take a look? Thanks!

@hubertlu-tw
hubertlu-tw self-requested a review August 27, 2026 17:25
@hubertlu-tw hubertlu-tw added amd run-ci CI: run the baseline test suite on this PR labels Aug 27, 2026
@hubertlu-tw

Copy link
Copy Markdown
Collaborator

This PR adds enable_register_for_capturing to the shared CustomAllreduce constructor and uses that flag in the capture path, so CUDA/MUSA files are in the diff. Behavior there is unchanged: CUDA/MUSA still return the class from dispatch_custom_allreduce without this policy, so the flag stays at its default (True unless memory-saver CUDA graph is on, which already used copy-in).

The new copy-in path is HIP-only and only when DP attention is on and the decode attention backend is dsa. DSA without DP attention, DP attention without DSA, and every other backend keep direct graph-input registration.

@hubertlu-tw

Copy link
Copy Markdown
Collaborator

@tanth47 ValueError: /sglang-checkout/test/registered/unit/distributed/test_custom_all_reduce_graph_capture_policy.py: missing if __name__ == "__main__": entry. Pytest-style tests in this file will silently skip under python3 file.py -f. Add unittest.main() (for unittest.TestCase) or sys.exit(pytest.main([__file__, "-v"])) (for pytest-style).
Could you please fix it? Thanks.

@github-actions

This comment has been minimized.

@tanth47 tanth47 changed the title [AMD] Fix custom AR capture for DSA DP dual graphs [Fix] [AMD] distributed: Fix custom AR capture for DSA DP dual graphs Oct 17, 2026
Adapt the capture policy to the current attn_dp_enabled parallel field. Use strict test doubles so removed configuration fields cannot silently pass the policy tests.
@tanth47

tanth47 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@hubertlu-tw @HaiShaw Merged current main into the branch; the diff is unchanged (custom_all_reduce.py + the policy test), and the __main__ entry you asked for is in. test_custom_all_reduce_graph_capture_policy.py: 6 passed on the merged tree. Could you take another look when you have a moment? Thanks!

@kevin-mii

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

kevin-mii and others added 2 commits November 15, 2026 16:15
… reduce-scatter

The DSA + DP-attention copy-in policy covered custom all-reduce only. The
AITER all-gather and reduce-scatter on the same TP group still registered
graph inputs during capture, so DP lanes replaying different decode graphs
read the other graph's peer buffers.

- parallel_state: all-gather and reduce-scatter capture now follow the
  communicator's enable_register_for_capturing (plus the existing
  memory-saver and SGLANG_AITER_CAPTURE_COPY_IN switches).
- custom_all_reduce: treat the deprecated "nsa" alias like "dsa"; keep
  direct registration when the exec config is not published instead of
  raising (which disabled custom AR for the group); log the copy-in
  decision once in the policy.
- Tests: nsa alias, unpublished config, and the all-gather/reduce-scatter
  capture helper.

Verified on 4x MI355X through GroupCoordinator (TP4, DP2 attention,
1 MiB per rank) with two captured graphs replayed by different DP lanes
(ranks 0-1 graph A, ranks 2-3 graph B), expecting AR=10, AG chunk r=r+1,
RS=10:
- Before, --attention-backend dsa: AR=10, AG other-lane chunks=0, RS=3/7.
- Before, --attention-backend nsa: AR=3/7, AG other-lane chunks=0, RS=3/7.
- This commit, dsa and nsa: AR=10, AG=[1,2,3,4], RS=10.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Registers a 4-GPU AMD test (stage-c-test-4-gpu-amd) that publishes DSA
with DP attention, captures two graphs through the TP GroupCoordinator,
and replays a different graph on each DP lane. All-reduce, all-gather
and reduce-scatter must still return full results.

On 4x MI355X the test fails on b14368b (all-gather and reduce-scatter
read the other lane's stale buffers) and passes on this branch.

Also notes the copy-in capture choice in the dispatch_custom_allreduce
docstring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kevin-mii

Copy link
Copy Markdown
Collaborator

Thanks @tanth47, great root-cause work. I pushed a fix on top (01509f1), so please pull before you push again:

AITER all-gather and reduce-scatter now follow the same copy-in choice as all-reduce. They were still registering graph inputs directly, and on 4x MI355X they returned wrong results when DP lanes replayed different graphs.
--attention-backend nsa is now treated like dsa.
The check no longer raises if the config isn’t published yet.

To finish this up:

Re-run the GLM-5.2 TP8/DP4 corruption check and TPOT on the new head. All-gather and reduce-scatter now copy too, so the −0.40% needs updating.
Add a sentence to the description on why you chose copy-in over having all DP lanes pick the same variant.

kevin-mii and others added 2 commits November 16, 2026 00:06
Keep the PR's test footprint to the existing CPU policy tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@kevin-mii kevin-mii left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[kevin-mii Review Agent] LGTM.

@kevin-mii
kevin-mii merged commit 1f2d76c into sgl-project:main Nov 19, 2026
166 of 176 checks passed
llying-001 added a commit to llying-001/sglang that referenced this pull request Dec 2, 2026
…A DP attention on HIP

On HIP every DSA DP-attention rank now replays the same decode variant (the
MLP-sync bound) and one target-verify graph, so the copy-in that sgl-project#36088 forced
for DSA + DP attention is no longer needed for correctness there. Keep copy-in
when the scheduler skips its all-gather (SGLANG_SCHEDULER_SKIP_ALL_GATHER), where
ranks still select variants independently, and on CUDA, where kernel-plugin
graph variants select from each rank's own lengths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][AMD] Custom AR graph registration corrupts DSA DP-attention graph-skew replay

3 participants