Skip to content

[HIP] [MXFP4 MoE] cover Qwen3.5-397B TP4: shape gate entry and tuned rows - #6981

Merged
gyohuangxin merged 4 commits into
mainfrom
zhiwei/qwen35-tp4-mxfp4-moe-shape
Nov 12, 2026
Merged

gyohuangxin merged 4 commits into
mainfrom
zhiwei/qwen35-tp4-mxfp4-moe-shape

Conversation

@ZhiweiYan-96

@ZhiweiYan-96 ZhiweiYan-96 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Qwen3.5-397B-A17B MXFP4 at TP4 has the MoE key expert=513 (512 routed + 1 fused shared), model_dim=4096, inter_dim=256, topk=11. This PR lets that key use a tuned expert chain: it adds (513, 4096, 256, 11) to the MXFP4 MoE shape gate (and to the codegen SHAPES list it must match), and adds 7 tuned rows for token 1–64 to model_configs/qwen3_5_397b_fp4_tuned_fmoe.csv. No kernel is added or changed.

Motivation

Two tables have to cover the key before the tuned chain can run, and neither did on main:

  • is_mxfp4_moe_shape_supported rejects (513, 4096, 256, 11), so any MXMOE (FlyDSL a4w4) row for it is discarded with [fused_moe] discarding MXMOE config: generated MXFP4 auxiliary kernels do not cover ...; using default heuristics (a warning, easy to miss in a server log).
  • No tuned table has a row for it: configs/tuned_fmoe.csv has no expert=513 row, and qwen3_5_397b_fp4_tuned_fmoe.csv had (256, 512, 10), (512, 512, 10) and (512, 513, 11) (TP2) but not TP4's (256, 513, 11). This case is silent.

So TP4 decode ran the default heuristic chain (5 kernels per layer at token=4).

Changes

  • aiter/ops/moe_mxfp4_aux.py: add (513, 4096, 256, 11) to MXFP4_MOE_SUPPORTED_SHAPES.
  • csrc/kernels/mxfp4_moe/moe_aux/codegen/gen_instances.py: add the same tuple to SHAPES, as the comment in moe_mxfp4_aux.py and op_tests/test_mxfp4_moe_aux_codegen.py::test_supported_shapes_have_generated_instances require. It generates no new instance: aux instances are named aux_<kind>_NE{ne}_TOPK{topk}_MB{mb}_H{h} (no inter_dim), are deduplicated by name, and NE=513/TOPK=11/H=4096 already exist from (513, 4096, 512, 11). The generated set is 446 instances before and after. inter_dim is a runtime argument (D_INTER of mxfp4_moe_sort).
  • aiter/configs/model_configs/qwen3_5_397b_fp4_tuned_fmoe.csv: 7 rows for gfx950, cu_num 256, (4096, 256, 513, 11), Silu, bf16, fp4x2/fp4x2, per_1x32, g1u1 (plus a trailing newline on the previous last line; that row is unchanged).
    • token 1, 2, 4: FLAT 1-stage asm fmoe_bf16_pertokenMXfp4_g1u1_flat_vs_silu_16x32 (route, activation quant and both GEMMs in one launch); token 8: fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x128. These were chosen by a CUDA-graph chain benchmark of the whole fused_moe call over the three FLAT variants against the FlyDSL rows, not by the tuner, so their us/tflops/bw columns are 0.
    • token 16, 32, 64: FlyDSL MXMOE a4w4 (flydsl_mxmoe_g1_a4w4_16x128x256_f16in[_hpf]_nt + flydsl_moe2_layout_afp4_wfp4_bf16_t16x128x{256,128}_atomic[_nt]_sbm16), from csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py on MI355X.
  • aiter/configs/model_configs/qwen3_5_397b_fp4_untuned_fmoe.csv: the same key at token 1–64, so a retune of this table covers it.

Tokens are bucketed by get_padded_M (next power of two), so token 3 uses the token-4 row and 5–8 the token-8 row. Token >= 128 has no row and keeps the previous default path.

Performance (if applicable)

Per-layer fused_moe call, CUDA-graph replay of the full call (route + sort + quant + GEMMs), 24 calls, token=4, MI355X gfx950 256 CU, Qwen3.5-397B TP4 key. Measured 2026-10-26 on an aiter build before #7110 (see unverified scope).

Hardware Workload/configuration Before (default heuristic chain) After (this table) Change
MI355X token=4, cold L2 35.15 us (5 kernels) 20.36 us (1 kernel) -42%
MI355X token=4, warm L2 31.31 us 18.29 us -42%

Derived: Qwen3.5-397B has 60 MoE layers, so (35.2 - 20.4) x 60 = 0.89 ms (cold) and (31.3 - 18.3) x 60 = 0.78 ms (warm) per decode iteration at token=4.

End to end, Qwen3.5-397B-A17B-MXFP4-AttnFP8-V2, MI355X TP4, AgentX workload, aiperf 3600 s per point, c4 p90 interactivity 307.11 -> 357.00 tok/s/user (+16.2%). This is a group measurement: the "after" run also carried ROCm/ATOM#2738, ROCm/ATOM#2739 and ROCm/ATOM#2708; baseline and group ran the same night in the same container and image. This PR's own share is not separated out.

Testing

  • Unit tests added or updated
  • Performance benchmarks run (MI355X, see above)
  • 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

Config rows and a shape-gate entry only.

Dependencies

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

Breaking Changes

None.

PR Self-Review

Reviewed revision

26b0bcc

Behavior and intent

For the Qwen3.5-397B TP4 MXFP4 key (expert 513, model_dim 4096, inter_dim 256, topk 11) on gfx950 with 256 CUs, fused_moe now uses a single FLAT asm kernel at token <= 8 and the tuned FlyDSL MXMOE chain at token 16–64, instead of the default heuristic chain. Before this PR the shape gate discarded any MXMOE row for this key and no tuned row existed, so there was nothing to select. The codegen SHAPES entry only keeps the gate and the generator in sync; it adds no compiled instance. No kernel source, binary or dispatch logic changes.

Validation and unverified scope

CPU, on this revision: python3 -m unittest op_tests.test_mxfp4_moe_aux_codegen passed (3 tests); before adding the SHAPES entry, test_supported_shapes_have_generated_instances failed on (513, 4096, 256, 11). Enumerating mxfp4_moe_aux_codegen.enumerate_instances() gives the same 446 instance names before and after. black --check and ruff check pass on the two Python files. The FlyDSL kernel names in the new rows parse with aiter/ops/flydsl/mxfp4_kname.py on main. Both CSVs keep a constant column count (29 tuned, 12 untuned). GPU, 2026-10-26 on MI355X: per-layer numbers in the Performance table; GSM8K FP4, 300 questions, 3-shot, strict 0.730 baseline -> 0.750 with the same group as the e2e run (standard error about ±0.025, so this shows no regression rather than a gain). Unverified on this revision: the GPU numbers predate #7110, which rebuilt the FLAT .co binaries for num_local_tokens, so the FLAT rows have not been re-timed or re-checked for numerics on current main; no op test has been run on GPU for this key at token 1–256 against a reference; this PR's e2e share is not isolated from the ATOM changes; gfx942 and cu_num other than 256 are not covered (no rows for them).

PR-specific question

The changed kernel path is selected only by an exact tuned-row key: gfx950, cu_num 256, model_dim 4096, inter_dim 256, expert 513, topk 11, Silu, bf16 input, fp4x2 activation and weight, per_1x32, g1u1, no stage-1 weighting, and padded token 1–64. Any other arch, CU count, dtype, activation or shape misses these rows and keeps its previous selection. The gate tuple is read through aiter.is_mxfp4_moe_shape_supported in three places in aiter/fused_moe.py: the MXMOE tuned-row admission check (_lookup_cfg), the heuristic MXMOE fallback (AITER_MXMOE_FALLBACK), and the explicit MXMOE -> OPUS selection contract (_mxmoe_opus_cfg_unsupported). The last one first requires an A8W4 (FP8-activation) GEMM1, so these A4W4 rows never reach it. The tuple also derives _MXFP4_MOE_SCATTER_KEYS as (model_dim, topk); (4096, 11) was already there from (513, 4096, 512, 11), so scatter support is unchanged. FLAT rows additionally go through the existing assert not metadata.flat or get_gfx() in ("gfx942", "gfx950"). Token >= 128 has no row and stays on the previous default path.

Changed op tests

None. The existing op_tests/test_mxfp4_moe_aux_codegen.py already checks gate/codegen consistency and fails without the SHAPES entry.

@github-actions

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

ZhiweiYan-96 and others added 2 commits November 2, 2026 06:58
is_mxfp4_moe_shape_supported dropped (513, 4096, 256, 11), so Qwen3.5-397B at
TP4 silently fell back to the heuristic expert chain, and no tuned table held
that key either: configs/tuned_fmoe.csv has no expert=513 row at all, and
model_configs/qwen3_5_397b_fp4_tuned_fmoe.csv had only (256,512,10),
(512,512,10) and (512,513,11), i.e. TP2's 513/11 but not TP4's.

No kernels have to be generated for the gate entry. The auxiliary instances do
not depend on the intermediate dimension: gen_instances.py unpacks each shape as
'for ne, h, e, topk in SHAPES' and no generator uses e, every instance being
named aux_<kind>_NE{ne}_TOPK{topk}_MB{mb}_H{h}. The generator relies on that --
its comment at line 358 is 'so dedup across shapes that share an (h, topk)', and
SHAPES already holds pairs differing only in e, such as (512,4096,256,10) with
(512,4096,512,10). D_INTER is a runtime argument of mxfp4_moe_sort. Instances for
NE=513, TOPK=11, H=4096 are already compiled from (513,4096,512,11).

The 7 tuned rows come from the bpreshuffle tuner on MI355X (gfx950, 256 CU) for
this shape: token <= 8 select the FLAT 1-stage asm kernel, token >= 16 the FlyDSL
a4w4 port. Per-layer CUDA-graph replay at token=4 goes 35.2 -> 20.4 us cold and
31.3 -> 18.3 us warm against the heuristic chain.

Measured end to end on Qwen3.5-397B-A17B-MXFP4-AttnFP8-V2, TP4, AgentX, 3600 s
per point: with three ATOM-side changes alongside it, p90 interactivity rose from
307.1 to 357.0 tok/s/user against a baseline on the same image. GSM8K FP4 300
questions 3-shot: 0.750 strict against 0.730, no regression.
op_tests/test_mxfp4_moe_aux_codegen.py::test_supported_shapes_have_generated_instances
requires every MXFP4_MOE_SUPPORTED_SHAPES entry to appear in the codegen SHAPES
list, and moe_mxfp4_aux.py says to keep the two synchronized. Add
(513, 4096, 256, 11) to SHAPES as well. Instances are deduplicated by name and
none depend on the intermediate dimension, so the generated set is unchanged
(446 instances before and after).

Also list the TP4 key at token 1-64 in qwen3_5_397b_fp4_untuned_fmoe.csv so a
retune of this table covers the rows that the tuned table now carries.
@ZhiweiYan-96
ZhiweiYan-96 force-pushed the zhiwei/qwen35-tp4-mxfp4-moe-shape branch from 004b2fe to 26b0bcc Compare November 2, 2026 13:03
@aiter-bot

aiter-bot commented Nov 2, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 65e50ff63bcb · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

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

@ZhiweiYan-96
ZhiweiYan-96 marked this pull request as ready for review November 2, 2026 13:11
@ZhiweiYan-96
ZhiweiYan-96 requested review from a team and a balanced review from Copilot November 2, 2026 13:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions github-actions Bot changed the title [MXFP4 MoE] cover Qwen3.5-397B TP4: shape gate entry and tuned rows [HIP] [MXFP4 MoE] cover Qwen3.5-397B TP4: shape gate entry and tuned rows Nov 2, 2026
@github-actions github-actions Bot added the HIP label Nov 2, 2026
@ZhiweiYan-96

Copy link
Copy Markdown
Contributor Author

/rerun

Keep both sides of qwen3_5_397b_fp4_tuned_fmoe.csv: this branch's TP4
(513, 4096, 256, 11) decode rows for M=1..64 and main's (#5988) rows for
M=8192..32768. No key is duplicated.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 06:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@yzhou103

yzhou103 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

@valar-cop review

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few small things..

numeric/perf re-check of the four FLAT rows (token 1/2/4/8) on this head?

ci green.

Comment thread aiter/ops/moe_mxfp4_aux.py Resolved
The token 1/2/4/8 FLAT rows carried us1/us = 0. Re-measured on this branch
(after #7110 rebuilt both FLAT kernels), per-layer chain on MI355X, warm
weights: 11.46 / 12.04 / 17.85 / 22.62 us, vs 27.42 / 29.31 / 32.95 / 41.56 us
for the heuristic chain; rel L2 against a bf16-activation reference is the
same as the heuristic's at every token count.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 14:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@yzhou103

Copy link
Copy Markdown
Contributor

@valar-cop review

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

ci Aiter Test failed — not sure yet (low): Failed on head 65e50ff; no job log was provided in .valar/ci, so the failing step/test is unidentifiable. The only change since the previously green head 2b574b9 is four numeric columns in a tuned CSV, which the op-test suite does not consume, so the PR is very unlikely to be the cause.

Aiter Test: failure https://github.com/ROCm/aiter/actions/runs/42637998794
next: Fetch the Aiter Test log (or rerun) and check whether the same failure reproduces on main; likely infra/flaky rather than this PR. https://github.com/ROCm/aiter/actions/runs/42637998794

@gyohuangxin
gyohuangxin merged commit 6057354 into main Nov 12, 2026
@gyohuangxin
gyohuangxin deleted the zhiwei/qwen35-tp4-mxfp4-moe-shape branch November 12, 2026 09:51
vpietila-amd pushed a commit that referenced this pull request Nov 12, 2026
…rows (#6981)

* [MXFP4 MoE] cover Qwen3.5-397B TP4: shape gate entry and tuned rows

is_mxfp4_moe_shape_supported dropped (513, 4096, 256, 11), so Qwen3.5-397B at
TP4 silently fell back to the heuristic expert chain, and no tuned table held
that key either: configs/tuned_fmoe.csv has no expert=513 row at all, and
model_configs/qwen3_5_397b_fp4_tuned_fmoe.csv had only (256,512,10),
(512,512,10) and (512,513,11), i.e. TP2's 513/11 but not TP4's.

No kernels have to be generated for the gate entry. The auxiliary instances do
not depend on the intermediate dimension: gen_instances.py unpacks each shape as
'for ne, h, e, topk in SHAPES' and no generator uses e, every instance being
named aux_<kind>_NE{ne}_TOPK{topk}_MB{mb}_H{h}. The generator relies on that --
its comment at line 358 is 'so dedup across shapes that share an (h, topk)', and
SHAPES already holds pairs differing only in e, such as (512,4096,256,10) with
(512,4096,512,10). D_INTER is a runtime argument of mxfp4_moe_sort. Instances for
NE=513, TOPK=11, H=4096 are already compiled from (513,4096,512,11).

The 7 tuned rows come from the bpreshuffle tuner on MI355X (gfx950, 256 CU) for
this shape: token <= 8 select the FLAT 1-stage asm kernel, token >= 16 the FlyDSL
a4w4 port. Per-layer CUDA-graph replay at token=4 goes 35.2 -> 20.4 us cold and
31.3 -> 18.3 us warm against the heuristic chain.

Measured end to end on Qwen3.5-397B-A17B-MXFP4-AttnFP8-V2, TP4, AgentX, 3600 s
per point: with three ATOM-side changes alongside it, p90 interactivity rose from
307.1 to 357.0 tok/s/user against a baseline on the same image. GSM8K FP4 300
questions 3-shot: 0.750 strict against 0.730, no regression.

* [MXFP4 MoE] keep the TP4 gate entry in sync with gen_instances SHAPES

op_tests/test_mxfp4_moe_aux_codegen.py::test_supported_shapes_have_generated_instances
requires every MXFP4_MOE_SUPPORTED_SHAPES entry to appear in the codegen SHAPES
list, and moe_mxfp4_aux.py says to keep the two synchronized. Add
(513, 4096, 256, 11) to SHAPES as well. Instances are deduplicated by name and
none depend on the intermediate dimension, so the generated set is unchanged
(446 instances before and after).

Also list the TP4 key at token 1-64 in qwen3_5_397b_fp4_untuned_fmoe.csv so a
retune of this table covers the rows that the tuned table now carries.

* [MXFP4 MoE] Qwen3.5-397B TP4: record the FLAT rows' measured time

The token 1/2/4/8 FLAT rows carried us1/us = 0. Re-measured on this branch
(after #7110 rebuilt both FLAT kernels), per-layer chain on MI355X, warm
weights: 11.46 / 12.04 / 17.85 / 22.62 us, vs 27.42 / 29.31 / 32.95 / 41.56 us
for the heuristic chain; rel L2 against a bf16-activation reference is the
same as the heuristic's at every token count.

---------

Co-authored-by: qichu <[email protected]>
ZhiweiYan-96 added a commit to ZhiweiYan-96/ATOM that referenced this pull request Nov 12, 2026
…+ TP2)

Fold the InferenceX FP4 submission into Agentic-Qwen3.5.md next to the FP8
recipe: the MXFP4-AttnFP8-V2 checkpoint, INT4 quick reduce left off, the
image requirements (ROCm/aiter#6981, ROCm#3106, ROCm#3108), TP2 points at CONC 12
and 16-40 with LMCache from CONC 16, the knobs measured and not adopted, and
the 2026-11-12 TP4 results against SGLang's public MI355X FP4 points.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants