Skip to content

[Config] [Tuning] [gfx950] Add MiniMax-M3.1 MXFP4 MoE configs (E=128, top-4, TP2/TP4); fix A16W4 tuner checks - #6942

Merged
zufayu merged 3 commits into
mainfrom
lirui/minimax_m3_moe_configs
Oct 27, 2026
Merged

zufayu merged 3 commits into
mainfrom
lirui/minimax_m3_moe_configs

Conversation

@lirui927

@lirui927 lirui927 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

MiniMax-M3.1 with MXFP4 experts and the shared expert not fused into the routed experts runs a fused MoE with E=128, top-4. main tunes only the fused shape (E=129, top-5), so E=128 falls back to the default kernel choice, and the MXFP4 aux kernels have no instance for it. This adds TP4 (inter_dim 768 per GPU) and TP2 (inter_dim 1536).

Changes

  • (128, 6144, 768, 4) and (128, 6144, 1536, 4) added to moe_aux/codegen/gen_instances.py and MXFP4_MOE_SUPPORTED_SHAPES. Without them, tuning and inference fail with no codegen'd instance for shape key 'aux_scatter_H6144_TOPK4_NT1'.
  • A4W4 rows (FP4 activations), tokens 1..32768, in minimax_m3_fp4_{untuned,tuned}_fmoe.csv.
  • A16W4 rows (bf16 activations), tokens 1..256, in minimax_m3_a16w4_tuned_fmoe.csv. fused_moe takes this path for M < 256; the key rounds M up to a power of two, so M in 129..255 reads the 256 row.
  • gemm_moe_tune.py, A16W4 only: stage2 always atomic-scatters into moe_buf, so the tuner zeroes it for every candidate and skips the reduce/persist names, which launch the same kernel. Before, reduce-named candidates accumulated and were rejected as errors. --run_config shuffles the stage-1 weight as GGUU, like the tuning path and op_tests/test_moe_2stage.py; with GUGU every A16W4 shape reported MISMATCH.

The config files only gain lines.

Op-level result

Production fused_moe via gemm_moe_tune.py --run_config, one gfx950 GPU. main uses only aiter/configs/tuned_fmoe.csv, which has no E=128 rows; PR uses this PR's rows. Each token uses the path fused_moe picks for it. All shapes match the torch reference on both.

token path TP4 main (us) TP4 PR (us) TP4 time saved TP2 main (us) TP2 PR (us) TP2 time saved
1 A16W4 31.52 27.65 12.3% 37.03 32.12 13.3%
2 A16W4 37.09 30.40 18.0% 43.68 40.93 6.3%
4 A16W4 45.45 38.79 14.7% 62.92 52.32 16.8%
8 A16W4 61.50 50.31 18.2% 96.96 87.66 9.6%
16 A16W4 90.42 77.12 14.7% 150.06 139.81 6.8%
32 A16W4 121.27 109.30 9.9% 234.42 225.27 3.9%
64 A16W4 161.24 146.77 9.0% 293.60 281.90 4.0%
128 A16W4 182.83 165.50 9.5% 321.27 303.96 5.4%
192 A16W4 332.11 312.59 5.9%
256 A4W4 180.42 170.93 5.3% 334.87 308.57 7.9%
512 A4W4 190.22 183.68 3.4% 347.10 323.39 6.8%
1024 A4W4 251.27 190.79 24.1% 455.71 343.14 24.7%
2048 A4W4 303.28 272.30 10.2% 492.36 441.48 10.3%
4096 A4W4 433.68 358.16 17.4% 627.40 593.92 5.3%
8192 A4W4 744.10 527.37 29.1% 1026.22 883.92 13.9%
16384 A4W4 1358.45 893.69 34.2% 1767.24 1485.23 16.0%
32768 A4W4 2477.70 1666.33 32.7% 3426.79 2798.39 18.3%

Token 192 exercises the A16W4 row keyed 256.

End-to-end result

MiniMax-M3

ATOM, MiniMax-M3-MXFP4 on gfx950 GPUs. This checkpoint's shared expert is MXFP4, so ATOM's fusion check was patched to return False to run the E=128, top-4 path; main and PR differ only in the MoE table, as above. In the server logs every E=128 lookup under PR hit a tuned row (TP2: 148 lookups, 0 default, 0 "no tuned FlyDSL config" warnings); under main all took the default.

GSM8K (5-shot, 1319 questions), mean of two runs: TP4 main 0.9420, PR 0.9416; TP2 main 0.9394, PR 0.9394. The gaps are within run-to-run noise.

benchmark_serving, ISL 8192 / OSL 1024, one run each: output throughput +3.5% (TP4) and +5.0% (TP2) at concurrency 4, +1.7% and +3.5% at 64.

TP concurrency metric main PR change
4 4 output throughput (tok/s) 466.6 483.1 +3.5%
4 4 mean TPOT (ms) 8.22 7.94 -3.5%
4 4 mean TTFT (ms) 234.0 228.8 -2.2%
4 64 output throughput (tok/s) 2587.7 2632.9 +1.7%
4 64 mean TPOT (ms) 23.46 23.08 -1.7%
4 64 mean TTFT (ms) 748.9 714.4 -4.6%
2 4 output throughput (tok/s) 390.5 410.0 +5.0%
2 4 mean TPOT (ms) 9.76 9.29 -4.7%
2 4 mean TTFT (ms) 346.8 328.8 -5.2%
2 64 output throughput (tok/s) 1686.9 1746.6 +3.5%
2 64 mean TPOT (ms) 36.15 34.91 -3.4%
2 64 mean TTFT (ms) 1114.3 1078.7 -3.2%

MiniMax-M3.1

ATOM-m3, MiniMax-M3.1-preview2 Quark MXFP4 on gfx950 GPUs. This checkpoint's shared expert is MXFP8, so ATOM keeps it out of the routed MoE without any patch and the routed MoE runs E=128, top-4; main and PR differ only in the MoE table. Under PR every E=128 lookup hit a tuned row (per GSM8K run 88 at TP4 and 44 at TP2, per benchmark run 104 and 52; 0 default); under main all took the default.

GSM8K (5-shot, 1319 questions): TP4 main 0.9510 (mean of three runs), PR 0.9522 (mean of four runs); TP2 main 0.9484, PR 0.9481 (mean of two runs).

benchmark_serving, ISL 8192 / OSL 1024, mean of two runs (one with PR first, one with main first):

TP concurrency metric main PR change
4 16 output throughput (tok/s) 826.4 849.6 +2.8%
4 16 mean TPOT (ms) 18.39 17.87 -2.8%
4 16 mean TTFT (ms) 632.5 623.0 -1.5%
4 32 output throughput (tok/s) 1177.0 1203.0 +2.2%
4 32 mean TPOT (ms) 25.57 25.03 -2.1%
4 32 mean TTFT (ms) 889.9 857.5 -3.6%
2 16 output throughput (tok/s) 591.5 594.5 +0.5%
2 16 mean TPOT (ms) 25.49 25.40 -0.4%
2 16 mean TTFT (ms) 1107.7 1072.2 -3.2%
2 32 output throughput (tok/s) 795.8 806.9 +1.4%
2 32 mean TPOT (ms) 37.74 37.24 -1.3%
2 32 mean TTFT (ms) 1555.6 1522.5 -2.1%

lirui927 and others added 3 commits October 26, 2026 09:16
…hared-expert fusion (E=128, top-4, TP4)

Without shared-expert fusion, MiniMax-M3 runs its routed experts as an
E=128, top-4 fused MoE (the shared expert stays a separate MXFP8 MLP).
main only covers the fused E=129, top-5 shapes.

- Register (128, 6144, 768, 4) in moe_aux gen_instances.py SHAPES and in
  MXFP4_MOE_SUPPORTED_SHAPES. Without the codegen line, candidates that
  need mxfp4_moe_scatter_reduce crash with "no codegen'd instance for
  aux_scatter_H6144_TOPK4_NT1"; without the Python line, fused_moe
  rejects the MXMOE path for this shape.
- Add 16 A4W4 rows (tokens 1..32768, inter_dim 768) to
  minimax_m3_fp4_{untuned,tuned}_fmoe.csv. Tuned with the default
  (flydslv2) tuner, then --mxfp4-flydsl --compare --update_improved;
  7 shapes (tokens 256, 1024..32768) took the MXMOE kernels, improving
  the production op by 3.8% to 26.3% over the first pass.

Swiglu MXFP4 MoE runs A4W4 only from 256 tokens up; below that it runs
A16W4, whose E=128 rows follow separately.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…16w4 tuner checks

- Add 9 A16W4 rows (bf16 A x MXFP4 W, tokens 1..256, E=128, top-4,
  model_dim 6144, inter_dim 768) to minimax_m3_a16w4_tuned_fmoe.csv,
  tuned with the FlyDSL a16w4 kernels. Against main's default kernel
  choice, the production fused_moe op is 9.0% to 18.2% faster for
  tokens 1..128 and its relative L2 error vs the torch reference drops
  from 0.53-0.66% to 0.35%.
- gemm_moe_tune.py, a16w4 FlyDSL stage2: the launcher always
  atomic-scatters into moe_buf and ignores the kernelName's reduce mode
  and persist (as fused_moe.stage2_uses_route_reduce already assumes),
  but the tuner zeroed moe_buf only for mode == "atomic". reduce-named
  candidates accumulated across timed iterations and were all rejected
  as catastrophic errors (max abs delta 97). Zero moe_buf for every
  a16w4 stage2 candidate, and skip the reduce/persist names, which
  launch the same kernel as the plain atomic one (stage2 candidates per
  shape 240 -> 60).
- gemm_moe_tune.py, --run_config: shuffle the a16w4 W1 with the
  standard GGUU layout (gate_up=False) as op_tests/test_moe_2stage.py
  and the tuning path do; only a8w4 (fp8 A) uses the interleaved GUGU
  layout. With GUGU every a16w4 shape reported MISMATCH (logits_diff
  ~0.89) for any kernel, including main's CK-Tile path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…P2 (E=128, top-4, inter_dim 1536)

- Register (128, 6144, 1536, 4) in MXFP4_MOE_SUPPORTED_SHAPES so fused_moe
  takes the MXMOE path at TP2, and list it in gen_instances.py next to the
  TP4 entry (the aux instances are keyed by NE/TOPK/H, so none are added).
- A4W4 rows, tokens 1..32768, in minimax_m3_fp4_{untuned,tuned}_fmoe.csv.
- A16W4 rows, tokens 1..256, in minimax_m3_a16w4_tuned_fmoe.csv.

Production fused_moe via gemm_moe_tune.py --run_config on one gfx950 GPU,
main's tables vs these rows: tokens 1..192 (A16W4) take 3.9% to 16.8% less
time, 256..32768 (A4W4) 5.3% to 24.7% less; all 17 shapes match the torch
reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lirui927
lirui927 requested a review from a team October 26, 2026 09:16
@github-actions

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 6942 --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] Add MiniMax-M3 non-fused MoE configs (E=128, top-4, TP2/TP4); fix a16w4 tuner checks [HIP] [CK] [Tuning] [gfx950] Add MiniMax-M3 non-fused MoE configs (E=128, top-4, TP2/TP4); fix a16w4 tuner checks Oct 26, 2026
@lirui927 lirui927 changed the title [HIP] [CK] [Tuning] [gfx950] Add MiniMax-M3 non-fused MoE configs (E=128, top-4, TP2/TP4); fix a16w4 tuner checks [Config] [Tuning] [gfx950] Add MiniMax-M3.1-Flash MoE configs (E=128, top-4, TP2/TP4); fix a16w4 tuner checks Oct 26, 2026
@lirui927 lirui927 changed the title [Config] [Tuning] [gfx950] Add MiniMax-M3.1-Flash MoE configs (E=128, top-4, TP2/TP4); fix a16w4 tuner checks [Config] [Tuning] [gfx950] Add MiniMax-M3.1 MXFP4 MoE configs (E=128, top-4, TP2/TP4); fix A16W4 tuner checks Oct 26, 2026
@zufayu
zufayu merged commit c364be8 into main Oct 27, 2026
56 checks passed
@zufayu
zufayu deleted the lirui/minimax_m3_moe_configs branch October 27, 2026 05:51
hongxiayang added a commit to hongxiayang/aiter that referenced this pull request Nov 2, 2026
…6 a4w4/a8w4, a8w8 block-scale TP4 shapes incl. split-K)

Extends the TP8 tables with the TP4 shapes of Mistral Large 4 on MI350X (gfx950,
256 CUs), tuned with the in-tree tuners of aiter 0.1.26 (--mxfp4-flydsl
--mxfp4-search-mode prune for a4w4, --mp 3, default errRatio):

- mistral_large4_{a8w4,a4w4}_tuned_fmoe.csv: +14 rows each, 128 experts top-4,
  inter_dim 1536, M = 1..8192. The a4w4 winners are 1-stage flydsl_mxmoe_g1_*
  kernels and need the (128, 6144, 1536, 4) MXFP4 aux shape (on main since ROCm#6942).
- a8w8_blockscale_tuned_gemm_mistral_large4.csv: +31 rows for N x K = 2048x6144
  and 12288x6144 (M = 1..16384) and 6144x2048 (M = 16384), with a split-K pass
  for M <= 256; 4096x6144 and 6144x6144 re-tuned on 0.1.26. The other TP4 shapes
  (3072x6144, 6144x1536, 6144x2048 below M = 16384) are already covered by the
  bundled ds_v3 / qwen3_next / glm5.2 tables and are left out.
- mistral_large4_bf16_tuned_gemm.csv: one duplicate (M=4, 512x6144) row removed.
- Untuned shape lists extended accordingly.

End to end (vLLM, TP4, a4w4 experts, bf16 KV, 8k in / 1k out): TPOT -14 / -9 / -8 %
and output throughput +16 / +9 / +9 % at concurrency 1 / 4 / 8 over the heuristic
configs; gsm8k unchanged.

Signed-off-by: Hongxia Yang <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
demonsan pushed a commit that referenced this pull request Nov 6, 2026
* [Config] Mistral Large 4: gfx950 TP8 tuned tables (fused MoE a8w4/a4w4, a8w8 block-scale, bf16 GEMM)

Tuned on MI350X (gfx950, 256 CUs) for Mistral Large 4 (hidden 6144, 128 experts
top-4, MLA ranks 512/64/128, vocab 204800) served at TP8, with the in-tree tuners
(--mp 8, default errRatio). Files go under aiter/configs/model_configs/ and are
named so the existing *tuned_fmoe* / *a8w8_blockscale_tuned_gemm* /
*bf16_tuned_gemm* globs merge them with the bundled tables; no shape overlaps
the bundled rows.

- mistral_large4_a8w4_tuned_fmoe.csv (14 rows) and mistral_large4_a4w4_tuned_fmoe.csv
  (9 rows): 2-stage fused MoE, 128 experts, top-4, inter_dim 768, SiLU, per_1x32
  MXFP4 weights; fp8 activations (a8w4) for M = 1..8192 and MXFP4 activations
  (a4w4, --mxfp4-flydsl prune search) for M = 32..8192 (no candidates below M=32
  in that port).
- a8w8_blockscale_tuned_gemm_mistral_large4.csv (91 rows): 128x128 block-scale fp8
  GEMMs, N x K = 1024x6144, 1536x6144, 4096x6144, 6144x768/1024/3072/6144,
  M = 1..16384, --libtype all, plus a split-K pass for M <= 256 that takes the
  K=6144 small-M shapes from ~19.6 us to 6-10 us.
- mistral_large4_bf16_tuned_gemm.csv (45 rows): bf16 GEMMs 512x6144, 576x6144,
  25600x6144, M = 1..16384. The two opus rows use the local kernel IDs introduced
  by #6937 (resolved with kid_for_name; same kernels as tuned).

The untuned inputs are added next to each tuned file for retuning.

Measured end to end (vLLM, TP8, 8k in / 1k out): +14-22% output throughput over
the heuristic configs across concurrency 1-64, accuracy unchanged.

Signed-off-by: Hongxia Yang <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* [Config] Mistral Large 4: gfx950 TP4 tunings (fused MoE inter_dim 1536 a4w4/a8w4, a8w8 block-scale TP4 shapes incl. split-K)

Extends the TP8 tables with the TP4 shapes of Mistral Large 4 on MI350X (gfx950,
256 CUs), tuned with the in-tree tuners of aiter 0.1.26 (--mxfp4-flydsl
--mxfp4-search-mode prune for a4w4, --mp 3, default errRatio):

- mistral_large4_{a8w4,a4w4}_tuned_fmoe.csv: +14 rows each, 128 experts top-4,
  inter_dim 1536, M = 1..8192. The a4w4 winners are 1-stage flydsl_mxmoe_g1_*
  kernels and need the (128, 6144, 1536, 4) MXFP4 aux shape (on main since #6942).
- a8w8_blockscale_tuned_gemm_mistral_large4.csv: +31 rows for N x K = 2048x6144
  and 12288x6144 (M = 1..16384) and 6144x2048 (M = 16384), with a split-K pass
  for M <= 256; 4096x6144 and 6144x6144 re-tuned on 0.1.26. The other TP4 shapes
  (3072x6144, 6144x1536, 6144x2048 below M = 16384) are already covered by the
  bundled ds_v3 / qwen3_next / glm5.2 tables and are left out.
- mistral_large4_bf16_tuned_gemm.csv: one duplicate (M=4, 512x6144) row removed.
- Untuned shape lists extended accordingly.

End to end (vLLM, TP4, a4w4 experts, bf16 KV, 8k in / 1k out): TPOT -14 / -9 / -8 %
and output throughput +16 / +9 / +9 % at concurrency 1 / 4 / 8 over the heuristic
configs; gsm8k unchanged.

Signed-off-by: Hongxia Yang <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Signed-off-by: Hongxia Yang <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
zufayu 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]>
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 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