Repository navigation
[HIP] [CI] Generate MXFP4 MoE aux kernels for (64, 4096, 4096, 2) - #7938
Conversation
Muse-Spark-Open-816B-A42B served at TP=4 with expert parallel (EP=4)
runs the MXFP4 fused MoE with 64 local experts, hidden 4096,
intermediate 4096 and top-2 routing. The generated MXFP4 aux kernels
(sort/quant, sort, quant, scatter-reduce) did not cover this shape:
- the MoE tuner (gemm_moe_tune.py --mxfp4-flydsl) aborts the whole
process on the first candidate that needs the scatter-reduce
epilogue (no instance for aux_scatter_H4096_TOPK2), at token >= 2048;
- fused_moe rejects tuned MXMOE rows for the shape ("generated MXFP4
auxiliary kernels do not cover ...").
Add the shape to gen_instances.py SHAPES and to
MXFP4_MOE_SUPPORTED_SHAPES. With expert parallel, MXMOE rows are still
rejected for the expert_mask reason; that is unchanged here.
Co-Authored-By: Claude <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
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 |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the added MXFP4 MoE shape coverage.
No open issues 🎉
What changed in this PR
This PR extends AITER’s MXFP4 MoE auxiliary-kernel coverage to (64, 4096, 4096, 2), addressing missing instances during tuning and enabling tuned MXMOE rows for non-expert-parallel use.
Changes:
- Adds the shape to both the kernel generator and the wrapper’s supported-shape set.
- Leaves kernel implementations, dispatch logic, and existing expert-parallel restrictions unchanged.
| File | Description |
|---|---|
csrc/kernels/mxfp4_moe/moe_aux/codegen/gen_instances.py |
Adds the shape to auxiliary-kernel instance generation. |
aiter/ops/moe_mxfp4_aux.py |
Adds matching coverage to the supported-shape set. |
Review effort: Balanced
|
I have reviewed every line of this PR and the self-review answers for revision |
|
@valar-cop review |
valar-cop
left a comment
There was a problem hiding this comment.
some changes needed..
please quote a module_moe_mxfp4_aux build on this head, the 407 count is from a different tree
ci green.
yzhou103
left a comment
There was a problem hiding this comment.
please check the comment
Run the BF16 and MXFP4 scatter-reduce reference and bounds tests for both
H=6144/TOPK=5 and the new H=4096/TOPK=2 key so the generated
aux_scatter{,q}_H4096_TOPK2_NT{0,1} instances are compiled and executed.
|
@yzhou103 fixed the issues |
There was a problem hiding this comment.
🟡 Changes recommended
The new regression cases are not executed by Aiter CI because the runner invokes the test file directly without a script entry point, leaving the BF16/MXFP4 reference and bounds checks unverified.
1 open issue
Review effort: Balanced
The file has pytest-style tests and no script entry point, so `python3 op_tests/test_moe_scatter_reduce.py` imported it and exited 0 without running a case.
opus::fp4_to_fp32_packed_x8 is a zero-returning stub on gfx942, so the packed-FP4 scatter output cannot match the reference in MI300X jobs now that the file runs under pytest. BF16 scatter tests stay enabled.
There was a problem hiding this comment.
🔵 Needs a closer look
Human review must confirm pending current-head gfx950 build and reference-test results for the new HIP sort and scatter instances, since older installed-aiter runs do not validate this revision.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
|
The three failing I don't have the rights to re-run jobs here. Could a maintainer re-run the failed jobs once the run completes? |
|
@yzhou103 three shard tests failed to download the artefact everything else is green |
|
@yzhou103 the |


Motivation
Muse-Spark-Open-816B-A42B served at TP=4 with expert parallel (EP=4) runs the MXFP4 fused MoE with 64 local experts, hidden 4096, intermediate 4096 and top-2 routing. The generated MXFP4 aux kernels don't cover this shape, which has two effects:
csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py --mxfp4-flydslaborts the whole tuning process at token >= 2048, on the first candidate whose stage-2 epilogue needs the scatter-reduce helper:mxfp4_moe_scatter_reduce: no codegen'd instance for shape key 'aux_scatter_H4096_TOPK2_NT1'. Earlier tuning of this model lost token 2048 / 8192 / 16384 this way.fused_moerejects tuned MXMOE rows for the shape:discarding MXMOE config: generated MXFP4 auxiliary kernels do not cover (expert=64, model_dim=4096, inter_dim=4096, topk=2).Technical Details
Adds
(64, 4096, 4096, 2)toSHAPESincsrc/kernels/mxfp4_moe/moe_aux/codegen/gen_instances.pyand toMXFP4_MOE_SUPPORTED_SHAPESinaiter/ops/moe_mxfp4_aux.py(kept in sync, checked byop_tests/test_mxfp4_moe_aux_codegen.py). No kernel or dispatch changes; on this head the generator emits 474 instances, 16 more thanmain(458):sortonly/sortzi/sort_quantforNE64_TOPK2_H4096,quantandsort3sfor MB32/64/128,sortscalesfor BM32/64/128, andscatter/scatterqH4096_TOPK2NT0/NT1.op_tests/test_moe_scatter_reduce.pywas pinned toH=6144, TOPK=5; it is now parametrized over(D_HIDDEN, TOPK)with a(4096, 2)case, so the newaux_scatter{,q}_H4096_TOPK2_NT{0,1}instances are compiled and run against the fp32 reference..github/scripts/aiter_test.shnow runs that file throughpython3 -m pytest: it has pytest-style tests and no script entry point, so the previouspython3 op_tests/test_moe_scatter_reduce.pyinvocation exited 0 without running any case. The MXFP4scatter_reduce_qtest is skipped unlessget_gfx_runtime() == "gfx950", becauseopus::fp4_to_fp32_packed_x8is a zero-returning stub on gfx942 and MI300X jobs would otherwise fail it; the BF16 scatter tests run on every arch.Scope: with expert parallel,
fused_moestill rejects MXMOE rows (the MXMOE output_aux sort drops expert_mask). That is unchanged here, so this alone does not make MXMOE rows usable for the EP deployment; it fixes the tuner abort and covers the shape for non-EP use.Not a duplicate
No open PR adds MXFP4 aux shapes for this model (
gh pr list --repo ROCm/aiter --search "gen_instances mxfp4 aux","muse spark mxfp4 aux").Test Plan
Earlier, on MI350P (gfx950, 128 CUs), with the same two lines applied to an older installed aiter (not this head):
module_moe_mxfp4_auxand callmxfp4_moe_scatter_reduceforNE=64, TOPK=2, D_HIDDEN=4096against a reference;fused_moe.get_2stage_cfgs(...)for the shape with a tuned MXMOE row (non-EP): the row is used instead of rejected;gemm_moe_tune.py --mxfp4-flydslfor token 8 to 16384.Test Result
test_mxfp4_moe_aux_codegen.py: 3 passed.gen_instances.pyon this head: 474 instances (458 onmain+ 16 for the new shape).mxfp4_moe_scatter_reducefor the new shape matched the reference (max abs error 0.015, bf16 rounding).test_moe_scatter_reduce.pywith the new(4096, 2)cases: pending a gfx950 run on this head (CI MI35X).get_2stage_cfgs(non-EP) now returns the tuned MXMOE kernels for token 8 and 2048 (using 2stage (kernelName1='flydsl_mxmoe_g1_a4w4_...')) instead of the "do not cover" rejection.PR Self-Review
Reviewed revision
baf8bd1768d5276cc32e9b60e5c1bd728fdb9c5aBehavior and intent
Adds
(64, 4096, 4096, 2)to both MXFP4 aux shape catalogs, somodule_moe_mxfp4_auxnow generates the BM16 sort (sort-only and zero-init) instances forNE=64, TOPK=2, D_HIDDEN=4096and the scatter / scatter-q instances for the(H=4096, TOPK=2)key. Before this, the shape was missing:gemm_moe_tune.py --mxfp4-flydslaborted at token >= 2048 withno codegen'd instance for shape key 'aux_scatter_H4096_TOPK2_NT1', andfused_moediscarded tuned MXMOE rows for the shape with "generated MXFP4 auxiliary kernels do not cover". No kernel source, dispatch logic or selection rules change; only the generated instance set grows (474 instances on this head vs 458 onmain).test_moe_scatter_reduce.pyis parametrized so the new scatter instances are exercised by a test.Validation and unverified scope
On this head:
python3 csrc/kernels/mxfp4_moe/moe_aux/codegen/gen_instances.py --working_path /tmp/genemits 474 instances; the same script onmainemits 458, and the 16-file difference is exactly the new-shape instances listed under Technical Details.blackandruff 0.16.0pass on the changed test;bash -n .github/scripts/aiter_test.shpasses and theop_tests/test_moe_scatter_reduce.pypath from the runner'sfind op_tests -maxdepth 1list matches the new pytest case.Earlier, on MI350P (gfx950, 128 CUs) with the two lines applied to an older installed aiter (not this head; its module had 407 instances, which is why that count differs):
python3 -m pytest op_tests/test_mxfp4_moe_aux_codegen.py -q: 3 passed (every supported shape has a generated instance).mxfp4_moe_scatter_reduceforNE=64, TOPK=2, D_HIDDEN=4096matched a reference (max abs error 0.015, bf16 rounding).fused_moe.get_2stage_cfgs(...)(non-EP) returns the tunedflydsl_mxmoe_g1_a4w4_...kernels for token 8 and 2048 instead of the "do not cover" rejection.gemm_moe_tune.py --mxfp4-flydslcompletes all 10 token counts (8 to 16384) with no abort; the scatter epilogue loses to atomic for this shape (3.8% / 3.1% slower at 8192 / 16384).Unverified / not covered:
module_moe_mxfp4_auxhas not yet been built andop_tests/test_moe_scatter_reduce.pyhas not yet been run on this head on gfx950 (pending CI MI35X); the new sort instances were exercised throughget_2stage_cfgsand the tuner, but not compared element-wise against a reference sort; no end-to-end model accuracy run (no lm_eval / served Muse Spark run) was done with this change; MI300X (gfx942) was not tested because the MXFP4 aux path is gfx950-only. The EP deployment (expert_maskset) remains unchanged and still does not use these generated kernels, as noted under Technical Details.PR-specific question
Architecture: the generated aux kernels are only reached through the MXFP4 FlyDSL MXMOE path, which is gfx950-only (
gemm_moe_tune.pyrefuses non-gfx950 GPUs for--mxfp4-flydsl; the fused decode sort/quant gate checksget_gfx_runtime() == "gfx950"). Dtype: bf16 activations withQuantType.per_1x32MXFP4 (fp4x2) weights and a bf16 output buffer for scatter-reduce. Shape: the sort instances are selected by the exact(NE, TOPK, D_HIDDEN, MB=16)key, here(64, 2, 4096);is_mxfp4_moe_shape_supportedadditionally requiresinter_dimrounded up to 256 to equal 4096; the scatter instances are keyed by(model_dim, topk) = (4096, 2)only, sois_mxfp4_moe_scatter_supportednow also admits the scatter epilogue in tuning for any otherH=4096, topk=2model, which is safe because the instance is generic over expert count and inter_dim.CI change:
.github/scripts/aiter_test.shonly addsop_tests/test_moe_scatter_reduce.pyto an existingcasebranch that switches the command frompython3 "$file"topython3 -m pytest -q "$file"under the sametimeout 60m. It runs in the existingpull_request-triggeredaiter-test.yamljobs, which already execute PRop_tests/code; no workflow permissions, secrets, triggers or interpolation of PR text change, so fork code or text gains no new path to a privileged context. pytest exits non-zero if collection or any case fails, so an empty or broken run can no longer pass silently.Invariant against unsupported inputs:
fused_moeonly takes the generated sort whenexpert_mask is Noneand_mxfp4_aux_instance_supported(experts, topk, hidden, block_m, zero_init)is true, otherwise it falls back to the Opus aux sort or discards the MXMOE row with a logged reason;prepare_mxfp4_moe_auxraises_MissingMxfp4MoeAuxInstancesif a stale built module lacks the instance; andtest_mxfp4_moe_aux_codegen.pyfails if a shape inMXFP4_MOE_SUPPORTED_SHAPEShas no matching entry ingen_instances.SHAPES. Existing shapes keep their selection because entries are only added, none changed or removed.Changed op tests
op_tests/test_moe_scatter_reduce.py: the four kernel tests (BF16 reference, negative/out-of-bounds skips, MXFP4scatter_reduce_qreference, last-row/all-skipped) are parametrized over(D_HIDDEN, TOPK)in((6144, 5), (4096, 2)). Before this, only the MiniMax-M3 key was run, so nothing compiled or executedaux_scatter{,q}_H4096_TOPK2_NT{0,1};test_mxfp4_moe_aux_codegen.pyonly checks that the catalogs agree, not that the kernels run. Not redundant: no other op test callsmxfp4_moe_scatter_reduceforH=4096, TOPK=2. The(6144, 5)cases keep the same coverage as before (the last-row map is identical; the skip map uses the same bad indices in different slots). The MXFP4 test is skipped off gfx950 because the FP4 decode is only implemented there; the BF16 tests are arch-independent.AI assistance (Claude) was used to find the cause, make the change, and run the tests; a human must review every line before merge.
🤖 Generated with Claude Code