Skip to content

[k3-455-dev] Kimi-K3 c192 (MI455X): MegaMoE #7345 port + #8880, LM / DSpark draft head BF16 tuning, empty-row GEMM fix - #9096

Merged
zejunchen-zejun merged 5 commits into
k3-455-devfrom
zejun/k3-455-dev-1202-c192
Dec 2, 2026
Merged

zejunchen-zejun merged 5 commits into
k3-455-devfrom
zejun/k3-455-dev-1202-c192

Conversation

@zejunchen-zejun

Copy link
Copy Markdown
Contributor

Summary

This PR brings the aiter code behind the Kimi-K3 1P1D c192 numbers measured on MI455X (E17) on 12-02 into k3-455-dev.
They are 58.5 tok/s/user and 530 tok/s/GPU, MLPerf Endpoints v1.0, full 2x613 window, with ROCm/ATOM#4106. It is the
build those runs used, zejun/k3-455-dev-1201-heads-mla @ e5ea5d2, minus its two MLA q7/q8 row-packing commits:
those were disabled in every run (AITER_MLA_PS1_PACK_ROWS=0), and their code objects need a re-export first (see
#8736).

Changes (5 commits on k3-455-dev 82eec19)

commit what default behavior
4768449 Port of #7345 @ a559927: MegaMoE gfx1250 decode megakernel (dispatch, GEMM1, GEMM2 and combine in one launch) for Kimi-K3 shapes, together with that PR's rework of the S1F stage 1 (s1f_stage1.py, s1f_ctl.py), the TDM GEMM (mxfp4_preshuffle_gfx1250_tdm.py), gemm_common_gfx1250.py, and the DSR1 / DSv4.1 tuned MoE CSVs megakernel opt-in (AITER_MEGAKERNEL=1). The S1F / TDM / GEMM rework is on the default path.
a5fc893 Port of #8880 @ 4214819 (Honglie Yi): MegaMoE compact plan re-seals the hist row head from each issuing wave before its TDM store fix, default path
eba0d45 bench_mega_moe.py: SiTUv2 activation, a model-sized instance, a simulated EP size (--act, --sim_ep) op_tests only
969a701 Kimi-K3 gfx1250 tuned rows for the LM head and the DSpark draft head, BF16, N 163840, K 7168, M 1-256 tuning config
0973db3 tuned_gemm: a FlyDSL GEMM with zero rows returns the empty product instead of launching fix

Validation

E17 05-08, Kimi-K3 + DSpark k=7, 1P1D (P PP8xTP1, D DP8 EP8), c192, MLPerf Endpoints v1.0, false mode. This code plus
the disabled MLA objects, with ROCm/ATOM#4106:

run window interactivity tok/s/GPU GSM8K strict-match turns
R11b 2x613 (1,980 s) 52.6 443 0.9674 30,787, 0 failed
R11c 1x613 (early window only) 68.2 480 0.9651 9,547, 0 failed
R11d (+ ATOM #4106's c192 defaults) 2x613 (1,660 s) 58.5 530 0.9704 31,064, 0 failed
  • Every run passed the multi-turn check (8/8) and the 64-way DSpark acceptance probe (turn 1 0.321-0.322).
  • bench_mega_moe.py ep4sim (EP4 simulating EP8, K3 decode MoE, 128-256 tokens a rank): MEGA-CHECK passes.

Not verified:

Dependencies / breaking changes

None. No new dependencies; no API change.

🤖 Generated with Claude Code

zejunchen-zejun and others added 5 commits December 2, 2026 04:13
…e 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]>
…uing 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]>
…e, 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]>
…63840, 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]>
…d 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]>
@zejunchen-zejun
zejunchen-zejun merged commit 4c4e333 into k3-455-dev Dec 2, 2026
@zejunchen-zejun
zejunchen-zejun deleted the zejun/k3-455-dev-1202-c192 branch December 2, 2026 14:32
gbyu-amd pushed a commit that referenced this pull request Dec 3, 2026
…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.
gbyu-amd added a commit that referenced this pull request Dec 3, 2026
…does (_ptdm / _ptdmi)

The rebase onto main 12-03 dropped k3-455-dev's pre-merge copy of #8031
(b445370, PR head 520f0bb) for main's merged deca29e. The two spell a
TDM HGEMM's wave schedule differently: the PR head wrote it as a name token,
`..._gm{g}_i0_ptdm_gfx1250` / `..._gm{g}_i1_ptdm_gfx1250`, while main's
final version folds it into the policy, `..._gm{g}_ptdm_gfx1250` (plain) /
`..._gm{g}_ptdmi_gfx1250` (interleaved), and its _HGEMM_KERNEL_RE has no
`_i` token. Main converted its own CSV rows; the K3 rows tuned on the PR head
kept the old spelling, so get_flydsl_hgemm_kernel_params() returns None for
them and every lookup logs "not recognized by the current catalog; falling
back to next candidate" and runs the default Triton gemm_a16w16 (C1203 on
e17: 1332 warnings per D tray, all during graph capture).

Rows affected, all gfx1250 bf16 -> bf16:
- kimik3_bf16_tuned_gemm.csv, 256 rows from #9096: LM / DSpark draft head,
  N 163840, K 7168, M 1-256;
- kimik3_bf16_tuned_gemm.csv, 20 rows from #8348: latent-MoE
  routed_expert_down_proj (N 3584, K 7168) and routed_expert_up_proj
  (N 7168, K 3584), M 1-32768;
- op_tests/k3_latent_bf16_tuned_rows.csv, the same 20 latent rows.

Rename only: `_i0_ptdm_` -> `_ptdm_`, `_i1_ptdm_` -> `_ptdmi_`; no other
byte changes. Every renamed name parses with this tree's
get_flydsl_hgemm_kernel_params() (TDM validator included) to the same
tile / stages / waves / split-K / group_m / interleave the old parser read
from the old name, and no file in the tree keeps `_i[01]_ptdm`. The TDM
kernel builder is unchanged between the two trees apart from the cache-policy
constant's name and the AOT factory wrapper.

Co-Authored-By: Claude Opus 5.5 <[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