Skip to content

[Fix] [AMD] qwen3_5: Rotate the online MXFP4 GDN projections by Hadamard-32 - #46059

Open
omirosh wants to merge 15 commits into
sgl-project:mainfrom
omirosh:rocm/qwen38-gdn-mxfp4-hadamard
Open

omirosh wants to merge 15 commits into
sgl-project:mainfrom
omirosh:rocm/qwen38-gdn-mxfp4-hadamard

Conversation

@omirosh

@omirosh omirosh commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

This ROCm accuracy fix rotates the online MXFP4 GDN in_proj_qkvz and out_proj of #43839 (merged) by a 32-point block Hadamard matrix, because plain MXFP4 there makes Qwen3.8-2.4T-A95B MXFP4 write 11% more tokens than BF16 on thinking-on GSM8K. With the rotation, the answers are 2% to 5% longer than BF16, and the median TPOT is within 0.6% of plain MXFP4 (+0.0% and +0.4% without MTP, +0.1% and +0.6% with NEXTN, geomean over 12 serving shapes in two runs, 8x MI355X, TP8).

The extra length repeats in every run. Against BF16, the per-question geomean of plain MXFP4 is 1.071, 1.070 and 1.073 in our three runs, and 1.073 in vllm#62750. With the rotation, it is 1.017, 1.021, 1.016 and 1.022. The accuracy drop of plain MXFP4 does not always repeat. It is 0.9641 to 0.9597 in our first run (McNemar p = 0.0017), 0.9638 to 0.9606 in our third run (p = 0.023) and 0.9630 to 0.9586 in vllm#62750 (p = 0.0027), but 0.9628 to 0.9626 in our second run (p = 0.94). With the rotation, no run shows an accuracy change against BF16 (p = 0.62, 0.73 and 0.73 here, 0.79 over 8 reps and 0.057 over 12 reps in vLLM).

The extra tokens cost decode time. At almost the same TPOT, the rotation gives 7.8%, 5.4% and 9.1% fewer tokens per thinking answer than plain MXFP4 in our three runs.

The rotation needs Rocm/aiter6734 (merged), which adds hadamard_rotate to per_1x32_f4_quant_hip. sglang#50759 moved the AITER pin of the gfx942/gfx950 rocm10 and rocm724 images to 581579ab51, which includes it.

The rocm720 images keep the old AITER pin 285579b621, whose quant has no hadamard_rotate. Their gfx950-rocm720 Dockerfile stage sets SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0 next to that pin, so they keep the plain MXFP4 of sglang#43839. The pin bump removes the line.

The 32-point Hadamard matrix H is orthonormal, so (x H)(w H)^T = x w^T and the product does not change. The rotation spreads outliers across each 32-element MXFP4 block, so the shared E8M0 scale fits the block better. SGLang rotates the weight once at load. The AITER quant kernel rotates the activation in registers, so there is no extra kernel and no extra pass over the activation. vllm#62750 (merged) adds the same rotation to vLLM in PyTorch, and vllm#63272 (draft) moves it into the same AITER quant.

Modifications

  • environ.py adds the boolean SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD, default true. It acts only on the projections that SGLANG_ROCM_GDN_ONLINE_MXFP4 quantizes. 0 gives the plain MXFP4 of [Perf] [AMD] qwen3_5: Quantize the BF16 GDN projections to MXFP4 online #43839.
  • quark_w4a4_mxfp4.py:
    • _block_hadamard32 multiplies each 32-wide block of the last dimension by scipy.linalg.hadamard(32) / sqrt(32), in fp32. The AITER kernel uses the same matrix.
    • AiterMxfp4OnlineLinearMethod(hadamard) keeps the flag. quantize_ rotates the BF16 weight once, before dynamic_mxfp4_quant, if the flag is set.
    • apply() passes hadamard_rotate=True to per_1x32_f4_quant_hip on both GEMM paths: the Triton preshuffled GEMM at 64 rows or less, and the ASM gemm_a4w4 above that. With the flag off, it does not pass the argument, so 0 runs on any AITER.
  • qwen3_5.py passes the variable to AiterMxfp4OnlineLinearMethod. The load log gives the number of rotated projections. On Qwen3.8 at TP8 it is Online MXFP4 GDN in_proj_qkvz,out_proj: 138 projections, 138 with Hadamard-32.
  • test_qwen35_gdn_online_mxfp4.py:
    • TestBlockHadamard32 needs no GPU. It checks that the rotation keeps the products under the BF16 default dtype of the model loader.
    • The gfx95x test also runs every shape and row count with the rotation, against a reference built from the rotated operands, when SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD is on.
  • docker/rocm.Dockerfile: the gfx950-rocm720 stage sets SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0.
  • environment_variables.mdx adds one row.

The change acts only where #43839 acts: gfx95x with SGLANG_USE_AITER=1, the qwen3_5_text and qwen3_5_moe_text model types, and BF16 GDN projections with N and K multiples of 256. With SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0, nothing changes from main.

Accuracy Tests

Each run used one MI355X node:

The later commits of this PR change how the load log counts the rotated projections and remove the AITER check. With an AITER that has hadamard_rotate, they do not change the computation. Run 3 tests the head. The merged Rocm/aiter6734 also adds a gfx950 check and an AR + RMSNorm epilogue that this PR does not use. Its rotation code is the same as at 72d86b515f.

Thinking length, with the method of vllm#62750. Thinking-on GSM8K, 1319 test questions, zero-shot, \boxed{} prompt, temperature 1.0, top-p 0.95, top-k 20, at most 32768 tokens, 8 reps per arm, 256 concurrent requests, no MTP. The token count is usage.completion_tokens, which includes the thinking. The arms are paired by (rep, question). The mean ratio is total tokens over total tokens, the geomean is over the per-question ratios, and the brackets are 95% bootstrap intervals over questions.

Run Arm Mean tokens Mean ratio to BF16 [95% CI] Per-question geomean [95% CI] Accuracy McNemar p against BF16
3 BF16 532 1 1 0.9638
3 MXFP4 594 1.117 [1.073, 1.162] 1.073 [1.064, 1.083] 0.9606 0.023
3 MXFP4 + Hadamard-32 540 1.016 [0.983, 1.049] 1.016 [1.007, 1.024] 0.9632 0.73
2 BF16 525 1 1 0.9628
2 MXFP4 584 1.113 [1.064, 1.164] 1.070 [1.061, 1.080] 0.9626 0.94
2 MXFP4 + Hadamard-32 553 1.053 [1.017, 1.089] 1.021 [1.013, 1.030] 0.9633 0.73
1 BF16 535 1 1 0.9641
1 MXFP4 592 1.107 [1.061, 1.157] 1.071 [1.062, 1.080] 0.9597 0.0017
1 MXFP4 + Hadamard-32 546 1.021 [0.984, 1.061] 1.017 [1.009, 1.026] 0.9633 0.62

Against plain MXFP4, the rotation gives a mean ratio of 0.909 [0.872, 0.948] in run 3, 0.946 [0.906, 0.990] in run 2 and 0.922 [0.888, 0.961] in run 1. One rep alone gives a mean ratio from 1.05 to 1.25 for plain MXFP4, so the 8-rep geomean is the steadier measure. No answer in run 2 reached the 32768-token limit. In run 3, 3 plain MXFP4 answers and 1 BF16 answer reached it, and no Hadamard-32 answer. With the same method over 8 reps, vllm#62750 measured a mean ratio of 1.122 and a geomean of 1.073 for plain MXFP4, and 1.059 and 1.022 for Hadamard-32.

The standard evals with the rotation, greedy where the eval allows it:

Eval Run 3, no MTP Run 3, NEXTN Run 2, no MTP Run 2, NEXTN Run 1, no MTP Run 1, NEXTN
GSM8K 5-shot, chat, thinking, flexible-extract (1319) 0.9742 0.9773 0.9780 0.9780 0.9780 0.9780
GPQA Diamond (198, thinking, temperature 1.0, one run) 0.9293 0.9343 0.9141 0.9192 0.9242 0.9293
RULER niah_single_2, 64k not run not run 0.998 not run 0.998 0.992
RULER niah_single_2, 128k not run not run 0.994 not run 0.996 0.996

On GSM8K 5-shot, plain MXFP4 gives 0.9719 without MTP and 0.9773 with NEXTN in run 3, and 0.9788 in both modes in run 2. GPQA is one sampled run per arm. Over 5 reps, vllm#62750 gives a standard deviation of 1.3 points for BF16 on this model.

At the head 7397386194, the unit test passes on MI355X on the run 3 image, with no AITER change (2 tests, no skip).

Speed Tests and Profiling

The 12 serving shapes and the server flags of #43839, one round per arm. Median TPOT, geomean of the per-cell ratios over the 12 cells:

Pair Run 3, no MTP Run 3, NEXTN Run 2, no MTP Run 2, NEXTN
MXFP4 + Hadamard-32 against plain MXFP4 +0.4% +0.6% +0.0% +0.1%
MXFP4 + Hadamard-32 against BF16 not run not run -3.7% -4.8%
Plain MXFP4 (#43839) against BF16 not run not run -3.7% -5.0%

In run 3, 10 of the 12 cells are within 1% in each mode. The highest cells are +3.0% (8k / 1k, concurrency 4, no MTP) and +2.8% (128k / 1k, concurrency 16, NEXTN). In run 1, Hadamard-32 against plain MXFP4 gave +0.2% without MTP over the same 12 cells. A second check in run 1 started the servers in the order plain, Hadamard, Hadamard, plain, at 8k / 1k and concurrency 1 to 64. It gave -0.2%, and two rounds of one server differed by up to 0.4%. Over the three runs, the cost of the rotation is 0.6% or less.

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ⊘ Skipped -- a maintainer comments /tag-and-rerun-ci to run CI tests.
Latest PR Test (Extra): ⊘ Skipped -- a maintainer comments /tag-and-rerun-ci to run CI tests.
Latest PR Test (AMD ROCm 10): ⚠️ Run #46849805720

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@mintlify

mintlify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 10b1c88.

Approve preview

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 23, 2026
omirosh and others added 2 commits October 28, 2026 09:20
…mard-32

Plain MXFP4 on the Qwen3.5 / Qwen3.8 GDN in_proj_qkvz and out_proj makes
the thinking longer. On thinking-on GSM8K (8 reps at temperature 1.0),
the answers are 10.7% longer than BF16, and the accuracy drops from
0.9641 to 0.9597 (McNemar p = 0.0017).

SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD (default true) rotates each 32-wide
input block of these projections by the orthonormal Hadamard matrix. The
weight is rotated once at load. The activation is rotated inside
per_1x32_f4_quant_hip (ROCm/aiter#6734), on the Triton and the ASM path.
The product does not change, and the MXFP4 error is lower. With the
rotation, the answers are 2.1% longer than BF16, and the accuracy is the
same (p = 0.62). TPOT changes by 0.2% or less.

Without hadamard_rotate in AITER, the layer raises RuntimeError. Set the
variable to 0 to run plain MXFP4.

Co-authored-by: Cursor <[email protected]>
The rotation is on by default. Before, an AITER without hadamard_rotate
on per_1x32_f4_quant_hip made the layer raise RuntimeError at load. Now
the layer logs one warning and runs plain MXFP4, so the change does not
depend on when the AITER pin moves.

The load log gives the number of rotated projections, not the variable.
A CPU test checks the fallback with a stub AITER.

Co-authored-by: Cursor <[email protected]>
@omirosh
omirosh force-pushed the rocm/qwen38-gdn-mxfp4-hadamard branch from b193a96 to 4131842 Compare October 28, 2026 07:22
quantize_ is a public classmethod. Before, it rotated the weight before
cls(hadamard) checked AITER for hadamard_rotate. A direct call with
hadamard=True on an AITER without that argument rotated the weight but
not the activation, and the output was wrong with no error.

Now quantize_ builds the method first. It rotates the weight only if
the method keeps the rotation. process_weights_after_loading passes the
checked flag, so the model path does not change.

Co-authored-by: Cursor <[email protected]>
@omirosh omirosh changed the title [Perf] [AMD] qwen3_5: Rotate the online MXFP4 GDN projections by Hadamard-32 [Fix] [AMD] qwen3_5: Rotate the online MXFP4 GDN projections by Hadamard-32 Oct 29, 2026

@rkarhila-amd rkarhila-amd 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.

As an accuracy fix this should be high priority to push through once Aiter in rocm sglang images is updated..

Few things:
(1) Don't check the capability of environment, the CI tests will take care of it.
(2) Can you explain in your own words, without asking the agent: What does the Hadamard transformation do?

"hadamard_rotate"
not in inspect.signature(per_1x32_f4_quant_hip).parameters
):
print_warning_once(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It is better than try-except, but again, wait for the aiter in rocm sglang images to be updated to a new enough version and then push this PR without checks.

There are so many warnings and log entries that this message will be unnoticed by most users (and many agents) so it is better to just make sure the image supports it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the check.
For the Hadamard transformation explanation: it reversibly mixes tensor values to spread outliers, so that quantization can be done more accurately.

for (n, k), m in itertools.product(SHAPES, ROWS):
with self.subTest(n=n, k=k, m=m):
rotations = [False]
if "hadamard_rotate" in inspect.signature(per_1x32_f4_quant_hip).parameters:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

remove the if "available" for the same reason as stated in earlier comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed

The review asks to not check AITER for hadamard_rotate. The SGLang AITER
pin must have ROCm/aiter#6734 before this PR merges. An AITER without it
raises TypeError at the first rotated quant.

With SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0, apply() does not give
hadamard_rotate to AITER, so plain MXFP4 runs on each AITER.

The fallback test goes away. The gfx95x test always runs both rotations.

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

@rkarhila-amd rkarhila-amd 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.

The accuracy fix is very subtle: mxfp4 model was producing ~7% more tokens than base model. Adding the hadamard transform reduces a large part of the extra tokens.

I don't see any issues with code.

@claude claude Bot 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 17, 2026
…th the Hadamard rotation

sgl-project/sglang#46059 rotates the weight of the
online MXFP4 in_proj_qkvz and out_proj by Hadamard-32. SGLang then
rotates the activation before its quant. The default of that PR is on.
K1 and K2 read the rotated weight, but they do not rotate the
activation. The output is then wrong, and no error shows.

The spec now accepts an MXFP4 GDN projection only for a known quant
method state with no rotation: SGLang before that PR, or
SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0. Each other state gives a
refusal, so a renamed flag cannot give a wrong output. The e2e servers
set the env to 0.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 17, 2026
…rd variable

SGLang reads SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD only from
sgl-project/sglang#46059 on. On an SGLang without that
PR, the e2e setting has no effect.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 17, 2026
sgl-project/sglang#46059 rotates the weights of the
MXFP4 GDN projections by Hadamard-32 by default. The spec refused that
state. Now it runs it with the qh and oh builds.

- _rotated reads the state of AiterMxfp4OnlineLinearMethod: no flags,
  hadamard off, or hadamard on with hadamard_rotate. Each other class or
  state gives a refusal, so a renamed or a new flag does not run silently.
- _format gives (MXFP4, rotated) for each projection. The K1, K2 and
  layer_block keys get the rotation, so each layer runs its own format.
- SGLANG_READS pins the class name AiterMxfp4OnlineLinearMethod.
- The e2e tests do not set SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD now, so
  they run the default of SGLang.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 17, 2026
…n the README

- Section 2 tells how the qh and oh builds rotate the activation of the
  MXFP4 GDN projections of sgl-project/sglang#46059,
  in the order of ROCm/aiter#6734.
- Section 5 refuses only an unknown quant method or state now. _build makes
  a launch for each format of the projections.
- Section 6 adds the quant check, and the e2e tests run the default
  rotation of SGLang.

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

omirosh commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

@sglang-bot please review this pr

@sglang-bot

Copy link
Copy Markdown
Member

[sglang-bot Review Agent] @omirosh gfx950-rocm720 still pins AITER at 285579b621 in docker/rocm.Dockerfile:137, so Qwen’s online MXFP4 in_proj_qkvz fails on its first forward when per_1x32_f4_quant_hip gets the unsupported hadamard_rotate keyword. Can you update that pin or fall back to plain MXFP4 before rotating the weights when the installed AITER lacks support?

… images

The gfx950-rocm720 stage holds AITER at 285579b62
(sgl-project#50759). That AITER has no
hadamard_rotate on per_1x32_f4_quant_hip, so the online MXFP4 GDN
projections raise TypeError at the first forward in that image.

Set SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0 next to the held pin. The pin
bump removes the line. The unit test runs the Hadamard cases only when the
flag is on. The rocm10 and rocm724 images keep the rotation.

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

omirosh commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Right, for the rocm720 images. sglang#50759 moved the gfx942/gfx950 AITER pin to 581579ab5, which has Rocm/aiter6734, in the rocm10 and rocm724 images. It kept both rocm720 stages at 285579b62, because the FlyDSL MoE AOT replay fails in docker build on that torch 2.9 base. On rocm720-mi35x the first forward of an online MXFP4 GDN projection would fail with

TypeError: per_1x32_f4_quant_hip() got an unexpected keyword argument 'hadamard_rotate'

and the Sunday rocm720 lane would fail the Hadamard cases of test_qwen35_gdn_online_mxfp4.py the same way.

@rkarhila-amd asked earlier for no runtime AITER check here, and a silent fallback would hide the accuracy loss, so a03ff97 does not probe AITER. The gfx950-rocm720 stage now sets SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0 next to the held pin, and the pin bump removes that line. The unit test runs the Hadamard cases only when the flag is on. The rocm10 and rocm724 images keep the rotation on by default.

@rkarhila-amd @kangwangamd does that work for you?

@github-actions github-actions Bot added the amd label Nov 30, 2026
@sglang-bot

Copy link
Copy Markdown
Member

[sglang-bot Review Agent] @omirosh That addresses the first-forward failure. docker/rocm.Dockerfile:141 disables rotation for gfx950-rocm720, so in_proj_qkvz quantizes the weights without rotation and calls AITER without hadamard_rotate.

omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 30, 2026
…nt_x by Hadamard-32

sgl-project/sglang#46059 rotates the weights of the
MXFP4 GDN projections by Hadamard-32. The activation must get the same
rotation before its MXFP4 quant.

- Add hadamard32_quad to mono/ops.py. It rotates a 1 x 32 block that lies on
  4 adjacent lanes. It adds in the order of hadamard32_rotate of
  ROCm/aiter#6734, so the bf16 values are the same
  bit for bit.
- Add the h32 flag to quant_x and _quad_scale in layer.py and in
  mono/stages/moe.py. The flag is off by default, so the plain builds do not
  change.
- Add check_quant.py and TestQwen38MoeQuant. The check compares the rotation
  and the LDS rows of quant_x with per_1x32_f4_quant_hip, plain and rotated,
  bit for bit. The rotation inputs have an exponent for each element, so the
  f32 sums round and a changed add order shows.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 30, 2026
…K2 and layer_block

Add the build flags for the rotated MXFP4 GDN projections of
sgl-project/sglang#46059:

- K1Build.qh rotates the activation of in_proj_qkvz.
- K2Build.oh and LayerBuild.oh rotate the activation of out_proj.

A flag needs the MXFP4 flag of its projection (qq or oq). The build refuses
it without that flag. A kernel name gets "_h1" only when the flag is on, so
the names of the plain builds do not change. in_proj_ba still reads the x
rows before quant_x, so it reads them without the rotation.

The spec does not select these builds yet. check_k1.py and check_k2.py
compile the new keys, and check_layer_block compares the rotated
layer_block with the rotated K2 halves.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 30, 2026
sgl-project/sglang#46059 rotates the weights of the
MXFP4 GDN projections by Hadamard-32 by default. The spec refused that
state. Now it runs it with the qh and oh builds.

- _rotated reads the state of AiterMxfp4OnlineLinearMethod: no flags,
  hadamard off, or hadamard on with hadamard_rotate. Each other class or
  state gives a refusal, so a renamed or a new flag does not run silently.
- _format gives (MXFP4, rotated) for each projection. The K1, K2 and
  layer_block keys get the rotation, so each layer runs its own format.
- SGLANG_READS pins the class name AiterMxfp4OnlineLinearMethod.
- The e2e tests do not set SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD now, so
  they run the default of SGLang.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 30, 2026
…n the README

- Section 2 tells how the qh and oh builds rotate the activation of the
  MXFP4 GDN projections of sgl-project/sglang#46059,
  in the order of ROCm/aiter#6734.
- Section 5 refuses only an unknown quant method or state now. _build makes
  a launch for each format of the projections.
- Section 6 adds the quant check, and the e2e tests run the default
  rotation of SGLang.

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

Copy link
Copy Markdown

I'm not sure I get this.
This is an accuracy fix that is enabled by default but then disabled in Dockerfile?
Aiter release for sglang images was updated, but it still isn't a version that supports the hadamard operation?

@sglang-bot sglang-bot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[sglang-bot Review Agent] One thing to fix before this can go in.

Comment thread docker/rocm.Dockerfile
ENV TRITON_COMMIT_DEFAULT="42270451990532c67e69d753fbd026f28fcc4840"
# This AITER has no hadamard_rotate on per_1x32_f4_quant_hip (ROCm/aiter#6734).
# Remove with the pin bump.
ENV SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[sglang-bot Review Agent] The rocm720 MI35x job installs this checkout into a published image. If that image predates this ENV, the test enables rotation against AITER 285579b621 and gets TypeError on hadamard_rotate. Could we pass the opt-out when CI starts that container too?

@omirosh

omirosh commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

I'm not sure I get this. This is an accuracy fix that is enabled by default but then disabled in Dockerfile? Aiter release for sglang images was updated, but it still isn't a version that supports the hadamard operation?

Aiter was updated for rocm 7.24 and 10 images, but not 7.20 (due to some fails). We are switching the rotation off for 7.20 images until they have an aiter update.

@sglang-bot

Copy link
Copy Markdown
Member

[sglang-bot Review Agent] @omirosh When the rocm720 MI35x job installs this checkout into an image built before the Dockerfile change, test_qwen35_gdn_online_mxfp4.py still passes hadamard_rotate to the pinned AITER and hits TypeError. Could scripts/ci/amd/amd_ci_start_container.sh pass -e SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0 when it starts that container?

yichiche pushed a commit to sgl-project/sgl-amd-mono that referenced this pull request Dec 1, 2026
…e layer_block launch (#154)

This PR sits on `main` `1cf7315`, which has
[sgl-amd-mono#92](#92).
Review the code commit `a8d1ae2` and the four test commits `bff8e00`,
`9727cd2`, `d9259d4` and `d28e839`.

## Motivation

This is a performance change. With it, a decode or verify step of 16
rows runs the second half of each layer as one `layer_block` launch, in
place of SGLang's forward. On 8× MI355X with TP8, 8192 input and 1024
output tokens, the per-user decode rate goes from 47.8 to 52.6 tok/s
(1.10×) at concurrency 16 without MTP. With NEXTN 3/1/4, it goes from
181.9 to 205.3 tok/s (1.13×) at concurrency 4. The other concurrencies
do not change.

K2 keeps a bf16 x tile of its rows in LDS. At 8 rows, this tile is 131
KB of the 160 KB of LDS of a CU, so K2 takes 8 rows at most. A step of 9
to 16 requests replays the CUDA graph of 16 rows. A NEXTN verify step of
4 requests has 16 rows. These steps run SGLang's forward now. At
concurrency 16 without MTP, the tail of each layer is 8 or 9 kernels and
takes 136 to 139 µs.

`layer_block` comes from
[vllm#67421](vllm-project/vllm#67421) at
`28f094565b`. That PR is an open draft. `layer_block` has the grid and
the stages of the `fse` build of K2: 256 CTAs of 512 threads. It keeps
no x tile in LDS. The `norm` tasks write the sums of the ranks to the
scratch, and each consumer builds its part of x from them. Thus the LDS
does not limit its rows to 8.

## Modifications

| Area | Change |
| --- | --- |
| `qwen38_a95b_mxfp4/gfx950/mono/` | New. `blocks.py` (the layer half of
the vLLM file, build key `LayerBuild`) and its stages `ops.py`,
`layout.py`, `common.py`, `mx_layout.py`, `stages/gemv.py`,
`stages/norm.py` and `stages/moe.py`. They are copies of
[vllm#67421](vllm-project/vllm#67421) at
`28f094565b`, with their source headers. Only the interface changes: the
mailboxes and the guard of `common/`, a msgspec build key, no health
words, and peer regions after the K2 regions and the guard flags. |
| `qwen38_a95b_mxfp4/spec.py` | Adds the width 16
(`mono/layout.SPLIT_MAX`). When each layer has the fused shared expert,
`_build` makes one `layer_block` launch for each `o_proj` or `out_proj`
dtype. A step of 16 rows runs SGLang's GDN or attention up to the input
of `out_proj` or `o_proj`, then `layer_block`. K1 does not run at 16
rows. Without the fused shared expert, a step of 16 rows runs SGLang's
forward, as before. Check mode compares `layer_block` with SGLang's
layer half, as it does for K2. |
| `qwen38_a95b_mxfp4/gfx950/__init__.py` | The docstring names
`layer_block`. |
| `test/kernels/qwen38_a95b_mxfp4/check_k2.py` | The compile check also
builds the `LayerBuild` keys. New checks at 16 rows: probe invariance,
agreement with two 8-row `fse` K2 launches, a CUDA graph that mixes the
K2 and `layer_block` widths, 10 chain cases, and the fault on one rank.
|
| `test/kernels/test_qwen38_a95b_mxfp4_kernels.py` | `test_chain` runs
each chain case in its own process. A launch that hangs stops only its
own case. |
| `test/e2e/test_qwen38_a95b_mxfp4_server.py` | The check-mode test with
the fused shared expert also sends a 16-row step. The NEXTN verify
server uses `--enforce-shared-experts-fusion`, so its 16-row verify
steps run `layer_block`. |
| `test/e2e/qwen38_a95b_mxfp4_server.py` | A comment only. |
| `test/unit/test_qwen38_a95b_mxfp4_spec.py` | The spec widths are 1 to
8 and 16. |
| `sgl_amd_mono/qwen38_a95b_mxfp4/README.md` | Adds `layer_block`: the
width 16, how it differs from K2, its peer regions, and its kernel
tests. |
| `NOTICE` | Names
[vllm#67421](vllm-project/vllm#67421), which
adapts parts of `layer_block` from ROCm/ATOM. |

**Refusals.** This PR adds no refusal. A model without the fused shared
expert gets no `layer_block` build, and its 16-row steps run SGLang's
forward. The Hadamard refusal of
[sgl-amd-mono#92](#92)
(`8975393`) also covers `layer_block`, which quantizes the `out_proj`
input with no rotation. That refusal runs for each layer before the
builds. So a rotated MXFP4 `out_proj` of
[sglang#46059](sgl-project/sglang#46059) stops
the server at startup.

With the test CUDA graphs (batch sizes 1, 2, 4, 8 and 16) and the fused
shared expert, each rank logs "Qwen3.8 monokernel: 8 K1, 8 K2 and 2
layer_block launches (widths [1, 2, 4, 8, 16], decode)". With NEXTN
3/1/4, each rank logs "0 K1, 4 K2 and 2 layer_block launches (widths [4,
8, 16], verify)". The two `layer_block` launches are the MXFP4
`out_proj` build of the 69 GDN layers and the bf16 `o_proj` build of the
23 attention layers.

This PR does not change `common/` or the other models.

## Accuracy Tests

The results below use this setup. The runs with the monokernels off and
on have their own setup table.

| Item | Value |
| --- | --- |
| GPUs | 8× MI355X (gfx950), one node |
| TP | 8 |
| Image |
`rocm/sgl-dev:v0.5.22-rocm10-mi35x-20261028@sha256:b51edf074b567263afb19be9108756645ee00d0604374b6e4c5006caccaa17fe`
|
| SGLang | `5bb7ecc2c247db05e3de41d21f36aed7aa1a2dfb`, which has
[sglang#41899](sgl-project/sglang#41899) and
[sglang#43839](sgl-project/sglang#43839), with
no unmerged SGLang PR |
| AITER, FlyDSL | `285579b6211b0da30f35b91a890c29c823597cd1`, 0.4.0 |
| Model revision | `13dc9676cdd9e2374c3efb50389d3392b975acae` |
| Server flags | `ARGS` and `ENV` of
`test/e2e/qwen38_a95b_mxfp4_server.py`, plus
`--enforce-shared-experts-fusion` and `--monokernel-backend amd` in both
arms |
| Base | The head `7ab73e3` of
[sgl-amd-mono#92](#92),
with the monokernels on. Its 16-row steps run SGLang's forward. |
| This PR | The code commit `8f27849`. After the rebase onto `a4c94bb`,
it was `a32391c`. On `main` `36c385e`, it was `7fc7b73`. On `main`
`1cf7315`, it is `a8d1ae2`. The test commits after it change only
`test/`. |

The runs use the P6 commits on the old head `7ab73e3` of
[sgl-amd-mono#92](#92).
The head of
[sgl-amd-mono#92](#92)
is now `a4c94bb` on `main`. In `qwen38_a95b_mxfp4/`, it adds only the
Hadamard refusal, its unit test and three README lines. The e2e server
sets `SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0`, and SGLang `5bb7ecc2c2`
ignores that variable. `common/` has new code of other models in
`sync.py`, `ops.py` and `rocm_codegen.py`. The calls of P6 into
`common/` keep their code path.

The rebased head passes the tests on one node, on the image of the table
above and on the 2026-11-17 nightly:

| Head | Image | unit | kernels | e2e |
| --- | --- | --- | --- | --- |
| `410ca78` | The image of the table above | 31 passed, 1 failed | 7
passed | 6 passed |
| `60914ed`: this PR and
[sgl-amd-mono#92](#92)
on `main` `fcdd39b` |
`rocm/sgl-dev:v0.5.23-rocm10-mi35x-20261117@sha256:09b8237296024285e6286ffb54d75c3af6d59342bbbb3558dea56bed86798814`
| 31 passed, 1 failed | 7 passed | 6 passed |

| Head | GSM8K decode (200) | GSM8K NEXTN (200) | Highest mean KL (2, 3,
7, 8 rows) | Rows that check mode skipped, without and with FSE | Lowest
`k2.out.cosine`, without and with FSE | Lowest `out` cosine of
`layer_block` (16 rows) |
| --- | --- | --- | --- | --- | --- | --- |
| `410ca78` | 0.985 | 0.985 | 0.0172 | 0 of 3956 and 1 of 8372 |
0.999190, 0.999170 | 0.999915 |
| `60914ed` | 0.980 | 0.980 | 0.0235 | 1 of 3956 and 0 of 8372 |
0.999704, 0.998633 | 0.999883 |

The head `05b9dd9` on `main` `36c385e` has the same files as `60914ed`
in `qwen38_a95b_mxfp4/`, in its tests and in `common/`.

The head `d28e839` on `main` `1cf7315` has the same files as `05b9dd9`
in `qwen38_a95b_mxfp4/`. On `main`,
[sgl-amd-mono#184](#184)
changed the server flag of the serving test to
`--enable-amd-monokernel`, and `common/` gets new code in `code_addr.py`
and `sync.py`, with no change to the existing code.

The failed unit test is the `test_contract.py` test of
`qwen38_flash_next`, as in the runs below. It also fails on `main`.
[sgl-amd-mono#104](#104)
made `qwen38_flash_next` read `srt/mem_cache/kv/router.py`. The 20261028
image does not have that file, and the 20261117 image does not have its
`"state"`.

The lowest `k2.out.cosine` of these two runs comes from checks of 1 row:
0.999190 and 0.999170 (`410ca78`), and 0.998633 (`60914ed`, with FSE).
In the three runs of `66ae2fa` below, the lowest is 0.999519. The bound
is 0.99. The rebase does not cause the lower values:

- `410ca78` and `66ae2fa` run the same K2 code on the same image. The
rebase changes no file in `qwen38_a95b_mxfp4/gfx950/`. In `common/`, it
changes only the structure of `Mailbox.poll`. Each other function that
K2 calls is the same.
- Each run checks other tokens. The e2e GSM8K samples at temperature
1.0. Only 5% to 10% of the 1-row checks of two runs give the same
cosine.
- The 1-row checks have the same distribution in the five runs, also in
`60914ed` on the new image. Their 1st percentile, 10th percentile and
median agree to 0.000004. 3 of the 5519 1-row checks of the `66ae2fa`
runs are below 0.9997, and 3 of the 3680 of the new runs (Fisher's exact
test, p = 0.46).

Each run has a few such tokens. K2 quantizes the expert inputs to MXFP4
as SGLang does, but it adds in another order (`spec.NUMERICS`). On the
six lowest 1-row checks of the five runs, the relative error is 2.4 to
4.9 times the median of their layer, and the cosine is about 1 - rel^2 /
2. Five of the six are in the test with the fused shared expert. A check
of more rows takes one cosine over all its rows, so its other rows
dilute such a token.

### GSM8K, 3 rounds for each arm

The test uses lm_eval 0.4.13 with `local-chat-completions` and the chat
template. It runs all 1,319 questions, 5-shot, at temperature 0, with
`max_gen_toks` 32768. Without MTP, it sends 16 concurrent requests, so
most decode steps have 9 to 16 rows. With NEXTN 3/1/4, it sends 4
concurrent requests, so most verify steps have 16 rows. Each arm starts
a fresh server. The arms run in the order base, PR, PR, base for each
round.

Right answers of 1,319 (flexible-extract / strict-match):

| Mode | Base round 1 | Base round 2 | Base round 3 | PR round 1 | PR
round 2 | PR round 3 |
| --- | --- | --- | --- | --- | --- | --- |
| No MTP, 16 requests | 1291 / 1191 | 1289 / 1191 | 1292 / 1185 | 1284 /
1177 | 1290 / 1197 | 1285 / 1186 |
| NEXTN, 4 requests | 1294 / 1196 | 1288 / 1200 | 1287 / 1179 | 1285 /
1184 | 1286 / 1174 | 1287 / 1200 |

For each question, the table below counts the right answers of each arm
over the 3 rounds. The sign test counts the questions where the PR is
right more often or less often than the base.

| Mode | Filter | Base mean | PR mean | PR right more often | PR right
less often | Sign test p (exact) |
| --- | --- | --- | --- | --- | --- | --- |
| No MTP | flexible-extract | 1290.7 (0.9785) | 1286.3 (0.9752) | 12 |
22 | 0.121 |
| No MTP | strict-match | 1189.0 (0.9014) | 1186.7 (0.8997) | 144 | 151
| 0.727 |
| NEXTN | flexible-extract | 1289.7 (0.9778) | 1286.0 (0.9750) | 14 | 25
| 0.108 |
| NEXTN | strict-match | 1191.7 (0.9035) | 1186.0 (0.8992) | 130 | 145 |
0.399 |

- The sign test finds no accuracy difference on any filter. The largest
difference of the means is 0.0043 (NEXTN strict-match). The GSM8K
tolerance of
[sgl-amd-mono#107](#107)
is 0.015.
- Round 1 alone gives McNemar's p 0.049 for NEXTN flexible-extract (13
questions right only in the base, 4 only in the PR). So we ran two more
rounds of each arm.
- At temperature 0, GSM8K is not deterministic on this server. Two
rounds of the same arm differ on 14 to 23 questions (flexible-extract).
Base round 1 against base round 2 with NEXTN gives 10 against 4.
- On flexible-extract, the PR is about 4 answers (0.3%) lower than the
base on average in both modes. This is in the spread of the rounds of
one arm (1289 to 1292 and 1287 to 1294 for the base).

### The monokernels off and on, on the 2026-11-17 nightly

These runs compare the monokernels off with the monokernels on. With the
monokernels off, the server runs SGLang's forward at each width. Both
arms use one image on one node. The image is a nightly with no SGLang or
AITER change, and only the plugin of this PR is installed on it.

| Item | Value |
| --- | --- |
| Image |
`rocm/sgl-dev:v0.5.23-rocm10-mi35x-20261117@sha256:09b8237296024285e6286ffb54d75c3af6d59342bbbb3558dea56bed86798814`
|
| SGLang | `c67db7c76280986ee936af4b3a1019397b0c285e`, the SGLang of the
image |
| AITER | `581579ab51ca26ddd4a08a6aa6aa983a78aaf276`, the AITER of the
image |
| Plugin | The head `05b9dd9` of this PR. The image build installs it
with `pip install --no-deps -e .` over the sgl-amd-mono of the image, as
the AMD PR test does. |
| Model revision | `13dc9676cdd9e2374c3efb50389d3392b975acae` |
| Server flags | The flags of the speed servers below. The arm with the
monokernels off has no `--monokernel-backend amd`. Without MTP, both
arms also set `--max-running-requests 64` and CUDA graphs at 1, 2, 4, 8,
16, 32 and 64 rows. Thus concurrency 32 and 64 have decode steps past
the largest width. |
| Server logs | With the monokernels on, each rank logs "8 K1, 8 K2 and
2 layer_block launches (widths [1, 2, 4, 8, 16], decode)" without MTP,
and "0 K1, 4 K2 and 2 layer_block launches (widths [4, 8, 16], verify)"
with NEXTN. With the monokernels off, the server logs no monokernel
build. |
| Order | Round 1 runs off, then on. Round 2 runs on, then off. Each arm
starts a fresh server. |

GSM8K runs 3 rounds of each arm, with the setup of the 3-round test
above: 16 concurrent requests without MTP, and 4 with NEXTN. Round 1 is
in the speed runs. Rounds 2 and 3 are GSM8K-only runs with the same
image and flags, on another node of the same type.

| Mode | Filter | Off, rounds 1, 2 and 3 | On, rounds 1, 2 and 3 |
| --- | --- | --- | --- |
| No MTP | flexible-extract | 0.9750, 0.9795, 0.9765 | 0.9712, 0.9795,
0.9742 |
| No MTP | strict-match | 0.9022, 0.8976, 0.8954 | 0.8817, 0.9045,
0.8893 |
| NEXTN | flexible-extract | 0.9788, 0.9757, 0.9765 | 0.9735, 0.9727,
0.9765 |
| NEXTN | strict-match | 0.8992, 0.8908, 0.8969 | 0.8863, 0.8848, 0.8969
|

For each question, the table below counts the right answers of each arm
over the 3 rounds, as in the 3-round test above. The two modes use
different servers, so their counts can go into one test (the "Both"
rows).

| Mode | Filter | Off mean | On mean | On right more often | On right
less often | Sign test p (exact) |
| --- | --- | --- | --- | --- | --- | --- |
| No MTP | flexible-extract | 1288.7 | 1286.0 | 13 | 21 | 0.229 |
| No MTP | strict-match | 1185.0 | 1176.3 | 142 | 160 | 0.328 |
| NEXTN | flexible-extract | 1288.7 | 1285.0 | 18 | 25 | 0.36 |
| NEXTN | strict-match | 1181.3 | 1173.0 | 142 | 154 | 0.523 |
| Both | flexible-extract | | | 31 | 46 | 0.11 |
| Both | strict-match | | | 284 | 314 | 0.236 |

- The sign test finds no accuracy difference on any filter, also with
both modes in one test.
- Round 1 alone favored the monokernels off. With both modes in one
test, McNemar gave p 0.043 on flexible-extract (21 against 9) and p
0.013 on strict-match (173 against 129). So we ran rounds 2 and 3. We
set the test and its limit (p < 0.05 on flexible-extract, both modes in
one test) before these runs.
- One arm also moves between rounds. With the monokernels on and no MTP,
round 1 against round 2 gives McNemar's p 0.027 on flexible-extract (5
against 16). There are 12 pairs of rounds of one arm (3 for each of the
4 arms). The other 11 pairs give p 0.13 or more.
- The means with the monokernels on are lower by 0.0020 to 0.0066. The
GSM8K tolerance of
[sgl-amd-mono#107](#107)
is 0.015.
- The arms differ in all the monokernels, also K1 and K2 of
[sgl-amd-mono#92](#92).
The 3-round test above compares this PR with the head of
[sgl-amd-mono#92](#92),
and it finds no difference.

### GPQA Diamond and SWE-bench Pro, 16 parallel requests

The PRs before this one ran these tests with 8 parallel requests. At 8
requests, no decode step has more than 8 rows, so `layer_block` does not
run. These runs send 16 parallel requests, so most decode steps replay
the CUDA graph of 16 rows. The server log of each PR arm gives "8 K1, 8
K2 and 2 layer_block launches".

The base arm runs the code commit `5d328f2` of
[sgl-amd-mono#92](#92),
which has the code of `7ab73e3`. The PR arm runs `66ae2fa`. The servers
use the flags of the GSM8K and speed servers plus
`--default-chat-template-kwargs '{"reasoning_effort": "xhigh"}'`, as in
[sgl-amd-mono#92](#92).
The SWE-bench servers leave out `--disable-radix-cache`, because the
turns of a task share long prefixes. Each arm starts a fresh server on
one node with 8× MI355X.

#### GPQA Diamond

The test uses sgl-eval 0.1.3 on all 198 questions, with 4 samples of
each question. It samples at temperature 1.0, top-p 0.95, top-k 20 and
min-p 0, with 131072 max tokens, and it sends 16 concurrent requests. In
the server log of the PR arm, 92% of the decode batches have 9 to 16
running requests.

| | Base | This PR | Model card |
| --- | --- | --- | --- |
| avg@4, with the 95% interval over the questions | 92.93 ± 3.14 | 92.68
± 3.23 | 92.6 |

Over the 198 paired questions, the PR minus the base is -0.25 points,
with a 95% interval of ±1.40. Nine questions score higher with the PR,
and 11 with the base. The sign test gives p 0.824 and finds no
difference. The model card value is the score in the Qwen3.8-Max column
of
[Qwen/Qwen3.8-2.4T-A95B](https://huggingface.co/Qwen/Qwen3.8-2.4T-A95B),
and it is inside the 95% interval of both arms. In each arm, 5 of the
792 samples stop at the 131072-token cap.

#### SWE-bench Pro

The test runs the 50 tasks of
[sgl-amd-mono#92](#92)
with the same protocol: Harbor 0.23.0, the `locked_claude_code` agent of
SWE-bench Pro V2, and 50 minutes for each task. It runs 16 tasks at a
time. In the server log of the PR arm, 59% of the decode batches have 9
to 16 running requests. After the run, `patch_replay` grades each patch
again on a fresh task image, and the table gives that grade.

| | Base | This PR |
| --- | --- | --- |
| Resolved | 44 of 50 (88%) | 47 of 50 (94%) |
| Agent timeouts | 4 | 2 |
| Other agent errors | 1 | 2 |
| Mean agent time of a task (minutes) | 26.1 | 23.7 |

Over the 50 paired tasks, 4 pass only with the PR, and 1 only with the
base. McNemar's exact test gives p 0.375 and finds no difference.

- In 3 of the 4 tasks that pass only with the PR, the agent of the base
ended without an error, and its patch failed the tests. In the fourth,
the agent of the base reached the 50-minute limit.
- The task that passes only with the base did not run with the PR.
Docker could not pull its task image, because the registry reset the
connection. Thus the agent did not start. Without this task, the counts
are 4 and 0, and p is 0.125.
- With 8 tasks at a time, the base code resolves 46 of 50 tasks, with 2
agent timeouts
([sgl-amd-mono#92](#92)).
With 16 tasks at a time, each agent decodes more slowly, and more agents
reach the limit.
- Fifty tasks find only a large change. The 95% interval of the resolved
rate is ±9.1 points for the base and ±6.6 points for the PR.

### Kernel checks (`test/kernels`)

| Check | Result |
| --- | --- |
| Compile every K2 and `layer_block` build key on every rank | All 34
keys compile in 25 s |
| Batch invariance (K2, widths 1 to 8) | 57 cases, the ranks agree |
| `layer_block` at 16 rows, bf16 and MXFP4 `o_proj`: the probe row does
not change with the other rows or its row, and the rows agree with two
8-row `fse` K2 launches on the same inputs | Worst cosine 1.0
(`res_out`) and 0.99999988 (`out`). The README bound is 0.9999 and 0.99.
|
| CUDA graph replay of widths 8, 16, 16, 1, 3, 8, 16, 2 and 5 on one
peer buffer | 200 replays bit for bit on every rank |
| Chain: `layer_block` launches at 16 rows in one epoch, as in a verify
step (10 cases: 24 launches with an epoch each or in one epoch, `o1` and
`o0` pairs in each order, a host sync between, rank 3 late) | 10 of 10
cases pass |
| Fault: a stalled wait on rank 3, in K2 at 1 row and in `layer_block`
at 16 rows | Each rank stops, and the launch returns in 0.52 s |

Each of the three test runs below passes these checks. The kernel tests
do not compare the kernels with SGLang's ops. Check mode in the e2e test
does that, with the real weights.

### Three runs of all tests

The runs use the head `66ae2fa` on one node.

| Run | unit | kernels | e2e | GSM8K decode (200) | GSM8K NEXTN (200) |
Highest mean KL (2, 3, 7, 8 rows) | Rows that check mode skipped,
without and with FSE | Lowest `k2.out.cosine`, without and with FSE |
Lowest `out` cosine of `layer_block` (16 rows) |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | 23 passed, 1 failed | 7 passed | 6 passed | 0.980 | 0.980 | 0.0196
| 0 of 3956 and 1 of 8372 | 0.999881, 0.999786 | 0.999873 |
| 2 | 23 passed, 1 failed | 7 passed | 6 passed | 0.980 | 0.975 | 0.0160
| 1 of 3956 and 1 of 8372 | 0.999788, 0.999519 | 0.999912 |
| 3 | 23 passed, 1 failed | 7 passed | 6 passed | 0.975 | 0.965 | 0.0254
| 0 of 3956 and 0 of 8372 | 0.999820, 0.999549 | 0.999895 |

- The failed unit test is `test_contract.py` for
`sgl_amd_mono/qwen38_flash_next/gfx950/runner.py`. This PR does not
change `qwen38_flash_next`.
- Check mode (`SGLANG_AMD_MONO_CHECK`, eager) runs SGLang's layer next
to each launch and compares the outputs. With the fused shared expert,
the test also sends a 16-row step. That test has 1104 K1 checks and 1748
K2 checks, and 276 of the K2 checks are `layer_block` checks at 16 rows.
Its rows are the 3956 rows at 1, 3 and 8 rows, and 4416 rows at 16 rows.
- The test without the fused shared expert has 1104 K1 checks and 1472
K2 checks, as in
[sgl-amd-mono#92](#92).
- In these three runs and the two runs of the rebased head, the lowest
`k1.core.cosine` is 0.999983, the lowest `k1.state.cosine` is 0.999985,
and `k2.res_out.cosine` rounds to 1.000000. This includes the
`layer_block` checks.
- The NEXTN verify test now uses `--enforce-shared-experts-fusion`, so
its 16-row verify steps run `layer_block`. Each of its 200 questions is
0.005 of the score. Run 3 gives 0.965, 3 questions below run 1. The full
GSM8K above finds no difference.
- The decode e2e tests (KL and GSM8K) run without the fused shared
expert, so their 16-row steps run SGLang's forward. The KL test covers
2, 3, 7 and 8 rows.

The tests do not cover TP4 or MI350X, because the spec serves only TP8
on MI355X.

### Test logs

The blocks give the result line of each test, the result lines of the
kernel checks and the e2e metrics. They cover the two runs of the
rebased head and the three runs of `66ae2fa`. A full log has about 4 MB,
most of it server output.

<details><summary>Unit tests (CPU): 31 passed and 1 failed on both
heads. The failure is in the qwen38_flash_next contract test, which this
PR does not change</summary>

`python3 -m pytest -v test/unit/test_contract.py
test/unit/test_qwen38_a95b_mxfp4_spec.py -k "qwen38 or common"`

```text
# 410ca78, rocm/sgl-dev:v0.5.22-rocm10-mi35x-20261028
PASSED test/unit/test_contract.py::test_every_sglang_import_is_declared[sgl_amd_mono/qwen38_a95b_mxfp4/check.py]
PASSED test/unit/test_contract.py::test_every_sglang_import_is_declared[sgl_amd_mono/qwen38_a95b_mxfp4/spec.py]
PASSED test/unit/test_contract.py::test_every_sglang_import_is_declared[sgl_amd_mono/qwen38_flash_next/check.py]
PASSED test/unit/test_contract.py::test_every_sglang_import_is_declared[sgl_amd_mono/qwen38_flash_next/draft.py]
PASSED test/unit/test_contract.py::test_every_sglang_import_is_declared[sgl_amd_mono/qwen38_flash_next/gfx950/runner.py]
PASSED test/unit/test_contract.py::test_every_sglang_import_is_declared[sgl_amd_mono/qwen38_flash_next/gfx950/weights.py]
PASSED test/unit/test_contract.py::test_every_sglang_import_is_declared[sgl_amd_mono/qwen38_flash_next/spec.py]
PASSED test/unit/test_contract.py::test_sglang_provides_what_the_plugin_reads[sgl_amd_mono/qwen38_a95b_mxfp4/check.py]
PASSED test/unit/test_contract.py::test_sglang_provides_what_the_plugin_reads[sgl_amd_mono/qwen38_a95b_mxfp4/spec.py]
PASSED test/unit/test_contract.py::test_sglang_provides_what_the_plugin_reads[sgl_amd_mono/qwen38_flash_next/check.py]
PASSED test/unit/test_contract.py::test_sglang_provides_what_the_plugin_reads[sgl_amd_mono/qwen38_flash_next/draft.py]
FAILED test/unit/test_contract.py::test_sglang_provides_what_the_plugin_reads[sgl_amd_mono/qwen38_flash_next/gfx950/runner.py]
PASSED test/unit/test_contract.py::test_sglang_provides_what_the_plugin_reads[sgl_amd_mono/qwen38_flash_next/gfx950/weights.py]
PASSED test/unit/test_contract.py::test_sglang_provides_what_the_plugin_reads[sgl_amd_mono/qwen38_flash_next/spec.py]
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_the_plugin_registers_the_spec
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_config_reasons
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_model_reasons[kw0]
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_model_reasons[kw1]
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_model_reasons[kw2]
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_model_reasons[kw3]
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_mxfp4_gdn_projections_have_no_rotation[state0-False-in_proj_qkvz]
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_mxfp4_gdn_projections_have_no_rotation[state0-False-out_proj]
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_mxfp4_gdn_projections_have_no_rotation[state1-False-in_proj_qkvz]
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_mxfp4_gdn_projections_have_no_rotation[state1-False-out_proj]
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_mxfp4_gdn_projections_have_no_rotation[state2-True-in_proj_qkvz]
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_mxfp4_gdn_projections_have_no_rotation[state2-True-out_proj]
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_mxfp4_gdn_projections_have_no_rotation[state3-True-in_proj_qkvz]
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_mxfp4_gdn_projections_have_no_rotation[state3-True-out_proj]
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_the_shared_expert_is_unfused_or_expert_512
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_check_compares_the_rows_routed_alike
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_model_reasons_name_the_layer
PASSED test/unit/test_qwen38_a95b_mxfp4_spec.py::test_aux_hidden_states_run_sglangs_forward
E           AssertionError: sgl_amd_mono/qwen38_flash_next/gfx950/runner.py: no file matches srt/mem_cache/kv/router.py
1 failed, 31 passed, 74 deselected, 18 warnings in 20.17s

# 60914ed, rocm/sgl-dev:v0.5.23-rocm10-mi35x-20261117: the same 32 results
E       AssertionError: SGLang no longer provides what sgl_amd_mono/qwen38_flash_next/gfx950/runner.py reads; repair it and its SGLANG_READS:
1 failed, 31 passed, 88 deselected, 18 warnings in 21.30s
```

</details>

<details><summary>Kernel tests (8 × MI355X): 7 passed on both
heads</summary>

`python3 -m pytest -v -s
test/kernels/test_qwen38_a95b_mxfp4_kernels.py`. Each case of
`test_chain` runs in its own process.

```text
# 410ca78, rocm/sgl-dev:v0.5.22-rocm10-mi35x-20261028
PASSED test/kernels/test_qwen38_a95b_mxfp4_kernels.py::TestQwen38MoeLayout::test_scales
PASSED test/kernels/test_qwen38_a95b_mxfp4_kernels.py::TestQwen38MoeLayout::test_w13_tiles
PASSED test/kernels/test_qwen38_a95b_mxfp4_kernels.py::TestQwen38MoeLayout::test_w2_tiles
compile: 64 K1 keys in 113 s
batch invariance: 57 cases, OK
graph replay: 200 replays of widths (8, 1, 3, 8, 2, 5): 0 mismatching checks
fault: error words {3: 2, 4: 1, 5: 0} in 1.09 s
PASSED test/kernels/test_qwen38_a95b_mxfp4_kernels.py::TestQwen38MoeK1::test_k1
chain 24 launches, an epoch each: OK
chain o1 o0, an epoch each: OK
chain o0 o1, an epoch each: OK
chain o1 o1 in one epoch: OK
chain o0 o0 in one epoch: OK
chain o1 o0 in one epoch: OK
chain o0 o1 in one epoch: OK
chain o1 o1 in one epoch, a sync between: OK
chain o1 o1 in one epoch, rank 3 late: OK
chain 24 launches in one epoch: OK
PASSED test/kernels/test_qwen38_a95b_mxfp4_kernels.py::TestQwen38MoeK2::test_chain
compile: 34 K2 and layer_block keys in 21 s: OK
batch invariance: 57 cases: OK, ranks agree True
layer_block at 16 rows: probe invariance and K2 agreement (worst cosine {'res_out': 1.0, 'out': 0.9999998807907104}): OK, ranks agree True
graph replay: 200 replays of widths (8, 16, 16, 1, 3, 8, 16, 2, 5): OK, ranks agree True
fault (K2Build at 1 rows): rank 3 stalled, returned in 0.52 s: OK
fault (LayerBuild at 16 rows): rank 3 stalled, returned in 0.52 s: OK
PASSED test/kernels/test_qwen38_a95b_mxfp4_kernels.py::TestQwen38MoeK2::test_k2
PASSED test/kernels/test_qwen38_a95b_mxfp4_kernels.py::TestQwen38MoePort::test_bitwise_against_sglang_43516
7 passed, 18 warnings in 357.56s (0:05:57)

# 60914ed, rocm/sgl-dev:v0.5.23-rocm10-mi35x-20261117: the same results; only the times differ
compile: 64 K1 keys in 108 s
fault: error words {3: 2, 4: 1, 5: 0} in 1.06 s
compile: 34 K2 and layer_block keys in 20 s: OK
7 passed, 4 warnings in 312.26s (0:05:12)
```

</details>

<details><summary>E2E (8 × MI355X, TP8): 6 passed on both
heads</summary>

`python3 -m pytest -v -s test/e2e/test_qwen38_a95b_mxfp4_server.py`. The
`[TP0]` line of each server gives its launches and widths. The KL values
are for 2, 3, 7 and 8 prompts. Check mode logs one line for each check.
The table above gives the lowest values, and no check reports a
violation.

```text
# 410ca78, rocm/sgl-dev:v0.5.22-rocm10-mi35x-20261028
[TP0] Qwen3.8 monokernel: 8 K1, 8 K2 and 0 layer_block launches (widths [1, 2, 4, 8], decode) in 12 s
avg_kl_div=0.011680872065834083
avg_kl_div=0.017200774970889832
avg_kl_div=0.008141895825633462
avg_kl_div=0.015790318887055642
PASSED test/e2e/test_qwen38_a95b_mxfp4_server.py::TestMonokernelDecode::test_covered_steps_match_prefill
[METRIC] gsm8k_score=0.985
PASSED test/e2e/test_qwen38_a95b_mxfp4_server.py::TestMonokernelDecode::test_gsm8k_past_the_largest_width
[TP0] Qwen3.8 monokernel: 0 K1, 4 K2 and 2 layer_block launches (widths [4, 8, 16], verify) in 5 s
[METRIC] gsm8k_score=0.985
PASSED test/e2e/test_qwen38_a95b_mxfp4_server.py::TestMonokernelVerify::test_gsm8k_past_the_largest_width
[TP0] Qwen3.8 monokernel: 16 K1, 16 K2 and 2 layer_block launches (widths [1, 2, 3, 4, 5, 6, 7, 8, 16], decode) in 17 s
PASSED test/e2e/test_qwen38_a95b_mxfp4_server.py::TestMonokernelCheck::test_each_covered_layer_with_the_fused_shared_expert
[TP0] Qwen3.8 monokernel: 16 K1, 16 K2 and 0 layer_block launches (widths [1, 2, 3, 4, 5, 6, 7, 8], decode) in 20 s
PASSED test/e2e/test_qwen38_a95b_mxfp4_server.py::TestMonokernelCheck::test_each_covered_layer_within_its_numerics
[TP0] Qwen3.8 monokernel: 8 K1, 8 K2 and 0 layer_block launches (widths [1, 2, 4, 8], decode) in 0 s
PASSED test/e2e/test_qwen38_a95b_mxfp4_server.py::TestMonokernelFault::test_a_stalled_rank_stops_the_server_without_tokens
6 passed, 18 warnings in 1428.16s (0:23:48)

# 60914ed, rocm/sgl-dev:v0.5.23-rocm10-mi35x-20261117
[TP0] Qwen3.8 monokernel: 8 K1, 8 K2 and 0 layer_block launches (widths [1, 2, 4, 8], decode) in 11 s
avg_kl_div=0.013788137483139949
avg_kl_div=0.016972911991684755
avg_kl_div=0.023546236037629453
avg_kl_div=0.021233452221209096
PASSED test/e2e/test_qwen38_a95b_mxfp4_server.py::TestMonokernelDecode::test_covered_steps_match_prefill
[METRIC] gsm8k_score=0.98
PASSED test/e2e/test_qwen38_a95b_mxfp4_server.py::TestMonokernelDecode::test_gsm8k_past_the_largest_width
[TP0] Qwen3.8 monokernel: 0 K1, 4 K2 and 2 layer_block launches (widths [4, 8, 16], verify) in 5 s
[METRIC] gsm8k_score=0.98
PASSED test/e2e/test_qwen38_a95b_mxfp4_server.py::TestMonokernelVerify::test_gsm8k_past_the_largest_width
[TP0] Qwen3.8 monokernel: 16 K1, 16 K2 and 2 layer_block launches (widths [1, 2, 3, 4, 5, 6, 7, 8, 16], decode) in 18 s
PASSED test/e2e/test_qwen38_a95b_mxfp4_server.py::TestMonokernelCheck::test_each_covered_layer_with_the_fused_shared_expert
[TP0] Qwen3.8 monokernel: 16 K1, 16 K2 and 0 layer_block launches (widths [1, 2, 3, 4, 5, 6, 7, 8], decode) in 19 s
PASSED test/e2e/test_qwen38_a95b_mxfp4_server.py::TestMonokernelCheck::test_each_covered_layer_within_its_numerics
[TP0] Qwen3.8 monokernel: 8 K1, 8 K2 and 0 layer_block launches (widths [1, 2, 4, 8], decode) in 0 s
PASSED test/e2e/test_qwen38_a95b_mxfp4_server.py::TestMonokernelFault::test_a_stalled_rank_stops_the_server_without_tokens
6 passed, 2 warnings in 1374.28s (0:22:54)
```

</details>

<details><summary>Three runs at 66ae2fa: the last line of each test
step, and the e2e metrics</summary>

The image is `rocm/sgl-dev:v0.5.22-rocm10-mi35x-20261028`. The unit
tests at `66ae2fa` are 23 of the 31 above. The other 8 come from
[sgl-amd-mono#92](#92),
which the rebase put below this PR.

```text
# run 1
unit:    1 failed, 23 passed, 36 deselected, 18 warnings in 19.34s
kernels: 7 passed, 18 warnings in 359.32s (0:05:59)
avg_kl_div=0.011668544202373846
avg_kl_div=0.010390199730303768
avg_kl_div=0.009592827912570405
avg_kl_div=0.01963395264529594
[METRIC] gsm8k_score=0.98
[METRIC] gsm8k_score=0.98
e2e:     6 passed, 18 warnings in 2118.80s (0:35:18)

# run 2
unit:    1 failed, 23 passed, 36 deselected, 18 warnings in 20.03s
kernels: 7 passed, 18 warnings in 356.16s (0:05:56)
avg_kl_div=0.01461470457820975
avg_kl_div=0.005748023170007832
avg_kl_div=0.010672180794671221
avg_kl_div=0.016046920236805876
[METRIC] gsm8k_score=0.98
[METRIC] gsm8k_score=0.975
e2e:     6 passed, 18 warnings in 1284.16s (0:21:24)

# run 3
unit:    1 failed, 23 passed, 36 deselected, 18 warnings in 19.43s
kernels: 7 passed, 18 warnings in 355.51s (0:05:55)
avg_kl_div=0.010932167024714293
avg_kl_div=0.008178661398081896
avg_kl_div=0.01294148417945942
avg_kl_div=0.025383164158194402
[METRIC] gsm8k_score=0.975
[METRIC] gsm8k_score=0.965
e2e:     6 passed, 18 warnings in 1250.62s (0:20:50)
```

</details>

## Speed Tests and Profiling

The test uses `sglang.bench_serve` with random prompts of 8192 input and
1024 output tokens (range ratio 0.8). It sends 12, 16, 32, 48 and 64
prompts at concurrency 1, 2, 4, 8 and 16. Each arm starts a fresh
server, in the order base, PR, PR, base. The servers use the flags and
environment of `test/e2e/qwen38_a95b_mxfp4_server.py`, plus
`--enforce-shared-experts-fusion`, `--tool-call-parser qwen3_coder` and
`--watchdog-timeout 12000`. The NEXTN servers add
`--speculative-algorithm NEXTN` with 3 steps, top-k 1 and 4 draft
tokens.

Without MTP:

| Concurrency | Base median TPOT (ms), rounds 1 and 2 | PR median TPOT
(ms), rounds 1 and 2 | Per-user decode tok/s, base and PR | Speedup |
Spread between rounds |
| --- | --- | --- | --- | --- | --- |
| 1 | 5.18, 5.16 | 5.17, 5.17 | 193.5, 193.3 | 1.00× | 0.4% |
| 2 | 6.69, 6.67 | 6.68, 6.66 | 149.7, 150.0 | 1.00× | 0.3% |
| 4 | 8.58, 8.55 | 8.57, 8.58 | 116.8, 116.6 | 1.00× | 0.3% |
| 8 | 12.68, 12.66 | 12.66, 12.66 | 78.9, 79.0 | 1.00× | 0.2% |
| 16 | 20.94, 20.91 | 19.01, 19.01 | 47.8, 52.6 | 1.10× | 0.1% |

With NEXTN 3/1/4:

| Concurrency | Base median TPOT (ms), rounds 1 and 2 | PR median TPOT
(ms), rounds 1 and 2 | Per-user decode tok/s, base and PR | Speedup |
Spread between rounds |
| --- | --- | --- | --- | --- | --- |
| 1 | 2.63, 2.63 | 2.63, 2.63 | 379.6, 379.9 | 1.00× | 0.1% |
| 2 | 3.52, 3.49 | 3.47, 3.51 | 285.2, 286.4 | 1.00× | 1.2% |
| 4 | 5.50, 5.49 | 4.89, 4.85 | 181.9, 205.3 | 1.13× | 0.9% |
| 8 | 7.33, 7.32 | 7.34, 7.31 | 136.5, 136.5 | 1.00× | 0.4% |
| 16 | 10.48, 10.46 | 10.49, 10.46 | 95.5, 95.5 | 1.00× | 0.2% |

- The speedup uses the mean of the two rounds.
- The spread is the largest difference between the two rounds of one
arm.
- Without MTP, only concurrency 16 has steps of 9 to 16 rows. With
NEXTN, only concurrency 4 has verify steps of 16 rows. Concurrency 8 and
16 with NEXTN have 32 and 64 rows and run SGLang's forward in both arms.
- No concurrency is slower by more than the spread.
- The output throughput goes from 728.9 to 798.5 tok/s at concurrency 16
without MTP, and from 673.4 to 752.7 tok/s at concurrency 4 with NEXTN.
- These YAMLs use 4 to 12 prompts for each slot, as the runs of P1 to P5
do.
[sgl-amd-mono#107](#107)
uses 10.

**The monokernels off and on.** These are the runs of "The monokernels
off and on, on the 2026-11-17 nightly" above. They use the cells of the
tables above. Without MTP, they add concurrency 32 and 64 (128 and 256
prompts). The speedup uses the mean of the two rounds.

Without MTP:

| Concurrency | Off median TPOT (ms), rounds 1 and 2 | On median TPOT
(ms), rounds 1 and 2 | Per-user decode tok/s, off and on | Speedup |
Spread between rounds |
| --- | --- | --- | --- | --- | --- |
| 1 | 8.63, 8.56 | 5.16, 5.15 | 116.4, 194.1 | 1.67× | 0.8% |
| 2 | 9.21, 9.21 | 6.55, 6.56 | 108.6, 152.6 | 1.41× | 0.1% |
| 4 | 11.21, 11.21 | 8.52, 8.52 | 89.2, 117.4 | 1.32× | < 0.1% |
| 8 | 14.29, 14.29 | 12.66, 12.67 | 70.0, 79.0 | 1.13× | < 0.1% |
| 16 | 20.23, 20.17 | 18.78, 18.79 | 49.5, 53.2 | 1.08× | 0.3% |
| 32 | 28.08, 28.06 | 28.14, 28.14 | 35.6, 35.5 | 1.00× | < 0.1% |
| 64 | 41.35, 41.33 | 41.39, 41.42 | 24.2, 24.2 | 1.00× | 0.1% |

With NEXTN 3/1/4:

| Concurrency | Off median TPOT (ms), rounds 1 and 2 | On median TPOT
(ms), rounds 1 and 2 | Per-user decode tok/s, off and on | Speedup |
Spread between rounds |
| --- | --- | --- | --- | --- | --- |
| 1 | 2.97, 2.96 | 2.56, 2.58 | 336.9, 389.1 | 1.15× | 0.6% |
| 2 | 3.67, 3.70 | 3.47, 3.43 | 271.5, 290.2 | 1.07× | 1.2% |
| 4 | 5.24, 5.25 | 4.76, 4.76 | 190.6, 210.1 | 1.10× | 0.2% |
| 8 | 6.92, 6.97 | 6.95, 6.94 | 144.0, 143.9 | 1.00× | 0.6% |
| 16 | 9.93, 9.90 | 9.94, 9.93 | 100.8, 100.7 | 1.00× | 0.3% |

- The geomean speedup is 1.30× without MTP (concurrency 1 to 16) and
1.11× with NEXTN (concurrency 1 to 4). Over all the concurrencies of a
table, it is 1.21× and 1.06×.
- This PR adds the gain of one cell in each mode: concurrency 16 without
MTP (1.08×) and concurrency 4 with NEXTN (1.10×). The monokernels of
[sgl-amd-mono#92](#92)
give the gain of the cells of 8 rows or fewer.
- Past the largest width, both arms run SGLang's forward: concurrency 32
and 64 without MTP, and concurrency 8 and 16 with NEXTN (32 and 64
rows).
- Without MTP, the arm with the monokernels on is 0.07 ms slower there:
0.25% at concurrency 32 and 0.16% at 64. The two rounds of each arm
agree to 0.1%. The output throughput does not drop: 1080.5 and 1082.7
tok/s at 32, and 1468.3 and 1469.0 tok/s at 64. The loss bound of
`scripts/ci` is 2%.
- With NEXTN, concurrency 8 and 16 agree to 0.2%, inside the spread of
the rounds.
- These runs use the 2026-11-17 nightly, and the tables above use the
2026-10-28 nightly. So the times of the two sets differ. For example, at
concurrency 16 without MTP, the arm with the monokernels on gives 18.78
ms, and the PR above gives 19.01 ms.

**Registers.** The table comes from a compile-only build of the
`layer_block` build keys at `66ae2fa` for gfx950. Each key has a
`stop=True` build (the spec) and a `stop=False` build (the tests). The
numbers come from the AMDGPU metadata in FlyDSL's ISA dump. Where the
two builds of one row differ, a cell gives the range.

| Width | Build | VGPR | VGPR spill | SGPR spill | LDS (bytes) | Scratch
(bytes) |
| --- | --- | --- | --- | --- | --- | --- |
| 16 | `qwen38_mono_layer_s16_o0_a0` (bf16 `o_proj`) | 231 to 235 | 0 |
18 to 20 | 104880 | 0 |
| 16 | `qwen38_mono_layer_s16_o1_a0` (MXFP4 `out_proj`) | 231 to 235 | 0
| 22 to 24 | 104880 | 0 |

- No `layer_block` build spills a VGPR or uses scratch. The SGPR spills
go to VGPR lanes.
- No build uses AGPRs.
- LDS is 104,880 of gfx950's 163,840 bytes. K2 at 8 rows uses up to
145,168 bytes.
- This PR does not change the K1 and K2 kernels. The same survey gives
the numbers of
[sgl-amd-mono#92](#92)
for them.

**Kernels before and after.** The table compares the decode steps of two
TP-0 profiles at concurrency 16 without MTP: the base and this PR. Both
servers ran on one node with 8× MI355X. The prompts have 8192 tokens,
and the outputs have 100 tokens. The counts and times come from the
kernels in the step slices, on the GPU stream of the step. The first 10
steps are warmup. Each time is the mean of the 89 steps after them.

| Part of the layer tail | Before: SGLang kernel | Calls per step | Time
per call (µs) | After |
| --- | --- | --- | --- | --- |
| The MXFP4 quantization of the `out_proj` input (GDN layers) |
`aiter::dynamic_per_group_scaled_quant_kernel<bf16, fp4>` | 69 | 4.6 |
One `layer_block` launch for each GDN layer:
`qwen38_mono_layer_s16_o1_a0` (69 calls per step, 112.7 µs each) |
| `out_proj` (MXFP4, GDN layers) | `_gemm_afp4wfp4_preshuffle_kernel`
(`BLOCK_SIZE_M_8`, `BLOCK_SIZE_N_64`) | 69 | 4.3 | In `layer_block` |
| `o_proj` (bf16, attention layers) | `_gemm_a16_w16_kernel`
(`BLOCK_SIZE_M_16`) | 23 | 7.6 | One `layer_block` launch for each
attention layer: `qwen38_mono_layer_s16_o0_a0` (23 calls per step, 115.7
µs each) |
| The all-reduce after `out_proj` or `o_proj`, and the MoE all-reduce |
`aiter::cross_device_reduce_2stage<bf16, 8>` | 184 | 9.5 | In
`layer_block` |
| The post-attention norm | `_gemma_fused_add_rmsnorm_kernel` | 92 | 4.2
| In `layer_block` |
| The router GEMM | `hgemm_bf16_t16x16x256x4_kst4` | 92 | 8.7 | In
`layer_block` |
| The top-k | `vllm::moe::topkGatingSoftmax` | 92 | 10.1 | In
`layer_block` |
| The shared expert append |
`_fused_append_shared_experts_with_weights_kernel` | 92 | 4.3 | In
`layer_block` |
| The experts, with the fused shared expert |
`aiter::fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x256` | 92 | 83.4
| In `layer_block` |
| The step epoch of the `layer_block` waits | None | | | One more
`CUDAFunctorOnSelf_add<int>` per step |

- The SGLang tail of a GDN layer takes 139.0 µs. `layer_block` takes
112.7 µs.
- The SGLang tail of an attention layer takes 135.7 µs. `layer_block`
takes 115.7 µs.
- The flat MoE alone takes 83.4 µs of each SGLang tail.
- Each decode step slice falls from 1671 to 959 kernels. Its mean kernel
time falls from 17.91 to 15.56 ms.
- Each verify step slice of NEXTN at concurrency 4 falls from 1688 to
976 kernels. Its mean kernel time falls from 17.80 to 14.96 ms (16
steps). There, `layer_block` takes 104.3 µs (GDN layers) and 105.1 µs
(attention layers). The NEXTN draft model stays on SGLang's forward.

The two figures show one decode step of 16 rows without MTP in the TP-0
trace, with the filter `Category = kernel`. The base step has 1671
kernels and 17.91 ms of kernel time. The step of this PR has 959
kernels, 15.67 ms and 92 `layer_block` launches. A selection that also
covers the second GPU stream shows 8 more kernels, which prepare the
next step.

Base:

<img width="2050" height="1274" alt="image"
src="https://github.com/user-attachments/assets/8ed1e0f4-9e2a-4d44-8387-644a6b97ec3f"
/>

This PR:

<img width="2050" height="1274" alt="image"
src="https://github.com/user-attachments/assets/de3cd70e-dea2-45e7-8481-55ebcdcec2dd"
/>

## Checklist

- [x] `pre-commit run --all-files` passes.
- [x] Tests under `test/` cover the change.
- [x] The SGLang commit or PR this was tested against is named above.
- [x] Accuracy and speed results are attached when kernel or forward
code changes.
- [x] A new model adds one line to `.github/CODEOWNERS` that names its
owner. (No new model.)

## Review and Merge Process

1. The `lint` and `Check PR title` checks must pass.
2. Ask a code owner from `.github/CODEOWNERS` to review.
3. Merge with "Squash and merge": the PR title becomes the commit title
on `main`.

---------

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Dec 1, 2026
…nt_x by Hadamard-32

sgl-project/sglang#46059 rotates the weights of the
MXFP4 GDN projections by Hadamard-32. The activation must get the same
rotation before its MXFP4 quant.

- Add hadamard32_quad to mono/ops.py. It rotates a 1 x 32 block that lies on
  4 adjacent lanes. It adds in the order of hadamard32_rotate of
  ROCm/aiter#6734, so the bf16 values are the same
  bit for bit.
- Add the h32 flag to quant_x and _quad_scale in layer.py and in
  mono/stages/moe.py. The flag is off by default, so the plain builds do not
  change.
- Add check_quant.py and TestQwen38MoeQuant. The check compares the rotation
  and the LDS rows of quant_x with per_1x32_f4_quant_hip, plain and rotated,
  bit for bit. The rotation inputs have an exponent for each element, so the
  f32 sums round and a changed add order shows.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Dec 1, 2026
…K2 and layer_block

Add the build flags for the rotated MXFP4 GDN projections of
sgl-project/sglang#46059:

- K1Build.qh rotates the activation of in_proj_qkvz.
- K2Build.oh and LayerBuild.oh rotate the activation of out_proj.

A flag needs the MXFP4 flag of its projection (qq or oq). The build refuses
it without that flag. A kernel name gets "_h1" only when the flag is on, so
the names of the plain builds do not change. in_proj_ba still reads the x
rows before quant_x, so it reads them without the rotation.

The spec does not select these builds yet. check_k1.py and check_k2.py
compile the new keys, and check_layer_block compares the rotated
layer_block with the rotated K2 halves.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Dec 1, 2026
sgl-project/sglang#46059 rotates the weights of the
MXFP4 GDN projections by Hadamard-32 by default. The spec refused that
state. Now it runs it with the qh and oh builds.

- _rotated reads the state of AiterMxfp4OnlineLinearMethod: no flags,
  hadamard off, or hadamard on with hadamard_rotate. Each other class or
  state gives a refusal, so a renamed or a new flag does not run silently.
- _format gives (MXFP4, rotated) for each projection. The K1, K2 and
  layer_block keys get the rotation, so each layer runs its own format.
- SGLANG_READS pins the class name AiterMxfp4OnlineLinearMethod.
- The e2e tests do not set SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD now, so
  they run the default of SGLang.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Dec 1, 2026
…n the README

- Section 2 tells how the qh and oh builds rotate the activation of the
  MXFP4 GDN projections of sgl-project/sglang#46059,
  in the order of ROCm/aiter#6734.
- Section 5 refuses only an unknown quant method or state now. _build makes
  a launch for each format of the projections.
- Section 6 adds the quant check, and the e2e tests run the default
  rotation of SGLang.

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

A rocm720 image built before docker/rocm.Dockerfile set
SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0 does not have the flag. Its AITER
has no hadamard_rotate (ROCm/aiter#6734), so the
online MXFP4 GDN tests fail there with a TypeError.
amd_ci_start_container.sh now sets the flag for --rocm-version rocm720.
Remove it with the pin bump of the rocm720 stage.

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

omirosh commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@sglang-bot Done in e68d594. scripts/ci/amd/amd_ci_start_container.sh now passes -e SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0 when it starts a container with --rocm-version rocm720. So a rocm720 image built before the Dockerfile line also gets the flag. The rocm10 and rocm724 containers keep the rotation on. The line goes away with the rocm720 AITER pin bump, as the Dockerfile line does.

@rkarhila-amd

Copy link
Copy Markdown

@omirosh ok, got it. Bit of a hack but cleanest way forward to get the functionality into 724 and 1000 images I guess.

@sglang-bot

Copy link
Copy Markdown
Member

[sglang-bot Review Agent] @omirosh That covers older rocm720 images too. In e68d594bfd, the CI launcher passes SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0 to docker run whenever --rocm-version rocm720 is selected.

@sglang-bot sglang-bot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[sglang-bot Review Agent] LGTM. Let's wait for CI.

Reviewed with gpt-6.2-astra · high.

@omirosh

omirosh commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@HaiShaw @bingxche could one of you comment /tag-and-rerun-ci here? The sglang-bot review is done (approved). The PR has no CI run yet. The last commits are the Dockerfile env for the rocm720 images and the same env in amd_ci_start_container.sh.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants