Skip to content

[Config] [Tuning][gfx950] Retune MiniMax-M3.1 TP4 A16W4 decode rows (E=128, top-4) for 8/16/32/64/128 tokens - #7414

Merged
zufayu merged 1 commit into
ROCm:mainfrom
Fangzhou-Ai:m31-a16w4-rows-v4
Nov 12, 2026
Merged

zufayu merged 1 commit into
ROCm:mainfrom
Fangzhou-Ai:m31-a16w4-rows-v4

Conversation

@Fangzhou-Ai

@Fangzhou-Ai Fangzhou-Ai commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What

aiter/configs/model_configs/minimax_m3_a16w4_tuned_fmoe.csv: replace the FlyDSL A16W4 kernel pair of the
E=128, topk=4, model_dim=6144, inter_dim=768 (TP4) rows for token = 8, 16, 32, 64, 128.
Rows for token = 1, 2, 4, 256 (#6942) and all A4W4 rows are untouched. No code change, decode rows only.

token stage 1 (before, #6942) -> (after) stage 2 (before) -> (after)
8 t16x32x128_w4_xcd1_kw4 -> t16x32x128_w2_xcd1_kw4 t16x256x128_atomic_xcd4 -> t16x128x256_reduce_bnt2
16 t16x32x128_w4_xcd1_kw2 -> t16x32x128_w2_xcd1_kw4 t16x128x256_atomic -> t16x256x128_atomic_bnt2_persist
32 t16x128x256_w2_xcd1 -> t16x32x128_w4_xcd1_kw2 t16x256x128_atomic_bnt2_xcd4 -> t16x256x256_reduce_bnt2
64 t16x192x128_w2_xcd1 -> t16x32x128_w2_xcd1_kw4 t16x256x256_atomic_bnt2_xcd4 -> t16x256x256_reduce_bnt2_xcd4_persist
128 t16x128x128_w3_xcd1 -> t16x32x128_w2_kw4 t16x256x128_atomic_bnt2 -> t16x256x256_reduce_bnt2_xcd4_persist

(all kernel names are flydsl_moe{1,2}_abf16_wfp4_bf16_<suffix>; every name exists in the FlyDSL registry of aiter main and of the 0.1.27 wheel.)

Why

#6942 tuned these rows with uniformly random routing. MiniMax-M3.1 does not route uniformly. I dumped the real per-layer top-k ids
(57 MoE layers) during decode of an AgentX replay (c16, ~15 min measured) and during decode of a random-token benchmark:

tokens in the step distinct experts per layer, real AgentX replay (p10..p90) random-token prompts uniform random
24 46.0 (37..54) 22 68
32 53.2 (43..65) 27 82
40 63.7 (55..74) 30 92
64 71.3 (63..83) 36 111
96 88.9 (76..101) 42 122

(Snapshots are the last step seen for each token count and may include mixed prefill+decode steps; real routing is about 65-75% of uniform.)
At this concentration the small tile_n=32 + k_wave FlyDSL kernels win and the token=64 row of #6942 (t16x192x128_w2_xcd1) is
slower than the CK-tile default.

How the rows were found

Swept the whole FlyDSL a16w4 registry for tile_m=16 (304 stage-1, 64 stage-2 names from get_flydsl_stage{1,2}_kernels('bf16','fp4','bf16')) with
fused_moe end to end: stage 1 with a fixed stage 2, then stage 2, then a refit of the top candidates, each time replaying the real routing
(57 layers, one CUDA graph, 6 distinct weight copies so weights do not stay in MALL, 1 snapshot per token count while sweeping, 4 for the final ranking).
The landscape is flat among the top few (within ~1-2%) and the winners are all the tile_n=32, tile_k=128 family.
us1/us2/us/err2 in the CSV are measured with uniform random routing at token=T (the tuner's convention; profiler kernel times for us1/us2,
graph time for us); err2 is the max-abs error of the whole fused op against a bf16 reference built from the dequantised MXFP4 weights, in % of max|ref|.
err1 is left empty (stage 1 alone was not checked).

Kernel-level results, per MoE layer (us, replay of the real AgentX routing, 57 layers/graph, MI355X, aiter 0.1.27 wheel)

My measurement (tokens replayed per bucket: 8 / 16 / 24,32 / 40..64 / 72..120):

bucket default (CK-tile, no row) aiter main (#6942 rows) this PR
8 43.2 43.1 40.2 (-7%)
16 60.0 60.0 56.2 (-6%)
32 79.9 82.0 77.8 (-5% vs #6942)
64 92.3 103.5 (+12%) 91.2 (-12% vs #6942)
128 92.8 95.7 89.3 (-7% vs #6942)

Gains vs the default CK-tile path are 1-7% under real routing (largest at 8/16 tokens), and vs #6942 up to 12% at 64 tokens.
Uniform-routing bound (all experts touched, the regime #6942 tuned for). In my same-GPU harness (M=8/16/32/64/128, us per call): default 57.7/84.1/119.1/145.7/167.6, #6942 51.8/77.6/111.5/139.4/154.2, this PR 50.8/79.2/118.9/139.8/158.8, i.e. between 2% faster and 7% slower than #6942. aiter's own gemm_moe_tune.py --run_config on current aiter main (uniform random routing, final rows, #6942 -> this PR, us): token 8: 50.4 -> 55.4, 16: 77.0 -> 81.8, 32: 107.0 -> 118.9, 64: equal, 128: 164.9 -> 175.0, i.e. 6-11% slower than #6942 at 8/16/32/128 tokens under uniform routing. These rows trade that for the real-routing results above, where routing is concentrated (46-89 distinct experts per layer instead of 68-122) and they are 1-7% faster than the default and up to 12% faster than #6942. Whether this matters depends on how concentrated the routing is in the target workload.
The GPU-to-GPU/run-to-run spread of these microbenchmarks is a few percent.

Correctness

  • Max-abs error of the fused MoE output vs the bf16 reference of the dequantised weights, using the real routing ids, 13 token counts 8..120,
    3 snapshots x 3 layers each (% of max|ref|, max / mean): default 0.60-0.91 / 0.49-0.66, this PR 0.52-0.77 / 0.45-0.55. No NaNs.
    Under uniform and correlated synthetic routing at M=8..192: 0.32-0.56%, same as the default path (0.35-0.52%).
  • gemm_moe_tune.py --run_config on current aiter main (JIT-built in an isolated directory; main = 41c2528) runs the new rows through production fused_moe and reports all of them OK against its torch reference.
  • Kernel-name check: all new names exist in get_flydsl_stage{1,2}_kernels('bf16','fp4','bf16') on aiter main and on the 0.1.27 wheel.

End-to-end (MiniMax-M3.1-Flash-Quark-MXFP4, TP4 on 4x MI355X, vLLM main + #63483 + #64448 + local attention patches, aiter 0.1.27, DSpark, DBO off)

Real AgentX replay (semianalysis_cc_traces_weka_062126, InferenceX harness 1.0.12, c16, 3600 s measured phase, one server at a time on the same 4 GPUs).
Arms differ only in the tuned rows (VLLM_ROCM_AITER_EXTRA_FMOE_CONFIGS=0/AITER_CONFIG_FMOE); the rest (vLLM router GEMM change, attention) is identical.
OFF = no E=128 rows (CK-tile default); #6942 = aiter main's rows; PR = this PR's rows on top of #6942 (the 8/16/32/64/128 rows replaced).

metric (c16) OFF #6942 PR earlier ON sample (older version of these rows)
P90 interactivity (tok/s) 194.5 190.9 200.1 195.1
P50 interactivity (tok/s) 275.2 277.7 282.7 283.8
ITL p50 (ms) 3.63 3.60 3.54 3.52
ITL p90 (ms) 5.14 5.24 5.00 5.13
TTFT p50 / p90 (s) 0.353 / 1.028 0.369 / 1.123 0.329 / 0.964 0.347 / 1.070
total tok/s/GPU 27763 27726 27890 27810

Reading: the PR arm has the best nominal ITL/interactivity, but OFF vs PR differs by +2.9% (P90 interactivity) while TTFT p50 moved -6.8%, which decode rows cannot cause
(they affect eager prefill only through the tiny 8..255-token a16w4 path), so the noise of one 3600 s replay is at least ~5% and the c16 replay does not resolve the
effect of these rows
. Decode-only controlled benchmark (random-token 150K prompts, N requests, 8 tokens each, decode step p50, rows only vs #6942 rows, earlier version of the same rows):
-3.0% (N=3) -2.8% (N=4) -6.6% (N=5) -7.3% (N=6) -5.2% (N=8) -2.0% (N=12), but that benchmark's routing is the concentrated one above, not real traffic.
Pending (I will update this description when they finish): c16 repeat arms to estimate the replay noise, c32 arms, and GSM8K (all 1319 questions) with and without the rows.

Limitations

Related: #6942 (rows this builds on).

Co-authored-by: lirui927 [email protected]

PR Self-Review

Reviewed revision

9e1c4ac

Behavior and intent

Changes the kernel pair (stage 1 / stage 2 FlyDSL a16w4 names) that fused_moe selects for five rows of minimax_m3_a16w4_tuned_fmoe.csv: token = 8, 16, 32, 64, 128 of the MiniMax-M3.1 TP4 shape (E=128, topk=4, model_dim=6144, inter_dim=768, bf16 activations x MXFP4 weights). No code changes. The rows added in #6942 were tuned under uniformly random routing, but real MiniMax-M3.1 decode routing touches far fewer experts per layer (46/53/64/71/89 distinct experts at 24/32/40/64/96 tokens against 68/82/92/111/122 for uniform random). With that routing the token = 64 row of #6942 is 12% slower than aiter's default CK-tile path (103.5 vs 92.3 us per MoE layer) and the other rows are at best equal to it, so the existing selection is insufficient for the workload this table exists for.

Validation and unverified scope

Validated on MI355X (gfx950, 256 CUs), aiter 0.1.27 wheel for the replays and a JIT-built current aiter main (41c2528) for the tuner:

  • Per-layer replay of the real per-layer top-k ids dumped from a live AgentX decode (57 layers per CUDA graph, 6 distinct weight copies), whole fused_moe op: tables in this description (default / [Config] [Tuning] [gfx950] Add MiniMax-M3.1 MXFP4 MoE configs (E=128, top-4, TP2/TP4); fix A16W4 tuner checks #6942 / this PR: 43.2 / 43.1 / 40.2 us at 8 tokens, 92.3 / 103.5 / 91.2 us at 64 tokens, 92.8 / 95.7 / 89.3 us at 128 tokens).
  • AITER_CONFIG_FMOE=<csv> python3 csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py --run_config on aiter main: all five new rows run through production fused_moe and report OK against the tuner's torch reference.
  • Correctness against a bf16 reference of the dequantised weights: 0.52-0.77% max-abs (% of max|ref|) with real routing ids, no NaNs (default path 0.60-0.91%).
  • Kernel names: all new names exist in get_flydsl_stage{1,2}_kernels('bf16','fp4','bf16') on aiter main and on the 0.1.27 wheel.
    Unverified: (a) end-to-end effect: the c16 AgentX replay arms are within the replay noise (at least ~5%), repeats, c32 and GSM8K are still running and will be added here; (b) under uniform random routing the same tuner reports these rows 6-11% slower than [Config] [Tuning] [gfx950] Add MiniMax-M3.1 MXFP4 MoE configs (E=128, top-4, TP2/TP4); fix A16W4 tuner checks #6942 at 8/16/32/128 tokens (equal at 64); this PR trades that for the real-routing results; (c) not run with v0.1.28 binaries, other TP sizes or workloads.

PR-specific question

Workload keys that consume the change: exactly the rows with gfx=gfx950, cu_num=256, expert=128, topk=4, model_dim=6144, inter_dim=768, act_type=Swiglu, dtype=bf16, q_dtype_a=bf16, q_dtype_w=fp4x2, q_type=per_1x32 at token = 8, 16, 32, 64, 128 (the lookup pads M up to these buckets: 1-8 -> 8, 9-16 -> 16, 17-32 -> 32, 33-64 -> 64, 65-128 -> 128). Evidence that other shapes keep their selection: the CSV has 27 rows before and after with an identical key set; a row-by-row comparison shows that exactly these five rows change kernelName1/kernelName2/block_m/ksplit and the other 22 rows are byte-identical (the diff is 5 lines +/- in one file). The token = 1, 2, 4, 256 rows and all a4w4 rows are untouched, and no other CSV or code path is modified.

Changed op tests

None.

AI assistance: this change was developed with Claude Code; the measurements above were run on MI355X (gfx950).

🤖 Generated with Claude Code

…=128, top-4) for 8/16/32/64/128 tokens

Replace the FlyDSL a16w4 kernel pair of the E=128/topk=4/inter_dim=768 rows for
tokens 8, 16, 32, 64 and 128 in minimax_m3_a16w4_tuned_fmoe.csv (rows 1, 2, 4,
256 and all A4W4 rows are unchanged). The rows added in ROCm#6942 were tuned under
uniformly random routing. Real MiniMax-M3.1 AgentX decode routing touches
46/53/64/71/89 distinct experts per layer at 24/32/40/64/96 tokens (uniform
random: 68/82/92/111/122), and there the token=64 row of ROCm#6942 is slower than
the CK-tile default.

Rows were swept over the FlyDSL a16w4 registry (tile_m=16, 304 stage-1 and 64
stage-2 kernels) with `fused_moe` end to end, replaying the real per-layer
top-k ids dumped from a live AgentX c16 run (57 layers per CUDA graph, 6 weight
copies). Per layer, us, vs ROCm#6942 rows: bucket 32 82.0 -> 77.8, 64 103.5 ->
91.2, 128 95.7 -> 89.3, 8 43.1 -> 40.2, 16 60.0 -> 56.2; default CK-tile path:
79.9 / 92.3 / 92.8 / 43.2 / 60.0. us1/us2/us/err2 are measured with uniform
random routing at token=T (err2: max-abs error of the whole fused op vs a bf16
reference of the dequantised weights, in % of max|ref|).

Co-authored-by: lirui927 <[email protected]>
Signed-off-by: Fangzhou Ai <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Fangzhou-Ai
Fangzhou-Ai requested a review from a team November 3, 2026 20:32
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7414 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@github-actions github-actions Bot changed the title [Config][Tuning][gfx950] Retune MiniMax-M3.1 TP4 A16W4 decode rows (E=128, top-4) for 8/16/32/64/128 tokens [Config] [Tuning][gfx950] Retune MiniMax-M3.1 TP4 A16W4 decode rows (E=128, top-4) for 8/16/32/64/128 tokens Nov 3, 2026
@github-actions github-actions Bot added the Config label Nov 3, 2026
@aiter-bot

aiter-bot commented Nov 3, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 9e1c4acea90b · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

Changes the kernel pair (stage 1 / stage 2 FlyDSL a16w4 names) that `fused_moe` selects for five rows of `minimax_m3_a16w4_tuned_fmoe.csv`: `token = 8, 16, 32, 64, 128` of the MiniMax-M3.1 TP4 shape (`E=128, topk=4, model_dim=6144, inter_dim=768`, bf16 activations x MXFP4 weights). No code changes. The rows added in #6942 were tuned under uniformly random routing, but real MiniMax-M3.1 decode routing touches far fewer experts per layer (46/53/64/71/89 distinct experts at 24/32/40/64/96 tokens against 68/82/92/111/122 for uniform random). With that routing the `token = 64` row of #6942 is 12% slower than aiter's default CK-tile path (103.5 vs 92.3 us per MoE layer) and the other rows are at best equal to it, so the existing selection is insufficient for the workload this table exists for.

Validation and unverified scope

Validated on MI355X (gfx950, 256 CUs), aiter 0.1.27 wheel for the replays and a JIT-built current aiter main (41c2528) for the tuner:
- Per-layer replay of the real per-layer top-k ids dumped from a live AgentX decode (57 layers per CUDA graph, 6 distinct weight copies), whole `fused_moe` op: tables in this description (default / #6942 / this PR: 43.2 / 43.1 / 40.2 us at 8 tokens, 92.3 / 103.5 / 91.2 us at 64 tokens, 92.8 / 95.7 / 89.3 us at 128 tokens).
- `AITER_CONFIG_FMOE=<csv> python3 csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py --run_config` on aiter main: all five new rows run through production `fused_moe` and report `OK` against the tuner's torch reference.
- Correctness against a bf16 reference of the dequantised weights: 0.52-0.77% max-abs (% of max|ref|) with real routing ids, no NaNs (default path 0.60-0.91%).
- Kernel names: all new names exist in `get_flydsl_stage{1,2}_kernels('bf16','fp4','bf16')` on aiter main and on the 0.1.27 wheel.
Unverified: (a) end-to-end effect: the c16 AgentX replay arms are within the replay noise (at least ~5%), repeats, c32 and GSM8K are still running and will be added here; (b) under uniform random routing the same tuner reports these rows 6-11% slower than #6942 at 8/16/32/128 tokens (equal at 64); this PR trades that for the real-routing results; (c) not run with v0.1.28 binaries, other TP sizes or workloads.

PR-specific question

Workload keys that consume the change: exactly the rows with `gfx=gfx950, cu_num=256, expert=128, topk=4, model_dim=6144, inter_dim=768, act_type=Swiglu, dtype=bf16, q_dtype_a=bf16, q_dtype_w=fp4x2, q_type=per_1x32` at `token = 8, 16, 32, 64, 128` (the lookup pads M up to these buckets: 1-8 -> 8, 9-16 -> 16, 17-32 -> 32, 33-64 -> 64, 65-128 -> 128). Evidence that other shapes keep their selection: the CSV has 27 rows before and after with an identical key set; a row-by-row comparison shows that exactly these five rows change `kernelName1/kernelName2/block_m/ksplit` and the other 22 rows are byte-identical (the diff is 5 lines +/- in one file). The `token = 1, 2, 4, 256` rows and all a4w4 rows are untouched, and no other CSV or code path is modified.

Changed op tests

None.

AI assistance: this change was developed with Claude Code; the measurements above were run on MI355X (gfx950).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@zufayu
zufayu self-requested a review November 4, 2026 01:30
@zufayu zufayu self-assigned this Nov 4, 2026
@zufayu
zufayu merged commit 90f8b5b into ROCm:main Nov 12, 2026
vpietila-amd pushed a commit that referenced this pull request Nov 12, 2026
…=128, top-4) for 8/16/32/64/128 tokens (#7414)

Replace the FlyDSL a16w4 kernel pair of the E=128/topk=4/inter_dim=768 rows for
tokens 8, 16, 32, 64 and 128 in minimax_m3_a16w4_tuned_fmoe.csv (rows 1, 2, 4,
256 and all A4W4 rows are unchanged). The rows added in #6942 were tuned under
uniformly random routing. Real MiniMax-M3.1 AgentX decode routing touches
46/53/64/71/89 distinct experts per layer at 24/32/40/64/96 tokens (uniform
random: 68/82/92/111/122), and there the token=64 row of #6942 is slower than
the CK-tile default.

Rows were swept over the FlyDSL a16w4 registry (tile_m=16, 304 stage-1 and 64
stage-2 kernels) with `fused_moe` end to end, replaying the real per-layer
top-k ids dumped from a live AgentX c16 run (57 layers per CUDA graph, 6 weight
copies). Per layer, us, vs #6942 rows: bucket 32 82.0 -> 77.8, 64 103.5 ->
91.2, 128 95.7 -> 89.3, 8 43.1 -> 40.2, 16 60.0 -> 56.2; default CK-tile path:
79.9 / 92.3 / 92.8 / 43.2 / 60.0. us1/us2/us/err2 are measured with uniform
random routing at token=T (err2: max-abs error of the whole fused op vs a bf16
reference of the dequantised weights, in % of max|ref|).

Signed-off-by: Fangzhou Ai <[email protected]>
Co-authored-by: lirui927 <[email protected]>
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
vgokhale added a commit that referenced this pull request Nov 12, 2026
Keeps this branch's MiniMax-M3.1 A16W4 rows at 8, 16, 32, 64, 128 and 256 tokens over #7414's: the fused shared expert needs the atomic stage-2 epilogue, and these rows carry the shared tiles measured with it.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit that referenced this pull request Nov 16, 2026
…ge 2

When main was merged in, the MiniMax-M3.1 TP4 A16W4 rows at 8-128 tokens
went back to #6942's kernels and undid #7414's retune for every caller.
They now use #7414's stage-1 kernels and its 16-token row. Only stage 2 at
8, 32, 64 and 128 tokens changes from the reduce to the atomic epilogue
(the fused shared expert needs it), and the rows carry shared-expert tiles
(_sh), which do not change the routed kernels.

Real routing (top-4 ids of all 57 MoE layers from an AgentX c16 replay,
114 layer routings per token count, cold weights, MI355X), wall us a call:

  tokens  #7414  this, routed only  this + shared expert  before + shared
       8   39.4               37.1                  37.5             39.6
      16   56.1               56.1                  58.0             61.5
      32   80.1               78.2                  89.0             84.9
      64  114.5              109.8                 112.8            120.3
     128  142.7              136.9                 142.6            150.7

CSV values: us1 = #7414's (the same stage-1 kernel); us2 and us = #7414's
plus the measured change of the whole op (uniform routing, same process);
err2 measured against the FP32 reference.

Signed-off-by: Vinayak Gokhale <[email protected]>
coderfeli pushed a commit that referenced this pull request Nov 17, 2026
* [FlyDSL] [Perf] A16W4 MoE: optional fused bf16 shared expert

The moe_2stage_a16wmix gemm1/gemm2 kernels can now compute a dense bf16
shared expert in the same launches as the routed experts. The shared
tiles take the first program ids. The routed tiles and the sort do not
change. Without shared weights, the kernels, names and launch signatures
do not change.

- gemm1/gemm2: dense=True body mode and *_shared kernel variants
  (compile parameters shared_tile_n/_m/_k and shared_k_wave).
- moe_kernels: parse the "_sh{M}x{N}x{K}[kw{W}]" kernel-name suffix;
  forward shared_w1_bf16/shared_w2_bf16/shared_inter_bf16.
- fused_moe: the FlyDSL stage wrappers forward the shared tensors.
- MiniMax-M3.1 TP4 A16W4 rows: shared tiles on the 32-256 rows and
  measured exact-width decode rows (40-168).
- Tests in op_tests/test_flydsl_moe_a16wfp4.py.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [FlyDSL] [Perf] A16W4 MoE: MXFP8 weights for the fused shared expert

The dense shared expert of the moe_2stage_a16wmix gemm1/gemm2 kernels can
now read MXFP8 weights (fp8 e4m3 codes + E8M0 1x32 scales) instead of a
bf16 copy, at half the weight bytes. The format follows the dtype of the
shared weight the caller passes; bf16 weights run as before.

- utils.make_b_loader: w_dtype "fp8". Codes in the shuffle_weight (16, 16)
  layout (two dwordx4 per lane and 128-K block, whole-line runs per load
  instruction), scales in the shuffle_scale layout (the routed MXFP4 scale
  path, reused). The codes are scaled to bf16 in registers right before the
  MFMA (v_cvt_scalef32_pk_bf16_fp8). An e4m3 value times a power of two is a
  bf16 value and the K order and MFMA sequence are the bf16 path's, so the
  output is bitwise that of the bf16 weights. gfx950 only.
- gemm1/gemm2: compile parameter shared_w_dtype ("bf16" or "fp8", kernel
  name suffix _mxfp8); the shared kernels take a scale pointer. gemm2
  asserts a power-of-two shared_tile_k (its A-LDS swizzle needs it).
- API: shared_w1 / shared_w1_scale and shared_w2 / shared_w2_scale
  (fused_moe naming) replace shared_w1_bf16 / shared_w2_bf16 in the FlyDSL
  stage wrappers and moe_kernels.
- MiniMax-M3.1 TP4 rows: shared tiles retuned for MXFP8 at the same shared
  k_wave (so bitwise to the bf16 path): g1 rows 32, 48-56, 72-168, g2 rows
  72-80.
- Tests: MXFP8 shared vs bf16 shared bitwise at every M3.1 TP4 decode row
  (1-256; stage 1 and stage-2 shared tiles), MXFP8 in the shared-expert
  correctness tests and the fused_moe_2stages test, argument checks.

MI355X, M3.1 TP4 rows, skewed routing, cold weights, CUDA graph, us per
layer (gemm1 + gemm2), bf16 shared at the previous tiles -> MXFP8 shared:
8 46.1 -> 43.0, 16 68.6 -> 60.2, 32 89.5 -> 86.1, 64 118.7 -> 117.1,
128 160.4 -> 152.4, 160 178.0 -> 161.4, 256 202.9 -> 195.9.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [FlyDSL] A16W4 shared expert: LDS checks and a bounded default tile width

- a16w4_default_shared_tile_n raises ValueError when N is not a positive
  multiple of step, and starts its search at N or below. Before, the
  search did not stop for such an N, or when tile_n / 4 was above N.
- The shared-expert builds of gemm1 and gemm2 compare their LDS size with
  get_lds_capacity_bytes and raise NotImplementedError above it, as the
  gemm2 reuse_lds build does. The shipped _sh tiles use at most 64 KB
  (gemm1) and 32 KB (gemm2).
- New tests: test_default_shared_tile_n_bounds,
  test_stage1_shared_rejects_oversized_lds and
  test_stage2_shared_rejects_oversized_lds.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [FlyDSL] A16W4 shared expert: name the arguments fused_shared_w*

op_tests/test_fhmoe.py::test_heterogeneous_moe_uses_a_separate_custom_op_schema
keeps FHMoE's argument names (shared_w1, shared_w2, shared_w1_scale,
shared_w2_scale, shared_expert_id, clamp_shared) off the ordinary MoE APIs,
so that the heterogeneous MoE keeps its own custom-op schema. The A16W4
shared expert used shared_w1 / shared_w1_scale / shared_w2 /
shared_w2_scale on flydsl_moe_stage1/2 and the FlyDSL stage wrappers, and
that test failed in CI. They are now fused_shared_w1, fused_shared_w1_scale,
fused_shared_w2 and fused_shared_w2_scale (the shared expert fused into the
routed launches); shared_inter_bf16 and shared_tile do not change.
FHMoE's own arguments in fused_moe do not change.

Signed-off-by: Vinayak Gokhale <[email protected]>

* [Config] M3.1 A16W4 rows at 8-128 tokens: #7414's kernels, atomic stage 2

When main was merged in, the MiniMax-M3.1 TP4 A16W4 rows at 8-128 tokens
went back to #6942's kernels and undid #7414's retune for every caller.
They now use #7414's stage-1 kernels and its 16-token row. Only stage 2 at
8, 32, 64 and 128 tokens changes from the reduce to the atomic epilogue
(the fused shared expert needs it), and the rows carry shared-expert tiles
(_sh), which do not change the routed kernels.

Real routing (top-4 ids of all 57 MoE layers from an AgentX c16 replay,
114 layer routings per token count, cold weights, MI355X), wall us a call:

  tokens  #7414  this, routed only  this + shared expert  before + shared
       8   39.4               37.1                  37.5             39.6
      16   56.1               56.1                  58.0             61.5
      32   80.1               78.2                  89.0             84.9
      64  114.5              109.8                 112.8            120.3
     128  142.7              136.9                 142.6            150.7

CSV values: us1 = #7414's (the same stage-1 kernel); us2 and us = #7414's
plus the measured change of the whole op (uniform routing, same process);
err2 measured against the FP32 reference.

Signed-off-by: Vinayak Gokhale <[email protected]>

---------

Signed-off-by: Vinayak Gokhale <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants