Repository navigation
[Config] [Tuning][gfx950] Retune MiniMax-M3.1 TP4 A16W4 decode rows (E=128, top-4) for 8/16/32/64/128 tokens - #7414
Conversation
…=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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
…=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]>
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]>
…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]>
* [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]>
What
aiter/configs/model_configs/minimax_m3_a16w4_tuned_fmoe.csv: replace the FlyDSL A16W4 kernel pair of theE=128, topk=4, model_dim=6144, inter_dim=768(TP4) rows fortoken = 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.t16x32x128_w4_xcd1_kw4->t16x32x128_w2_xcd1_kw4t16x256x128_atomic_xcd4->t16x128x256_reduce_bnt2t16x32x128_w4_xcd1_kw2->t16x32x128_w2_xcd1_kw4t16x128x256_atomic->t16x256x128_atomic_bnt2_persistt16x128x256_w2_xcd1->t16x32x128_w4_xcd1_kw2t16x256x128_atomic_bnt2_xcd4->t16x256x256_reduce_bnt2t16x192x128_w2_xcd1->t16x32x128_w2_xcd1_kw4t16x256x256_atomic_bnt2_xcd4->t16x256x256_reduce_bnt2_xcd4_persistt16x128x128_w3_xcd1->t16x32x128_w2_kw4t16x256x128_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:
(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_waveFlyDSL kernels win and thetoken=64row of #6942 (t16x192x128_w2_xcd1) isslower 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 fromget_flydsl_stage{1,2}_kernels('bf16','fp4','bf16')) withfused_moeend 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=128family.us1/us2/us/err2in the CSV are measured with uniform random routing attoken=T(the tuner's convention; profiler kernel times forus1/us2,graph time for
us);err2is the max-abs error of the whole fused op against a bf16 reference built from the dequantised MXFP4 weights, in % of max|ref|.err1is 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):
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_configon 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
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_configon current aiter main (JIT-built in an isolated directory; main = 41c2528) runs the new rows through productionfused_moeand reports all of themOKagainst its torch reference.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).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
gemm_moe_tune.py --run_config; not run with v0.1.28 binaries.token = 1, 2, 4, 256unchanged (no real-routing data at 1/2/4 tokens; 129..255 tokens were not dumped).flydsl_mxmoe_g1_*kernels are discarded on aiter 0.1.27 becauseaiter.is_mxfp4_moe_shape_supported(128, 6144, 768, 4)is Falsewithout the
gen_instances.pychange of [Config] [Tuning] [gfx950] Add MiniMax-M3.1 MXFP4 MoE configs (E=128, top-4, TP2/TP4); fix A16W4 tuner checks #6942 and a rebuiltmodule_moe_mxfp4_aux.so; in the PR arm 56 such rows were discarded with a warning, only the decode a16w4 rows (+ the non-mxmoetoken=512row of [Config] [Tuning] [gfx950] Add MiniMax-M3.1 MXFP4 MoE configs (E=128, top-4, TP2/TP4); fix A16W4 tuner checks #6942) were consumed.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_moeselects for five rows ofminimax_m3_a16w4_tuned_fmoe.csv:token = 8, 16, 32, 64, 128of 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 thetoken = 64row 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:
fused_moeop: 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_configon aiter main: all five new rows run through productionfused_moeand reportOKagainst the tuner's torch reference.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_1x32attoken = 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 changekernelName1/kernelName2/block_m/ksplitand the other 22 rows are byte-identical (the diff is 5 lines +/- in one file). Thetoken = 1, 2, 4, 256rows 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