Skip to content

feat(ops): Qwen3.5 MXFP4 MoE at TP4 and at larger TP2 verify sizes, and its bf16 lm_head at TP4 and TP2 - #223

Merged
RuibinCheung merged 2 commits into
mainfrom
dev/qwen35-mxfp4-schema-gaps
Nov 18, 2026
Merged

RuibinCheung merged 2 commits into
mainfrom
dev/qwen35-mxfp4-schema-gaps

Conversation

@ChengYao-amd

@ChengYao-amd ChengYao-amd commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Qwen3.5-397B-A17B MXFP4 (AttnFP8-V2) still falls back with no_workload in three places after #209:

  • MoE at TP4. Each MoE layer is one aiter fused_moe a4w4 call with 513 experts (the fused shared expert is expert 512), top-11 and inter 256 per rank. sglang's own W4A16 path takes 40 tokens and fewer; above that, [email protected] takes the call but has no schema for inter 256. With EAGLE (3 steps, top-k 1, 4 draft tokens) the verify step runs the MoE on 4·bs tokens, so at concurrency 12–16 the verify graphs of bs 12–32 (48–128 tokens) all go to aiter.
  • MoE at TP2, larger batches. feat(flydsl): fused MoE kernel for model dim 4096, 513 experts, top-11, inter 512 #209 covers 4–160 tokens. The verify graphs of bs 22 and 44–80 (88, 176–320 tokens; concurrency 32–40) are still on aiter.
  • lm_head. LogitsProcessor._compute_lm_head already routes the bf16 head into [email protected], but nothing has its shape: 62080 × 4096 at TP4, 124160 × 4096 at TP2 (vocabulary 248320). It runs once per verify (m = 4·bs) and once per draft step (m = bs), and is 2–4% of the wall clock in an AgentX run.

Scope

  • fused_moe_shuffled_16x16_model_dim4096_n_experts513_topk11_inter_dim256 (new): 64140271, 48–128 tokens in steps of 8. Same two-launch kernel as feat(flydsl): fused MoE kernel for model dim 4096, 513 experts, top-11, inter 512 #209 (in-LDS routing sort, MXFP4 quantization of the gathered rows and gate/up GEMM in stage 1; down GEMM with bf16 atomics in stage 2), with the inter dim halved.
  • fused_moe_shuffled_16x16_model_dim4096_n_experts513_topk11_inter_dim512: a second schema 8e3f0f83 next to 657d1f53, for 88 and 176–320 tokens (176–256 in steps of 16, 288, 320). Same kernel as 657d1f53; only its token-count list differs.
  • gemm_n62080_k4096 (f72cfb48) and gemm_n124160_k4096 (8960372a) (new): the weight-streaming body of gemm_n25256_k8192 (gemm_stream.h, unchanged), with its tile picked per m bucket for these shapes. m 1–8, 10–16, 88, 96, 104–128 for both; 56, 64 for n 62080 and 52–64 for n 124160.
  • No contract, route or committed schema change.

Tradeoffs

  • lm_head between the buckets stays on aiter. At m 18–48 and 72–80, aiter's gemm_a16w16 (hipBLASLt) already streams the weight at 6.0–6.5 TB/s and this kernel measured 0.99–1.06x, so those sizes are not listed. The kernel reaches 6.7–7.1 TB/s at m ≤ 16. Above m 128 it is slower than hipBLASLt, so nothing larger is listed.
  • TP2 MoE at 104–120 tokens stays on aiter (1.04–1.05x). There, stage 1 re-reads and re-quantizes each block's 16 hidden rows for each of its four column blocks. Fixing that needs a different stage-1 layout, not a tuning change.
  • Skewed routing at 176–320 tokens. With all routes on 24 hot experts (over 100 rows each), the inter-512 kernel measured 0.80–0.94x of aiter outside validation: its 16-row expert blocks re-read a hot expert's weights once per block. With the shared expert in every row and the rest uniform, as in serving, it measured 1.09–1.20x in the same harness.
  • Rounding at TP4. At inter 256 aiter runs a different FlyDSL chain (mfma_moe1_silu_mul_afp4_wfp4_bf16_t32x128x256 + mfma_moe2_afp4_wfp4_bf16_cshuffle), whose MXFP4 rounding matches the reference's: 47 dB to the reference against this kernel's 29 dB. Against a reference with unrounded activations both are equally accurate (13.2–13.4 dB each, at 48 and 128 tokens, with uniform and shared-expert routing). At inter 512, this kernel and aiter's chain are 45 dB apart, as in feat(flydsl): fused MoE kernel for model dim 4096, 513 experts, top-11, inter 512 #209.

Verification

CI: run 43840808340: code-lint passed; unittest-aklr failed only on test_reference[[email protected]], which also fails on main (run 43832645862), so validation was skipped. The tables and log below are a local run of the same validation.
Environment: MI355X, lmsysorg/sglang:v0.5.22-rocm10-mi35x, ROCm 7.15, torch 2.11.0+rocm10.0.0, Triton 3.8.0, FlyDSL 0.3.2, AITER as ci.yaml's AKLR_BASELINE_AITER.
Gate overrides: none

Kernels

contract baseline measured accuracy (bound) speedup
[email protected] aklr.ops.fused_moe.baseline.fused_moe_baseline (aiter fused_moe, a4w4 per_1x32) 20/20 20/20 (SqnrBound 13 dB; worst violation fraction 0) inter 256: 1.25x – 1.32x; inter 512: 1.05x – 1.07x (lower bound)
[email protected] aklr.ops.gemm.baseline.gemm_baseline (aiter gemm_a16w16) 42/42 42/42 (worst violation fraction 0) 1.10x – 1.72x (lower bound)

fused_moe inter 256 (64140271)

tokens aiter µs this µs lower bound
48 121.8 92.1 1.320
56 134.2 101.9 1.315
64 136.6 105.4 1.290
72 147.2 116.4 1.263
80 149.6 119.1 1.251
88 153.9 119.6 1.286
96 160.0 125.5 1.267
104 161.6 127.2 1.265
112 162.5 128.0 1.264
120 167.9 129.4 1.290
128 169.1 132.6 1.268

fused_moe inter 512 (8e3f0f83)

tokens aiter µs this µs lower bound
88 245.5 230.3 1.062
176 283.2 265.2 1.066
192 286.8 268.2 1.067
208 284.0 266.4 1.065
224 285.3 267.9 1.059
240 285.3 266.6 1.068
256 285.6 267.3 1.067
288 288.3 268.0 1.074
320 289.0 274.7 1.051

gemm_n62080_k4096 (f72cfb48)

m aiter µs this µs lower bound
1 122.2 73.1 1.667
2 122.5 72.7 1.681
3 121.9 73.2 1.664
4 122.2 73.2 1.667
5 121.7 73.3 1.657
6 121.9 73.4 1.656
7 121.6 73.5 1.650
8 121.6 73.5 1.652
10 121.6 73.9 1.637
12 121.0 74.2 1.629
14 121.5 74.6 1.626
16 120.9 74.0 1.630
56 133.8 77.6 1.716
64 131.9 77.4 1.701
88 91.5 82.9 1.101
96 92.4 83.1 1.109
104 130.9 83.6 1.563
112 129.0 83.8 1.538
120 136.4 84.7 1.606
128 136.2 84.8 1.600

gemm_n124160_k4096 (8960372a)

m aiter µs this µs lower bound
1 252.1 146.0 1.724
2 251.9 145.4 1.718
3 251.8 145.6 1.715
4 252.0 146.0 1.716
5 251.1 145.6 1.720
6 251.3 146.1 1.710
7 251.2 145.9 1.716
8 251.8 146.3 1.704
10 250.7 146.1 1.709
12 250.8 146.7 1.698
14 250.9 146.6 1.706
16 251.1 147.4 1.701
52 186.0 155.4 1.190
56 187.1 155.7 1.195
60 186.4 156.0 1.192
64 187.4 156.7 1.190
88 184.9 161.1 1.143
96 186.6 161.7 1.150
104 268.9 165.1 1.621
112 267.2 166.6 1.594
120 278.1 165.6 1.676
128 278.2 169.2 1.635

Against the image's own aiter (0.1.23.dev183+ge7d2453f2, FlyDSL 0.3.4.1), the same kernels measured: inter 256, 1.25x–1.33x; inter 512 at 88 and 176–256 tokens, 1.05x–1.08x (288 and 320 not run there); lm_head, 1.10x–1.73x (lower bounds). Every listed point was ≥ 1.05x in each of the 3–4 runs made (both aiters). Outside validation: at inter 512 the output's SQNR to the reference equals aiter's at 88–320 tokens with every token routed to expert 512 (as the fused shared expert is) and with all routes on 24 hot experts; at inter 256 its SQNR to the unrounded-activation reference equals aiter's at 48 and 128 tokens, with uniform and expert-512 routing.

Validation log
$ python -m aklr validate --base origin/main --stages audit,bench --devices 0-7
[09:28:35] validate: collecting schemas and platform
[09:28:36] validate: 2026-11-16, head 732322d0a609, base 51acbd5fbf3a, MI355X gfx950 x8
[09:28:36] audit: started (stage 1/2)
[09:28:36] audit: checking 4 schemas
[09:28:37] audit: checking changes against base 51acbd5fbf3a
[09:28:37] audit: passed, findings: 0, 0:00:01
[09:28:37] bench: started (stage 2/2)
[09:28:37] bench: reading 4 schemas
[09:28:37] bench: 6 batches (4 schemas), 62 workloads, 8 devices
[09:30:12] bench: 1/6 passed hip/gemm_n62080_k4096/f72cfb48: 10 wl, speedup 1.10x-1.72x, acc ok
[09:30:12] bench: 2/6 passed hip/gemm_n62080_k4096/f72cfb48: 10 wl, speedup 1.63x-1.68x, acc ok
[09:30:19] bench: 3/6 passed hip/gemm_n124160_k4096/8960372a: 11 wl, speedup 1.14x-1.70x, acc ok
[09:30:22] bench: 4/6 passed hip/gemm_n124160_k4096/8960372a: 11 wl, speedup 1.70x-1.72x, acc ok
[09:30:41] bench: 5/6 passed flydsl/fused_moe_shuffled_16x16_model_dim4096_n_experts513_topk11_inter_dim512/8e3f0f83: 9 wl, speedup 1.05x-1.07x, acc ok
[09:30:55] bench: 6/6 passed flydsl/fused_moe_shuffled_16x16_model_dim4096_n_experts513_topk11_inter_dim256/64140271: 11 wl, speedup 1.25x-1.32x, acc ok
[09:30:55] bench: 62 workloads
[09:30:55] bench:   outcome                         workloads
[09:30:55] bench:   passed                                 62
[09:30:55] bench:   speedup  best 1.72x, median 1.60x, worst 1.05x  (workloads with a speedup value)
[09:30:55] bench:   accuracy FAIL 0, ok 62, not measured 0
[09:30:55] bench:   per-schema table: report.md
[09:30:55] bench: passed, findings: 0, 0:02:18
validation passed

Code

python -m aklr export check, python -m aklr validate --base origin/main --stages audit, pytest tests/ops/test_contracts.py: passed. pytest tests: 1166 passed, 1 failed: test_reference.py::...[[email protected]] (delta_state violation fraction 6.1e-05), which fails the same way on origin/main (51acbd5) here and does not touch these ops. tests/ops/names.txt already lists both name patterns.

Serving check (not end to end): Qwen3.5-397B-A17B-MXFP4-AttnFP8-V2 on MI355X, EAGLE 3/1/4 with the InferenceX agentic recipe's server arguments for TP2 + HiCache concurrency 32 (--max-running-requests 64 --cuda-graph-max-bs-decode 64), TP4 concurrency 8 (--max-running-requests 16 --cuda-graph-max-bs-decode 16) and TP4 concurrency 16 (--max-running-requests 32 --cuda-graph-max-bs-decode 32, driven at 32 parallel requests so verify reaches 128 tokens), the image's aiter, acceptance not simulated, AKLR_MIN_SPEEDUP=0 (these files have no CI speedup yet), AKLR_EXPORT=1.

  • On every rank, each listed count was served: TP2 c32, fused_moe inter 512 at 4–96, 128 and 160 (feat(flydsl): fused MoE kernel for model dim 4096, 513 experts, top-11, inter 512 #209) plus 88 and 176–256, and lm_head n 124160 at all 22 listed m; TP4 c8, fused_moe inter 256 at 48–64 and lm_head n 62080 at m 1–16, 56, 64; TP4 c16, fused_moe inter 256 at all of 48–128 and lm_head at all 20 listed m.
  • GSM8K (400 questions, zero-shot chat, thinking off, parallel = concurrency), AKLR off / on: TP2 c32 0.963 / 0.965; TP4 c8 0.953 / 0.958; TP4 c16 (parallel 32) 0.963 / 0.965.

Not run

  • End to end throughput (optional for schemas on existing routes).

Risk

Affects: Qwen3.5-397B MXFP4 (V2) at TP4 and TP2: the MoE at the listed verify token counts, and the lm_head at the listed m (target verify and EAGLE draft steps).
If wrong: wrong MoE or logits output, or slower steps at those counts.
Undo: [email protected] / [email protected], or git revert.

🤖 Generated with Claude Code

@ChengYao-amd

Copy link
Copy Markdown
Collaborator Author

CI run 43840808340: unittest-aklr fails only on tests/ops/test_reference.py::TestReference::test_backend_matches_reference[[email protected]] (delta_state violation fraction 6.1e-05), so validation was skipped. The same test fails on main's own CI (run 43832645862, 4dce72d) and locally on plain origin/main 51acbd5; this PR only adds fused_moe and gemm schemas. Once main has a fix I'll merge it and re-run all jobs. A local run of the CI validation (--base origin/main, 4 schemas) passed 62/62, as in the description.

ChengYao-amd and others added 2 commits November 18, 2026 10:00
…ore inter-512 token counts

Two schemas of [email protected] at model dim 4096, 513 experts (512 routed plus the fused
shared expert), top-11, the Qwen3.5-397B MXFP4 MoE:

- inter 256 (TP4): n_tokens 48 to 128 in steps of 8, the EAGLE verify sizes above the
  40 tokens where sglang's own W4A16 path stops. Same two-launch kernel as the inter-512
  schema with the inter dim halved. 1.25-1.33x over aiter.
- inter 512 (TP2): a second schema next to 657d1f53 for n_tokens 88 and 176 to 320,
  the verify sizes of graph batch sizes 22 and 44 to 80. Same kernel as 657d1f53 with
  these token counts. 1.05-1.07x over aiter. 104, 112 and 120 stay on aiter
  (1.04-1.05x).

Accuracy matches aiter's (SQNR to the reference within 0.1 dB, zero violations).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…at K 4096

gemm_n62080_k4096 and gemm_n124160_k4096, the lm_head of a 248320-token vocabulary
under TP4 and TP2 (Qwen3.5-397B), on the weight-streaming body of gemm_n25256_k8192
(gemm_stream.h, unchanged) with tiles picked per m bucket.

Workloads are the EAGLE draft and verify sizes where the kernel is clearly ahead:
m 1-16 (1.61-1.73x over aiter), 52-64 (1.18-1.72x), 88-96 (1.10-1.18x) and
104-128 (1.53-1.70x). Between them, at m 18-48 and 72-80, aiter's GEMM already
streams the weight at a similar rate (0.99-1.06x), so those sizes stay on it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@RuibinCheung RuibinCheung left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@RuibinCheung
RuibinCheung merged commit 8fadd1c into main Nov 18, 2026
17 checks passed
@RuibinCheung
RuibinCheung deleted the dev/qwen35-mxfp4-schema-gaps branch November 18, 2026 08:44

This branch was previously deployed

1 inactive deployment
gpu-trusted — bb47b811 Deployed Nov 18, 2026 by zhenhuang12 via prepare-gpu / prepare #1033
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.

3 participants