Skip to content

[FlyDSL] A4W4 compact MoE: MXFP4 prefill MoE for gfx950 (MiniMax-M3 TP2 / TP4 / TP8) - #6330

Draft
akii96 wants to merge 1 commit into
ROCm:mainfrom
akii96:aakif/moe-a4w4-compact
Draft

akii96 wants to merge 1 commit into
ROCm:mainfrom
akii96:aakif/moe-a4w4-compact

Conversation

@akii96

@akii96 akii96 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

MiniMax-M3-MXFP4 on gfx950 spends most of its long-context and high-concurrency serving time in prefill MoE calls of 512 to 32768 tokens (chunked prefill at max_num_batched_tokens=32768). In a live vLLM TP4 server, 38–78% of the time on the 60k and 128k rows is in MoE calls of at least 1024 tokens, almost all of it in full 32k-token chunks.

That range runs on kernels built around padding. Every expert's rows are padded to the tile height, and inter_dim is padded too: vLLM rounds the TP8 shard (384) up to 512. TP2 (inter_dim=1536) has no tuned rows at all, and its default kernel rounds the intermediate to bf16 before requantizing (0.16 relative L2 against an fp32 intermediate, vs 2.4e-3 here).

Changes from the PR

A new, additive FlyDSL kernel family for MXFP4 activations and weights with SwiGLU-OAI, built for prefill and needing no padding:

  • Compact rows: exactly tokens × topk expert-sorted rows. Tail tiles never load or store past an expert's count.
  • True widths: any inter_dim that is a multiple of 128 runs at its real size.
  • Fused prologue: activation quant and a parallel counting sort on device, no host syncs.
  • Stage 1 fuses gate/up GEMM, SwiGLU-OAI and MXFP4 requant of the intermediate, with a persistent 2×2-wave 256×256 tile for large batches.
  • Stage 2 applies the router weight in the epilogue. The plan checks on the device, for every batch, whether expert E-1 is a shared expert routed exactly once per token. If it is, the combine is folded into the shared expert's epilogue. If not, the separate combine runs, so every routing is exact and there is nothing to opt into.
  • No extra weight memory: reads the standard preshuffled weights (shuffle_weight(16, 16) + e8m0_shuffle, gate/up separated) in place; only the e8m0 scales are repacked.

Tuned rows name each stage, like the other FlyDSL MoE rows:

block_m 256, kernelName1 flydsl_a4w4c_g1_256x256_il4_d3_w4_wm2_persist_fexp_bar8_s1tr_epg8_ht
             kernelName2 flydsl_a4w4c_g2_256x256_il4_d3_w4_wm2_persist_nt_s2tl_ht_fc_128x256_hybrid_d3_w4_agpr136_fcskip

aiter/ops/flydsl/a4w4c_kname.py builds and parses these names, and get_2stage_cfgs routes a flydsl_a4w4c_g1_ row to the family's whole-graph implementation. No existing kernel, dispatch path or weight format changes.

Padding policy. The family never runs on padded weights. Rows exist at true widths only. Any call with hidden_pad / intermediate_pad (for example today's vLLM TP8 shard, padded 384→512) is discarded at dispatch and falls back to the existing kernels. A test pins this.

Results (MI350X, kernel benchmarking)

These rows are produced by the tuner (gemm_moe_tune.py --a4w4-compact --fused-shared-expert). For each shape it re-times main's row end to end through fused_moe in the same process, and writes a compact row only if a candidate is faster. 129 experts including the fused shared expert, topk 5. Compact rows record end-to-end fused_moe time in us. Main's rows record the sum of separately timed kernels, so the two us columns in the CSV are not directly comparable; the tuner never compares them.

inter_dim Tokens Main, end to end (µs) This PR (µs) Speedup
384 (TP8) 2048 236.6 229.0 1.03×
4096 348.4 315.2 1.11×
8192 615.9 517.0 1.19×
16384 1029.1 927.5 1.11×
32768 1960.7 1769.9 1.11×
768 (TP4) 2048 356.1 349.4 1.02×
8192 838.0 717.9 1.17×
16384 1342.5 1245.3 1.08×
32768 2542.2 2243.4 1.13×
1536 (TP2) 1024 593.0 503.6 1.18×
2048 667.1 573.1 1.16×
4096 914.6 766.8 1.19×
8192 1494.1 1178.3 1.27×
16384 2677.9 1963.0 1.36×
32768 5280.8 3598.7 1.47×

Main keeps its rows for TP8/TP4 at 512–1024 tokens (it is 10–14% faster there), TP4 at 4096 (a tie) and TP2 at 512.

The TP8 rows above compare against main's 384 rows called directly. vLLM never reaches those: it rounds the ROCm MXFP4 intermediate size up to 256, so the 384-wide TP8 shard is stored and computed as 512. A third of the stage-1 output columns and stage-2 K are zeros, and no tuned row exists at 512, so it runs main's default heuristic. Against what vLLM runs at TP8 today:

Tokens vLLM today: 512-padded (µs) This PR: true 384 (µs) Speedup
512 163.7 127.9 1.28×
1024 232.6 151.8 1.53×
2048 299.5 220.1 1.36×
4096 471.3 306.6 1.54×
8192 825.7 522.9 1.58×
16384 1493.5 1022.2 1.46×
32768 2990.5 1894.5 1.58×

At 512–1024 tokens this PR's column is main's own 384 row: dropping the padding gives that gain on its own. Most of the TP8 win is removing the padding; this family adds another 1.02–1.18× on top. The padded default path also rounds the intermediate to bf16 before requantizing, which costs accuracy (0.16 relative L2 against an fp32-intermediate reference, vs 2.4e-3; it matches a bf16-intermediate reference to 3.2e-3).

This PR also adds tuned bf16-activation decode rows at inter_dim=384 (minimax_m3_a16w4_tuned_fmoe.csv, 1–256 tokens). At those sizes they take 0.66–0.95× the time of the 512-padded rows vLLM runs today, and without them the unpadded shard falls back to a default heuristic that is up to 2.1× slower.

TP8 serving (MI350X, vLLM)

vLLM pads the TP8 shard to 512. The companion vLLM change (akii96/vllm aakif/mxfp4-rocm-a4w4-128-align) keeps it at 384 for AITER A4W4. Four arms, same image and serving flags (fused shared experts, chunked prefill at 32768 tokens, fp8 KV cache). Output tok/s, mean of two runs:

Arm 60000/600 c64 128000/1024 c4 8192/1024 c128 GSM8K 5-shot
A. vLLM today (512-padded), AITER main 465.9 296.3 3122 87.6%
B. Unpadded, AITER main 492.9 276.5 3276 88.3%
C. Unpadded, this PR's prefill rows only 518.7 278.7 3417 87.3%
D. Unpadded, this PR (prefill + decode rows) 536.3 323.8 3598 88.6%
D vs A +15.1% +9.3% +15.3%
  • Removing the padding alone (B) helps prefill-heavy traffic but slows decode, because no tuned rows exist at 384 (128k c4 TPOT 9.6 → 10.8 ms).
  • The compact prefill kernels add most of the long-prompt gain (60k c64 TPOT 115 → 96 ms with D).
  • The 384 decode rows recover and beat the padded decode (128k c4 TPOT 9.6 → 8.8 ms).
  • Output quality is unchanged: GSM8K is within its ±0.9% error in every arm.
  • 128000/1024 c4: 6 of 16 requests exceed --max-model-len in every arm; the rows are the 10 that complete.
  • 8192/1024 c128 varies by about ±7% between runs in every arm.

Accuracy. Relative L2 2.4e-3 for every shipped row against a torch reference using AITER's MX quantization. The CSV's err1/err2 (3.9–5.4%) are the element-wise atol/rtol=0.01 mismatch ratio against that reference. On real MiniMax-M3 checkpoint weights (one layer, all three TP widths, real router) it is 2.3e-3 for every config.

Known limitations

  • Fused combine needs expert E-1 to be a shared expert routed exactly once per token. Enable it with AITER_MOE_A4W4_COMPACT_FUSED_SHARED_EXPERT=1 (vLLM fused shared experts). Without it, the same rows use the separate combine and stay exact for any routing.
  • Activation scale rule. The family matches AITER's runtime MX quant (round-up). AITER_MOE_A4W4_COMPACT_SCALE_RULE=even matches checkpoints calibrated with Quark's even rule.

Test plan [to-do]

  • Unit and dispatch tests: op_tests/test_flydsl_moe_a4w4_compact.py, op_tests/test_moe_mxfp4_inter_dim_dispatch.py
  • Accuracy of every config against the torch reference, including MiniMax-M3 checkpoint weights
  • Kernel-level performance and accuracy on MI355X
  • vLLM end to end before / after, TP2 / TP4 / TP8
  • GSM8K before / after

@github-actions

github-actions Bot commented Oct 9, 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: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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 6330 --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.

@akii96
akii96 force-pushed the aakif/moe-a4w4-compact branch 5 times, most recently from c4e5148 to 33284bd Compare October 10, 2026 16:22
A FlyDSL MoE family for MXFP4 activations and weights with SwiGLU-OAI, built
for prefill calls of 512 to 32768 tokens and dispatched from fused_moe.

- Compact expert-sorted rows: exactly tokens * topk rows, never padded to the
  tile height.
- Activation quant and a parallel counting sort run on device with no host
  syncs. Stage 1 fuses gate/up GEMM, SwiGLU-OAI and the MXFP4 requant of the
  intermediate in a persistent 256x256 tile; stage 2 applies the router weight.
  When expert E-1 is a shared expert routed exactly once per token (checked on
  device per batch), the combine is folded into the shared expert's epilogue;
  otherwise the separate combine runs, so any routing is exact.
- Reads the standard preshuffled weights (shuffle_weight (16, 16) and
  e8m0_shuffle, gate/up separated) in place; only the e8m0 scales are
  repacked.

Tuned rows name each stage like the other FlyDSL MoE rows
(kernelName1 = flydsl_a4w4c_g1_..., kernelName2 = flydsl_a4w4c_g2_...,
aiter/ops/flydsl/a4w4c_kname.py). get_2stage_cfgs routes them to the
whole-graph implementation; malformed names, padded calls and unsupported
shapes fall back to the existing kernels.

MiniMax-M3 MXFP4 rows:
- A4W4 prefill rows from this family for TP2 / TP4 / TP8 (inter_dim 1536 /
  768 / 384) where it beats the existing rows; other shapes keep them.
- Rows from the existing FlyDSL kernels where they are faster: A16W4 decode
  (1-256 tokens) at inter_dim 384 and 1536, and A4W4 at 256-1024 tokens for
  inter_dim 1536, which had no tuned rows.

Tests: op_tests/test_flydsl_moe_a4w4_compact.py, including skewed and
arbitrary routing, malformed-name fallback and optional accuracy on real
MiniMax-M3 checkpoint weights (AITER_MINIMAX_M3_MXFP4_PATH).

Signed-off-by: Aakif Nawaz <[email protected]>

This branch has not been deployed

No deployments
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.

1 participant