Skip to content

[ASM] [HIP] [MoE] Run the FLAT and EMSORT MXFP4 fmoe tiles on padded intermediate widths - #7611

Merged
JohnNikolay84 merged 7 commits into
ROCm:mainfrom
mjkvaak-amd:flat-mxfp4-padded-inter-dim
Nov 26, 2026
Merged

JohnNikolay84 merged 7 commits into
ROCm:mainfrom
mjkvaak-amd:flat-mxfp4-padded-inter-dim

Conversation

@mjkvaak-amd

@mjkvaak-amd mjkvaak-amd commented Nov 7, 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.

Replaces #7012, which GitHub closed when its base branch qwe38_flash_mxfp4_asm was deleted after #5757 merged. Unblocks vllm-project/vllm#64025.

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 SiLU/GELU 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 rounded up to whole tiles, which only adds zero-pad columns. They raise an error only if that exceeds the stored width, so every row that ran at its stored width before still runs. Host-sorted kernels, and the Situv2 and SwiGLU OAI tiles (whose manifests have no dim_align), get no pad and run over the stored width as before.
  • get_2stage_cfgs retries a missed lookup at inter_dim - intermediate_pad and accepts only a FLAT or EMSORT MXFP4 SiLU/GELU 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. The tuned-CSV pass, which CI runs, reruns each SiLU/GELU MXFP4 FLAT/EMSORT row with a pad. Rows whose width is not a multiple of 128 run at vLLM's stored layout (Flash-Next 320 as 384/64, 160 as 256/96). Each kernel and shape also runs once at its own width with pad 64 (e.g. 16x256 at 256). test_fmoe records every fmoe_g1u1 launch and asserts that the row's kernel was the only one launched, so a 2-stage fallback fails.

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, non-MXFP4 fmoe and the MXFP4 Situv2 and SwiGLU OAI tiles 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 main with #5757 merged (measured at a10f4be, whose MoE files equal main @ 581579a) 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, identical to main in the files this PR touches), 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

74835b1

Behavior and intent

A padded MXFP4 fused_moe call (stored inter_dim, non-zero intermediate_pad) with SiLU or GELU now reaches #5757's FLAT and EMSORT 1-stage rows tuned at the logical width. Those kernels launch over the logical columns, rounded up to whole tiles, while striding over the stored ones. Rows tuned at the stored width keep running with a pad. 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 performance, serving and GSM8K numbers above were measured on the first commit's patch (4c0ffeb, base a10f4be). The control ran this PR's test_moe_2stage.py, so both arms build the same padded weights. On 080a278 (rebased onto main @ 8b13d52, with the round-up), the same two ladders dispatch the same rows. They time within the run-to-run spread of the table (TP2 13.0–123 µs, TP4 11.5–66.6 µs, logits_diff ≤ 1.2e-3):

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

On fb7d8f2 (080a278 plus a main merge and the launch assertion), all 35 padded CSV cases launch their expected kernel, with logits_diff ≤ 1.0e-3. With the logical-width retry disabled, the suite fails on the first padded Flash-Next case ("expected 1-stage …flat_novs_silu_16x32E, launched no fmoe_g1u1"). On 025ebcb, the stored-width cases raise (16x128 at 512, pad 64: "needs inter_dim - intermediate_pad divisible by sub_GU"). AITER_MOE_2STAGE_CI_PROFILE=standard python op_tests/test_moe_2stage.py --csv-filter "" passes. The empty filter lifts the FlyDSL AOT run-only guard, because the image JIT-builds FlyDSL. The run had 1326 cases, plus 30 large shapes skipped for free memory on a shared GPU; none of the skips were padded cases.

On 31100d9 (e620d659, rebased onto main @ 31f72a4081, plus the SiLU/GELU gate), a probe calls get_2stage_cfgs on a padded layout whose logical width has a tuned FLAT row. Before the gate, MiniMax-M3 SwiGLU OAI (stored 896, pad 128) took the retry onto flat_vs_swiglu_oai_16x32 tuned at 768. With the gate it does not, and Flash-Next SiLU (256, pad 96) still does. The MXFP4 CSV suite runs the same 90 cases as on fb7d8f2, with 40 padded lookups resolved by the retry, and passes. The CI profile passes with 1374 cases; one unpadded 32768-token case is skipped by the existing FlyDSL 32-bit workspace guard.

On 74835b1 (merge of main @ 6a0a23ff3a, which includes the #7901 revert #8489), the SiLU/GELU MXFP4 manifests are again identical to 31100d9's. The MXFP4 CSV suite (90 cases, 40 padded lookups) and the CI profile (1406 cases, the same one skip) pass.

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: serving and GSM8K were not rerun on 080a278 or fb7d8f2; the latter changes only the test since 080a278. The round-up leaves the Flash-Next grid unchanged, because 320 and 160 are whole numbers of their tiles. The padded-vs-unpadded probe, the model_dim table and test_moe.py are from the FLAT-only revision and were not rerun. 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. The new CSV cases cover SiLU/GELU rows only, which is now also the only scope of the change. No padded Situv2 or SwiGLU OAI kernel launch was run; those calls take the stored-width launch that main uses.

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. The new tuned-CSV cases would fail on main, because the padded lookup misses and the expected kernel is not dispatched. They would also fail on this PR's first head, where the stored-width cases raise.

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). The bf16/fp8 defaults (192, 128) and the a4w4 default (0, 0) are unchanged. _iter_csv_cases adds 35 padded MXFP4 FLAT/EMSORT cases to CI's tuned-CSV pass: 20 at vLLM's stored layout and 15 stored-width rows with pad 64. Each asserts the launched 1-stage kernel, for every activation, and the accuracy against the torch reference.

Co-authored-by: Cursor [email protected]

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7611 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@github-actions github-actions Bot changed the title [ASM][MoE] Run the FLAT and EMSORT MXFP4 fmoe tiles on padded intermediate widths [ASM] [HIP] [MoE] Run the FLAT and EMSORT MXFP4 fmoe tiles on padded intermediate widths Nov 7, 2026
@aiter-bot

aiter-bot commented Nov 7, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 74835b173d84 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

A padded MXFP4 `fused_moe` call (stored `inter_dim`, non-zero `intermediate_pad`) with SiLU or GELU now reaches #5757's FLAT and EMSORT 1-stage rows tuned at the logical width. Those kernels launch over the logical columns, rounded up to whole tiles, while striding over the stored ones. Rows tuned at the stored width keep running with a pad. 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 performance, serving and GSM8K numbers above were measured on the first commit's patch (`4c0ffeb`, base `a10f4be`). The control ran this PR's `test_moe_2stage.py`, so both arms build the same padded weights. On `080a278` (rebased onto `main` @ `8b13d52`, with the round-up), the same two ladders dispatch the same rows. They time within the run-to-run spread of the table (TP2 13.0–123 µs, TP4 11.5–66.6 µs, `logits_diff` ≤ 1.2e-3):

```bash
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
```

On `fb7d8f2` (`080a278` plus a `main` merge and the launch assertion), all 35 padded CSV cases launch their expected kernel, with `logits_diff` ≤ 1.0e-3. With the logical-width retry disabled, the suite fails on the first padded Flash-Next case ("expected 1-stage …flat_novs_silu_16x32E, launched no fmoe_g1u1"). On `025ebcb`, the stored-width cases raise (16x128 at 512, pad 64: "needs inter_dim - intermediate_pad divisible by sub_GU"). `AITER_MOE_2STAGE_CI_PROFILE=standard python op_tests/test_moe_2stage.py --csv-filter ""` passes. The empty filter lifts the FlyDSL AOT run-only guard, because the image JIT-builds FlyDSL. The run had 1326 cases, plus 30 large shapes skipped for free memory on a shared GPU; none of the skips were padded cases.

On `31100d9` (`e620d659`, rebased onto `main` @ `31f72a4081`, plus the SiLU/GELU gate), a probe calls `get_2stage_cfgs` on a padded layout whose logical width has a tuned FLAT row. Before the gate, MiniMax-M3 SwiGLU OAI (stored 896, pad 128) took the retry onto `flat_vs_swiglu_oai_16x32` tuned at 768. With the gate it does not, and Flash-Next SiLU (256, pad 96) still does. The MXFP4 CSV suite runs the same 90 cases as on `fb7d8f2`, with 40 padded lookups resolved by the retry, and passes. The CI profile passes with 1374 cases; one unpadded 32768-token case is skipped by the existing FlyDSL 32-bit workspace guard.

On `74835b1` (merge of `main` @ `6a0a23ff3a`, which includes the #7901 revert #8489), the SiLU/GELU MXFP4 manifests are again identical to `31100d9`'s. The MXFP4 CSV suite (90 cases, 40 padded lookups) and the CI profile (1406 cases, the same one skip) pass.

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.)

<details>
<summary>Earlier revision (2026-10-27, FLAT only): padded vs unpadded weights and the model_dim check</summary>

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.

</details>

What remains unverified: serving and GSM8K were not rerun on `080a278` or `fb7d8f2`; the latter changes only the test since `080a278`. The round-up leaves the Flash-Next grid unchanged, because 320 and 160 are whole numbers of their tiles. The padded-vs-unpadded probe, the `model_dim` table and `

[truncated in readiness report; see the PR description for the full answer]

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`. The new tuned-CSV cases would fail on `main`, because the padded lookup misses and the expected kernel is not dispatched. They would also fail on this PR's first head, where the stored-width cases raise.

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). The bf16/fp8 defaults (192, 128) and the a4w4 default (0, 0) are unchanged. `_iter_csv_cases` adds 35 padded MXFP4 FLAT/EMSORT cases to CI's tuned-CSV pass: 20 at vLLM's stored layout and 15 stored-width rows with pad 64. Each asserts the launched 1-stage kernel, for every activation, and the accuracy against the torch reference.

Co-authored-by: Cursor <[email protected]>

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@JohnNikolay84

JohnNikolay84 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor
  1. Existing setups can now fail with a hard error. At csrc/py_itfs_cu/asm_fmoe.cu:152, every FLAT or
    EMSORT launch with a non-zero pad now requires (inter_dim - pad) % sub_GU == 0.
    • Before this PR, a tuned FLAT row with an exact match on the stored width ran over the full stored width. That
      was correct whenever the stored width was a multiple of the tile width, because the padding is zeros.

    • With this PR, the same row raises an error if the logical width is not tile-aligned. For example, a 16x256 row
      at stored width 256 with pad 64 gives logical width 192 and now throws.

    • Suggested fix: launch round_up(logical, sub_GU) columns when that is <= stored. The extra columns are zero
      padding. Otherwise fall back to the stored width if that is tile-aligned, and raise only when neither works.
      Mirror this in grid_inter_dim() and kernel_fits().

    • This keeps every case that worked before and still handles 320→384 and 160→256.

@JohnNikolay84

Copy link
Copy Markdown
Contributor

We need to test this path in CI, but right now it is not being picked up.

CI never reaches the new path. The a4w4 default -hip is still (0, 0) /op_tests/test_moe_2stage.py:1356). Neither the padded launch nor the logical-width retry is tested. Add one small CI case, for example -dim 2560,384 -hip 0,64 with a few token counts. That would cover FLAT 16x160 and 16x320, EMSORT, and the retry.

@mjkvaak-amd
mjkvaak-amd force-pushed the flat-mxfp4-padded-inter-dim branch from 025ebcb to 080a278 Compare November 12, 2026 15:31
mjkvaak-amd added a commit to mjkvaak-amd/aiter that referenced this pull request Nov 12, 2026
…ed rows in CI

Review follow-up on ROCm#7611.

- FLAT and EMSORT launch round_up(inter_dim - intermediate_pad, sub_GU)
  columns and raise only if that exceeds the stored width. Requiring the
  logical width to be tile-aligned rejected rows tuned at the stored width
  that ran correctly before, e.g. 16x256 at 256 with pad 64.
  launch_kernel, grid_inter_dim() and kernel_fits() share one helper.
- _iter_csv_cases reruns each SiLU/GELU MXFP4 FLAT/EMSORT row with a pad:
  rows not a multiple of 128 at vLLM's stored layout (logical-width retry),
  and once per kernel and shape at the row's own width with pad 64.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
@JohnNikolay84

Copy link
Copy Markdown
Contributor

@mjkvaak-amd , this PR contains improvements for con 128 and 256

#7901

@mjkvaak-amd

Copy link
Copy Markdown
Contributor Author
  1. Existing setups can now fail with a hard error. At csrc/py_itfs_cu/asm_fmoe.cu:152, every FLAT or
    EMSORT launch with a non-zero pad now requires (inter_dim - pad) % sub_GU == 0.

    • Before this PR, a tuned FLAT row with an exact match on the stored width ran over the full stored width. That
      was correct whenever the stored width was a multiple of the tile width, because the padding is zeros.
    • With this PR, the same row raises an error if the logical width is not tile-aligned. For example, a 16x256 row
      at stored width 256 with pad 64 gives logical width 192 and now throws.
    • Suggested fix: launch round_up(logical, sub_GU) columns when that is <= stored. The extra columns are zero
      padding. Otherwise fall back to the stored width if that is tile-aligned, and raise only when neither works.
      Mirror this in grid_inter_dim() and kernel_fits().
    • This keeps every case that worked before and still handles 320→384 and 160→256.

Thanks! FLAT and EMSORT now launch round_up(inter_dim - intermediate_pad, sub_GU) columns and raise only if that exceeds the stored width. launch_kernel, grid_inter_dim() and kernel_fits() share one helper, so the heuristic, ps_grid_fits and EMSORT's ps_deno/total_tgs all see the same width.

@mjkvaak-amd

Copy link
Copy Markdown
Contributor Author

We need to test this path in CI, but right now it is not being picked up.

CI never reaches the new path. The a4w4 default -hip is still (0, 0) /op_tests/test_moe_2stage.py:1356). Neither the padded launch nor the logical-width retry is tested. Add one small CI case, for example -dim 2560,384 -hip 0,64 with a few token counts. That would cover FLAT 16x160 and 16x320, EMSORT, and the retry.

Rather than one fixed -dim, _iter_csv_cases now reruns each SiLU/GELU MXFP4 FLAT/EMSORT row with a non-zero pad, and requires the row's kernel to dispatch. CI's no-argument run picks these up:

  • Padded layout: rows whose width is not a multiple of 128 run at the stored layout, e.g. Flash-Next 320 as 384 with pad 64 and 160 as 256 with pad 96.
  • Stored width: each kernel and shape runs once more at its own width with pad 64, e.g. 16x256 at 256 (logical 192), 16x128 at 512, 16x160 at 160 and EMSORT 16xstk at 256.

On MI355X, all pass (35 cases, logits_diff at most 1.0e-3 against the 1e-2 limit).

@JohnNikolay84

Copy link
Copy Markdown
Contributor

P2: SiLU/GELU padded tests can pass without running FLAT/EMSORT

_iter_padded_flat_cases sets expected_kernel1. However, test_fmoe checks it only inside the SwiGLU branch. The SiLU and GELU padded cases therefore test accuracy but not which kernel
ran.

I confirmed this by disabling the logical-width retry in a scratch copy:

  • The PR's CSV suite still passed all 84 cases, including the 35 padded cases.
  • The retry log message appeared 0 times, against 40 on head.
  • The padded Flash-Next cases took the two-stage fallback: accuracy stayed near 1e-5, but they were up to 2.3× slower.

So if the retry or the kernel picker broke later, CI would lose the speedup without failing.

Fix: for every activation, assert that expected_kernel1 is dispatched and that run_1stage is used.

mjkvaak-amd added a commit to mjkvaak-amd/aiter that referenced this pull request Nov 17, 2026
… rows for inter_dim=256, M>=1024

TP4 stores the per-rank MoE intermediate (160) padded to 256. Gate
(513, 2560, 256, 11) and add tuned 2-stage FlyDSL rows for M = 1024..16384,
with the same scope as the TP2 rows: smaller M is left to the 160-keyed
rows that ROCm#7611 reaches.

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
mjkvaak-amd added a commit to mjkvaak-amd/aiter that referenced this pull request Nov 18, 2026
…ctivation

Review follow-up on ROCm#7611. expected_kernel1 was only checked on the
SwiGLU OAI path, so the padded SiLU/GELU FLAT/EMSORT cases passed on accuracy
alone when fused_moe fell back to 2-stage. test_fmoe now records every
aiter.fmoe_g1u1 launch during the timed fused_moe calls and asserts that the
expected kernel is the only one launched.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
@mjkvaak-amd

Copy link
Copy Markdown
Contributor Author

P2: SiLU/GELU padded tests can pass without running FLAT/EMSORT

_iter_padded_flat_cases sets expected_kernel1. However, test_fmoe checks it only inside the SwiGLU branch. The SiLU and GELU padded cases therefore test accuracy but not which kernel ran.

I confirmed this by disabling the logical-width retry in a scratch copy:

  • The PR's CSV suite still passed all 84 cases, including the 35 padded cases.
  • The retry log message appeared 0 times, against 40 on head.
  • The padded Flash-Next cases took the two-stage fallback: accuracy stayed near 1e-5, but they were up to 2.3× slower.

So if the retry or the kernel picker broke later, CI would lose the speedup without failing.

Fix: for every activation, assert that expected_kernel1 is dispatched and that run_1stage is used.

You're right, thanks for checking. My earlier SiLU/GELU cases checked accuracy but not dispatch.

Now fixed: whenever expected_kernel1 is set, test_fmoe now records every aiter.fmoe_g1u1 launch during the timed fused_moe calls and asserts that the only kernel launched is the expected one. This checks what actually ran, for every activation. A 2-stage fallback launches no fmoe_g1u1, so it now fails instead of passing on accuracy alone.

Let me know what you think.

JohnNikolay84
JohnNikolay84 previously approved these changes Nov 18, 2026
yifehuan pushed a commit that referenced this pull request Nov 18, 2026
…DSL rows for padded inter_dim, M>=1024 (#8123)

* [Config][MoE] Qwen3.8-Flash-Next MXFP4 TP2: aux shape gate and FlyDSL rows for inter_dim=384, M>=1024

vLLM stores the TP2 MoE intermediate (320) padded to 384 with
intermediate_pad=64. Add (513, 2560, 512, 11) to the MXFP4 aux shape gate
and tuned 2-stage FlyDSL rows for M = 1024..16384. Smaller M is left to
the 320-keyed rows that #7611 reaches: the inline-sort winners at M <= 512
are rejected under a pad and would shadow them.

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>

* [Config][MoE] Qwen3.8-Flash-Next MXFP4 TP4: aux shape gate and FlyDSL rows for inter_dim=256, M>=1024

TP4 stores the per-rank MoE intermediate (160) padded to 256. Gate
(513, 2560, 256, 11) and add tuned 2-stage FlyDSL rows for M = 1024..16384,
with the same scope as the TP2 rows: smaller M is left to the 160-keyed
rows that #7611 reaches.

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>

---------

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
mjkvaak-amd and others added 3 commits November 18, 2026 23:03
…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]>
…ed rows in CI

Review follow-up on ROCm#7611.

- FLAT and EMSORT launch round_up(inter_dim - intermediate_pad, sub_GU)
  columns and raise only if that exceeds the stored width. Requiring the
  logical width to be tile-aligned rejected rows tuned at the stored width
  that ran correctly before, e.g. 16x256 at 256 with pad 64.
  launch_kernel, grid_inter_dim() and kernel_fits() share one helper.
- _iter_csv_cases reruns each SiLU/GELU MXFP4 FLAT/EMSORT row with a pad:
  rows not a multiple of 128 at vLLM's stored layout (logical-width retry),
  and once per kernel and shape at the row's own width with pad 64.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
…ctivation

Review follow-up on ROCm#7611. expected_kernel1 was only checked on the
SwiGLU OAI path, so the padded SiLU/GELU FLAT/EMSORT cases passed on accuracy
alone when fused_moe fell back to 2-stage. test_fmoe now records every
aiter.fmoe_g1u1 launch during the timed fused_moe calls and asserts that the
expected kernel is the only one launched.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
Conflicts in the SiLU/GELU MXFP4 manifests, where ROCm#7901 appended the
emsort 16x320_stk rows: keep this branch's dim_align column and give the
new rows 512, as for the other EMSORT rows.

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
Conflicts in the SiLU/GELU MXFP4 manifests from the ROCm#7901 revert (ROCm#8489):
drop the emsort 16x320_stk rows it removes, keeping this branch's
dim_align column on the rest.

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
@yzhou103

Copy link
Copy Markdown
Contributor

@valar-cop review

@JohnNikolay84
JohnNikolay84 merged commit a8de641 into ROCm:main Nov 26, 2026
63 of 64 checks passed
ZLkanyo009 added a commit that referenced this pull request Nov 27, 2026
Align the three affected legacy MoE golden snapshots with the explicit intermediate_pad=0 keyword introduced by #7611. Exact baseline and PR-head CPU snapshots are byte-identical across all four simulated architectures; all 2130 changed records only add this keyword. Preserve frozen tuning inputs, normalization, assertions and gfx1201.
GwilliamHu added a commit that referenced this pull request Nov 27, 2026
…termediate_pad

a8de641 (#7611) passes intermediate_pad to fused_moe.fused_moe_1stage, so
every 1-stage record now carries `"intermediate_pad": 0` in stage1.kw and
tests/test_moe_dispatch_snapshot.py fails on main. No dispatch decision
changed: stripping that kwarg, all records match the previous golden on every
arch (and the old golden has no intermediate_pad anywhere).

`python tests/moe_dispatch/snapshot.py --update`:

  gfx942: 26191 keys, 610 changed, 0 new, 0 missing
  gfx942_cu80: 32928 keys, 674 changed, 0 new, 0 missing
  gfx950: 32363 keys, 846 changed, 0 new, 0 missing
  gfx1201: 25684 keys, unchanged

All 2130 changed keys are fused_moe_1stage records gaining intermediate_pad=0,
for example:

  ~ changed: grid|base|M=1024|H=2048|I=768|E=128|k=8|Gelu|bfloat16|float8_e4m3fnuz|float8_e4m3fnuz|per_Token|g1u1=1|dw=0|gate=SEPARATED
      golden: {..., "stage1": {"fn": "fused_moe.fused_moe_1stage", "kw": {"activation": "ActivationType.Gelu", "flat": 0, "kernelName": "", ...}}, ...}
      now:    {..., "stage1": {"fn": "fused_moe.fused_moe_1stage", "kw": {"activation": "ActivationType.Gelu", "flat": 0, "intermediate_pad": 0, "kernelName": "", ...}}, ...}

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zufayu pushed a commit that referenced this pull request Nov 27, 2026
…termediate_pad (#8790)

a8de641 (#7611) passes intermediate_pad to fused_moe.fused_moe_1stage, so
every 1-stage record now carries `"intermediate_pad": 0` in stage1.kw and
tests/test_moe_dispatch_snapshot.py fails on main. No dispatch decision
changed: stripping that kwarg, all records match the previous golden on every
arch (and the old golden has no intermediate_pad anywhere).

`python tests/moe_dispatch/snapshot.py --update`:

  gfx942: 26191 keys, 610 changed, 0 new, 0 missing
  gfx942_cu80: 32928 keys, 674 changed, 0 new, 0 missing
  gfx950: 32363 keys, 846 changed, 0 new, 0 missing
  gfx1201: 25684 keys, unchanged

All 2130 changed keys are fused_moe_1stage records gaining intermediate_pad=0,
for example:

  ~ changed: grid|base|M=1024|H=2048|I=768|E=128|k=8|Gelu|bfloat16|float8_e4m3fnuz|float8_e4m3fnuz|per_Token|g1u1=1|dw=0|gate=SEPARATED
      golden: {..., "stage1": {"fn": "fused_moe.fused_moe_1stage", "kw": {"activation": "ActivationType.Gelu", "flat": 0, "kernelName": "", ...}}, ...}
      now:    {..., "stage1": {"fn": "fused_moe.fused_moe_1stage", "kw": {"activation": "ActivationType.Gelu", "flat": 0, "intermediate_pad": 0, "kernelName": "", ...}}, ...}

Co-authored-by: Claude Opus 5.5 <[email protected]>
ganyi1996ppo added a commit to ganyi1996ppo/aiter that referenced this pull request Nov 30, 2026
Pick up ROCm#8790's regenerated MoE-dispatch golden (intermediate_pad field from
ROCm#7611) so the shard-2 'test_legacy_dispatch_matches_golden_snapshot' gate clears.
This branch only touches the a16wfp4 Triton path, disjoint from the golden.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@mjkvaak-amd mjkvaak-amd mentioned this pull request Nov 30, 2026
2 of 10 tasks
@qli88 qli88 mentioned this pull request Nov 30, 2026
5 of 10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants