Repository navigation
[ASM][MoE] Run the FLAT MXFP4 fmoe tiles on padded intermediate widths, and gate model_dim per kernel - #7012
Closed
mjkvaak-amd wants to merge 1 commit into
Closed
mjkvaak-amd wants to merge 1 commit into
mjkvaak-amd wants to merge 1 commit into
Conversation
JohnNikolay84
force-pushed
the
qwe38_flash_mxfp4_asm
branch
2 times, most recently
from
October 31, 2026 19:22
6b2e9ba to
f429787
Compare
mjkvaak-amd
force-pushed
the
flat-mxfp4-padded-inter-dim
branch
from
November 2, 2026 18:50
a8109ea to
937264d
Compare
mjkvaak-amd
added a commit
to mjkvaak-amd/aiter
that referenced
this pull request
Nov 4, 2026
ROCm#7012's manifest predates ROCm#5757's "Extend TP4/TP2 kernels to conc512", so taking it reset emsort_silu_16x160 and 16x320 to max_tokens 256 and max_assignments 2816 while their .co files and the tuned rows are the conc512 ones. A 512-token MoE call then failed in launch_kernel with "EMSORT ... supports token_cnt <= 256; got 512". Signed-off-by: Mikko Tukiainen <[email protected]> Co-authored-by: Cursor <[email protected]>
mjkvaak-amd
force-pushed
the
flat-mxfp4-padded-inter-dim
branch
from
November 4, 2026 11:44
937264d to
289e558
Compare
JohnNikolay84
force-pushed
the
qwe38_flash_mxfp4_asm
branch
2 times, most recently
from
November 6, 2026 14:18
b209886 to
70ed590
Compare
mjkvaak-amd
marked this pull request as ready for review
November 6, 2026 17:54
…diate widths vLLM stores the MoE intermediate width padded (Qwen3.8-Flash-Next: 320 stored as 384 at TP2, 160 as 256 at TP4) and passes the zero-filled delta as intermediate_pad. The FLAT 16x32/16x160/16x320 tiles and the EMSORT 16x160/16x320 persistent tiles need the logical width, so a padded call never reached them. - fmoe_g1u1 takes intermediate_pad. The FLAT and EMSORT branches keep the stored inter_dim in KernelArgs (gate/up row offset, w1 scale offset, w2 scale pitch) and size the grid, and the EMSORT ps_deno and total_tgs, from inter_dim - intermediate_pad. - POST_REDUCE keeps the stored width. The logical-width grid is NO_SORT and EMSORT only. - get_heuristic_kernel matches FLAT and EMSORT tiles on the logical width. - get_2stage_cfgs falls back to the FLAT or EMSORT MXFP4 1-stage row tuned at inter_dim - intermediate_pad when the stored width has no row. - The pertokenMXfp4 manifests gain a dim_align column. Kernels without the 512-column tail drain declare 1024, and fmoe_g1u1 passes model_dim to the kernel picker, so the alignment applies per kernel. The conc512 EMSORT limits on the upmerged base are unchanged. - test_moe_2stage passes -hip through for a4w4. Co-authored-by: Cursor <[email protected]> Signed-off-by: Mikko Tukiainen <[email protected]>
mjkvaak-amd
force-pushed
the
flat-mxfp4-padded-inter-dim
branch
from
November 6, 2026 17:56
289e558 to
4c0ffeb
Compare
Merged
4 of 10 tasks
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
vLLM stores Qwen3.8-Flash-Next's MoE intermediate width padded (320 → 384 at TP2, 160 → 256 at TP4), so the FLAT and EMSORT MXFP4 1-stage tiles from #5757 never run. This PR launches them over
inter_dim - intermediate_pad, which raises TP2 output throughput by 14.1% at concurrency 1 and 6.9% geomean over concurrency 1–128 on an unmodified vLLM nightly, with GSM8K unchanged.Motivation
At TP2 vLLM calls
fused_moe(inter_dim=384, intermediate_pad=64). #5757's tuned rows are keyed at 320, so the lookup misses and 2-stage runs. Forcing a FLAT tile at 384 gives wrong results for 16x160 and 16x320 (relative error 0.66 to inf); 16x32 is correct but computes the 64 pad columns.Not a duplicate: searched open PRs for "intermediate_pad fmoe", "FLAT MXFP4 padded", "asm_fmoe model_dim 1024". #6184 changes 2-stage inline-sort dispatch and #6598 the FlyDSL stage-1 grid.
Changes
fmoe_g1u1gainsintermediate_pad(default 0). FLAT and EMSORT MXFP4 kernels keep the storedinter_diminKernelArgs, which sets the gate-to-up offset, the w1 scale offset and the w2 scale pitch. They size the grid, and EMSORT'sps_denoandtotal_tgs, frominter_dim - intermediate_pad, and raise an error if that is not a whole number of tiles. Host-sorted kernels are unchanged.get_2stage_cfgsretries a missed lookup atinter_dim - intermediate_padand accepts only a FLAT or EMSORT MXFP4 1-stage row.fused_moe_1stagepasses the pad through, and the heuristic matches on the logical width.dim_align, fixes a silent bug: FLAT 16x128, 16x256 andvs16x32 (SiLU and GELU) have no 512-column tail, so atmodel_dim2560 they skipped 512 output columns. They now declare 1024 and are rejected there. Other rows declare 512, and manifests without the column keep the old 512 rule.test_moe_2stage.py -hipnow applies to a4w4. Its default (0, 0) is unchanged.This does not help at TP1 (640 stored unpadded, no rows) or for prefill chunks above #5757's 512-token rows. At TP4 vLLM rounds the pad of 96 down to 64; vllm-project/vllm#64025 passes the true pad and stays in draft until this PR is merged and released. 2-stage MXFP4 and non-MXFP4 fmoe are untouched.
Performance (if applicable)
MI355X (gfx950, 256 CUs),
fused_moethroughtest_moe_2stage.py, E = 513, top-k 11,model_dim2560, mean of two runs. Before is #5757 alone (qwe38_flash_mxfp4_asm@a10f4be) on the same padded call, which runs 2-stage.TP2 M=32 depends on the routing draw. Over eight draws (the test's RNG state after different preceding cases, identical in both arms), EMSORT 16x320 took 64–67 µs in seven and 99 µs in one, against 93–102 µs for 2-stage. Every other point repeats within 2%.
Serving,
amd/Qwen3.8-Flash-Next-Quark-MXFP4(revisionb2091c38), TP2, MI355X,vllm/vllm-openai-rocm:nightly-4fab5a07475822c6eaa971dceb2e2220d0446808. Both arms build AITER from source: the control ata10f4be(#5757), the candidate with this PR on top. This nightly stores 320 as 384 and passesintermediate_pad=64unchanged. The candidate server logs FLAT 16x32 / 16x160 / 16x320 and EMSORT 16x320; the control logs none of them.Two rounds, the arms side by side on HIP 0,1 and 2,3, swapping pairs for the second round. Output throughput is the mean of the two rounds:
Concurrency 2 is round 1 only: round 2 was contended in both arms (mean TPOT 1.4× the median). Concurrency 64 gained 4.6% and 1.7% in the two rounds. The gain is largest at concurrency 1–4, where FLAT runs, and flat at 128, where 8k prefill chunks are 2-stage in both arms and take most of each step. TTFT is unchanged.
Accuracy, GSM8K on the round-2 servers: all 1319 questions, thinking off, paired per question with an exact McNemar test. 84.5% of generations differ textually, so the claim is no directional change.
Testing
Documentation
fmoe_g1u1has no docstring, andintermediate_padhas the same meaning as the existingfused_moeargument it is passed from.Dependencies
Breaking Changes
None.
intermediate_paddefaults to 0. FLAT 16x128, 16x256 andvs16x32 forced atmodel_dim2560 now raise an error instead of returning wrong output.PR Self-Review
Reviewed revision
4c0ffeb
Behavior and intent
A padded MXFP4
fused_moecall (storedinter_dim, non-zerointermediate_pad) now reaches #5757's FLAT and EMSORT 1-stage rows tuned at the logical width, and those kernels launch over the logical columns while striding over the stored ones. Before, the lookup missed and 2-stage ran, and forcing the tiles gave wrong results. FLAT tiles without a 512-column tail are now rejected atmodel_dim % 1024 != 0instead of skipping columns.Validation and unverified scope
MI355X (gfx950, 256 CUs), the two images above, on
4c0ffeband its basea10f4be. The control ran this PR'stest_moe_2stage.py, so both arms build the same padded weights:The padded FLAT and EMSORT
logits_diffis 2.2e-4 to 1.2e-3, against about 1.2e-5 for 2-stage; the test fails above 1e-2. The gap is the 1-stage kernels' in-register activation quantization: on the FLAT-only revision, unpadded 320 gave 4.9e-4 to 1.4e-3. (checkAllclose ... failed!prints for every MXFP4 case, 2-stage included:atol=0.01is tighter than MXFP4.)Earlier revision (2026-10-27, FLAT only): padded vs unpadded weights and the model_dim check
The same tile on padded and on unpadded weights, M = 1–64, max abs diff. The reference is an unpadded rerun, since the top-k accumulation is atomic. On #5757 alone, padded 16x160 and 16x320 give relative error 0.66 to inf.
At
model_dim2560, FLAT 16x128, 16x256 andvs16x32 went from relative error 0.45 to rejected; at 3072 they give 0.03–0.04. Thetest_moe.pyint8/fp8 g1u1 cases behaved as on stock.What remains unverified: the padded-vs-unpadded probe, the
model_dimtable andtest_moe.pyare from the FLAT-only revision and were not rerun on4c0ffeb. The EMSORT probe against unpadded weights was not run; its accuracy evidence islogits_diffand GSM8K. GPQA-Diamond was not rerun (0.904 → 0.914 on the FLAT-only revision). TP4 serving needs vllm-project/vllm#64025 and was not run here. Not tested on MI250X or MI300X, because the kernels are gfx950-only. NIAH was not run. CI keeps-hipat (0, 0) for a4w4, so it does not reach a padded launch.PR-specific question
What would each changed op test fail on before this PR, and why does an existing canonical test not cover it?
Before this PR, the a4w4 cases of
test_moe_2stage.pyhard-codedintermediate_pad=0and ignored-hip, so no test could build a padded MXFP4 call. With-dim 2560,384 -hip 0,64the case reaches the FLAT and EMSORT rows. Without thefmoe_g1u1change, 16x160 and 16x320 return wrong results on that layout. No existing test passes a non-zerointermediate_padto an a4w4fused_moe.Changed op tests
op_tests/test_moe_2stage.py:-hip(hidden and intermediate pad) now also applies to the a4w4 cases, which used to hard-code (0, 0). This covers the padded FLAT and EMSORT dispatch and its accuracy against the torch reference. The bf16/fp8 defaults (192, 128) and the a4w4 default (0, 0) are unchanged, so CI runs the same cases as before.Co-authored-by: Cursor [email protected]