Skip to content

Fix/epv2 1250x r1 combine - #886

Merged
zhangfei829 merged 3 commits into
mainfrom
fix/epv2-1250x-r1-combine
Nov 2, 2026
Merged

zhangfei829 merged 3 commits into
mainfrom
fix/epv2-1250x-r1-combine

Conversation

@zhangfei829

Copy link
Copy Markdown
Collaborator

fix(ep/v2): three 1250x combine slow paths at topk 9 (DeepSeek-R1)

Three fixes in src/ops/dispatch_combine_v2/ep_intranode_1250x.hpp, each
found as a cell far off its neighbours in the EP4 / EP8 / EP16 dtype x
token combine latency table of main on gfx1250. All three are hit by
topk 9 (DeepSeek-R1, hidden 7168). No new switches or env vars.

  1. Pull combine: compact sources where npes < topk (EP8 bf16).
    Dispatch sends a token to a rank at most once, so at most npes of
    its topk source pointers are non-null. The null ones were squeezed
    out only at npes <= 4. At EP8 with topk 9 the source count stayed
    at 9, above the min(npes, topk) = 8 that the TDM path takes, so both
    TDM branches were skipped and every token count below globalWarpNum
    fell back to WarpAccumLF. Sources are now compacted at
    npes <= 4 || npes < topk.

  2. Push combine: keep the row arrays out of scratch past 8 rows (EP16
    fp8 / fp4). The kRows loops left at the row count of the token with
    break. LLVM fully unrolls a loop with an early exit only up to 8
    trips (-unroll-max-upperbound), so at kRows = min(worldSize, topk)
    = 9 they stayed rolled and the per-row arrays pk[] / sb[] went to
    scratch. Past 8 rows the loops continue instead, which gives them an
    exact trip count. kRows <= 8 keeps break and compiles to the same
    instructions as before.

  3. Pull combine: give every warp at least 128 B of a token (bf16, few
    tokens). EpMultiWarpIter splits a token over
    ceil(globalWarpNum / numTokens) warps, and a slice under 128 B takes
    _cFoldPeers, one scalar load per lane per peer. When the pull path
    is usable, the warps of a token are now capped at
    hiddenDim / (128 / sizeof(TokT)), 112 for 7168 bf16.

MI450, HIP graph mode, CHECK passed at every measured point. Combine
latency in us, median of 3 alternating rounds, main -> this change;
every speed-up below held in all 3 rounds.

  • EP4 R1 bf16, fix 3 (64 x 4 combine warps up to 64 tokens, so 1 / 2 /
    4 tokens get 56 / 112 / 224 B slices): 1 token 18.17 -> 12.10,
    2 tokens 18.69 -> 12.27; 4 to 512 tokens within 0.16 us every round.
  • EP8 R1 bf16, fix 1: 8 tokens 49.6 -> 14.3, 256 tokens 349.2 -> 31.8,
    384 tokens 633.0 -> 47.3; 512 and 16384 tokens unchanged.
  • EP16 R1 fp8 / fp4 push, fix 2: 16384 tokens 2652.6 -> 1046.5 (fp8)
    and 1388.3 -> 605.1 (fp4); faster at every measured token count from
    1 to 16384.
  • DeepSeek-V4-Pro (topk 6): within 0.15 us at EP4 and 1.5 us at EP8.

EP8 and EP16 were measured with fix 1 alone and fix 2 alone; those
combine kernels compile to the same instructions as this change
(without fix 3 for EP8). Against main, 16 of the 54 combine kernels of
a rebuilt JIT cache change (the 12 bf16 pull combines and the 4 EP16
topk 9 fp8 / fp4 push combines); the other 38 are identical and none
uses scratch. 43 of the 53 dispatch kernels differ, only in the
immediates of s_add_nc_u64 (PC-relative addresses of read-only data).
Not measured: EP8 / EP16 bf16 at 1 to 4 tokens, and EP32.

At 4 < npes < topk (EP8 with topk 9) validAccumCount stayed topk while the pull has min(npes, topk) slots a warp, so every token below globalWarpNum fell to WarpAccumLF. R1 EP8 bf16 combine C8+C16, 3 alternating rounds: 256 tokens 349.2 -> 31.8 us, 384 633.0 -> 47.3 us; 512 and up and topk 6 unchanged.
…rows

The kRows loops of the 1250x push combine leave at the row count of the token with break. LLVM fully unrolls a loop that can leave early only up to -unroll-max-upperbound (8) trips, so at kRows = min(worldSize, topk) = 9 (DeepSeek-R1, topk 9, at EP16 and up) these loops stay rolled, and the per-row arrays pk[] and sb[] are indexed at run time and placed in scratch: fp8 ws16 k9 64x8 has 304 B private, 70 scratch stores and 14 loads; fp4 ws16 k9 64x8 has 160 B, 162 and 18.

Past 8 rows the loops now skip the trips past the row count of the token (continue), which gives them an exact trip count; both kernels then use no scratch (VGPRs 141 to 172 and 192 to 186). Configurations with kRows <= 8 keep break and compile to the same instructions as before (all 52 combine kernels of a JIT cache rebuilt and compared).
EpMultiWarpIter splits a token over ceil(globalWarpNum / numTokens) warps, so with few tokens the hidden slice of a warp falls under 128 B (7168 bf16 over 512 warps is 14 elements), and the TDM stage of the pull combine then takes _cFoldPeers, one scalar load per lane per peer. When the pull path is usable the warps of a token are now capped at hiddenDim / (128 / sizeof(TokT)), 112 for 7168 bf16, so every slice keeps the TDM path.

R1 (topk 9, 64 experts a rank) EP4 bf16 pull combine, one MI450 node, graph mode, 3 alternating rounds, median: 1 token 18.17 -> 12.10 us, 2 tokens 18.69 -> 12.27 us; 4 to 512 tokens, whose slices were already 128 B or more, within 0.16 us in every round. V4-Pro (topk 6) unchanged.
@zhangfei829
zhangfei829 merged commit c7da62d into main Nov 2, 2026
6 checks passed
@QizhouZhang97
QizhouZhang97 deleted the fix/epv2-1250x-r1-combine branch November 10, 2026 13:19
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.

1 participant