Skip to content

[gfx1250] DSR1 EP4: add topk9 dispatch+combine schedule - #725

Merged
jhchouuu merged 1 commit into
ROCm:mainfrom
karverma-amd:karverma-amd/gfx1250-dsr1-topk9-dispatch-schedule
Oct 10, 2026
Merged

jhchouuu merged 1 commit into
ROCm:mainfrom
karverma-amd:karverma-amd/gfx1250-dsr1-topk9-dispatch-schedule

Conversation

@karverma-amd

Copy link
Copy Markdown
Contributor

Summary

Add gfx1250 EP4 schedule-table entries for (world=4, hidden=7168, topk=9) to
both the dispatch and combine tables, and retune the dispatch geometry to block
256. topk=9 is DeepSeek-R1's real dispatch width at EP4 (8 routed + 1 shared).

Motivation

DSR1 at EP4 dispatches topk=9, but the gfx1250 tables only had topk=8 entries.
lookup() returns the block-64 single-shot default unless both a dispatch
and a combine entry exist for the key, so the engine silently fell back to the
block-64 path. At the ~3456-recv decode operating point that geometry starves
the 256-CU GPU. Block 256 saturates it. The combine half must be present too (it
mirrors topk=8 geometry, unchanged) purely so the dispatch schedule resolves.

Test Plan

  • tests/python/ops/dispatch_combine_v2/bench_ep.py with DISP=fp4 HIDDEN=7168 TOPK=9 EPR=64 across the decode token sweep, hip backend.
  • In-engine DSR1 1k4k conc6144 bs1536 (TP4/DP4/EP4) decode trace:
    mori dispatch 67.8 µs → 38.8 µs (−29 µs/step).

Accuracy

Pure scheduling/geometry change — no arithmetic is altered, output is
bit-identical. End-to-end GSM8K 5-shot (1319 q, FAKE_EPLB=0) unchanged at
0.958 (flexible-extract), matching the reference.

DeepSeek-R1 at EP4 dispatches topk=9 (8 routed + 1 shared), but the
gfx1250 schedule tables only had topk=8 entries, so lookup() fell back to
the block-64 single-shot default. At the ~3456-recv decode operating point
that starves the 256-CU GPU. Add (4,7168,9) entries to both the dispatch
and combine tables (lookup requires both halves) and retune the dispatch
geometry to block 256. In-engine DSR1 1k4k conc6144 decode: mori dispatch
67.8 -> 38.8 us. Combine geometry unchanged (pure scheduling, no math).

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

LGTM

Comment on lines 179 to 186
"gfx1250": {
(4, 7168, 8, None): ((None, 64, 8),),
# topk 9 = 8 routed + 1 shared (ATOM's actual dispatch key). Needed so the
# dispatch schedule has a combine half -- lookup() returns the block-64
# single-shot default unless BOTH halves exist. Combine geometry mirrors
# topk 8 (unchanged); only the dispatch half is retuned to block 256.
(4, 7168, 9, None): ((None, 64, 8),),
(4, 7168, 6, None): ((None, 64, 8),),

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.

have you tested on gfx1250?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes !

@jhchouuu
jhchouuu merged commit 489d617 into ROCm:main Oct 10, 2026
zhangfei829 added a commit that referenced this pull request Oct 11, 2026
Conflicts were all #726's selfFirst-follows-TOKOFF_EXT, which this branch already replaced with aggReserve on the same tokOffExt field; kept the branch side. #725's EP4 topk 8/9 dispatch rows are taken, and its topk 9 row is folded into the one (4, 7168, 9) key so #726's fp4 row no longer shadows it. #735 is taken: the gfx1250 dispatch still stores totalRecvTokenNum.
@zhangfei829 zhangfei829 mentioned this pull request Oct 11, 2026
zhangfei829 added a commit that referenced this pull request Oct 11, 2026
gfx1250 EPv2: one-RMW slot reservation, EP16 fp4 dispatch and push combine, fp8 push combine

## Summary
- Dispatch slot reservation: a rank's blocks add up their token counts and the last block reserves once per destination (one RMW on the slot word instead of one per block). Replaces selfFirst; `MORI_EP_TOKOFF_EXT=1` keeps the per-block protocol for a single-host EP.
- EP16 fp4 dispatch: 128x16 sends each destination's rows from a pinned set of warps.
- fp4 push combine: the landing offset rides the 64-bit dispatch signal, and the landing area is M x min(world, topk) rows instead of world x world x M, so EP16 push fits at 16384 tokens a rank.
- fp8 push combine (`fp8_blockwise`).
- EP16 64x16 bf16/fp8: a metadata warp holding exactly two runs loads both, then stores both. Built into those instances and chosen at run time, with no switch.
- Tuning tables: EP16 dispatch and fp4 push combine, EP4 fp8 push combine. Removed the `MORI_V2_EP_{DISP,COMB}_{BLOCKS,WARPS}` overrides.
- Merged main: #725 and #735 taken; #726's selfFirst change superseded. The duplicate `(4, 7168, 9)` dispatch key on main is folded into one, so #725's topk 9 row takes effect.

## Test
CHECK=1 passes on EP4 (topk 6 and 9), EP8 (2 hosts) and EP16 (4 hosts) at 1 / 64 / 512 / 4096 / 8192 / 8193 / 16384 tokens a rank, for fp4 push, fp4 pull, bf16 and fp8 push.

EP16 (4 hosts x 4 gfx1250), fp4 dispatch, topk 6, 96 experts/rank, HIP graph, ITERS=50, 3 alternating rounds, medians in us. The baseline has main's kernel and its untuned 64x16 geometry; main cannot allocate the fp4 push landing area at EP16 with 16384 tokens, so its combine is pull. The fp4 machine code is identical to this branch's head.

| tokens/rank | dispatch main → branch | combine main (pull) → branch (fp4 push) |
|---:|---:|---:|
| 64 | 27.39 → 26.56 | 17.95 → 16.02 |
| 512 | 38.83 → 31.66 | 50.57 → 28.33 |
| 4096 | 113.03 → 92.57 | 275.81 → 87.99 |
| 16384 | 378.46 → 292.98 | 1032.22 → 302.42 |

EP4 is about even with main: topk 9 fp4 push, same node, 3 alternating rounds, dispatch +0.1..+1.2 us, combine +0.2..+0.7 us (+2.5 at 1536).
jhchouuu added a commit to jhchouuu/mori that referenced this pull request Oct 12, 2026
Conflicts in hip_tuning_configs.py, resolved to this branch's tables:
- topk-9 fp4 dispatch: this branch's sweep (main kept ROCm#726's row under
  "fp4_disp_bf16_comb"; main also un-shadowed the ROCm#725 row, as this branch did).
- topk-6 fp4 dispatch: same buckets, keyed "fp4" as on this branch.
- the combine-table comment: main's (EP8 and EP16).

Main's new EP16 dispatch row is re-keyed from "fp4_disp_bf16_comb" to "fp4",
since lookup() now reads that spelling as "fp4"; under the old key the row
would never match. Checked against main over every table key, dispatch dtype
and quant type (112 lookups): every key but topk 9 returns what main returns
for "bf16", "fp8" and "fp4_disp_bf16_comb".

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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