Repository navigation
[HIP] [MXFP4 MoE] cover Qwen3.5-397B TP4: shape gate entry and tuned rows - #6981
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
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.
004b2fe to
26b0bcc
Compare
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
|
/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.
|
@valar-cop review |
valar-cop
left a comment
There was a problem hiding this comment.
a few small things..
numeric/perf re-check of the four FLAT rows (token 1/2/4/8) on this head?
ci green.
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.
|
@valar-cop review |
valar-cop
left a comment
There was a problem hiding this comment.
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
…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]>
…+ 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.
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 codegenSHAPESlist it must match), and adds 7 tuned rows for token 1–64 tomodel_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_supportedrejects(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).configs/tuned_fmoe.csvhas no expert=513 row, andqwen3_5_397b_fp4_tuned_fmoe.csvhad(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)toMXFP4_MOE_SUPPORTED_SHAPES.csrc/kernels/mxfp4_moe/moe_aux/codegen/gen_instances.py: add the same tuple toSHAPES, as the comment inmoe_mxfp4_aux.pyandop_tests/test_mxfp4_moe_aux_codegen.py::test_supported_shapes_have_generated_instancesrequire. It generates no new instance: aux instances are namedaux_<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_INTERofmxfp4_moe_sort).aiter/configs/model_configs/qwen3_5_397b_fp4_tuned_fmoe.csv: 7 rows forgfx950, 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).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 theirus/tflops/bwcolumns are 0.flydsl_mxmoe_g1_a4w4_16x128x256_f16in[_hpf]_nt+flydsl_moe2_layout_afp4_wfp4_bf16_t16x128x{256,128}_atomic[_nt]_sbm16), fromcsrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.pyon 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).
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
Documentation
Config rows and a shape-gate entry only.
Dependencies
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 codegenSHAPESentry 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_codegenpassed (3 tests); before adding theSHAPESentry,test_supported_shapes_have_generated_instancesfailed on(513, 4096, 256, 11). Enumeratingmxfp4_moe_aux_codegen.enumerate_instances()gives the same 446 instance names before and after.black --checkandruff checkpass on the two Python files. The FlyDSL kernel names in the new rows parse withaiter/ops/flydsl/mxfp4_kname.pyon 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.cobinaries fornum_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_supportedin three places inaiter/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_KEYSas(model_dim, topk);(4096, 11)was already there from(513, 4096, 512, 11), so scatter support is unchanged. FLAT rows additionally go through the existingassert 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.pyalready checks gate/codegen consistency and fails without theSHAPESentry.