Repository navigation
Conversation
2c8902d to
3499407
Compare
The decode MoE gate of the route fused into the activation quant (_fuse_tp_route_quant_enabled) read AITER_TDM_FUSE_TP_ROUTE_QUANT from os.environ on every call, and the fused branch of flydsl_moe_fused_quant_preshuffle read AITER_FLYDSL_TOKEN_MULTIDEST_QUANT. The first is now functools.cache'd. The second goes through token_multidest_quant_enabled(), which the quant dispatch uses as well, so both see one value. Same defaults and accepted values (1/true/True). Tests that flip AITER_TDM_FUSE_TP_ROUTE_QUANT between calls clear the cache after each setenv and around each test; the placeholder test clears the other. token_multidest_quant_enabled() and its placeholder-test fixture are byte-identical to the ones ROCm#7547 adds at the same place, so the two PRs merge cleanly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The decode gate of the route-in-quant fusion and the A1 quant dispatch (_compact_ascale) each called _use_fused_quant_preshuffle with the same arguments. _grouped_a8w4_tdm_moe now evaluates it at most once per call and hands the answer to both; same result, same order of evaluation. CPU (MiniMax-M3 TP4: E=129, topk 5, dim 6144, fp4 activations), gate plus dispatch question per decode MoE call (4-256 tokens), with the env commit: 1.17-1.20 -> 0.86-0.89 us. The memo block and the _compact_ascale line are byte-identical to the ones ROCm#7547 adds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
d0fd64c to
0067b65
Compare
The decode MoE gate of the route fused into the activation quant (_fuse_tp_route_quant_enabled) read AITER_TDM_FUSE_TP_ROUTE_QUANT from os.environ on every call, and the fused branch of flydsl_moe_fused_quant_preshuffle read AITER_FLYDSL_TOKEN_MULTIDEST_QUANT. The first is now functools.cache'd. The second goes through token_multidest_quant_enabled(), which the quant dispatch uses as well, so both see one value. Same defaults and accepted values (1/true/True). Tests that flip AITER_TDM_FUSE_TP_ROUTE_QUANT between calls clear the cache after each setenv and around each test; the placeholder test clears the other. token_multidest_quant_enabled() and its placeholder-test fixture are byte-identical to the ones #7547 adds at the same place, so the two PRs merge cleanly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The decode gate of the route-in-quant fusion and the A1 quant dispatch (_compact_ascale) each called _use_fused_quant_preshuffle with the same arguments. _grouped_a8w4_tdm_moe now evaluates it at most once per call and hands the answer to both; same result, same order of evaluation. CPU (MiniMax-M3 TP4: E=129, topk 5, dim 6144, fp4 activations), gate plus dispatch question per decode MoE call (4-256 tokens), with the env commit: 1.17-1.20 -> 0.86-0.89 us. The memo block and the _compact_ascale line are byte-identical to the ones #7547 adds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
0067b65 to
5f6b55e
Compare
0fa193d to
07cf264
Compare
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (8)
- Remove the host work this PR adds to every grouped-MoE call.
aiter/ops/flydsl/grouped_moe_gfx1250.py:863-871builds afunctools.cache(lambda)on every path, EP included;:947callstp_route_state_bufferon every eager TP call;:948-955runs the gate (two imports and an env read) on every non-fused TP call. CPU A/B against main (base-vs-base ±0.14 µs): decode +5.3 µs, fused small route +5.2, compact-pair prefill +11, E=384 +8.3, fp8 prequant +8.9, A-preshuffle +8.1, EP +3.6.AITER_FLYDSL_TOKEN_MULTIDEST_QUANT=0removes none of it. Use a plain bool, run the cheap checks (E bound, A-preshuffle, dtype, env, eligibility) first and only whennot _fused_tp_route, reuse the bool at_compact_ascale, and hoist the imports. Please post eager decode and non-route prefill numbers before and after. - Use
aiter/utility/graph_alloc.pyfor the counter instead of a new cache.capture_scoped_cache+persistent_alloc(:28/:76, used bygemm_kernels.py:464-474and others) already give a zeroed buffer that is shared across eager calls and captures. Replace_TP_ROUTE_STATE_CACHE/tp_route_state_buffer(:2258-2295), the scratch counter (:2364-2367), the eager pre-allocation (:941-947) and theself_clean=Falsekernel variant with@capture_scoped_cache _tp_route_state(E, device)and always launch_sc. Key it by (E, device), not by stream: captures run on a side stream. Today a capture with no earlier eager call records one zero-fill per layer, and AOT never builds the non-_scvariant. - Don't mirror the quant dispatch in the gate.
_tp_route_quant_takes_route(:2306-2344, "Mirrors the quant dispatch") re-derivesuse_token_multidest+row_to_token is Nonefrommoe_kernels.py:3723-3732; if they drift,moe_kernels.py:3735raises on default TP prefill. Export one predicate frommoe_kernelsand use it in both places. - Show that the default token-multidest kernel is unchanged, or keep its signature. The non-route kernel and launcher now take
row_starts/final_rows(moe_fused_route_quant_scatter.py:2251-2252, 2475-2486), and every default launch passestopids_to_rows_i32twice (moe_kernels.py:3801-3808). The kernarg segment goes from 36 to 56 B, the user-SGPR count changes, and the module name stays the same. Post a disassembly diff (user_sgpr_count, kernarg_size, prologues_loads) plus timing, or give the route build its own launcher. - Fix the docstrings that describe behaviour wrongly.
:2317-2319: the compact pair writesrow_to_tokenitself (moe_fused_route_quant_scatter.py:2704-2709); it is excluded because it has noroute_startsdecode.:2357-2359: every call during such a capture uses a scratch counter, not only the first.:945"one dict lookup" (1.1 µs measured).
Nits (also required):
6. Test the shapes the route takes by default. op_tests/test_moe_prefill_route_in_quant.py runs only fp4, E=129, wmma_rep 2/8, and its autouse fixture forces compact off. Shipped rows also route E256/k6/dim4096 fp8 (342-1023 and 16385-32768, wmma_rep 16) and dim7168/E96 fp4/fp8. Add fp8, E∈{64,256}, and one default-config case without the override.
7. tp_route_state_buffer docstring (:2276-2283): one overlap of two same-E calls leaves the counter corrupted for every later call until restart, not only the overlapping pair. Say so. moe_route_maps.py:333: use get_warp_size(), as moe_g2l_lut.py:43 does, instead of hard-coding wave_size = 32.
8. kernel_bench_callable "quant_a1" (:1532-1554) times the non-route multidest build and never the new route. Pass the encoded rows with route_starts/route_expert_bits.
Also: #7543 changes the same build_moe_token_multidest_quant_module with a different route-in-quant design (tp_route_slots, row_starts reused as expert ids), and the two conflict in all three files. Please pick one design or say how they fit together.
Reviewed at 07cf264 (Deep; 2 kernel/host hunters + independent pass B + 2 verifiers + miss pass). The ticket/last-block protocol, row encode/decode, self-clean across graph replays and the gather-reduce row handoff checked out in CPU models. Serving only reaches this route at 410-1023 tokens for MiniMax-M3 while the compact pair starts at 1024. CI green.
|
Thanks @valarLip. On how this fits with #7543: the two cover different batch ranges of the same token-multidest quant. #7543 folds the single-workgroup TP route into the quant (token_num x topk <= 2048, so up to 409 tokens for MiniMax-M3 and every decode). This PR replaces the three-launch route that larger batches take (410-1023 tokens for M3 today). Plan: #7543 lands first, split as you asked: the default-kernel quant refactor first, with ISA-equality evidence, and then the route-in-quant fusion. This PR will then be rebased onto #7543's builder, with |
07cf264 to
3e2a90e
Compare
|
Thanks for the review. All eight items are addressed. The branch is now rebuilt on #7543's reworked builder, so this PR depends on #7543 and on its first half, #8496 (see the last section). Line numbers below refer to the new head 1. Host work on every grouped-MoE call
Same-round deltas in µs, median over 8 rounds, at 5342a7ed; the review fixes after that only added checks on the route path. Focused re-run, this head vs #7543 B on the paths that showed a gap (16 interleaved rounds, median and interquartile range):
2. Counter via
3. One predicate
4. Default token-multidest kernel unchanged
5. Docstrings
6. Tests
7. Counter docstring,
8.
How it fits with #7543
Validation
|
3e2a90e to
28384ab
Compare
|
Restacked: this branch is now |
Move the per-warp _emit_quant_block_loop context of the token-multidest quant into a _quant_ctx closure in its builder. The kernel now only loads its routes' rows and hands them over with the hidden-row staging. Pull the pk8 hidden-row load of _emit_quant_block_loop into _hidden_pk8_load. No behaviour change: every quant build that goes through _emit_quant_block_loop compiles to the same gfx1250 ISA as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t context _quant_ctx took the fields that say how the hidden row arrives through a **staging catch-all, and _emit_quant_block_loop reads hidden_chunks, chunk_prefetch, hidden_lds_load and mx_group_base back with getattr defaults. A misspelled keyword at a call site would take the default without an error: with hidden_lds_load set and hidden_chunks misspelled, every chunk would be read from LDS slot 0. They are now seven required keyword-only parameters, so a missing or misspelled name raises TypeError when the kernel is built. No behaviour change: the call site already passes all seven, and every quant build that goes through _emit_quant_block_loop compiles to the same gfx1250 ISA as before. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Add tp_route_params to flydsl_moe_fused_quant_preshuffle. With it, the quant launch does the work of moe_route_psum_fused itself: every quant workgroup loads all expert ids, counts them in LDS (all routes, and the routes before its own), scans the tile-aligned counts, and gives its own routes their rows. It writes topids_to_rows, and block 0 writes masked_m and psum, so gemm1, gemm2 and the gather-reduce read what they read before. No workgroup waits on another, and nothing is left in global memory between calls. Both quant kernels the route batches use take it, as a tp_route_slots build option (0 = off): the route-indexed kernel, and the K-split build of the token-multidest kernel (from 64 tokens). The token-multidest route build is a second entry point next to the default one and shares its quant context. The wrapper keeps one token-multidest branch: the route adds its operands and needs a K-split build, else the batch takes the route-indexed kernel, whose route build is K-split too. The id loads and the lane's hidden-row loads are issued before the first barrier, so the route work hides under them. Each thread loads 8 id slots, enough for the 2048 routes the fused TP route serves, and skips the slots a smaller call does not use, so one build serves every batch. Rows within an expert follow route order, the same in every block. moe_route_psum_fused assigns them with LDS atomics, so its order varies from call to call; each route's quantized row, masked_m and psum are bitwise those of the split path, and the MoE output too, because no GEMM row or gather-reduce result depends on where a row sits. The wrapper refuses buffers the kernel cannot write in place (non-int32, strided or other-device topids_to_rows, masked_m or psum, too few grouped rows), tile_m <= 0, a route count that is 0, above TP_ROUTE_MAX_NUMEL (2048) or not a multiple of topk, an expert count outside 1..TP_ROUTE_MAX_EXPERTS, and the modes the fused route does not cover (prequantized, A-preshuffle, remap, EP psum, row-major scales, num_valid_routes, row_to_token). topk_ids must not share storage with the outputs. The quant kernels without the route compile to the same ISA as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Small TP batches (token_num * topk <= 2048) build their routes with moe_route_psum_fused, one workgroup that counts, scans and remaps every route, and then quantize the bf16 hidden rows into expert order in a second launch. On MiniMax-M3 TP4 decode (E = 129, top-5 with the shared expert on every token) that route launch runs once per MoE layer. The grouped MoE now hands those batches to the quant launch with tp_route_params, so a MoE call runs 4 kernels instead of 5. It is taken for the fused TP route batches with topk <= E <= TP_ROUTE_MAX_EXPERTS, bf16 input, at most TP_ROUTE_MAX_NUMEL routes, no a1_scale, no A-preshuffle and not the compact-scale quant pair; every other batch keeps its launches. AITER_TDM_FUSE_TP_ROUTE_QUANT=0 restores the separate route launch, like AITER_TDM_FUSE_PSUM_QUANT does for the EP psum. _compact_ascale (with _quant_mode and _prequantized) moves above the TP route gate and keeps its guards, so EP, prequantized and A-preshuffled calls still skip _use_fused_quant_preshuffle. The kernel-bench quant_a1 callable passes tp_route_params, so it times the launched kernel. test_grouped_skips_pad_rows_routed_to_minus_one checked that a 128-token TP batch with pad rows routed to -1 reaches the token-multidest quant; that batch now takes the route-in-quant build. The test now runs it with the route in its own launch and in the quant, and the compact-scale case with the switch at its default, and checks zero pad rows and unchanged real rows on each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
op_tests/test_moe_tp_route_quant_fused.py compares the fused route + quant with fused_route_psum_remap followed by the quant, at 1 to 409 tokens with M3 routing (E = 129, top-4 plus a shared expert), padded TP rows and dropped or out-of-range ids, and at the kernel limits (E = 256, top-8 uniform ids with repeats within a token, up to 2048 routes): - masked_m, psum and topids_to_rows equal a CPU reference; - payload and scales equal the split path's once each route's row is moved, with sentinel-filled outputs so an unwritten row fails; - a HIP graph replayed with new routes rewrites every route output; - buffers and modes the kernel cannot serve are refused: strided or host outputs, too few rows, tile_m 0, 0, 19 or 2050 routes, a negative expert count, a compact-scale row_to_token; - the public fused_moe output (a4w4 and a8w4) is bitwise equal with the switch on and off, and only the switch-off call launches the route. At model_dim 1024 and 80 tokens that call reaches the token-multidest route build. python3 op_tests/test_moe_tp_route_quant_fused.py runs the split vs fused check over a token sweep at dim 1024 and 6144 and prints the split and fused route + quant times. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add moe_route_lds_psum_sc, a TP route kernel that also produces the tile-aligned expert prefix: - It routes as moe_route_lds does. After a workgroup's global slot reservations return, it draws a ticket on counter[E]; the one that draws the last ticket sees every final count and writes masked_m, the tile-aligned exclusive starts and psum, then zeroes the counts and the ticket, so the counter is zero again for the next launch. - A route kernel cannot know an expert's start before the whole batch is counted, so each route's row is written as (slot << expert_bits) | expert instead of a final row. The token-multidest A1 quant gets a third route mode next to the default and tp_route_slots: route_expert_bits > 0 decodes the loaded rows to starts[expert] + slot before the shared quant context, and its K-group-0 blocks write the resolved rows to final_rows for the gather-reduce, so no psum-remap launch is needed. That build has its own kernel and launcher, with row_starts and final_rows appended after token_num; the default kernel keeps its name, arguments and ISA. The two route modes are exclusive. flydsl_moe_fused_quant_preshuffle takes route_starts, route_expert_bits and route_rows_out, and rejects them before any launch unless the call takes the token-multidest quant without a row_to_token map (otherwise the encoded rows would be read as final rows), and unless route_starts and route_rows_out are contiguous int32 and route_rows_out has one element per route, since both go to the kernel as raw pointers. Whether a routed call takes the token-multidest quant is now token_multidest_quant_used(), which the dispatch uses and the grouped MoE can ask before it picks its route. Co-Authored-By: Claude Opus 5.5 <[email protected]>
On gfx1250 TP batches too large for the single-workgroup route (_fused_tp_route), three launches ran before the A1 quant: a zero fill of the per-expert counter, moe_route_lds and moe_contiguous_psum_remap. When the A1 quant is the token-multidest launch, they become one moe_route_lds_psum_sc launch, and the quant places each route at starts[expert] + slot. The gate is one bool, evaluated only when _fused_tp_route is off: no HERD, compact plan or EP, not the compact-scale quant pair (it has no row decode), bf16 activations, E <= 256, token_multidest_quant_used() for the call, and token_num * topk < 2^(31 - expert_bits) so the encoded row stays a positive int32. _compact_ascale moves above the routing to feed it, so _use_fused_quant_preshuffle is still asked once per call; its EP test is now written as not _is_ep, which is what _ep_nvr is None meant there. The route counter is a zeroed (E + 1,) int32 buffer from capture_scoped_cache + persistent_alloc, keyed by (E, device): eager calls and captures share it, and a capture that runs before any eager call builds its own, zeroed on every replay (that case needs torch >= 2.10, as persistent_alloc does). The route zeroes it behind itself, so calls that share it must not overlap; _tp_route_state says what an overlap breaks. kernel_bench_callable's "quant_a1" times this route's quant with the encoded rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
op_tests/test_moe_prefill_route_in_quant.py, gfx1250 only: - route + A1 quant stage, one launch vs the split launches, against a CPU reference: exact masked_m/starts/psum, each expert owning rows [start, start + count), payload and scale bytes equal to the split route's, dropped routes kept at -1, the counter zero afterwards. Cases: MiniMax-M3 (E=129, topk 5, dim 6144) fp4 at wmma_rep 2/8 and fp8, E=64 topk 8 dim 7168 fp4, E=256 topk 6 dim 4096 fp8 at wmma_rep 16, and 9000 tokens, where the quant does not split K; padded cases also drop single routes, and the bytes past the last expert's tiles stay untouched; - fused_moe bitwise equal to the split route, eager and as a two-layer CUDA graph replayed with new routing, with two fewer kernels and no fill or psum-remap launch: MiniMax-M3 fp4 at 2048/4536 tokens, fp8 at 2048, E=64 topk 8 at 1024, and MiniMax-M3 at 410 tokens on the shipped config; - graph capture sharing the eager counter, and capture before any eager call (skipped on torch < 2.10). All but the shipped-config case pin the A1 quant to the token-multidest launch: no A-preshuffle, and AITER_FLYDSL_COMPACT_SCALE_MIN_TOKENS set high so the compact-scale pair does not replace it. python3 op_tests/test_moe_prefill_route_in_quant.py runs the tests, then times the stage both ways and prints a markdown table. Co-Authored-By: Claude Opus 5.5 <[email protected]>
28384ab to
f5a0231
Compare
moe_fused_route_quant_scatter.py imports _warp_inclusive_prefix_i32 from kernels/topk/topk_common.py, which imports kernels/dpp_utils.py. Main has since put the quant builders of that file behind AOT caches, so with the import undeclared the five caches built from it (moe_fused_quant_preshuffle_route_ksplit, moe_token_multidest_quant, moe_token_multidest_compact_quant, moe_apre_quant, moe_apre_scatter) fail the declared-sources check, a prebuild raises and every launch falls back to a JIT trace. Both files join _GFX1250_MOE_ROUTE_QUANT. Co-Authored-By: Claude Fable 5.2 <[email protected]>
- tp_route_slots() always returned one constant and repeated the route limit the quant wrapper already checks; the wrapper passes TP_ROUTE_SLOTS. - The compact-scale decision is made once before the routes are built (not _is_ep is what _ep_nvr is None said there: every EP branch sets it), where the route choice of a later change can read it too. - tp_route_params without topids_to_rows is refused in the row-indexed branch it would reach, not ahead of every routed call. - python3 op_tests/test_moe_tp_route_quant_fused.py takes -p/--pattern, so "wide" (E = 256, top-8) times the batches at the 2048-route limit. No kernel changes: the route builds keep their names and ISA. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ll-moe-route Conflicts: the imports of kernels/moe_route_maps.py (main's aot_factory next to get_warp_size) and the head of the routed branch of flydsl_moe_fused_quant_preshuffle (the tp_route_params refusal moved into the row-indexed branch). Co-Authored-By: Claude Fable 5.2 <[email protected]>
… caches - The route kernel moves to kernels/moe_route_lds_psum.py and is an aot_factory like the routes next to it. In moe_route_maps.py its import of topk/topk_common.py made every AOT cache built from that file (moe_topids_to_rows, moe_topids_to_rows_lds, moe_contiguous_psum_remap, moe_route_psum_fused) fail the declared-sources check after the merge with main; that file is unchanged again, and the new cache declares its own sources. - flydsl_moe_fused_quant_preshuffle takes route_rows (the encoded rows) and route_starts, and writes topids_to_rows, as it does for tp_route_params. route_rows_out and route_expert_bits are gone (the bits follow from the length of route_starts), and the three refusals are one. - tp_route_rows_fit(experts, numel) is the one statement of what the route kernel serves; the gate and tp_prefill_route_psum both read it. tp_prefill_route_psum returns a plain tuple. - The gate is one negated group plus the three positive conditions. The kernels are unchanged. Co-Authored-By: Claude Fable 5.2 <[email protected]>
278 -> 215 lines, 51 -> 8 cases. - fused_moe with the fold off and on, bitwise, is the main check: 4 cases (the route-indexed and the token-multidest route build, fp4 and fp8 activations) instead of 8. - The kernel-level check keeps the four cases no MoE config reaches: one token, out-of-range ids, and the limits (E = 256, top-8, 2048 routes). The 42-case tokens x pattern x tile sweep, its graph replay and the refusal-by-refusal contract test are gone. - One id generator and one CPU reference, inlined where it is used. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
301 -> 224 lines. - Every case goes through fused_moe and compares it, bitwise, with the launches the route replaces: eager with dropped routes, and a two-layer graph replayed with new routes, with two fewer kernels. - The stage-level harness (route + quant against a CPU reference, 12 cases) and the test of its case table are gone. Its two shapes that no MoE case had, E = 256 fp8 and the batch that does not split K (9000 tokens), are MoE cases now; MiniMax-M3 fp4 at 2048 tokens, the same build as 4536, is dropped. - python3 op_tests/test_moe_prefill_route_in_quant.py times the whole fused_moe call on the split route and on this one. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The _quant_ctx / _hidden_pk8_load refactor is no longer needed, and the net diff against main has none of it. - Token-multidest quant: the route operands are a tuple operand of the one kernel, tp_route=() (empty with the route off, so that build, its name and its launcher are main's, untouched). The route step and the early hidden-row loads sit in the kernel body under a compile-time condition; a route build adds only its launcher. There is no second kernel and nothing to share between two entries. - Route-indexed quant: the row load is main's again, and the route build replaces its result. - _emit_quant_block_loop is main's plus the hidden_preloaded hook. Outside the route additions the file reads as on main: +434/-1 against main, was +613/-119. Final ISA (compile-only, gfx1250): the 81 kernels without the route are byte-identical to main, the six route-indexed route builds to the previous head. The six token-multidest route builds gain main's "block owns a token" guard (s_cmp_ge_u32 + s_cbranch_scc1) and split one s_lshl3_add_u32 into shift + add, 2 or 3 instructions on 926-988; the rest is the same instructions with other register numbers and order. Co-Authored-By: Claude Fable 5.2 <[email protected]>
ROCm#7543 no longer needs the _quant_ctx refactor: its route is a tuple operand of main's token-multidest kernel. Conflict in kernels/moe_fused_route_quant_scatter.py: this PR's row decode sat between the row loads and _quant_ctx. It is re-expressed the same way, as a second tuple operand of the one kernel, route_rows=() (row_starts, final_rows), whose decode feeds the kernel body the rows it would otherwise load. The _token_multidest_entry shell and the second kernel are gone; the route build adds only its launcher. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… the route ran Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Card
Step 8 gates |
|
The
Card
Step 8 gates |
The counter stays keyed by (experts, device): a capture runs on a side stream, so a per-stream key gives every graph its own counter and a zero fill per replay, which the 11-19 review asked to avoid. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
The
Card
Step 8 gates |
|
Reply to the review of 2026-11-19 (valarLip, at 07cf264). Status of the eight items at
On #7543: the two are route modes of one builder and are exclusive there (#7543's Also in this revision: the route kernel moved, unchanged, to its own module What ran, on one idle MI455X (gfx1250),
Still open:
|
|
Reply to the
|
What it does
On gfx1250, a TP MoE batch too large for the single-workgroup route (
_fused_tp_route) runs three launches before the A1 quant: a zero fill of the per-expert counter,moe_route_ldsandmoe_contiguous_psum_remap. When the A1 quant is the token-multidest launch, this PR replaces the three with one launch,moe_route_lds_psum_sc.One route launch. The kernel lives in its own module,
kernels/moe_route_lds_psum.py, and is anaot_factorywith its own declared sources, sokernels/moe_route_maps.pyand the AOT caches built from it are unchanged. It routes asmoe_route_ldsdoes. Each workgroup then draws a ticket, and the last one sees every final count. That workgroup writesmasked_m, the tile-alignedstartsandpsum, then zeroes the counter for the next call.The quant places the rows. Each route's row is written as
(slot << expert_bits) | expert. The token-multidest quant gets a third route mode next to [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543'stp_route_slots:route_expert_bits > 0decodes the row tostarts[expert] + slotbefore the shared quant context and writes the final rows for the gather-reduce.route_rows=()(row_starts,final_rows), empty without the mode, and the route build adds only its launcher.route_rowswithroute_startsand writestopids_to_rows, as it does for [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543'stp_route_params. The expert bits follow from the length ofroute_starts.Gate. It is one bool:
moe_kernels.token_multidest_quant_used()is true (no A-preshuffle, not prequantized). The quant dispatch uses the same predicate;tp_route_rows_fit(E, routes): E <= 256 and the encoded row fits in int32.tp_prefill_route_psumchecks the same function.Every other case keeps the old launches.
AITER_FLYDSL_TOKEN_MULTIDEST_QUANT=0turns this route off together with the token-multidest quant.Default scope. By default the route serves TP batches with more than 2048 routes and fewer than 1024 tokens (top-5: 410–1023 tokens). At 2048 routes or fewer the single-workgroup route runs; from 1024 tokens (2048 on wmma_rep 1 rows) the compact-scale quant pair keeps the old launches. The other cases in the test run under an override that forces it: a raised
AITER_FLYDSL_COMPACT_SCALE_MIN_TOKENSand a masked A-preshuffle on the tuned row.Counter. It is a zeroed
(E + 1,)buffer fromgraph_alloc.capture_scoped_cache+persistent_alloc, keyed by (E, device) and shared by eager calls and captures. Calls that use it must not overlap: two in flight at once (e.g. on two streams of one device) mix their counts.Benefit
Whole
fused_moecall, this head, on one idle MI455X (gfx1250),rocm/fw-bringup:gfx1250-minimax-m3-20261112with FlyDSL 0.5.3:python3 op_tests/test_moe_prefill_route_in_quant.py(exit 0, one run). The baseline is the three launches this PR replaces, on the same tree. The output is bitwise equal in every row (err 0), and the pytest cases (check_moe) check from the kernel names that the one-launch route ran (the benchmark itself asserts only err 0). All five rows run under the test's override (Default scope).The gain is small: 0.7% to 2.5% of the call in this run (0.2% to 2.0% in a second run). The default window (MiniMax-M3 at 410–1023 tokens) was not timed at this head. The route + quant stage table of earlier heads is dropped: the quant builds changed since.
Host time per grouped-MoE call (CPU, launches stubbed, one pinned core, 10 interleaved rounds against #7543's branch with an A/A control). Measured at an earlier revision of this branch and not repeated.
Deltas are same-round differences in µs (median, interquartile range). Calls that do not take the route run 40 to 105 more Python bytecodes (0.3-0.7%) and are inside the A/A spread.
Testing
On one idle MI455X (gfx1250), this head,
rocm/fw-bringup:gfx1250-minimax-m3-20261112, FlyDSL 0.5.3:python3 -m pytest -q -s op_tests/test_moe_prefill_route_in_quant.py: 8 passed.python3 -m pytest -q -s op_tests/test_moe_tp_route_quant_fused.py([FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543's test): 8 passed.python3 op_tests/test_moe_prefill_route_in_quant.py: exit 0 (the table above).python3 -m pytest -q op_tests/flydsl_tests/test_flydsl_grouped_gemm.py, at the parent commit86a18b08: 56 passed, 7 failed. See Unverified.On CPU:
black --checkandruff checkare clean on the 8 changed files at this head.86a18b08, whose tree is identical to this head's (the two commits after it cancel out).aiter.aot.flydsl.dry_run("gfx1250")withCOMPILE_ONLY=1, final ISA compared withcmp): the 81 kernels without a route mode, the default token-multidest builds among them, are byte-identical to mainea578b41. [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543's 12 route kernels are byte-identical to [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543's head. Againstb871d56b, this branch before [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543's rework was merged in,moe_route_lds_psum_scis byte-identical and the 21 row-decode quant builds are not: the row and start loads now sit ahead of the kernel's "block owns a token" guard (0 to 6 instructions fewer on 286-1809).aot_cache._undeclared_imports): clean for the 7 caches around the route and the quant.python -m aiter.aot.flydsl.moe: 96 ok, and 48 ok with--row-tokens-only;--checkpasses for both.launch_route_psumandlaunch_token_multidest_route_rowsare among the launchers.route_startswith too few tokens,row_to_token,tp_route_params, missing or shortroute_rows, int64 or strided buffers, and accepts the 512-token call;tp_route_rows_fitis false past 256 experts and where the encoded row leaves int32;pytestof the neighbouring tests gives the same outcomes as [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543's head.Not covered
Dependencies
Stacks on #7543 (TP route inside the activation quant): the branch contains #7543's head
5689d664and mainea578b41by merge, and it merges after #7543.PR Self-Review
Reviewed revision
99359c2
Behavior and intent
moe_route_ldsandmoe_contiguous_psum_remapbecome onemoe_route_lds_psum_sclaunch when the A1 quant is the token-multidest kernel. The quant decodes(slot << bits) | experttostarts[expert] + slot.route_rows=()is a tuple operand next to [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543'stp_route=(). The default kernel is unchanged (ISA-identical to main). The route kernel has its own module and AOT cache._compact_ascaleandtoken_multidest_quant_used()with the quant dispatch andtp_route_rows_fit()with the route launcher, and the quant rejects encoded rows before any launch if the two ever disagree.fused_moecall: 0.7% to 2.5% faster in the five benchmark cases (table above; one run a row).Validation and unverified scope
f5a0231b:ea578b41.kernels/moe_route_lds_psum.pyas anaot_factory;moe_route_maps.pyis main's again.flydsl_moe_fused_quant_preshuffletakesroute_rowsandroute_startsand writestopids_to_rows;route_expert_bitsandroute_rows_outare gone, and the three refusals are one.moe_fused_route_quant_scatter.pyadds 76 lines over [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543).tp_route_rows_fit()is the one statement of what the route kernel serves.grouped_moe_gfx1250.pyadds 96 lines over [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543._tp_route_stateis keyed by (E, device), as the 11-19 review asked; a per-stream key was tried and reverted (same tree as86a18b08).op_tests/test_moe_prefill_route_in_quant.py: 224 lines, every case throughfused_moe; its benchmark times the whole call.rocm/fw-bringup:gfx1250-minimax-m3-20261112, FlyDSL 0.5.3:python3 -m pytest -q -s op_tests/test_moe_prefill_route_in_quant.py: 8 passed.python3 -m pytest -q -s op_tests/test_moe_tp_route_quant_fused.py: 8 passed.python3 op_tests/test_moe_prefill_route_in_quant.py: exit 0; 5 rows, err 0.python3 -m pytest -q op_tests/flydsl_tests/test_flydsl_grouped_gemm.pyat86a18b08: 56 passed, 7 failed.black --check,ruff check: clean.86a18b08(same tree as this head):aiter.aot.flydsl.dry_run("gfx1250")withCOMPILE_ONLY=1,cmpon the final ISA: 81/81 kernels without a route mode equal to mainea578b41; 12/12 of [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543's route kernels equal to [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543's head.aot_cache._undeclared_imports: clean.python -m aiter.aot.flydsl.moeon the MiniMax-M3 rows: 96 ok,--row-tokens-only48 ok;--checkpasses for both.pytestof the neighbouring tests: same outcomes as [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543's head.test_flydsl_grouped_gemm.pyis not a usable regression signal in that image: its 7 failures are all "FLYDSL_RUNTIME_RUN_ONLY=1 but no usable AOT cache", and mainea578b41in the same container fails the same first 5 and then aborts (rc 134); this PR does not change that file beyond [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543;--checkran);PR-specific question
What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
test_moe_prefill_route_in_quant.pyis new. It asserts thatfused_moelaunchesmoe_route_lds_psum_scand two fewer kernels than the split route, with the same output; before this PR that kernel does not exist.test_capture_route_statechecks the shared and capture-scoped counter, and that replays match the eager output; only the new route has this counter.test_moe_route_rows.pyandtest_route_psum_fused.pycover the split route and the single-workgroup route. Neither covers a ticketed last-workgroup psum or slot-encoded rows.Changed op tests
op_tests/test_moe_prefill_route_in_quant.py(new, 226 lines, 8 cases)fused_moe:moe_route_lds_psum_scand two fewer kernels: MiniMax-M3 fp4 with and without K-split (4536 and 9000 tokens), fp8 activations, E = 64 top-8 and E = 256 top-6, with dropped routes, eager and in a two-layer graph replayed with new routes;op_tests/test_moe_tp_route_quant_fused.py(new, from [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543; this PR does not change it)fused_moebitwise equal with the fold on and off, and the kernel limits against a CPU reference.op_tests/flydsl_tests/test_flydsl_grouped_gemm.py(modified by [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543; this PR does not change it)fuse_route=1case fails its path assertion.