Skip to content

perf(ep/v2): AsyncLL segmented receive layout for single-node SDMA - #918

Merged
jhchouuu merged 5 commits into
ROCm:mainfrom
ChengYM5685:perf/asyncll-zero-copy
Nov 13, 2026
Merged

jhchouuu merged 5 commits into
ROCm:mainfrom
ChengYM5685:perf/asyncll-zero-copy

Conversation

@ChengYM5685

@ChengYM5685 ChengYM5685 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

AsyncLL moves tokens with SDMA, which copies contiguous ranges only, so two compute-stream copy passes exist purely to change layout: dispatch's RecvCopy compacts the per-source landing slices into one dense prefix, and combine's SendCopy scatters the expert output back into per-destination staging. On DeepSeek-V4-Pro EP8 prefill (single-stream TBO, mxfp8 dispatch) the two cost about 25 ms per forward on the busiest rank (rank 0, 122 calls per forward).

This PR adds a segmented receive layout that removes both: the expert reads the landing segments in place and writes its output in the same layout, which combine sends as is. The dispatch-side gather into staging and both SDMA legs are unchanged; what changes is the receive layout the consumer sees.

Depends on #906: the first commit here (da9c47a) is #906's, which this builds on; review the commits after it (the layout and its review follow-ups). Once #906 lands, this rebases onto it.

Technical Details

API (all on EpDispatchCombineConfig / EpDispatchCombineOp):

async_ll_recv_layout "compact" (default), "segmented" (refused on an unsupported config) or "auto" (resolved from the config before the arena is allocated, so every rank agrees). Supported on one node over SDMA without the fused receive.
dispatch(..., segment_stride=S) runs a segmented round on a "segmented" op; without it the same op runs a compact round (e.g. under CUDA graphs)
segment_counts() device int64[world_size]: n_s of the last segmented round
segment_error_counts() / segment_error_flags(clear=) overflow / mismatch counters since the op was built or last reset(), and the bits since the last clear

Consumer contract (documented on async_ll_recv_layout):

  • The recv views have world_size * S rows. Valid rows are [s*S, s*S + n_s) per source, not a prefix. The rest (holes) carry the next rank's first expert id with weight 0 and zeroed scales, so a local expert_mask drops them; their hidden bytes are stale.
  • total_recv reads world_size * S in a segmented round, the row count, so it is the right num_local_tokens for aiter fused_moe; do not truncate the views below it.
  • The expert output goes into combine_in_view() (also world_size * S rows); combine copies any other tensor there first.
  • S is the same on every rank, at least every rank's token count, at most effective_max_recv_per_rank. Compute it from values every rank shares (e.g. the max token count after the DP all-gather). A stride past the cap is refused on the host before launch, which is safe only when every rank refuses it; a rank that alone passes one leaves the others waiting.
  • The error flags differ between ranks (below), so reduce them across ranks (e.g. an all-reduce max) before acting on them, such as falling back to compact.
out, w, s, idx, total, routing = op.dispatch(x, w, s, idx, return_routing=True,
                                              segment_stride=S)
y = fused_moe(out, w1, w2, w, idx, expert_mask, num_local_tokens=total,
              output=op.combine_in_view(), ...)
op.combine(y, routing=routing)

Kernels. SendCopySeg writes per-field staging (own rows straight into the landing segment); SendTransferSeg posts one SDMA copy per field plus the mode word and, with early notify, the count, in one reservation; RecvFinalizeSeg replaces RecvCopy (invalidates holes, records n_s, checks mode words); CombineSendTransferSeg sends each source's segment straight from the expert output; CombineRecvCopySeg reads replies at [d*S + slot].

Mode and stride agreement. Segmented vs compact, and S, must agree across ranks in a round. Every dispatch on a segmented-capable op, compact rounds included, sends each peer a mode word (round epoch, S) ahead of its count on the same SDMA queue, and every receive compares each peer's word with its own. A disagreement (e.g. one rank in a CUDA-graph compact round while the others prefill segmented) is counted as a mismatch on every rank. A stride below a rank's rows for a peer drops the rest and is counted as an overflow on that rank only; its peers see a short segment and count nothing. The epoch comes from crossDeviceBarrierFlag, so a word left over from an earlier round cannot match. Counters only ever increase on the device and the host keeps its own baseline, so reading never loses a concurrent update.

Cost on ops without the layout: none. The only new kernel argument is segStride (0 on those ops, which keep their pass sequences, regions and arguments). Segmented-capable ops add 2*world_size+3 words to send_count and one 8-byte SDMA put per peer per compact round.

Performance

Where it pays and where it does not. Holes are a large share of the world_size * S rows: n_s counts only the tokens with an expert on this rank, about 45% holes at EP8 top-6 with uniform routing. aiter's sort, EP zero-fill and scale sort scale with the row count, so part of the saving goes back into the MoE. Per-layer microbenchmark from review (slowest rank):

T=1024 T=4096 T=8192
bf16 1.86 -> 1.58 ms 4.82 -> 4.38 8.90 -> 8.34
a8w4 1.12 -> 1.10 2.95 -> 2.86 (noise) 6.02 -> 5.53

End to end, DeepSeek-V4-Pro on 8x MI355X, prefill EP8, single-stream TBO (4096 tokens per micro-batch), mxfp8 dispatch, a8w4 MoE. The compact baseline's MoE already runs at the receive bound (32768 rows), which the segmented rows do not exceed:

setup compact AsyncLL segmented delta
rank-0 profile, ms per forward (*) 790.1 766.8 -2.95% (copies -23.7 ms, MoE +-0)
prefill throughput, 1024 x 8k, 6 runs (*) 80,048 tok/s 82,580 tok/s +3.2%
single node A/B, 8k / 16k inputs +3.4% / +2.8%
1P1D AgentX c512, 1 h window, req/s, 3 rounds on the same nodes (prefill varied, decode fixed) 9.08 / 9.23 / 8.85 (mean 9.05) 9.53 / 8.87 / 9.38 (mean 9.26) +2.3% on the mean, within the ~3% run-to-run noise

(*) measured on the prototype of this layout, before it was folded into this PR's kernels; the other rows are this PR.

Follow-ups to close the hole cost, not in this PR: shrink S with a per-destination count exchange (S = max n_{s->d}), or hand the consumer the segments so it skips holes. sglang already enables the layout only for prefill and falls back to compact when the per-rank token counts are uneven.

Test Plan

  • test_asyncll.py (8x MI355X), the four CI legs: sdma early notification (gfx950 default), legacy (MORI_ASYNCLL_EARLY_NOTIFY=0), fused receive (segmented must be refused, "auto" -> compact), lsa (same). Segmented checks: every segment holds exactly its source's tokens field for field, holes invalidated (expert, weight, scales), total_recv == world_size*S, segment_counts() per source, through stride changes, shrinking counts under one stride, a compact round on the same op (must not count a mismatch), refused arguments, one rank using a different stride and one rank running the round compact (both counted on every rank, next round clean), and two segmented ops in the single-stream TBO order with no host sync.
  • New test_asyncll_aiter.py (8x MI355X, skips without aiter): each round runs compact and segmented on the same inputs through aiter fused_moe (num_local_tokens=total_recv, output in place in combine_in_view() and in a separate tensor), bf16 and fp8 block scale (per_128x128), uneven counts with an empty rank; both must match each other and an fp32 reference; error counters stay 0.
  • test_asyncll_options.py (no GPU): config values, pass sequences, region sizes.

Test Result

gfx950, EP8 (one node), ROCm 7.2.4, aiter 0.1.26 (with fused_moe(output=)), on this head (5ef8577, on main 338f5fe):

  • test_asyncll_options.py: OK
  • test_asyncll.py, the four CI legs, 0 failed checks each: sdma early notification PASS (segmented: "segmented" and "auto", including the mismatch-after-reset() case), legacy (MORI_ASYNCLL_EARLY_NOTIFY=0) PASS (same), fused receive PASS (segmented refused), lsa PASS (segmented refused)
  • test_asyncll_aiter.py: bf16 PASS, fp8 block scale PASS, 0 failed checks across 8 ranks

Negative check: f0a82b8 with this head's test_asyncll.py fails only the new reset() case (early and legacy, 16 failed checks = 8 ranks x 2 levels, segment error flags 0, want 2).

The same set also passed on f0a82b8 and, before the rebase, on 198ff64 (main bd2e243). gfx1250, EP4, before the rebase (2afc72d): test_asyncll_options.py OK; test_asyncll.py sdma early notification, legacy, fused receive and lsa PASS (test_asyncll_aiter.py not run there, no usable aiter build).

Submission Checklist

@jhchouuu jhchouuu 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.

Thanks for this. I reviewed both commits and ran zero copy end to end through aiter fused_moe.

Setup: 8x MI355X; EP8, hidden 7168, 384 experts top-6, T = 1024/4096/8192 tokens per rank; bf16, fp8 blockscale and a8w4 (MXFP8 dispatch, MXFP4 weights).

Commit 1 looks good. On the compact path, dispatch goes 0.556 → 0.475 ms (a8w4, T=4096); moe and combine are unchanged. The tests pass, also with MORI_ASYNCLL_EARLY_NOTIFY=1. It is independent of zero copy, so I'd land it as its own PR.

Zero copy works when the consumer is wired for it. Its output matches the compact path (bit-identical for bf16 and a8w4, within 0.9% for fp8 blockscale) when the call is fused_moe(num_local_tokens=<W*S tensor>, expert_mask=<binary>, output=combine_in_view()). Two problems:

  1. The consumer contract is undocumented, and today's integrations break silently.
    • Valid rows are [s*S, s*S+n_s), not a prefix, and total_recv (Σn_s) is not the row count.
    • sglang (num_local_tokens=total_recv, truncation to recv_cap) and ATOM both assume a prefix. Run that way, about 41% of the tokens are dropped with no error.
    • num_local_tokens=None is not safe either: it crashes aiter's 1-stage fp8 blockscale path (partial_transpose(num_rows=None)).
    • Please document the contract, add an end-to-end test through aiter, and consider returning the row count or per-source counts next to total_recv.
  2. A mode mismatch across ranks corrupts data, mostly silently.
    • With rank 0 compact and the others zero copy, every rank gets wrong tokens and no rank sets a flag. The compact receive never reads or clears the stride words, so the check compares against a stale stride.
    • This is reachable under DP attention: one rank in a CUDA-graph decode round while the others prefill.
    • Please either detect it, e.g. have the compact path on a zero-copy-capable op clear or post the stride word, or put an epoch in it; or require and document that the choice is global per round.

Gain is smaller than the copies removed. Per layer, slowest rank:

T=1024 T=4096 T=8192
bf16 1.86 → 1.58 ms 4.82 → 4.38 8.90 → 8.34
a8w4 1.12 → 1.10 2.95 → 2.86 (noise) 6.02 → 5.53
  • The holes are 45% of the W·S rows here: 1 − P(a token hits a rank), and about 68% at EP16 top-6.
  • aiter's sort, EP zero-fill and scale sort all scale with W·S, which cancels most of the a8w4 saving at T ≤ 4096.
  • Writing the expert output anywhere but combine_in_view() adds back 0.15–0.4 ms.
  • Ideas for closing the gap:
    • pass the segments to the consumer so it skips holes;
    • shrink S, e.g. by exchanging per-destination counts first and using max n_{s→d};
    • enable the mode by shape.

The name. "Zero copy" overstates it. Dispatch still gathers into staging on the CU, and both legs still use SDMA; what goes away is the receive compaction and the combine staging scatter. What the consumer has to handle is a different receive layout, so naming the option after the layout would make the contract visible at the call site. For example: async_ll_recv_layout="compact" | "segmented", segment_stride=S, segment_error_flags().

Smaller items

  • dispatch_combine_op.py:1307 (the seam note) no longer holds.
  • Holes keep stale hidden and scale bytes.
  • The S cap uses effective_max_recv_per_rank, but the regions are sized by max_num_inp_token_per_rank.
  • zero_copy_error_flags(clear=True) is read-then-zero, so a flag set in between is lost.
  • CI doesn't exercise the early-notify paths on gfx950.
  • The PR description is empty.

@ChengYM5685
ChengYM5685 force-pushed the perf/asyncll-zero-copy branch from 25e18d8 to fd718da Compare November 6, 2026 06:31
@ChengYM5685 ChengYM5685 changed the title Perf/asyncll zero copy perf(ep/v2): AsyncLL segmented receive layout (zero copy) for single-node SDMA Nov 6, 2026
@ChengYM5685
ChengYM5685 marked this pull request as ready for review November 10, 2026 07:50
@ChengYM5685

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review and the end-to-end numbers. Point by point, as of the current head:

  • Commit 1 is perf(ep/v2): AsyncLL slot assignment by block, receive copy over the whole grid #906 (identical diff). Please review it there; once perf(ep/v2): AsyncLL slot assignment by block, receive copy over the whole grid #906 lands I'll rebase this PR so only the segmented-layout commits remain.
  • Naming. The option is now async_ll_recv_layout="compact" | "segmented" | "auto", with dispatch(..., segment_stride=S), segment_counts(), segment_error_counts() and segment_error_flags().
  • Consumer contract. It is documented on EpDispatchCombineConfig.async_ll_recv_layout and in dispatch(). In a segmented round total_recv now reads world_size * S, the row count of the views, so num_local_tokens=total_recv is correct and truncating to recv_cap is a no-op (W*S <= recv_cap). Per-source counts are in segment_counts(). The layout is opt-in per call: an integration that does not pass segment_stride keeps the compact prefix layout unchanged.
  • End-to-end test. The new test_asyncll_aiter.py runs compact and segmented on the same inputs through aiter fused_moe (bf16, and fp8 per_128x128, the 1-stage path that cannot take num_local_tokens=None). It uses uneven counts with one empty rank and writes the output both into combine_in_view() and into a separate tensor. Both layouts must match each other and an fp32 reference, and the error counters must stay 0. It skips without aiter, and the CI image has none, so for now it is a manual test.
  • Mode/stride mismatch. Every dispatch on a segmented-capable op, compact rounds included, sends each peer a mode word (round epoch, S), and every receive compares each peer's word with its own. A disagreement is counted on every rank (segment_error_counts() / segment_error_flags()), and the epoch keeps a stale word from matching. The contract also requires the mode and S to be the same on every rank in a round. test_asyncll.py covers one rank running compact and one rank using a different S: both are counted on all ranks and the next round is clean. That round's data is still wrong; the counters detect the error, they do not recover from it.
  • Smaller items:
    • The seam note now covers segmented rounds: the views are the landing region, so reading them in the seam reads bytes the engines are still writing.
    • Holes get another rank's expert, weight 0 and zeroed scales. Their hidden bytes are left stale on purpose (25-50x the metadata), and the contract says not to reduce hidden states across rows.
    • S cap vs. region sizing: the field blocks are sized by max_num_inp_token_per_rank rows per source (the compact landing already needs that much), while the reverse map and combine_in_view() are sized by effective_max_recv_per_rank, which is at most that. So the receive cap is the binding bound. The host checks it on every rank, and the kernels clamp S to it as well. A stride below a rank's own token count is not refused on the host, because only that rank would raise and the others would wait forever; the sender drops the extra rows and counts an overflow instead.
    • Error flags: the device only adds to the counters and the host keeps its own baseline, so clear=True cannot lose a concurrent update.
    • Early notify on gfx950: early notification is the gfx950 default on main, so CI's default sdma leg runs it, with legacy (MORI_ASYNCLL_EARLY_NOTIFY=0) and fused receive as separate legs. The segmented checks run in the early and legacy legs, and segmented is refused in fused and lsa.
    • The description is filled in.
  • Performance. Agreed, the gain is below the copies removed; the description now carries your per-layer table and the hole share. Shrinking S with a per-destination count exchange, and handing the segments to the consumer so it skips holes, are follow-ups for a separate PR. Per-shape enabling is already up to the caller: a dispatch without segment_stride runs compact on the same op.

@jhchouuu jhchouuu closed this Nov 10, 2026
@jhchouuu jhchouuu reopened this Nov 10, 2026
@jhchouuu jhchouuu closed this Nov 10, 2026
@jhchouuu jhchouuu reopened this Nov 10, 2026
@jhchouuu

Copy link
Copy Markdown
Collaborator

Sorry for the close/reopen. It re-triggers CI on the current main, which runs only the tests this PR's changes need (#970) instead of the full suite. Nothing in the PR changed. CI now runs only the build and the EPv2 tests.

xiangch and others added 4 commits November 11, 2026 08:44
…whole grid

Two dispatch passes of the AsyncLL family were well short of what their
work needs. Measured at sglang's DeepSeek-V4 shape (EP8, hidden 7168,
top-6 of 384 experts, 4096 tokens/rank, fp8 dispatch with 224 B of e8m0
scales, sdma, early notification), mean of 8 ranks, 3 interleaved runs:

                       before    after
  dispatch slotassign  58.6 us   6.6 us
  dispatch recvcopy    65.4 us  53.9 us

SlotAssign claimed each entry's slot with its own atomicAdd on one of
worldSize counters: ~18k atomics on 8 addresses, for a pass that moves a
few hundred KB of routing. Warps now count their claims per destination
PE with a ballot and take a run inside the block through LDS; one thread
per PE then claims the block's run from the global counter, ~200 global
atomics in all. Which slot an entry gets was already atomic order, and
RecvCopy records each token's origin, so nothing downstream depends on it.

RecvCopy split its grid evenly across source PEs, so the PE that sent the
most set the kernel's length while the other groups idled. The whole grid
now walks the concatenated output and finds each row's source PE from
the prefix sum with one ballot. The payload copy keeps four 16 B loads in
flight per lane (the source is what SDMA just wrote, so it comes from
HBM), and the short metadata fields go a 4 B word per lane, with a byte
fallback for unaligned fields, instead of through WarpCopy's byte tail.

The other copy passes already run at 4.5-5 TB/s and are unchanged. Two
SendCopy variants were tried and dropped: reading each token once for all
its destinations (+19%) and a 4-deep copy (+25%).

test_asyncll passes on 8x MI355X for sdma (legacy, early, early + fused
receive) and lsa. The fp8 benchmark above also checks every received
row, index, weight and scale byte for byte against its source, and the
combined output against the expected sum.
… landing segments in place

AsyncLL moves tokens with SDMA, which copies contiguous ranges only. So the
send side gathers each destination's tokens into staging (SendCopy), every
source's rows land in their own slice of the receiver's inter_dispatch_inp,
and RecvCopy compacts those slices into the dispatch output; combine scatters
the expert output back into per-destination staging (SendCopy) before its
transfer. On DeepSeek-V4-Pro EP8 prefill (single-stream TBO, mxfp8 dispatch)
the dispatch RecvCopy and the combine SendCopy cost about 25 ms per forward
on the compute stream of the busiest rank.

The segmented layout removes both. The dispatch SendCopy and both SDMA legs
stay; what changes is the receive layout the consumer sees. A dispatch called
with segment_stride=S on an op built with async_ll_recv_layout="segmented"
lays inter_staging / inter_dispatch_inp out as one block per field (hidden,
indices, weights, scales, source token) and lands source s's rows at
[s*S, s*S + n_s), so the recv views are plain [world_size*S, ...] arrays the
expert reads in place:

- SendCopySeg writes the per-field staging (this rank's own rows straight into
  its landing segment); SendTransferSeg posts one SDMA copy per field, the
  mode word and, with early notify, the count in one reservation.
- RecvFinalizeSeg replaces RecvCopy: rows past n_s (holes) still hold an
  older round's data, so it points their experts at the next rank's first
  expert with weight 0 (the caller's expert mask drops them) and zeroes their
  scales; it records the n_s and checks every peer's mode word.
- The expert writes its output in the same layout into combine_in_view();
  CombineSendTransferSeg sends each source's segment from there and
  CombineRecvCopySeg reads the replies at [d*S + slot].

The consumer contract (documented on async_ll_recv_layout): every one of the
world_size*S rows is an input row and the holes are masked, so total_recv
reads world_size*S in a segmented round and is the bound to pass as e.g.
aiter fused_moe num_local_tokens; segment_counts() has the per-source n_s; the
expert output goes into combine_in_view() (any other tensor is copied there
first). Holes are typically a large share of the rows: n_s counts only the
tokens with an expert on this rank.

S is chosen per call by the caller: identical on every rank, at least every
rank's token count, at most effective_max_recv_per_rank. Calls without a
stride run the compact layout on the same op, so one op serves both (e.g.
compact under CUDA graphs). Whether a round is segmented, and S, must agree
on every rank. Every dispatch on a segmented-capable op, compact rounds
included, sends each peer a mode word (round epoch, stride) ahead of its
count, and every receive compares it with its own: a round where ranks
disagree is counted on every rank, as is a stride below a rank's rows (those
rows are dropped). segment_error_counts() reads the counters and
segment_error_flags(clear=) the bits since the last clear; the host never
writes the counters, so nothing set concurrently is lost.

async_ll_recv_layout is "compact" (default), "segmented" (refused when the op
is built on an unsupported config) or "auto" (resolved from the config before
the arena is allocated, so every rank agrees; op.cfg reads the outcome). The
segmented layout is supported on one node over SDMA without the fused
receive. The only new kernel argument is segStride (0 on ops without the
layout, so their pass sequences, regions and arguments are unchanged), and
send_count grows by 2*world_size+3 words on ops with it.
- A segment_stride below a rank's token count is no longer refused on the
  host: the error fired on that rank alone and left the others waiting in the
  receive. The send pass already drops the rows past the stride and counts an
  overflow; only the receive cap (the same on every rank) is still refused.
- The device clamps the stride to the per-source receive capacity, so
  arguments that bypass the host check stay inside the peers' field blocks.
- RecvFinalizeSeg treats a zero count as an empty segment instead of letting
  announced - 1 wrap to a full one.
- inter_dispatch_staging keeps its compact size (world_size x receive cap):
  the segmented expert output never exceeds it, and with max_total_recv_tokens
  the old override gave back the arena the cap saves.
- Refuse world_size > 64 up front instead of failing the JIT build.
- EpAsyncLLIsSegmented() replaces an enum-order comparison; per-lane field
  tables replace the ternary chains in SendTransferSeg; SEG_CAPABLE_BIT names
  the segStride flag on the host.
- Comments: the landing region's write-after-read ordering through combine,
  no cross-row reductions over the holes, a fixed S under CUDA graphs, what
  the error counters mean.
- Tests: an overflow round (stride below some rank's rows) completes on every
  rank and flags only the ranks that dropped rows; the staging size with and
  without a receive cap.
Same constraints, fewer lines: the overflow/mismatch details live on
segment_error_counts(), and which expert a hole points at is a kernel detail.
@ChengYM5685
ChengYM5685 force-pushed the perf/asyncll-zero-copy branch from 198ff64 to f0a82b8 Compare November 11, 2026 09:18

@jhchouuu jhchouuu 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.

Thanks for the thorough follow-up. I re-tested the current head (f0a82b8) on 8x MI355X in a ROCm 10 container with aiter 285579b62. Every point from the first round is addressed and holds up on the GPU. Three smaller things are left; details at the end.

What I ran

  • This PR's tests: test_asyncll_options.py, test_asyncll.py with early notification on and off, and test_asyncll_aiter.py (bf16 and fp8 block scale). All pass.

  • The integration call: fused_moe(num_local_tokens=total_recv, output=combine_in_view()) on a segmented round, compared with a compact round on a plain op (no layout option) on the same inputs.

    • bf16, fp8 block scale and a8w4 at T = 1024, 4096 and 8192 tokens per rank (fp8 block scale at 1024 and 4096). No row is off by more than 2%. a8w4 at 4096/8192 and bf16 at 8192 are bit-identical.
    • The fp8 block-scale differences match those between two compact rounds, so they come from aiter's own run-to-run variation.
    • total_recv reads W*S, the holes are about 44% of the rows, and the error flags stay 0.
    • Writing the expert output into a separate tensor is correct, and so is num_local_tokens=None (bf16 and a8w4).
  • Disagreement across ranks: one rank segmented and the others compact (and the reverse), and one rank with a different stride inside the cap. All 8 ranks flag a mismatch, and the next agreed round is clean. Same result with early notification on and off.

  • Two ops in TBO order: a compact op and a segmented op, d1 d2 c1 c2 with no host sync, for 500 rounds. No false mismatch, and the data is correct.

  • Cost of the mode word on compact rounds of a segmented-capable op: none measurable.

    • bf16 dispatch+combine under CUDA graphs, slowest rank, plain op vs segmented-capable op:

      tokens per rank 1 16 64 128 256
      plain op (µs) 79.8 101.4 109.9 144.0 182.6
      segmented-capable (µs) 75.0 103.8 115.3 137.4 186.0
    • a8w4 at 1024 and 4096 tokens: within 1.6%, in both directions, over two 60-iteration runs.

  • Gain per layer: median, slowest rank, plain compact op vs segmented with the output in combine_in_view(), interleaved in one run, ms:

    T=1024 T=4096 T=8192
    bf16 1.814 → 1.491 4.593 → 4.170 8.429 → 7.874
    a8w4 1.309 → 1.304 3.225 → 3.166 5.658 → 5.522

Remaining points

  1. reset() makes segment_error_flags() miss errors.
    • reset() zeroes the arena, including the error counters in send_count, but _seg_error_base keeps its old value.
    • After a reset, new errors are not flagged until the counters climb back past the old baseline.
    • Repro on 8 ranks: force a mismatch, call segment_error_flags(clear=True), call reset() on every rank, then force the same mismatch again. The second read returns 0 on all ranks, where it should return 2. On rank 0 the counter reached 7 again, exactly the old baseline.
    • The fix is to reset _seg_error_base in reset(). The docstring of segment_error_counts() ("since the op was built") would then say "since the op was built or last reset".
  2. An overflow is flagged only on the rank that dropped rows.
    • The description says a stride below a rank's rows "is counted on every rank". In the code and in the new test, only the sending rank counts it.
    • Measured: all ranks at S=64, rank 0 with more rows than that for its peers. Only rank 0 reports SEGMENT_ERR_OVERFLOW, and the others read 0.
    • That is fine as long as it is stated. A caller that decides to fall back to compact from its local flags would then diverge from the other ranks in the next round.
    • Please fix the description. Either say in the contract that the flags should be reduced across ranks before acting on them, or have the receiver count an overflow too.
  3. A stride above the receive cap on one rank only.
    • The host raises ValueError on that rank alone, and the other ranks enter the round and wait for it.
    • This is the same asymmetry that the follow-up commit removed for strides below the token count.
    • This only happens if S is not computed identically on every rank, which the contract already requires. Either handle it the same way (clamp on the device and count), or state next to the cap check that S must come from values every rank shares.

@jhchouuu

Copy link
Copy Markdown
Collaborator

cc @yangyuhuiling

- reset() zeroes the arena, segment error counters included, but kept the
  host baseline of segment_error_flags(), so errors after a reset stayed
  hidden until the counters climbed back past the old baseline. reset() now
  restarts the baseline too; segment_error_counts() counts since the op was
  built or last reset().
- An overflow is counted only on the rank that dropped rows, while a
  mismatch is counted on every rank. The contract and segment_error_counts()
  now say so, and that the flags must be reduced across ranks before acting
  on them, or the ranks diverge in the next round.
- A stride past the receive cap is refused on the host; when only one rank
  passes one, the others enter the round and wait. The contract and the cap
  check now say that S must come from values every rank shares (e.g. the max
  token count after the DP all-gather).
- Test: a mismatch right after reset() is flagged on every rank.
@github-actions

Copy link
Copy Markdown
Contributor

GPU CI for 5ef85778 (run): changed areas: epv2

lane runs jobs
mori no MI355X intranode, MI355X ROCm 7.14, MI355X JAX, MI355X internode
mi300x no MI300X intranode, MI300X internode
umbp no UMBP unit test
cco yes CCO unit test, CCO EPv2 single-node test, CCO internode
fused no CCO fused GEMM test
build yes MoRI build (compile check)

Test groups (the steps that run in those jobs): epv2.

Lanes follow the changed files. Adding ci:full re-runs CI with every lane, the full internode sweeps and every fused GEMM case; adding ci:mi300x re-runs it with the MI300X lanes added. /ci-rerun re-runs CI against the current main.

@ChengYM5685

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough follow-up. I re-tested the current head (f0a82b8) on 8x MI355X in a ROCm 10 container with aiter 285579b62. Every point from the first round is addressed and holds up on the GPU. Three smaller things are left; details at the end.

What I ran

  • This PR's tests: test_asyncll_options.py, test_asyncll.py with early notification on and off, and test_asyncll_aiter.py (bf16 and fp8 block scale). All pass.

  • The integration call: fused_moe(num_local_tokens=total_recv, output=combine_in_view()) on a segmented round, compared with a compact round on a plain op (no layout option) on the same inputs.

    • bf16, fp8 block scale and a8w4 at T = 1024, 4096 and 8192 tokens per rank (fp8 block scale at 1024 and 4096). No row is off by more than 2%. a8w4 at 4096/8192 and bf16 at 8192 are bit-identical.
    • The fp8 block-scale differences match those between two compact rounds, so they come from aiter's own run-to-run variation.
    • total_recv reads W*S, the holes are about 44% of the rows, and the error flags stay 0.
    • Writing the expert output into a separate tensor is correct, and so is num_local_tokens=None (bf16 and a8w4).
  • Disagreement across ranks: one rank segmented and the others compact (and the reverse), and one rank with a different stride inside the cap. All 8 ranks flag a mismatch, and the next agreed round is clean. Same result with early notification on and off.

  • Two ops in TBO order: a compact op and a segmented op, d1 d2 c1 c2 with no host sync, for 500 rounds. No false mismatch, and the data is correct.

  • Cost of the mode word on compact rounds of a segmented-capable op: none measurable.

    • bf16 dispatch+combine under CUDA graphs, slowest rank, plain op vs segmented-capable op:

      tokens per rank
      1
      16
      64
      128
      256

      plain op (µs)
      79.8
      101.4
      109.9
      144.0
      182.6

      segmented-capable (µs)
      75.0
      103.8
      115.3
      137.4
      186.0

    • a8w4 at 1024 and 4096 tokens: within 1.6%, in both directions, over two 60-iteration runs.

  • Gain per layer: median, slowest rank, plain compact op vs segmented with the output in combine_in_view(), interleaved in one run, ms:

    T=1024
    T=4096
    T=8192

    bf16
    1.814 → 1.491
    4.593 → 4.170
    8.429 → 7.874

    a8w4
    1.309 → 1.304
    3.225 → 3.166
    5.658 → 5.522

Remaining points

  1. reset() makes segment_error_flags() miss errors.

    • reset() zeroes the arena, including the error counters in send_count, but _seg_error_base keeps its old value.
    • After a reset, new errors are not flagged until the counters climb back past the old baseline.
    • Repro on 8 ranks: force a mismatch, call segment_error_flags(clear=True), call reset() on every rank, then force the same mismatch again. The second read returns 0 on all ranks, where it should return 2. On rank 0 the counter reached 7 again, exactly the old baseline.
    • The fix is to reset _seg_error_base in reset(). The docstring of segment_error_counts() ("since the op was built") would then say "since the op was built or last reset".
  2. An overflow is flagged only on the rank that dropped rows.

    • The description says a stride below a rank's rows "is counted on every rank". In the code and in the new test, only the sending rank counts it.
    • Measured: all ranks at S=64, rank 0 with more rows than that for its peers. Only rank 0 reports SEGMENT_ERR_OVERFLOW, and the others read 0.
    • That is fine as long as it is stated. A caller that decides to fall back to compact from its local flags would then diverge from the other ranks in the next round.
    • Please fix the description. Either say in the contract that the flags should be reduced across ranks before acting on them, or have the receiver count an overflow too.
  3. A stride above the receive cap on one rank only.

    • The host raises ValueError on that rank alone, and the other ranks enter the round and wait for it.
    • This is the same asymmetry that the follow-up commit removed for strides below the token count.
    • This only happens if S is not computed identically on every rank, which the contract already requires. Either handle it the same way (clamp on the device and count), or state next to the cap check that S must come from values every rank shares.

Thanks for the re-test and the extra measurements, especially the TBO-order and mixed-mode runs. All three points are addressed in 5ef8577:

  1. reset() and segment_error_flags(). reset() now restarts the host baseline (_seg_error_base) together with the arena zero, and segment_error_counts() counts "since the op was built or last reset()". test_asyncll.py reproduces your sequence on every rank: force a mismatch, clear the flags, reset(), force it again. Every rank must then report 2.
  2. Overflow vs mismatch. The description was wrong; the code is unchanged. The contract (on async_ll_recv_layout) and segment_error_counts() now say that an overflow is counted only on the rank that dropped rows, while a mismatch is counted on every rank. So the flags must be reduced across ranks (e.g. an all-reduce max) before acting on them, such as falling back to compact. The PR description is updated the same way.
  3. Stride past the receive cap on one rank. I kept the host check and documented it rather than clamping on the device. The contract and the comment next to the cap check now say that S must be computed from values every rank shares (e.g. the max token count after the DP all-gather). The cap check then fails on every rank before any of them launches; a rank that alone passes a stride past the cap leaves the others waiting.

Re-tested 5ef8577 on 8x MI355X (gfx950, ROCm 7.2.4, aiter 0.1.26):

  • test_asyncll_options.py OK.
  • test_asyncll.py: sdma early notification and legacy PASS (segmented and auto, including the new reset case), fused receive and lsa PASS (segmented refused).
  • test_asyncll_aiter.py: bf16 and fp8 block scale PASS.

As a negative check, f0a82b8 with the new test_asyncll.py fails exactly the new case on early and legacy: 16 failed checks (8 ranks x 2 levels), each mismatch after reset: segment error flags 0, want 2, and nothing else.

@jhchouuu jhchouuu changed the title perf(ep/v2): AsyncLL segmented receive layout (zero copy) for single-node SDMA perf(ep/v2): AsyncLL segmented receive layout for single-node SDMA Nov 13, 2026
@jhchouuu
jhchouuu merged commit 482db5c into ROCm:main Nov 13, 2026
20 checks passed
zhangfei829 added a commit that referenced this pull request Nov 13, 2026
Conflict with #918 in dispatch_combine_op.py: keep its async_ll_recv_layout
field and segment_stride argument next to low_latency and
max_num_inp_token_across_ranks; low_latency stays the last config field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants