Skip to content

[diffusion] perf: move MiniMax-H3's pipelined Ulysses copies off the SMs - #43361

Merged
mickqian merged 7 commits into
mainfrom
mick/diffusion-h3-ce-copies-off-sm
Oct 10, 2026
Merged

mickqian merged 7 commits into
mainfrom
mick/diffusion-h3-ce-copies-off-sm

Conversation

@mickqian

@mickqian mickqian commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #43164 (merged). The branch carries #43164's original commits and a merge of main, so against main the diff is only this change.

Motivation

After #43164 (and #43327 / #43337), a profile of MiniMax-H3's pipelined Ulysses attention shows almost no exposed exchange left: 0.09–0.24 ms per layer. What remains on the SMs is the exchange's own data movement. Per head group and destination, two PyTorch strided copies run:

  • v into the exchange block, from the fill;
  • this rank's and each peer's rows into the merged output.

That is 28 elementwise copy kernels per layer at Ulysses 2 and 56 at Ulysses 4. Measured alone they move 0.8–1.4 TB/s (read plus write), and inside the pipeline they compete with FlashAttention, which wants every SM. Their SM time per layer, from isolated timings at the real shapes:

Case (rows per rank) merge copy v copy per layer share of the layer
Ref2VA, Ulysses 2 (24826) 35.7 µs 37.6 µs 14 × 73 µs = 1.03 ms 1.2%
T2VA, Ulysses 2 (18871) 28.6 µs 30.2 µs 14 × 59 µs = 0.82 ms 1.5%
T2VA, Ulysses 4 (9436) 12.2 µs 12.6 µs 28 × 25 µs = 0.69 ms 2.4%

Modifications

Every copy of the exchange now runs on the copy engine, as a pitched cuMemcpy2DAsync issued next to the stream memory operations it already uses. Nothing moves on the SMs, and the result stays bit-identical: it is pure data movement, and attention sees the same values.

  • Receive slots are split by part: [2, groups, 3, world, chunk]. Group g's q, k and v from every rank are each one contiguous [S, group_heads, head_dim] tensor, and attention reads them directly.
  • v moves straight from the projection output into every destination's receive slot, this rank's own included. It no longer passes through the send buffer.
  • q/k:
    • With a fill (H3's QK-norm), the fill writes q and k into the send buffer, and one 2-row copy takes both to the peer.
    • Without a fill, q, k and v all move straight from their sources, and the pack kernel is gone.
  • The merge: this rank's rows and each peer's rows land in their output block with a pitched copy on the group stream.
  • fill(head_start, head_count, q_dst, k_dst) now writes only q and k.
  • Memory: the send buffer holds q/k only, so the buffers are 10 × (rows per rank) × heads × head_dim instead of 11 ×, which is 3.6 GB for Ref2VA at Ulysses 2. The cookbook note says so.

Accuracy Tests

  • test_ipc_a2a_multi_gpu.py passes at 2 and 4 ranks. It compares against the sequential exchange byte for byte, with and without a fill, including the automatic group count and the head count that must decline.
  • End to end on 4×H200, the MP4 md5 is unchanged in all twelve runs: T2VA at Ulysses 2 and 4, and Ref2VA at Ulysses 2.

Speed Tests and Profiling

Client end-to-end latency, 4×H200, 50 steps, default quality. These runs sit on top of #43164, #43327 and #43337. The arms ran ABBA on one box (without, with, with, without):

Case without with e2e denoise stage
T2VA 5 s, 4 GPUs, Ulysses 4 71.66 / 71.69 s 70.88 / 70.95 s −1.06% 69.88 → 69.09 s (−1.13%)
T2VA 5 s, 2 GPUs, Ulysses 2 140.40 / 140.38 s 139.91 / 139.87 s −0.36% 136.63 → 135.82 s (−0.59%)
Ref2VA 5 s, 2 GPUs, Ulysses 2 218.50 / 218.74 s 217.82 / 218.00 s −0.32% 212.27 → 211.07 s (−0.57%)

The gain is largest at Ulysses 4, which ran 56 copy kernels per layer against 28 at Ulysses 2. It is below the SM time the copies held, because part of that time overlapped attention tails anyway, and the H200s sit at their 700 W cap, so part of the freed time comes back as a lower clock.

Checklist

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ✅ Run #37946366275
Latest PR Test (Extra): ❌ Run #37946365882
Latest PR Test (AMD ROCm 10): ❌ Run #37946366140

mickqian and others added 6 commits October 9, 2026 00:36
…ntion over the copy engine

MiniMax-H3's Ulysses exchange around dense attention runs on SMs (an NCCL
send/recv for q/k/v, SM copies back), between kernels that keep every SM
busy. This adds an opt-in copy-engine transport for same-host Ulysses groups
of any size and uses it to pipeline the exchange against attention over head
groups: group g's q/k/v copies run on the copy engine while group g-1
attends, each group attends on its own stream and sends its output from
there, and stream memory operations order copies and kernels without holding
an SM.

- SGLANG_DIFFUSION_ULYSSES_PIPELINE_GROUPS=<G> pipelines MiniMax-H3's dense
  FA attention; G must divide the heads per rank.
- SGLANG_DIFFUSION_IPC_A2A_MULTI=1 also routes the plain Ulysses
  all-to-all through the copy engine.
- Falls back to the sequential exchange when a rank lacks peer access or
  stream memory operations (agreed across the group), during graph capture,
  under torch.compile, and for other attention backends.

The result is bit-identical to the sequential exchange; a 2- and 4-rank test
checks it byte for byte.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mickqian
mickqian requested a review from ping1jing2 as a code owner October 9, 2026 10:59
@mickqian mickqian added run-ci CI: run the baseline test suite on this PR diffusion SGLang Diffusion labels Oct 9, 2026
@mickqian mickqian added the run-ci CI: run the baseline test suite on this PR label Oct 9, 2026
@mickqian mickqian added the diffusion SGLang Diffusion label Oct 9, 2026
@mintlify

mintlify Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
sglang-doc 🟢 Ready View Preview Oct 9, 2026, 2:47 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

…copies-off-sm

# Conflicts:
#	docs/cookbook/diffusion/MiniMax/MiniMax-H3.mdx
#	python/sglang/multimodal_gen/runtime/distributed/device_communicators/ipc_a2a_multi.py
#	python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py
#	python/sglang/multimodal_gen/test/single_test_file/test_ipc_a2a_multi_gpu.py
@mickqian
mickqian merged commit bd7c797 into main Oct 10, 2026
135 of 150 checks passed
@mickqian
mickqian deleted the mick/diffusion-h3-ce-copies-off-sm branch October 10, 2026 00:58

This branch was successfully deployed

1 active deployment
staging - docs — 2764535e Deployed Oct 9, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion documentation Improvements or additions to documentation run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant