Repository navigation
perf(ep/v2): AsyncLL segmented receive layout for single-node SDMA - #918
Conversation
jhchouuu
left a comment
There was a problem hiding this comment.
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:
- The consumer contract is undocumented, and today's integrations break silently.
- Valid rows are
[s*S, s*S+n_s), not a prefix, andtotal_recv(Σn_s) is not the row count. - sglang (
num_local_tokens=total_recv, truncation torecv_cap) and ATOM both assume a prefix. Run that way, about 41% of the tokens are dropped with no error. num_local_tokens=Noneis 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.
- Valid rows are
- 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 bymax_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.
25e18d8 to
fd718da
Compare
|
Thanks for the thorough review and the end-to-end numbers. Point by point, as of the current head:
|
|
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. |
…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.
198ff64 to
f0a82b8
Compare
jhchouuu
left a comment
There was a problem hiding this comment.
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.pywith early notification on and off, andtest_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_recvreadsW*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
reset()makessegment_error_flags()miss errors.reset()zeroes the arena, including the error counters insend_count, but_seg_error_basekeeps 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), callreset()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_baseinreset(). The docstring ofsegment_error_counts()("since the op was built") would then say "since the op was built or last reset".
- 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.
- A stride above the receive cap on one rank only.
- The host raises
ValueErroron 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.
- The host raises
- 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.
|
GPU CI for
Test groups (the steps that run in those jobs): epv2. Lanes follow the changed files. Adding |
Thanks for the re-test and the extra measurements, especially the TBO-order and mixed-mode runs. All three points are addressed in 5ef8577:
Re-tested 5ef8577 on 8x MI355X (gfx950, ROCm 7.2.4, aiter 0.1.26):
As a negative check, f0a82b8 with the new |
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.
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)"segmented"op; without it the same op runs a compact round (e.g. under CUDA graphs)segment_counts()int64[world_size]:n_sof the last segmented roundsegment_error_counts()/segment_error_flags(clear=)reset(), and the bits since the last clearConsumer contract (documented on
async_ll_recv_layout):world_size * Srows. 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 localexpert_maskdrops them; their hidden bytes are stale.total_recvreadsworld_size * Sin a segmented round, the row count, so it is the rightnum_local_tokensfor aiterfused_moe; do not truncate the views below it.combine_in_view()(alsoworld_size * Srows); combine copies any other tensor there first.Sis the same on every rank, at least every rank's token count, at mosteffective_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.Kernels.
SendCopySegwrites per-field staging (own rows straight into the landing segment);SendTransferSegposts one SDMA copy per field plus the mode word and, with early notify, the count, in one reservation;RecvFinalizeSegreplaces RecvCopy (invalidates holes, recordsn_s, checks mode words);CombineSendTransferSegsends each source's segment straight from the expert output;CombineRecvCopySegreads 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 fromcrossDeviceBarrierFlag, 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 add2*world_size+3words tosend_countand 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 * Srows:n_scounts 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):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:
(*) 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
Swith 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.test_asyncll_aiter.py(8x MI355X, skips without aiter): each round runs compact and segmented on the same inputs through aiterfused_moe(num_local_tokens=total_recv, output in place incombine_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: OKtest_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 ranksNegative check: f0a82b8 with this head's
test_asyncll.pyfails only the newreset()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.pyOK;test_asyncll.pysdma early notification, legacy, fused receive and lsa PASS (test_asyncll_aiter.pynot run there, no usable aiter build).Submission Checklist