Repository navigation
[FlyDSL] MegaMoE gfx1250 S1F: fix the stage-1 plan's LDS overflow on large arenas (hipErrorInvalidValue) and run SiTUv2 in the stage-1 kernel - #8483
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
… head 2026-11-19T13:20:38Z) Snapshot of #8189 (all 6 files, PR diff against its main base). For Kimi-K3 it supplies the stage-1 fused kernel's flag tiles for more than 4 source ranks: without it the S1F stage-1 kernel fails to compile at EP8 ("vector index 4 out of range for numel 4" in s1f_stage1.ready_of). Needed with #8483 for S1F on the K3 DP8EP8 decode node (wuhuikx/LLM-Booster#722). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nas and run SiTUv2 in the stage-1 kernel (#8483 @ 45fbfb7, head 2026-11-23T06:55:24Z) Snapshot of #8483. The stage-1 compact plan sizes its per-m-tile LDS table by the S1F receive cap instead of the arena (Kimi-K3 EP8 at 16384 tokens a rank: 569 KiB -> 73 KiB, limit 320 KiB), and SiTUv2 runs in the stage-1 kernel with its betas. Validated with #8189 on two MI455X trays: K3 DP8EP8 serving with AITER_MEGA_S1F=1, every decode step on s1f_stage1, GSM8K unchanged (wuhuikx/LLM-Booster#722 comment 7121412936). Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 (7)
- Use aiter's LDS capacity query instead of a hand-written constant.
PLAN_LDS_BYTES = 320 * 1024(compact_plan.py:277-279) copiesaiter.jit.utils.chip_info.get_lds_capacity_bytes("gfx1250")(lds_capacity.py:15).aiter/ops/flydsl/AGENTS.mdrequires the query.dispatch_tdm.py:64ands1f_stage1.py:812hold the same value as pre-existing copies.
- Tie
compact_plan_lds_bytesto the allocator it mirrors.compact_plan.py:306-309recomputesroute_vec/per_block/chunk_cap/merge_routesfrom:513-524.:312-332restates thesmem.allocatesequence at:664-746by hand.- It matches today; a CPU replay over Kimi-K3/DSV4.1, EP4/8, align 16-256 and blocks 1-16 found 0 mismatches. But #8189 is already editing these allocations. An under-count brings back the silent
hipErrorInvalidValue; an over-count gives a false fallback. - Fix: share one geometry helper, and assert at trace time, after the last allocate, that the allocator's byte count equals
compact_plan_lds_bytes(...).
- Memoize the stage-1 LDS verdict per
align_m.tile_reasons()(s1f_ctl.py:313-319) now runs a function-level import plusplan_lds_bytes()on every call. A microbench measured +0.79 µs per call.- It is called about 5-6 times per MoE layer per eager step (
eligible,wants_fused_quant×2,plan_mode×2,step_will_run). That is about 0.3 ms per eager step on a 61-layer model, on the defaultAITER_MEGA_S1F=1path. - Every input is fixed after
arm(), so cache the reason list peralign_mthere.
- Post the validation the body lists as pending. This PR turns SiTUv2 on in the default S1F path for every Kimi-K3 config whose plan fits, and those already include EP4 at ≤16384 tokens a rank. Before merge, post:
- SiTUv2 (and a Silu control) with S1F on vs off against the fp32 reference;
- per-layer decode time with S1F on vs off;
- a GSM8K run against S1F=0.
Please also land thebench_mega_moe.pyedits so the case can be reproduced.
- Add host-side tests in
tests/test_mega_moe_gfx1250_recipe.py, next totest_compact_plan_limits. Say which CI lane runs that file; it is importorskip'd on flydsl/mori. Cover:- Kimi-K3 EP8 is over 320 KiB at
geo.capand under it atplan_cap; tile_reasonsreturns the LDS reason when the plan cannot fit;- the item-2 assert.
- Kimi-K3 EP8 is over 320 KiB at
- Judge the ahead plan by the next step's bound.
dispatch_compact.py:617-631restoresself._step = savedbefore_launch_plan. So_plan_fordecidesplan_s1fwith the current step'srecv_bound.- With this PR, a stage-1 plan built that way is capped at
plan_capand silently drops tok_map rows past it (compact_plan.py:1568). - It is unreachable today: only
bench_mega_moe.pypassesnext_topk_ids. Restore_stepafter_launch_planinstead.
- Fix
plan_capand the text around it.max(geo.tile_m, align_m)(s1f_ctl.py:338-341) is alwaysgeo.tile_m, because_step_forclampsalign_m. Usegeo.tile_mand fix the docstring ("at the step's alignment").dispatch_compact.py:870-874"takes the S1F receive cap's (above)" is missing a noun. The "arena's row count" sentence now holds only for the S1F=0 plan.:861-864"would size … past" should be "can".- The
ValueErroratcompact_plan.py:567-573reports m-tiles even for non-s1f plans; print that clause only whens1f.
Checked and fine:
- Dependencies: none. Every symbol used is on main. #7410 and #8189 only overlap (rebase).
- LDS table: the body's numbers reproduce (572→76 KiB at align 16).
- Real S1F steps: they stay within
plan_cap, including under graph capture and on the profiling step. - Compiles: no extra compiles.
- SiTUv2 betas: they arrive as Python floats, the same scalars the unfused GEMM1 uses.
- CI: the MI35X failures (
test_flydsl_hgemm.py,test_gemm_a4w4.py) are unrelated.
Reviewed at 45fbfb7 (deep, two independent passes, CPU LDS replay + tile_reasons microbench). Already fixed: n/a (first review).
… cap; SiTUv2 in the stage-1 kernel The S1F compact plan keeps one LDS word per destination m-tile (t2e), sized from the compact rows it is compiled with. It took the arena's row count, so a large arena (Kimi-K3 EP8: 8 ranks x 16384 tokens x top-16, about 2.1M rows) asked for 572 KiB of LDS at 16-row tiles, and the plan's first launch failed with hipErrorInvalidValue. A step runs S1F only while its receive bound is within max_recv(), so the stage-1 plan now bounds its rows by that (61-76 KiB for Kimi-K3 EP8). compile_tdm_compact_plan checks its LDS against the 320 KiB a gfx1250 workgroup has and names the numbers when it does not fit, and tile_reasons() keeps the dispatch + GEMM1 path for a tile whose stage-1 plan would not fit. The stage-1 kernel's GEMM1 already has the SiTUv2 epilogue (stage1_act 3) but was handed betas of 1.0: make_s1f_stage1 now takes f32_situ_beta and f32_situ_linear_beta, the GEMM1 hook passes them and accepts stage1_act 3, and eligible() admits ActivationType.Situv2. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…SiTUv2 - --max_tokens_per_rank sizes the arena apart from -tpr, so a small step runs on an arena sized for wider ones, as a serving engine's decode does. That is the case where the S1F compact plan used to overflow LDS. - Each forward passes recv_token_bound = world x -tpr, as ATOM does. Without it the step takes the arena's bound and S1F turns itself off past max_recv(). With the default arena the two are equal, so default runs are unchanged. - --activation situv2 (with --situ_beta / --situ_linear_beta, Kimi-K3's 4 / 25) runs SiTUv2 on the device and in the fp32 reference. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- PLAN_LDS_BYTES, dispatch_tdm's _LDS_BUDGET and the stage-1 CTA check take the LDS size from aiter.jit.utils.chip_info.get_lds_capacity_bytes. - compact_plan_lds_bytes and the plan kernel take their table sizes from one _plan_geometry. After its last allocation the kernel checks, at trace time, that the allocator handed out exactly the bytes sized. - _Stage1Fusion.tile_reasons is worked out once per alignment; arm() resets the cache. - The next step's plan is judged by the next step: _step is restored after _launch_plan, not before it. - plan_cap pads to the arena's tile, as no step aligns past it, and takes no alignment. Comment and message fixes. - tests/test_mega_moe_gfx1250_recipe.py: Kimi-K3 EP8 plan LDS at the arena's rows and at plan_cap, tile_reasons' LDS reason, and traced plan kernels for the allocator check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
45fbfb7 to
21120ee
Compare
|
@valarLip thanks. I rebased onto main
On #7921: its prefill S1F runs only on shapes whose receive cap is unbounded (DSV4.1 Flash EP2 / EP4, |
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (2)
Thanks for the rework. Items 1, 2, 3, 6 and 7 from round 1 are fixed at this head, and the code for item 5 is in:
PLAN_LDS_BYTESand the other two gfx1250 LDS sizes now useget_lds_capacity_bytes._plan_geometryfeeds bothcompact_plan_lds_bytesand the kernel, andcompact_plan.py:867raises at trace time unlesssmem.allocated_bytesequals the sized bytes. I compared the size list with everysmem.allocateat:705-786: same order and alignment.tile_reasonsis worked out once per alignment and reset byarm().- The ahead plan keeps
_stepon the next step through_launch_plan(try/finally). plan_cap()usesgeo.tile_m, and the comments and theValueErrorare fixed.
- Post the validation from round-1 item 4, plus a run of the new tests.
- S1F is the default, and this PR turns on SiTUv2 + S1F for Kimi-K3. None of these numbers are posted yet: SiTUv2 and a Silu control with S1F on vs off against the fp32 reference, per-layer decode time on vs off, and GSM8K against S1F=0.
- The new tests in
tests/test_mega_moe_gfx1250_recipe.py(plan LDS bound, LDS reason, traced allocator check) have never run: no CI lane runs this file, and the body says they are unverified at this head. Please paste their pytest output from the gfx1250 node.
- Nit: reuse the existing SiTUv2 reference in
op_tests/multigpu_tests/bench_mega_moe.py:625-631.RefModel._ffnhand-writesb*tanh(g/b)*sigmoid(g) * lb*tanh(u/lb). That isaiter.moev2.reference.torch_moe.situv2(torch_moe.py:134-142), re-exported asaiter.fused_moe.situv2.- Call
situv2(gate, up, b, lb)from there.
Root cause vs patch
Root problem: the stage-1 plan sized its per-m-tile LDS table by the arena's rows instead of the rows an S1F step can receive. This head compiles stage-1 plans against the S1F receive cap's rows. The LDS size and the allocations come from one geometry, with a trace-time check, and a plan that still does not fit falls back to dispatch + GEMM1. SiTUv2 is enabled as a generic activation (stage1_act 3 already exists in GEMM1), not a model branch. Verdict: root fix. What is left is validation.
Prior asks: 1, 2, 3, 6 and 7 are fixed. 4 is open (the bench edits landed, the numbers have not). 5 has its code in but has not run.
CI: green. No lane exercises the gfx1250 S1F path. #8189 touches the same files (rebase only).
Reviewed at 21120ee (round 2, pass A; true delta = 45fbfb7 rebased onto the new merge base -> 21120ee). Already fixed: LDS query, shared plan geometry + allocator check, tile_reasons memo, ahead-plan step, plan_cap/text, host tests added.
…DSpark draft head BF16 tuning, empty-row GEMM fix (#9096) * MegaMoE gfx1250: decode megakernel (dispatch, GEMM1, GEMM2 and combine in one launch), Kimi-K3 shapes (#7345 @ a559927, head 2026-12-01T13:13:28Z) Opt-in with AITER_MEGAKERNEL=1. Each step chooses by its receive bound: - "slots" (fixed per-expert slots) for bounds up to SLOTS_RECV (2048; with IOD-placed weights, 3072 for Kimi-K3's 3584 x 3072); - "compact" up to COMPACT_MAX_TOKENS per rank; - otherwise the staged path. Off by default, so nothing changes unless the variable is set. The PR's tests show the output bitwise equal to the staged path. Ported onto k3-455-dev as the squashed PR diff (merge base ce334d0). Four files conflicted: - s1f_ctl.py: kept k3-455-dev's receive caps (_S1F_MAX_RECV 4096 plus #8189's _S1F_MAX_RECV_BY_SHAPE) and its s1f_max_recv(); the PR's base had no cap. Both __init__ fields are kept (#8483's _plan_lds, the PR's _packed_sc). - s1f_stage1.py: added the PR's s1f_apre_* helpers. The stage-1 launch keeps #8483's SiTUv2 arguments and adds the PR's value_attrs. - gemm_common_gfx1250.py: kept k3-455-dev's prefetch_kernel_code(max_bytes=...), a superset of the PR's. - dsr1_tuned_grouped_fmoe.csv: kept k3-455-dev's DeepSeek-R1 rows and dropped the PR's two DSR1 rows (not Kimi-K3). Placement is detected from the GEMM builder's signature (BUILDER_LOC), so without IOD placement the placed paths stay off. Co-Authored-By: Claude Opus 5.5 <[email protected]> * MegaMoE gfx1250 compact plan: re-seal the hist row head from each issuing wave before its TDM store (#8880 @ 4214819, head 2026-11-28T16:07:47Z) Fixes the intermittent S1F spin trap (HSA_STATUS_ERROR_EXCEPTION 0x1016): the TDM that sends a hist row to rank w is issued by wave w and could read the row head before wave 0's LDS tag was visible to it. Every sending wave now re-seals the tag before its store. Kimi-K3's D runs this compact plan (dispatch=compact). (cherry picked from commit 4214819) Co-Authored-By: Claude Opus 5.5 <[email protected]> * bench_mega_moe: SiTUv2, a model-sized instance and a simulated EP size, for Kimi-K3's A/Bs --act situv2 (with --situ_beta / --situ_linear_beta), --max_tpr / --recv_bound and --sim_ep N (a rank of an EP-N group on fewer GPUs, e.g. EP8 on one tray with -e 448 --sim_ep 8), all opt-in. Same commit as on the IOD branch (zejun/k3-455-dev-1201-iod); here it is merged with #7345's bench: #7345's routing checks stay, and the step bounds come from resolve_step_bounds, which equals #7345's inline logic without --sim_ep. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Config] Kimi-K3 gfx1250 LM head and DSpark draft head BF16 rows (N 163840, K 7168), M 1-256 Neither head had a gfx1250 row, so both ran the default bandwidth-bound gemm_a16w16 at 3.4-4.3 TB/s (one D decode step at c192: 546-603 us for the target head, ~360-600 us for the draft head). A FlyDSL hgemm whose M tile covers every row reads the 2.35 GB weight once: per M bucket (32 / 64 / 96 / 128 / 160 / 192 / 256 rows) the best block_n / block_k / stages / waves of a tdm or ft sweep, measured with 2 weight copies alternated in a CUDA graph on one MI455X (bf16 error 3e-3, fp32 3e-6 against an f32 matmul): rows bf16 out fp32 out 1-32 1.04-1.16x 1.0-1.12x (rows <= 8 keep production) 33-64 1.25-1.37x 1.31-1.35x 65-128 1.43-1.62x 1.53-1.63x 129-160 2.04-2.44x 2.10-2.43x (c192's verify / draft rows) 161-192 2.33-2.49x 2.42-2.66x 193-256 2.10-2.72x 2.17-2.77x At c192 (133-175 rows) that is ~300-500 us a head, ~0.6 ms a D step. Co-Authored-By: Claude Opus 5.5 <[email protected]> * tuned_gemm: an empty-row FlyDSL GEMM returns the empty product instead of launching An idle DP rank's dummy step runs its GEMMs with M = 0, and the lookup pads M = 0 into a tuned row: with a FlyDSL row there (Kimi-K3's head rows, the commit before) validate_gemm_gfx1250_config refused the empty dimension and the engine died at its first prefill ("dimensions, tiles, stages, wave counts and WMMA sizes must be positive integers"; DP4 one-tray D, 12-02). Return the [0, N] result (or the caller's buffer) without a launch, as the default kernel effectively did. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Honglie Yi <[email protected]>
…nas and run SiTUv2 in the stage-1 kernel (#8483 @ 45fbfb7, head 2026-11-23T06:55:24Z) Snapshot of #8483. The stage-1 compact plan sizes its per-m-tile LDS table by the S1F receive cap instead of the arena (Kimi-K3 EP8 at 16384 tokens a rank: 569 KiB -> 73 KiB, limit 320 KiB), and SiTUv2 runs in the stage-1 kernel with its betas. Validated with #8189 on two MI455X trays: K3 DP8EP8 serving with AITER_MEGA_S1F=1, every decode step on s1f_stage1, GSM8K unchanged (wuhuikx/LLM-Booster#722 comment 7121412936). Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 7ecc055) Rebase onto main 12-03: main now has #8189's final head (the k3 copy of #8189 is dropped). Two textual conflicts, both sides kept: s1f_ctl.py _Stage1Fusion.__init__ sets main's _packed_sc and this PR's _plan_lds; s1f_stage1.py launch passes this PR's f32_situ_beta / f32_situ_linear_beta before main's value_attrs keyword (the PR head's order). Multi-GPU MegaMoE not run on the rebased tree. Updated 12-03 to the PR head #8483 @ 21120ee: folds in the PR's later commits de043bb bench_mega_moe: --max_tokens_per_rank, the step's receive bound, and SiTUv2; 21120ee mega_moe gfx1250 S1F: address review of the stage-1 plan LDS bound.
…DSpark draft head BF16 tuning, empty-row GEMM fix (#9096) * MegaMoE gfx1250: decode megakernel (dispatch, GEMM1, GEMM2 and combine in one launch), Kimi-K3 shapes (#7345 @ a559927, head 2026-12-01T13:13:28Z) Opt-in with AITER_MEGAKERNEL=1. Each step chooses by its receive bound: - "slots" (fixed per-expert slots) for bounds up to SLOTS_RECV (2048; with IOD-placed weights, 3072 for Kimi-K3's 3584 x 3072); - "compact" up to COMPACT_MAX_TOKENS per rank; - otherwise the staged path. Off by default, so nothing changes unless the variable is set. The PR's tests show the output bitwise equal to the staged path. Ported onto k3-455-dev as the squashed PR diff (merge base ce334d0). Four files conflicted: - s1f_ctl.py: kept k3-455-dev's receive caps (_S1F_MAX_RECV 4096 plus #8189's _S1F_MAX_RECV_BY_SHAPE) and its s1f_max_recv(); the PR's base had no cap. Both __init__ fields are kept (#8483's _plan_lds, the PR's _packed_sc). - s1f_stage1.py: added the PR's s1f_apre_* helpers. The stage-1 launch keeps #8483's SiTUv2 arguments and adds the PR's value_attrs. - gemm_common_gfx1250.py: kept k3-455-dev's prefetch_kernel_code(max_bytes=...), a superset of the PR's. - dsr1_tuned_grouped_fmoe.csv: kept k3-455-dev's DeepSeek-R1 rows and dropped the PR's two DSR1 rows (not Kimi-K3). Placement is detected from the GEMM builder's signature (BUILDER_LOC), so without IOD placement the placed paths stay off. Co-Authored-By: Claude Opus 5.5 <[email protected]> * MegaMoE gfx1250 compact plan: re-seal the hist row head from each issuing wave before its TDM store (#8880 @ 4214819, head 2026-11-28T16:07:47Z) Fixes the intermittent S1F spin trap (HSA_STATUS_ERROR_EXCEPTION 0x1016): the TDM that sends a hist row to rank w is issued by wave w and could read the row head before wave 0's LDS tag was visible to it. Every sending wave now re-seals the tag before its store. Kimi-K3's D runs this compact plan (dispatch=compact). (cherry picked from commit 4214819) Co-Authored-By: Claude Opus 5.5 <[email protected]> * bench_mega_moe: SiTUv2, a model-sized instance and a simulated EP size, for Kimi-K3's A/Bs --act situv2 (with --situ_beta / --situ_linear_beta), --max_tpr / --recv_bound and --sim_ep N (a rank of an EP-N group on fewer GPUs, e.g. EP8 on one tray with -e 448 --sim_ep 8), all opt-in. Same commit as on the IOD branch (zejun/k3-455-dev-1201-iod); here it is merged with #7345's bench: #7345's routing checks stay, and the step bounds come from resolve_step_bounds, which equals #7345's inline logic without --sim_ep. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Config] Kimi-K3 gfx1250 LM head and DSpark draft head BF16 rows (N 163840, K 7168), M 1-256 Neither head had a gfx1250 row, so both ran the default bandwidth-bound gemm_a16w16 at 3.4-4.3 TB/s (one D decode step at c192: 546-603 us for the target head, ~360-600 us for the draft head). A FlyDSL hgemm whose M tile covers every row reads the 2.35 GB weight once: per M bucket (32 / 64 / 96 / 128 / 160 / 192 / 256 rows) the best block_n / block_k / stages / waves of a tdm or ft sweep, measured with 2 weight copies alternated in a CUDA graph on one MI455X (bf16 error 3e-3, fp32 3e-6 against an f32 matmul): rows bf16 out fp32 out 1-32 1.04-1.16x 1.0-1.12x (rows <= 8 keep production) 33-64 1.25-1.37x 1.31-1.35x 65-128 1.43-1.62x 1.53-1.63x 129-160 2.04-2.44x 2.10-2.43x (c192's verify / draft rows) 161-192 2.33-2.49x 2.42-2.66x 193-256 2.10-2.72x 2.17-2.77x At c192 (133-175 rows) that is ~300-500 us a head, ~0.6 ms a D step. Co-Authored-By: Claude Opus 5.5 <[email protected]> * tuned_gemm: an empty-row FlyDSL GEMM returns the empty product instead of launching An idle DP rank's dummy step runs its GEMMs with M = 0, and the lookup pads M = 0 into a tuned row: with a FlyDSL row there (Kimi-K3's head rows, the commit before) validate_gemm_gfx1250_config refused the empty dimension and the engine died at its first prefill ("dimensions, tiles, stages, wave counts and WMMA sizes must be positive integers"; DP4 one-tray D, 12-02). Return the [0, N] result (or the caller's buffer) without a launch, as the default kernel effectively did. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Honglie Yi <[email protected]> (cherry picked from commit 4c4e333) Rebase onto main 12-03: main since has #8189's final head, #8889 (packed A only where its stores fit storecnt, tdm_b_th from the tuned row) and #8737 (LDS-to-TDM flush, C staged at the arena tail). Resolved: s1f_ctl.py keeps main's _s1f_gemm_opts / _s1f_packed_a_ok / s1f_prefill_tile(config, ...) / _s1f_warps(config, ...) (this commit's same-purpose _gemm_opts method and (world_size, topk) helpers are dropped) and adds this commit's IOD placement next to main's tdm_b_th: _launcher / _precompile take both, the launcher key and the precompile keys carry (tdm_b_th, placed), make_s1f_stage1 gets tdm_b_th, b_placed, loc_group. s1f_stage1.py: the producer role is this commit's s1f_produce(_PCtx(...)) (its body is main's inline producer, packed A and WAIT_STEPS included); OP_STORES / the storecnt check use main's s1f_packed_a_op_stores / s1f_packed_a_fits (R is 8 there); make_s1f_stage1 takes tdm_b_th and b_placed / loc_group; imports both. dispatch_compact.py: main's 4-tuple _compact_gemm_tiles. mxfp4_preshuffle_gfx1250_tdm.py: main's single C_OFF staging (arena tail, flush scratch at the head) is kept; this commit's a/c cache modifiers, scatter cache policy and defer_ep_wait are added, defer_ep_wait moving C_OFF past the input stages (and growing the arena) instead of this commit's C_EP_OFF / C_Q_OFF; the kernel name carries both suffixes. kimik3_bf16_tuned_gemm.csv: the 504 LM / draft head rows replayed by key. Multi-GPU MegaMoE / megakernel not run on the rebased tree. Rebase onto main 12-03: after #8483 was updated to its PR head 21120ee (which adds its own bench_mega_moe flags --max_tokens_per_rank / --activation / --situ_beta), op_tests/multigpu_tests/bench_mega_moe.py keeps this commit's version (--max_tpr / --recv_bound / --act / --situ_beta / --sim_ep cover the same knobs); taking both would define --situ_beta twice.
Summary
Two fixes so that MegaMoE's stage-1 fusion (S1F: dispatch + GEMM1 in one kernel,
AITER_MEGA_S1F=1, the default) runs Kimi-K3 EP8 decode on gfx1250:hipErrorInvalidValue.Motivation
Kimi-K3 DP8EP8 with MegaMoE (compact dispatch, fp4 wire, fused combine) cannot run with
AITER_MEGA_S1F=1on gfx1250, so it is served withAITER_MEGA_S1F=0. With S1F on, every rank printshipModuleLaunchKernel(...) failed with 'hipErrorInvalidValue'on the first decode step, and torch then raisesCUDA error: invalid argumentat an unrelated op.Root cause.
compile_tdm_compact_plan(s1f=True)keepst2e, one i32 per destination m-tile, in LDS:ceil(compact_cap / tile_m)entries._CompactDispatch._plan_forcompiled it with the arena's row count (geo.cap): about 2.1M rows for Kimi-K3 EP8 (8 ranks x 16384 tokens x top-16), at the 16-row tile Kimi-K3's grouped CSV picks for decode.Only decode steps fail: a step whose receive bound exceeds
max_recv()(4096 at EP8 top-16) runs the S1F=0 plan, which has not2e. DSV4.1 EP8 (48 experts a rank, top-6) runs S1F at decode because its arena is about 5x smaller.SiTUv2.
_Stage1Fusion.eligible()admitted only Silu and Swiglu.build_gemm_a8w4_tdm_taskalready has the SiTUv2 epilogue (stage1_act3), butmake_s1f_stage1called it with both betas fixed at 1.0.Changes
compact_plan.py:compact_plan_lds_bytes()computes the plan's dynamic LDS. It and the kernel take their table sizes from one_plan_geometry, and the kernel checks at trace time, after its last allocation, that the allocator handed out exactly the bytes sized.PLAN_LDS_BYTESisget_lds_capacity_bytes("gfx1250").compile_tdm_compact_planraises aValueErrornaming the sizes instead of compiling a plan whose launch fails without a reason.s1f_ctl.py:_Stage1Fusion.plan_cap(): the row bound of stage-1 plans, the S1F receive cap's rows (min(config.max_recv, max_recv())tokens) padded to the arena's tile, capped by the arena's count. A step runs S1F only while its receive bound is withinmax_recv(), so its rows fit.tile_reasons()keeps the dispatch + GEMM1 path for a tile whose stage-1 plan would not fit, and is worked out once per alignment (reset byarm()).eligible()admitsActivationType.Situv2; the GEMM1 hook acceptsstage1_act3 and passessitu_beta/situ_linear_beta.s1f_stage1.py: the launcher and the kernel takef32_situ_beta/f32_situ_linear_betaand hand them to the embedded GEMM1 (they werefx.Float32(1.0)).stages/dispatch_compact.py:_plan_forcompiles stage-1 plans withfusion.plan_cap(); the S1F=0 plan keeps the arena's row count. A plan prefetched for the next layer is judged by the next step's receive bound (_stepis restored after_launch_plan).dispatch_tdm.py,s1f_stage1.py: the two other hard-coded gfx1250 LDS sizes use the same query.op_tests/multigpu_tests/bench_mega_moe.py:--max_tokens_per_rank(the arena apart from the step's tokens), the step's receive bound passed as ATOM passes it, and--activation situv2with--situ_beta/--situ_linear_betaagainst an fp32 reference.tests/test_mega_moe_gfx1250_recipe.py: the Kimi-K3 EP8 plan LDS at the arena's rows and atplan_cap,tile_reasons' LDS reason, and traced plan kernels for the allocator check.No new environment variables. Silu / Swiglu kernels compile as before (the betas are unused there). #8189 (open) edits the same S1F files; whichever lands second rebases.
Performance (if applicable)
Pending, on 8 x MI455X (gfx1250): Kimi-K3 EP8 decode per-layer time with S1F on vs off, and the decode step time of a DP8EP8 server.
Testing
gfx1250-only code. See "Validation and unverified scope".
Documentation
Internal behaviour of the S1F path only.
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
21120ee4aBehavior and intent
Validation and unverified scope
Done:
rocm/fw-bringup:gfx1250-atom-k3-20261120, aiter226aa69a, whose four S1F files equalled main's),bench_mega_moe.pywith this PR's options: Kimi-K3 MoE shapes at EP4 (-e 896 -k 16 -hd 3584 -id 3072 -q a4w4_mxfp4 --dispatch_wire fp4 --combine_quant mxfp4 --stage1_fused true --stage2_fused true), 8 tokens a rank,AITER_TDM_TILE_M=16.--max_tokens_per_rank 32768(plan 556 KiB) reproduces the failure:hipModuleLaunchKernel ... hipErrorInvalidValue, thenCUDA error: invalid argumentat an unrelated op, as in the Kimi-K3 EP8 server.AITER_TDM_TILE_M=64) got past the plan launch. It then hung in a platform fault of those trays (MES not responding) that every MegaMoE run on them hit, so it gave no accuracy or timing.compact_plan_lds_bytes; the reviewer's CPU replay of the allocations matched it.Unverified at this head (needs a gfx1250 node with mori and a built aiter):
tests/test_mega_moe_gfx1250_recipe.py, including the traced plan kernels;AITER_MEGA_S1F=1: GSM8K against S1F=0, and the decode step time.No PR CI lane runs
tests/test_mega_moe_gfx1250_recipe.py:split_tests.shtakes onlytest_flydsl_aot_*.pyand the moev2 files fromtests/, and the file skips withoutmori.cco, which only the multi-GPU job installs.PR-specific question
op_tests/multigpu_tests/bench_mega_moe.pyis the only changed op_tests file, and it is a benchmark, not a canonical test. Before this PR it could not reach the failure: its arena was sized by the step's own token count, and it passed no receive bound, so S1F turned itself off. With--max_tokens_per_rankand the step's receive bound it reproduces thehipErrorInvalidValueof the Kimi-K3 server on unpatched code, and--activation situv2checks the SiTUv2 stage-1 path against its fp32 reference. No other test runs S1F with a large arena or SiTUv2.Changed op tests
op_tests/multigpu_tests/bench_mega_moe.py: adds--max_tokens_per_rank(the arena apart from the step's tokens), passes the step's receive bound as ATOM does so that the step can run S1F, and adds--activation situv2with--situ_beta/--situ_linear_betaagainst an fp32 reference. It is the reproduction of this PR's failure and the bench for the S1F on/off comparison; no other op test covers either.🤖 Generated with Claude Code