Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
c4e5148 to
33284bd
Compare
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]>
33284bd to
69546dc
Compare
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_dimis 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:
tokens × topkexpert-sorted rows. Tail tiles never load or store past an expert's count.inter_dimthat is a multiple of 128 runs at its real size.E-1is 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.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:
aiter/ops/flydsl/a4w4c_kname.pybuilds and parses these names, andget_2stage_cfgsroutes aflydsl_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 throughfused_moein 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-endfused_moetime inus. Main's rows record the sum of separately timed kernels, so the twouscolumns in the CSV are not directly comparable; the tuner never compares them.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:
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:--max-model-lenin every arm; the rows are the 10 that complete.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
E-1to be a shared expert routed exactly once per token. Enable it withAITER_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.AITER_MOE_A4W4_COMPACT_SCALE_RULE=evenmatches checkpoints calibrated with Quark'sevenrule.Test plan [to-do]
op_tests/test_flydsl_moe_a4w4_compact.py,op_tests/test_moe_mxfp4_inter_dim_dispatch.py