Skip to content

[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
ROCm:qwe38_flash_mxfp4_asmfrom
mjkvaak-amd:flat-mxfp4-padded-inter-dim
Closed

mjkvaak-amd wants to merge 1 commit into
ROCm:qwe38_flash_mxfp4_asmfrom
mjkvaak-amd:flat-mxfp4-padded-inter-dim

Conversation

@mjkvaak-amd

@mjkvaak-amd mjkvaak-amd commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

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_g1u1 gains intermediate_pad (default 0). FLAT and EMSORT MXFP4 kernels keep the stored inter_dim in KernelArgs, which sets the gate-to-up offset, the w1 scale offset and the w2 scale pitch. They size the grid, and EMSORT's ps_deno and total_tgs, from inter_dim - intermediate_pad, and raise an error if that is not a whole number of tiles. Host-sorted kernels are unchanged.
  • get_2stage_cfgs retries a missed lookup at inter_dim - intermediate_pad and accepts only a FLAT or EMSORT MXFP4 1-stage row. fused_moe_1stage passes the pad through, and the heuristic matches on the logical width.
  • A new manifest column, dim_align, fixes a silent bug: FLAT 16x128, 16x256 and vs 16x32 (SiLU and GELU) have no 512-column tail, so at model_dim 2560 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 -hip now 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_moe through test_moe_2stage.py, E = 513, top-k 11, model_dim 2560, mean of two runs. Before is #5757 alone (qwe38_flash_mxfp4_asm @ a10f4be) on the same padded call, which runs 2-stage.

Hardware Workload/configuration Before After Change
MI355X TP2: 384 stored, pad 64, M=1 (FLAT 16x32) 30.5 µs 13.5 µs 2.27×
MI355X TP2, M=4 (FLAT 16x32) 38.5 µs 18.8 µs 2.05×
MI355X TP2, M=8 (FLAT 16x160) 50.7 µs 28.5 µs 1.78×
MI355X TP2, M=16 (FLAT 16x320) 68.1 µs 46.1 µs 1.48×
MI355X TP2, M=32 (EMSORT 16x320) 93–102 µs 64–99 µs 1.03–1.45×
MI355X TP2, M=64 (EMSORT 16x320) 129.2 µs 107.3 µs 1.20×
MI355X TP2, M=128 (EMSORT 16x320) 156.1 µs 123.3 µs 1.27×
MI355X TP4: 256 stored, pad 96, M=1 (FLAT 16x32) 29.4 µs 11.4 µs 2.59×
MI355X TP4, M=4 (FLAT 16x32) 34.2 µs 12.9 µs 2.66×
MI355X TP4, M=8 (FLAT 16x32) 41.8 µs 18.4 µs 2.27×
MI355X TP4, M=16 (FLAT 16x160) 59.3 µs 28.0 µs 2.12×
MI355X TP4, M=32 (EMSORT 16x160) 83.0 µs 51.4 µs 1.62×
MI355X TP4, M=64 (EMSORT 16x160) 96.8 µs 57.1 µs 1.69×
MI355X TP4, M=128 (EMSORT 16x160) 113.3 µs 65.2 µs 1.74×

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 (revision b2091c38), TP2, MI355X, vllm/vllm-openai-rocm:nightly-4fab5a07475822c6eaa971dceb2e2220d0446808. Both arms build AITER from source: the control at a10f4be (#5757), the candidate with this PR on top. This nightly stores 320 as 384 and passes intermediate_pad=64 unchanged. The candidate server logs FLAT 16x32 / 16x160 / 16x320 and EMSORT 16x320; the control logs none of them.

VLLM_ROCM_USE_AITER=1 VLLM_ROCM_USE_AITER_FUSION_SHARED_EXPERTS=1 \
vllm serve amd/Qwen3.8-Flash-Next-Quark-MXFP4 --tensor-parallel-size 2 \
  --default-chat-template-kwargs '{"enable_thinking": false}' \
  --trust-remote-code --no-enable-prefix-caching

# C = 1 2 4 8 16 32 64 128, N = max(4 * C, 8)
vllm bench serve --backend vllm --model amd/Qwen3.8-Flash-Next-Quark-MXFP4 --dataset-name random \
  --random-input-len 8192 --random-output-len 1024 --random-range-ratio 0 --ignore-eos \
  --max-concurrency $C --num-prompts $N --num-warmups $C --seed 7

lm_eval --model local-chat-completions --tasks gsm8k --num_fewshot 5 --apply_chat_template \
  --model_args "model=amd/Qwen3.8-Flash-Next-Quark-MXFP4,base_url=http://localhost:8000/v1/chat/completions,num_concurrent=32,timeout=1200,max_retries=3,tokenized_requests=False,max_gen_toks=2048" \
  --seed 4321 --log_samples

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 Output tok/s Mean TPOT (ms)
1 155.9 → 177.8 (+14.1%) 5.94 → 5.14 (−13.4%)
2 276.7 → 313.2 (+13.2%) 6.52 → 5.68 (−13.0%)
4 449.6 → 497.5 (+10.7%) 7.51 → 6.65 (−11.4%)
8 688.6 → 733.2 (+6.5%) 9.11 → 8.39 (−7.9%)
16 962.5 → 1009.9 (+4.9%) 12.87 → 12.06 (−6.3%)
32 1215.1 → 1257.0 (+3.5%) 21.52 → 20.49 (−4.7%)
64 1340.5 → 1381.7 (+3.1%) 40.99 → 39.52 (−3.6%)
128 1568.1 → 1570.8 (+0.2%) 71.28 → 71.34 (+0.1%)

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.

Metric Control This PR Fixed / broken McNemar p
strict-match 0.9666 0.9636 10 / 14 0.541
flexible-extract 0.9659 0.9651 11 / 12 1.000

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

fmoe_g1u1 has no docstring, and intermediate_pad has the same meaning as the existing fused_moe argument it is passed from.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. intermediate_pad defaults to 0. FLAT 16x128, 16x256 and vs 16x32 forced at model_dim 2560 now raise an error instead of returning wrong output.

PR Self-Review

Reviewed revision

4c0ffeb

Behavior and intent

A padded MXFP4 fused_moe call (stored inter_dim, non-zero intermediate_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 at model_dim % 1024 != 0 instead of skipping columns.

Validation and unverified scope

MI355X (gfx950, 256 CUs), the two images above, on 4c0ffeb and its base a10f4be. The control ran this PR's test_moe_2stage.py, so both arms build the same padded weights:

python op_tests/test_moe_2stage.py -q 4 -a silu -e 513 -k 11 -t 1 2 4 8 16 32 64 128 --no-flydsl-csv -dim 2560,384 -hip 0,64
python op_tests/test_moe_2stage.py -q 4 -a silu -e 513 -k 11 -t 1 2 4 8 16 32 64 128 --no-flydsl-csv -dim 2560,256 -hip 0,96

The padded FLAT and EMSORT logits_diff is 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.01 is 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.

Logical → stored (pad) Tile padded vs unpadded unpadded rerun
320 → 384 (64) 16x32 0.094–0.22 0.125–0.22
320 → 384 (64) 16x160 0.047–0.125 0.0625–0.109
320 → 384 (64) 16x320 0.047–0.094 0.047–0.094
160 → 256 (96) 16x32 0.055–0.109 0.0625–0.109
160 → 256 (96) 16x160 0.031–0.047 0.031–0.055
640 → 768 (128) 16x320 0.0625–0.156 0.094–0.156

At model_dim 2560, FLAT 16x128, 16x256 and vs 16x32 went from relative error 0.45 to rejected; at 3072 they give 0.03–0.04. The test_moe.py int8/fp8 g1u1 cases behaved as on stock.

What remains unverified: the padded-vs-unpadded probe, the model_dim table and test_moe.py are from the FLAT-only revision and were not rerun on 4c0ffeb. The EMSORT probe against unpadded weights was not run; its accuracy evidence is logits_diff and 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 -hip at (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.py hard-coded intermediate_pad=0 and ignored -hip, so no test could build a padded MXFP4 call. With -dim 2560,384 -hip 0,64 the case reaches the FLAT and EMSORT rows. Without the fmoe_g1u1 change, 16x160 and 16x320 return wrong results on that layout. No existing test passes a non-zero intermediate_pad to an a4w4 fused_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]

@JohnNikolay84
JohnNikolay84 force-pushed the qwe38_flash_mxfp4_asm branch 2 times, most recently from 6b2e9ba to f429787 Compare October 31, 2026 19:22
@mjkvaak-amd
mjkvaak-amd force-pushed the flat-mxfp4-padded-inter-dim branch from a8109ea to 937264d Compare November 2, 2026 18:50
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
mjkvaak-amd force-pushed the flat-mxfp4-padded-inter-dim branch from 937264d to 289e558 Compare November 4, 2026 11:44
@JohnNikolay84
JohnNikolay84 force-pushed the qwe38_flash_mxfp4_asm branch 2 times, most recently from b209886 to 70ed590 Compare November 6, 2026 14:18
@mjkvaak-amd
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

Copy link
Copy Markdown
Contributor Author

Superseded by #7611: this PR was closed automatically when its base branch qwe38_flash_mxfp4_asm was deleted after #5757 merged. #7611 is the same commit rebased onto main.

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.

2 participants