Skip to content

[Perf] [AMD] quark/Qwen3.8: Quantize the BF16 shared expert of Quark MXFP4 checkpoints to MXFP4 while loading for shared-expert fusion - #41899

Merged
HaiShaw merged 6 commits into
sgl-project:mainfrom
amd-oshkarav:fse-online-mxfp4
Oct 26, 2026

Conversation

@amd-oshkarav

@amd-oshkarav amd-oshkarav commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

This is a ROCm performance change. With --enforce-shared-experts-fusion the
BF16 shared expert of a Quark MXFP4 checkpoint is quantized to MXFP4 at load and fused into
the routed grouped GEMM (general matrix multiply), instead of running as a separate BF16
MLP (multi-layer perceptron). On amd/Qwen3.8-2.4T-A95B-Quark-MXFP4 over 8x MI355X at TP8
that is worth +4.5% output throughput and -4.6% mean ITL (inter-token latency), as a
geomean across a 12-point serving sweep.

There is currently no Qwen3.8-2.4T-A95B checkpoint in which the shared expert is FP4
quantized, so shared-expert fusion is unavailable for this model family on MXFP4.

amd/Qwen3.8-2.4T-A95B-Quark-MXFP4 quantizes the routed experts to MXFP4 but lists the
shared-expert body in the Quark quantization config's exclude list, so
gate_proj/up_proj/down_proj of the shared expert ship in BF16. Shared-expert fusion
works by appending the shared expert as one more routed expert at slot num_experts, so
that a single grouped GEMM serves top-k routed experts plus the shared one. That requires
every slot in the fused weight to have the same dtype, so today
QuarkConfig.can_fuse_shared_expert() sees the format mismatch and refuses, and the model
falls back to running the shared expert as a separate BF16 MLP alongside the routed grouped
GEMM. Rather than wait for a new checkpoint, this PR quantizes the BF16 shared expert at
load time so the existing checkpoint can use the fused path.

The feature is off by default and gated behind the existing
--enforce-shared-experts-fusion server argument, which already means "fuse the shared
expert even where the gate would normally refuse". In the fused path the shared expert goes
through the routed experts' W4A4 grouped GEMM, so its weights and its input activations
are quantized to MXFP4, where the standalone path it replaces ran BF16 x BF16. That is a
real precision trade and should be an explicit choice rather than something a checkpoint
opts into silently.

Reproduction

Run inside lmsysorg/sglang:v0.5.21-rocm10-mi35x with this branch reinstalled in full over
the stock SGLang:

SGLANG_USE_AITER=1 \
AITER_USE_FLYDSL_MOE_SORTING=1 \
ROCM_QUICK_REDUCE_QUANTIZATION=INT4 \
SAFETENSORS_FAST_GPU=1 \
SGLANG_WARMUP_TIMEOUT=10000 \
python3 -m sglang.launch_server \
 --model-path amd/Qwen3.8-2.4T-A95B-Quark-MXFP4 \
 --tp-size 8 \
 --trust-remote-code \
 --reasoning-parser qwen3 \
 --tool-call-parser qwen3_coder \
 --attention-backend aiter \
 --kv-cache-dtype fp8_e4m3 \
 --mamba-ssm-dtype bfloat16 \
 --page-size 64 \
 --chunked-prefill-size 16384 \
 --max-prefill-tokens 16384 \
 --max-running-requests 256 \
 --disable-radix-cache \
 --mem-fraction-static 0.9 \
 --model-loader-extra-config '{"enable_multithread_load": true}' \
 --watchdog-timeout 12000 \
 --enforce-shared-experts-fusion

Dropping --enforce-shared-experts-fusion gives the baseline: the shared expert stays BF16
and runs unfused.

Modifications

Nine files, and nothing else in the tree differs from upstream: four under
python/sglang/srt, two documentation pages, three test files. No new flag is added, so
environ.py and the environment-variable reference are untouched.

File Delta Role
python/sglang/srt/arg_groups/fields/exec_.py +1 -1 extends the --enforce-shared-experts-fusion help text
python/sglang/srt/layers/quantization/quark/quark.py +211 -7 decides whether the conversion applies
python/sglang/srt/layers/quantization/quark/schemes/quark_w4a4_mxfp4_moe.py +52 performs the MXFP4 quantization, ROCm only
python/sglang/srt/layers/moe/fused_moe_triton/layer.py +81 the weight-loader hook that calls it
docs/docs/advanced_features/server_arguments.mdx +1 -1 documents what the flag additionally does here
docs/cookbook/autoregressive/Qwen/Qwen3.5.mdx +1 -1 mentions it in the Qwen3.5 AMD recipe
test/registered/unit/layers/quantization/test_quark_config.py +546 -3 the gating decision
test/registered/unit/layers/quantization/test_quark_shared_expert_online_mxfp4_loader.py +474 the loader hook (new file)
test/registered/amd/accuracy/mi35x/test_qwen38_mxfp4_eval_mi35x.py +103 -6 the MI35x nightly gate, extended with a fused-shared-expert phase, skiped for now

The decision of whether to convert lives with the quantization
config, the ROCm-only kernel call lives with the MXFP4 scheme, and the copy into the fused
slot lives with FusedMoE alongside the FP8 hook that already solves the same problem.

The change depends on #40754
(e2f4fed, merged 2026-09-24), which is in main. That PR gave the text-only
Qwen3_5MoeForCausalLM the shared-expert fusion weight remapping its multimodal sibling
already had, mlp.shared_expert.* -> mlp.experts.{num_experts}.*. Without it those weights
were silently dropped and the fused slot left uninitialized. The remap is what makes the
shared-expert tensors arrive at the fused slot at all, and the loader hook added here
intercepts them at that slot and converts them on the way in. #40754 covered checkpoints
whose shared expert already matches the routed-expert dtype (FP8), so no conversion was
needed; this PR extends the same path to the Quark MXFP4 checkpoint, where the shared expert
is BF16 and the conversion is the missing piece.

Accuracy Tests

gsm8k under the nightly e2e test's own parameters, greedy

This is the headline accuracy result. It is the only pair measured with the parameter set
test/registered/amd/accuracy/mi35x/test_qwen38_mxfp4_eval_mi35x.py uses, and with sampling
switched off, so it is the pair that answers "does this change what CI will report".

fusion ON fusion OFF Δ (on − off)
gsm8k score 0.9764 0.9726 +0.38 pp
correct, of 1314 1283 1278 +5 questions
eval wall time 215.6 s 227.2 s −5.1 %
eval output throughput 841.4 tok/s 806.1 tok/s +4.4 %

Both arms are one image, one node, one day. Built from fse-online-mxfp4 at 747482984,
this PR's HEAD as submitted, on lmsysorg/sglang:v0.5.21-rocm10-mi35x, run back to back on the
same MI355X host, and every
logged server parameter is identical except --enforce-shared-experts-fusion.

GPQA, NIAH

The branch at abddcd87 was re-measured end to end on 2026-10-11, and two further evals ran inside each of those two serving sweeps, against the same server instance that produced the speed numbers below:

Eval fusion ON fusion OFF
GPQA via sglang run_eval, temperature 1.0, top-p 0.95, thinking enabled 0.9242 0.9192
RULER niah_single_2 at 65536 via lm_eval 1.0 1.0
RULER niah_single_2 at 131072 via lm_eval 1.0 1.0

Benchmarking

Measured with sglang.bench_serve through a 12-point sweep, twice, changing only
--enforce-shared-experts-fusion.

Model amd/Qwen3.8-2.4T-A95B-Quark-MXFP4
Hardware 8x MI355X (gfx950), single node, TP8
Base image lmsysorg/sglang:v0.5.21-rocm10-mi35x
Branch commit abddcd8701376e29ad460b80a68c1589a9835174, rebased onto main at 11bfd868
aiter the base image's, ROCm/aiter acf8fdf93 of 2026-09-12
Server --attention-backend aiter --kv-cache-dtype fp8_e4m3 --mamba-ssm-dtype bfloat16 --page-size 64 --chunked-prefill-size 16384 --max-prefill-tokens 16384 --max-running-requests 256 --mem-fraction-static 0.9 --disable-radix-cache
Env SGLANG_USE_AITER=1, AITER_USE_FLYDSL_MOE_SORTING=1, ROCM_QUICK_REDUCE_QUANTIZATION=INT4, SAFETENSORS_FAST_GPU=1
Sweep ISL 8192 / OSL 1024 at concurrency 4 to 256; ISL 60000 / OSL 600 at 4/16/64; ISL 128000 / OSL 1024 at 4/16. random_range_ratio 0.8 and an unbounded request rate throughout
Baseline fusion OFF: no --enforce-shared-experts-fusion, shared expert stays BF16 and unfused
Candidate fusion ON: --enforce-shared-experts-fusion, shared expert quantized to MXFP4 at load and fused

Every one of the 12 points improved on throughput, ITL, TPOT (time per output token), end-to-end
latency and median TTFT (time to first token). Across all logged server parameters the two sweeps
differ only in --enforce-shared-experts-fusion, verified programmatically.

Geomean per metric over the 12-point sweep

Metric Unit fusion OFF fusion ON Δ Direction Improved at
Output throughput tok/s 409.8 428.3 +4.51% better 12 of 12
Request throughput req/s 0.5089 0.5319 +4.51% better 12 of 12
Mean ITL ms 46.2 44.1 −4.57% better 12 of 12
P99 ITL ms 326.4 316.2 −3.11% better 12 of 12
Mean TPOT ms 46.0 43.9 −4.57% better 12 of 12
Mean E2E latency ms 41,200.4 39,452.6 −4.24% better 12 of 12
Median TTFT ms 1,219.3 1,200.7 −1.53% better 12 of 12
Mean TTFT ms 3,337.3 3,313.6 −0.71% better 11 of 12
P99 TTFT ms 16,122.0 16,074.3 −0.30% better 10 of 12

No metric regresses on geomean.

Output throughput (tok/s) per sweep point, better at 12 of 12

ISL OSL Concurrency fusion OFF fusion ON Δ
8192 1024 4 280.5 309.6 +10.38%
8192 1024 8 421.4 458.4 +8.79%
8192 1024 16 631.7 664.8 +5.25%
8192 1024 32 906.8 964.7 +6.38%
8192 1024 64 1,258.4 1,315.5 +4.53%
8192 1024 128 1,579.0 1,628.8 +3.16%
8192 1024 256 1,897.0 1,949.1 +2.75%
60000 600 4 133.9 140.4 +4.90%
60000 600 16 184.7 188.0 +1.79%
60000 600 64 215.6 218.0 +1.13%
128000 1024 4 112.6 117.2 +4.04%
128000 1024 16 146.4 148.6 +1.50%
geomean 409.8 428.3 +4.51%

TTFT and mean ITL per sweep point

ISL OSL Concurrency Median TTFT off Median TTFT on Δ median TTFT Δ P99 TTFT Δ mean ITL
8192 1024 4 335.6 329.2 −1.89% +1.71% −9.67%
8192 1024 8 345.4 335.5 −2.88% −0.72% −8.26%
8192 1024 16 353.7 346.0 −2.19% −0.66% −5.01%
8192 1024 32 461.3 447.3 −3.03% −0.65% −6.12%
8192 1024 64 611.1 596.8 −2.35% −0.63% −4.47%
8192 1024 128 796.7 784.9 −1.48% −0.55% −3.19%
8192 1024 256 1,201.8 1,187.8 −1.17% −0.73% −2.65%
60000 600 4 2,372.9 2,343.2 −1.25% −0.34% −5.53%
60000 600 16 2,859.7 2,841.5 −0.64% −0.54% −2.27%
60000 600 64 4,890.1 4,866.4 −0.48% −0.57% −1.05%
128000 1024 4 5,207.0 5,189.0 −0.35% −0.28% −4.62%
128000 1024 16 5,646.7 5,616.3 −0.54% +0.42% −1.58%

Checklist

  • Format your code according to the Format code with pre-commit.
  • Add unit tests according to the Run and add unit tests.
  • Update documentation according to Write documentations.
  • Provide accuracy and speed benchmark results according to Test the accuracy and Benchmark the speed.
  • Follow the SGLang code style guidance.

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
  1. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base)::x: Run #38552091400
Latest PR Test (Extra)::x: Run #38552091567
Latest PR Test (AMD ROCm 10)::x: Run #38552091315


CI States

Latest PR Test (Base): ✅ Run #40173610615
Latest PR Test (Extra): ❌ Run #40173610536
Latest PR Test (AMD ROCm 10): ❌ Run #40173610552

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Sep 30, 2026
@amd-oshkarav amd-oshkarav changed the title Fse online mxfp4 [ROCm][Perf] Quantize the BF16 shared expert of Quark MXFP4 checkpoints to MXFP4 while loading for shared-expert fusion Sep 30, 2026
@amd-oshkarav amd-oshkarav changed the title [ROCm][Perf] Quantize the BF16 shared expert of Quark MXFP4 checkpoints to MXFP4 while loading for shared-expert fusion [AMD][Perf] Quantize the BF16 shared expert of Quark MXFP4 checkpoints to MXFP4 while loading for shared-expert fusion Oct 1, 2026
Comment thread python/sglang/srt/environ.py Outdated
@@ -882,6 +882,7 @@ class Envs:
# stays accuracy-gated and default OFF.
SGLANG_ENABLE_DP_GATHER_FP8 = EnvBool(False)
SGLANG_USE_AITER_UNIFIED_ATTN = EnvBool(False)
SGLANG_FUSE_SHARED_EXPERTS_ONLINE_MXFP4 = EnvBool(False)

@ColinZ22 ColinZ22 Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A --enforce-shared-experts-fusion CLI arg already exists from the upstreamed DeepSeek-V4 online shared-expert requant feature (FP8 -> MXFP4) from PR #27349, and the CLI arg's description is already "Enforce shared experts fusion even when it would normally be disabled", so maybe consider following the existing convention and have the Qwen3.5 gate also honor and use that CLI arg instead of adding this new env var.

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.

@ColinZ22 thank you. will implement in the next round. Have been busy with accuracy.

@ColinZ22

ColinZ22 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

As mentioned in the PR description:

Limits of this evidence. At N=198 the GPQA stderr is ~1.8 points, so the pairing only
resolves a regression of roughly 5 points or more, and RULER at 0.996/1.000 is saturated.
Together they rule out a large quality loss, not a small one, which is a weak bar for a
change that rounds both the weights and the activations of one MLP per layer. A greedy
GSM8K run (1319 questions) with the flag off and on, or the top-1 agreement and mean KL of
next-token logprobs over a fixed prompt set, would measure a small shift where these evals
cannot. Both runs were also at TP8, and w2 (down_proj) is the projection whose K
dimension TP splits, so other TP sizes exercise shard boundaries these numbers do not
cover.

Unless averaged across many runs, simply using GPQA cannot reliably detect some subtle accuracy degredations. Please add a paired greedy GSM8K results comparing before and after PR changes, and it'd be nice to have test points at different TP sizes as well.

@amd-oshkarav

Copy link
Copy Markdown
Contributor Author

As mentioned in the PR description:

Limits of this evidence. At N=198 the GPQA stderr is ~1.8 points, so the pairing only
resolves a regression of roughly 5 points or more, and RULER at 0.996/1.000 is saturated.
Together they rule out a large quality loss, not a small one, which is a weak bar for a
change that rounds both the weights and the activations of one MLP per layer. A greedy
GSM8K run (1319 questions) with the flag off and on, or the top-1 agreement and mean KL of
next-token logprobs over a fixed prompt set, would measure a small shift where these evals
cannot. Both runs were also at TP8, and w2 (down_proj) is the projection whose K
dimension TP splits, so other TP sizes exercise shard boundaries these numbers do not
cover.

Unless averaged across many runs, simply using GPQA cannot reliably detect some subtle accuracy degredations. Please add a paired greedy GSM8K results comparing before and after PR changes, and it'd be nice to have test points at different TP sizes as well.

@ColinZ22. Indeed i will add old good gsm8k. Im now running more GPQA runs, and again in another run FSE bits not-FSE. Niag was ok anyway. B

there will be only TP8 though because it is a big model, i have tried TP4 -- no space, crash.

@amd-oshkarav

Copy link
Copy Markdown
Contributor Author

As mentioned in the PR description:

Limits of this evidence. At N=198 the GPQA stderr is ~1.8 points, so the pairing only
resolves a regression of roughly 5 points or more, and RULER at 0.996/1.000 is saturated.
Together they rule out a large quality loss, not a small one, which is a weak bar for a
change that rounds both the weights and the activations of one MLP per layer. A greedy
GSM8K run (1319 questions) with the flag off and on, or the top-1 agreement and mean KL of
next-token logprobs over a fixed prompt set, would measure a small shift where these evals
cannot. Both runs were also at TP8, and w2 (down_proj) is the projection whose K
dimension TP splits, so other TP sizes exercise shard boundaries these numbers do not
cover.

Unless averaged across many runs, simply using GPQA cannot reliably detect some subtle accuracy degredations. Please add a paired greedy GSM8K results comparing before and after PR changes, and it'd be nice to have test points at different TP sizes as well.

@ColinZ22

Here is the situation: the loss of accuracy on strict match when running:

python3 -m sglang.launch_server \
    --model amd/Qwen3.8-2.4T-A95B-Quark-MXFP4 \
    --host 0.0.0.0 \
    --port 5060 \
    --tp-size 8 \
    --trust-remote-code \
    --reasoning-parser qwen3 \
    --tool-call-parser qwen3_coder \
    --attention-backend aiter \
    --kv-cache-dtype fp8_e4m3 \
    --mamba-ssm-dtype bfloat16 \
    --enforce-shared-experts-fusion \
    --page-size 64 \
    --chunked-prefill-size 16384 \
    --max-prefill-tokens 16384 \
    --max-running-requests 256 \
    --disable-radix-cache \
    --mem-fraction-static 0.9 \
    --model-loader-extra-config '{"enable_multithread_load": true}' \
    --watchdog-timeout 12000 \
    --log-requests \
    --log-requests-level 3

with e.g.

lm_eval \
  --model local-chat-completions \
  --model_args model=amd/Qwen3.8-2.4T-A95B-Quark-MXFP4,base_url=http://localhost:5060/v1/chat/completions,num_concurrent=32,tokenized_requests=False,timeout=7200,max_retries=1 \
  --tasks gsm8k \
  --num_fewshot 5 \
  --apply_chat_template \
  --batch_size 64 \
  --gen_kwargs ''"'"'{"temperature":1.0,"max_gen_toks":32768}'"'"'' \
  --seed 1234
Screenshot 2026-10-06 215528

I will need to check if the following PR [Fall back to Triton quant kernels when Gluon lacks scaled_downcast- #10
] (amd-sriram/aiter#10) helps, but I think it fixes the error which is not on stock image of 5.21. The sglang.run_eval accuracy with this PR looks just fine. But I will need to repeat the llm_eval set up on this PR (will be overnight for me) to get clear picture on what is going on.

@amd-oshkarav

amd-oshkarav commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author

@ColinZ22
There are new accuracy results, slightly improved by removing the "Question" word from the stop-list of the lm_eval command, which by default was there.

gen_kwargs: '''{"temperature":1.0,"max_gen_toks":32768,"until":["</s>","<|im_end|>"]}'''

The model stops generating output once one of the stop-words occurs, and the word "Question" occurs in thinking sequence often and it was one of the reasons of poor results I shared yesterday. Also, run_eval does not pass such list, and the flexible-match results are now on the same level as run_eval.
No aiter PRs was used when obtaining the results below and the accuracy tests with the PR amd-sriram/aiter#10 did not provide improvements.

strict-match — requires a literal #### N

conc fusion ON fusion OFF delta (on − ff) P
4 0.8052 0.8620 -5.68 pp 8.6e-05
32 0.8400 0.8658 -2.58 pp 0.061
64 0.8256 0.8620 -3.64 pp 0.010
pooled 0.8236 0.8633 -3.97 pp 1.2e-06

flexible-extract — last number anywhere in the reply

conc fusion ON fusion OFF delta (on − off) P
4 0.9750 0.9719 +0.31 pp 0.62
32 0.9750 0.9780 -0.30 pp 0.61
64 0.9727 0.9757 -0.30 pp 0.63
pooled 0.9742 0.9752 -0.10 pp 0.78

P is a two-sided two-proportion z-test using lm_eval's own stderrs. The pooled row combines the
three concurrencies, 3957 questions per arm.

The lost of accuracy on strict-match is obvious but flexible-extract is just fine. What shall we do?
I see two options: I can publish the PR and we consider strict-match accuracy issue as a separate task for me. For some use cases good results equivalent to run_eval are just fine, and for the others we recommend not to use --enforce-shared-experts-fusion until we fix it.
Alternatively, if you think that the strict-accuracy should be fixed within this PR I will continue to dig and keep this PR as draft until we find solution.

omirosh added a commit to omirosh/sglang that referenced this pull request Oct 14, 2026
sgl-project#41899 now gates the online MXFP4 shared expert on
--enforce-shared-experts-fusion, not on an env var, and checks each MoE
layer. Rebuild the three runtime files from the image base 1203eb9 plus
the net sgl-project#41899 diff, and take its loader test. Drop the old env var.

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

amd-oshkarav commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

@mintlify

mintlify Bot commented Oct 21, 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 2fc4490.

Approve preview

@amd-oshkarav
amd-oshkarav force-pushed the fse-online-mxfp4 branch 8 times, most recently from a68c99f to 93c2eb6 Compare October 24, 2026 18:18
@HaiShaw
HaiShaw merged commit 0cd2a63 into sgl-project:main Oct 26, 2026
188 of 201 checks passed
yichiche pushed a commit to sgl-project/sgl-amd-mono that referenced this pull request Nov 16, 2026
…-project/sglang#41899 (#90)

Part 4 of 5 of the split of
[sgl-amd-mono#16](#16).
[sgl-amd-mono#83](#83),
[sgl-amd-mono#88](#88)
and
[sgl-amd-mono#89](#89)
have merged. The diff has only the code commit `975ef81` and the README
commit `5daa3b7` of this PR.

## Motivation

With `--enforce-shared-experts-fusion`, sgl-project/sglang#41899
quantizes the bf16 shared expert of the Quark MXFP4 checkpoint to MXFP4
while it loads. It adds the shared expert as routed expert 512. Each
token then picks expert 512 as its 11th expert, with the weight
sigmoid(x · w_sg). SGLang runs the shared expert in the same MoE kernel
as the routed experts.

The earlier PRs of this split refuse this flag at startup. This PR adds
the `fse` variant of K2 from sgl-project/sglang#43516, so the spec
serves the fused layout too.

## Modifications

| Area | Change |
| --- | --- |
| `qwen38_a95b_mxfp4/gfx950/layer.py` | Adds the `fse` build flag. With
`fse`, expert 512 of w13 and w2 is the shared expert. Each token picks
it at top-k index 10, with the weight sigmoid(bf16(x · w_sg)) in f32. K2
then runs no separate shared-expert stage. The router, the route and the
expert stages have `fse` branches. With 4 rows or more, the shared
expert's gate and up tasks run before the route, because they do not
depend on it. |
| `qwen38_a95b_mxfp4/spec.py` | Builds K2 for each width and each
shared-expert layout that the model has. Accepts a layer with a bf16
shared expert, or a fused one with 513 routed experts. Drops the FSE
refusal and its read of `enforce_shared_experts_fusion`. |
| `qwen38_a95b_mxfp4/check.py` | Check mode compares K2's top-k with
SGLang's top-k without SGLang's shared slot. |
| `test/kernels/qwen38_a95b_mxfp4/check_k2.py`, `check_port.py`,
`inputs.py` | The compile check also builds the `fse` keys. The port
test also compares `fse` at 1, 4 and 8 rows with
sgl-project/sglang#43516, bit for bit. |
| `test/e2e/test_qwen38_a95b_mxfp4_server.py` | Adds a second check-mode
test with `--enforce-shared-experts-fusion`. It also checks that SGLang
logs the shared-expert quantization, because SGLang only warns when it
cannot fuse. |
| `test/unit/test_qwen38_a95b_mxfp4_spec.py` | Checks that FSE gives no
refusal, and the rule for the shared-expert layout. |
| `README.md` | The requirements name sgl-project/sglang#41899. |
| `sgl_amd_mono/qwen38_a95b_mxfp4/README.md` | The README commit adds
the fused shared expert to the folder README and removes it from the
limitations. |

**Refusals.** This PR removes the FSE refusal. It adds one refusal: a
layer that has no shared expert and no fused expert 512. The
routed-expert shape check takes 513 experts when SGLang fuses the shared
expert.

With FSE, all the K2 kernels of a server are `fse` builds. The
check-mode test with FSE has no CUDA graphs, and each rank logs "Qwen3.8
monokernel: 16 K1 and 8 K2 launches (widths [1, 2, 3, 4, 5, 6, 7, 8],
decode)". The FSE speed servers use CUDA graphs, and each rank logs
"Qwen3.8 monokernel: 8 K1 and 4 K2 launches (widths [1, 2, 4, 8],
decode)".

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

## Accuracy Tests

All the results below use this setup:

| 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
sgl-project/sglang#41899 and sgl-project/sglang#43839, with no unmerged
SGLang PR |
| AITER, FlyDSL | `285579b6211b0da30f35b91a890c29c823597cd1`, 0.4.0 |
| Model revision | `13dc9676cdd9e2374c3efb50389d3392b975acae` |
| Server flags | `ARGS` of `test/e2e/qwen38_a95b_mxfp4_server.py`, plus
`--enforce-shared-experts-fusion` where a test or arm says FSE. The
monokernel-on servers add `--monokernel-backend amd`. |
| Branch commit | `368eecf` (tag `q38v3-tested/4-fse`). The code commit
`975ef81` is rebased onto `main` at `59fc441`, after
[sgl-amd-mono#89](#89)
merged. Its model code and tests are the same as at `fc098d3`, the code
commit before the rebases. They differ from the tested commit only in
the text of a docstring and a skip message. The test runs used the old
base `0aa9749`, before
[sgl-amd-mono#76](#76)
changed `PeerBuffer.close()`. |

The port test (`check_port.py`) compares K1 and K2 with the original
kernels of sgl-project/sglang#43516 at `51b0c592b2`. That PR is not
merged, so the test run mounts its two kernel folders (`k3_mono_flydsl`
and `qwen3_5_mono_flydsl`) read-only into SGLang's tree in the
container. No SGLang code imports them. Only the port test does.

### GSM8K with FSE, monokernels on and off

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. Both arms use `--enforce-shared-experts-fusion`.
The test sends 8 concurrent requests, so the decode steps take the K1
and K2 path. Each arm starts a fresh server. Each question has the same
`prompt_hash` in both arms.

| Filter | Monokernels off | Monokernels on | Right only off | Right
only on | McNemar's p (exact) |
| --- | --- | --- | --- | --- | --- |
| flexible-extract | 1288 (0.9765) | 1285 (0.9742) | 10 | 7 | 0.629 |
| strict-match | 1062 (0.8052) | 1077 (0.8165) | 121 | 136 | 0.383 |

The arms differ by 3 questions on flexible-extract and by 15 on
strict-match. McNemar's test finds no accuracy difference on either
filter.

Strict-match needs a `#### N` line. Of the answers that flexible-extract
finds right, 226 have no `#### N` line in the off arm, and 208 in the on
arm. Strict-match fails exactly these answers. Most of them end in
`**Answer: N**` instead (150 and 143). So the strict-match gap is in the
answer format, not in the answers.

Both arms have a lower strict-match than the arms of #89 without FSE
(0.8719 off and 0.8643 on). In #89, only 140 and 155 right answers have
no `#### N` line. The off arm here runs no monokernel, so FSE itself
causes this change. SGLang logs that FSE quantizes the BF16 shared
expert and its input to MXFP4, and that this "may degrade prediction
quality". Flexible-extract is 0.9765 off and 0.9742 on here, and 0.9780
and 0.9818 in #89.

### GPQA Diamond and SWE-bench Pro with FSE, monokernels on and off

These runs use the code commit `fc098d3` in one image, with the flags of
the GSM8K and speed servers plus `--default-chat-template-kwargs
'{"reasoning_effort": "xhigh"}'`. Claude Code sends the effort `high`,
which the chat template refuses. With this flag, the template renders
its default effort, xhigh, for every request. Both arms use
`--enforce-shared-experts-fusion`. 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 8 concurrent requests.

| | Monokernels off | Monokernels on | Model card |
| --- | --- | --- | --- |
| avg@4, with the 95% interval over the questions | 92.55 ± 3.21 | 92.80
± 3.08 | 92.6 |

Over the 198 paired questions, on minus off is +0.25 points, with a 95%
interval of ±1.05. Eight questions score higher with the monokernels on,
and seven with them off. The sign test gives p 1.000 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. With the monokernels
off, 3 of the 792 samples stop at the 131072-token cap, and 2 do with
them on.

#### SWE-bench Pro

The test runs 50 tasks of [SWE-bench Pro
V2](https://github.com/scaleapi/SWE-bench_Pro-os/tree/66f92766bba642462d4bbe5479e83f91f9211862/v2),
Scale's validated set of 642 tasks. The 50 tasks come from 11 repos.
`random.Random(20261105).sample(sorted(ids), 50)` picks them from the
642 task names in `v2/tasks`. Harbor 0.23.0 runs Claude Code with the
`locked_claude_code` agent of V2, 8 tasks at a time. Each task gets 50
minutes, network access only to the model server, and no WebFetch or
WebSearch. Each turn can have 32768 output tokens and 31999 thinking
tokens. The server samples with the defaults of the checkpoint
(temperature 1.0, top-p 0.95, top-k 20). In the server log of the on
arm, 110 of the 13,522 decode log lines show 9 running requests, all in
the first 4 minutes of the run. The monokernels take 1 to 8 rows, so
those steps run without them. All other decode batches have 1 to 8
running requests, so the decode steps take the K1 and K2 path. After the
run, `patch_replay` grades each patch again on a fresh task image, and
the table gives that grade.

| | Monokernels off | Monokernels on |
| --- | --- | --- |
| Resolved | 47 of 50 (94%) | 44 of 50 (88%) |
| Agent timeouts | 2 | 2 |

Over the 50 paired tasks, 3 pass only with the monokernels off, and none
only with them on. McNemar's exact test gives p 0.250 and finds no
difference. In 2 of these tasks, the agent of the on arm ended without
an error, and its patch failed the tests. In the third, the agent of the
on arm reached the 50-minute limit, and the task failed.

The saved results name a task by the first 32 characters of its name,
and the 3 protonmail tasks have the same 32 characters. Each arm fails 2
of them. If the two arms fail different protonmail tasks, the counts are
4 and 1, and p is 0.375.

Fifty tasks find only a large change. The 95% interval of the resolved
rate is ±6.6 points with the monokernels off and ±9.1 points with them
on. We did not run the other 592 tasks of V2.

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

| Check | Result |
| --- | --- |
| Compile every K2 build key (widths 1 to 8, with and without `fse`) on
every rank | All 16 keys compile |
| Port test: K2's `out` and `res_out` against the
sgl-project/sglang#43516 kernels, on every rank | 11 cases (widths 1 to
8 without `fse`, and `fse` at 1, 4 and 8 rows) are bit for bit equal |

Each run also repeats the K1 and K2 checks of #89, with the same
results. The kernel tests do not compare K2 with SGLang's ops. Check
mode in the e2e test does that, with the real weights.

### Three runs of all tests

| 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 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | 14 passed | 6 passed | 6 passed | 0.980 | 0.980 | 0.0182 | 0 and 1
of 3956 | 0.999128, 0.999505 |
| 2 | 14 passed | 6 passed | 6 passed | 0.980 | 0.975 | 0.0190 | 0 and 0
of 3956 | 0.999576, 0.999694 |
| 3 | 14 passed | 6 passed | 6 passed | 0.980 | 0.975 | 0.0094 | 1 and 1
of 3956 | 0.999414, 0.999312 |

Each check-mode test has 1104 K1 checks and 1472 K2 checks. In run 3,
one 1-row check had its only row routed elsewhere, so that check
compared only `res_out`. In all runs, the lowest `k1.core.cosine` is
0.999984, and `k2.res_out.cosine` rounds to 1.000000.

The e2e tests are the five tests of #89 and one new test:

- GSM8K decode, GSM8K NEXTN, prefill match and fault injection: as in
#89, without FSE.
- Check mode: each K1 and K2 layer output is within `NUMERICS`, at 1, 3
and 8 rows, without FSE.
- Check mode with FSE (new): the same test with
`--enforce-shared-experts-fusion`. SGLang logs "Quantizing the BF16
shared expert to MXFP4 while loading" on each rank.

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

## Speed Tests and Profiling

The test uses `sglang.bench_serve` with random prompts of 8192 input and
1024 output tokens (range ratio 0.8). Each arm starts a fresh server, in
the order off, on, on, off. 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`.

| 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 | 9.73, 9.74 | 6.37, 6.39 | 102.7, 156.7 | 1.53× | 0.3% |
| 2 | 10.38, 10.38 | 7.97, 7.96 | 96.3, 125.5 | 1.30× | 0.1% |
| 4 | 12.54, 12.53 | 9.90, 9.90 | 79.8, 101.0 | 1.27× | 0.1% |
| 8 | 16.00, 15.99 | 14.13, 14.13 | 62.5, 70.8 | 1.13× | 0.1% |
| 16 (past the largest width) | 22.12, 22.11 | 22.12, 22.10 | 45.2, 45.2
| 1.00× | 0.1% |

- The speedup uses the mean of the two rounds.
- The spread is the largest difference between the two rounds of one
arm.
- At concurrency 16, most steps have more than 8 rows and run SGLang's
path, so the speed does not change.
- No concurrency is slower with the monokernels on.
- The arms of #89 ran on the same node without FSE. Against them, FSE
makes the off arm 1.05× to 1.13× faster, and the on arm 1.03× to 1.10×
faster.

**Registers.** The table comes from a compile-only build of the 8 K2
`fse` build keys at `afcc356` (the head before the rebase, with the same
kernel code) 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 differ, a cell gives
the range.

| Width | VGPR | VGPR spill | SGPR spill | LDS (bytes) | Scratch (bytes)
|
| --- | --- | --- | --- | --- | --- |
| 1 | 197 | 0 | 13 | 27680 | 0 |
| 2 | 201 | 0 | 19 | 46240 | 0 |
| 3 | 203 | 0 | 16 | 62736 | 0 |
| 4 | 214 | 0 | 16 to 17 | 79216 | 0 |
| 5 | 216 | 0 | 15 | 95712 | 0 |
| 6 | 218 | 0 | 15 to 16 | 112192 | 0 |
| 7 | 220 | 0 | 15 | 128688 | 0 |
| 8 | 222 | 0 | 15 to 17 | 145168 | 0 |

- No `fse` build spills a VGPR or uses scratch. The SGPR spills go to
VGPR lanes.
- No build uses AGPRs. Each build has 106 SGPRs.
- LDS grows with the width, to 145,168 of gfx950's 163,840 bytes at 8
rows.
- The K2 builds without `fse` use 48 more bytes of LDS than in #83.
Their VGPR and spill numbers do not change. The K1 builds do not change.

**Kernels before and after.** The table compares one decode step at
batch 1 in two TP-0 profiles with `--enforce-shared-experts-fusion`:
monokernels off and monokernels on. Both servers ran the head `fc098d3`
on one node with 8× MI355X. The prompt has 8192 tokens, and the output
has 100 tokens. The counts come from the `step[DECODE bs=1]` slices on
the GPU stream. All 89 decode steps after the first 10 have the same
counts. Each time is the mean of these 89 steps.

| Part of the layer | Before: SGLang kernel | Calls per step | Time per
call (µs) | After |
| --- | --- | --- | --- | --- |
| out_proj (69 GDN layers) or o_proj (23 attention layers) |
`_gemm_a16_w16_kernel` (`SPLITK_BLOCK_SIZE_2048`) | 92 | 8.2 | One
`qwen38_mono_k2_s1_f1_a0` launch for each layer: 92 calls per step, 33.8
µs each |
| The all-reduce after out_proj | `aiter::ar_ll_gfx9` | 92 | 6.7 | In K2
|
| The post-attention norm | `_gemma_fused_add_rmsnorm_kernel` | 92 | 4.4
| In K2 |
| The router | `aiter::wv_splitk_small_fp16_bf16_kernel` | 92 | 8.0 | In
K2 |
| The top-k | `vllm::moe::topkGatingSoftmax` | 92 | 9.9 | In K2 |
| The shared expert gate (GEMV, sigmoid and scale), which adds expert
512 to the top-k | `_fused_append_shared_experts_with_weights_kernel` |
92 | 4.0 | In K2 |
| The routed experts and the shared expert (expert 512) |
`aiter::fmoe_bf16_pertokenMXfp4_g1u1_flat_vs_silu_16x32` | 92 | 19.2 |
In K2 |
| The MoE all-reduce | `aiter::ar_ll_gfx9` | 92 | 6.5 | In K2 |
| The GDN front: the input norm, in_proj, the split, the conv update,
the gated delta rule and the gated norm | The 6 kernels of the table in
#89 | 69 each | 40.2 for the 6 | K1 of #89: `qwen38_mono_k1_s1_f0_b1`
(68 calls per step, 27.8 µs each) and `qwen38_mono_k1_s1_f1_b1` (layer
0, 26.4 µs) |
| The step epoch of the K2 waits | None | | | One
`CUDAFunctorOnSelf_add<int>` per step |

- The 8 kernels of a layer tail take 66.9 µs together. The `fse` K2
takes 33.8 µs. On the same node, the K2 of #89 without FSE takes 40.1
µs.
- The step falls from 1393 to 405 kernels, and from 10.54 to 6.63 ms of
kernel time.
- With FSE, SGLang runs no separate shared-expert GEMMs. `fmoe` runs the
shared expert as the 11th expert of each token.
- Each screenshot selects one `step[DECODE bs=1]` slice and shows only
its kernels (filter `Category = kernel`).

Before (FSE, monokernels off), one decode step: 
<img width="2089" height="1172" alt="image"
src="https://github.com/user-attachments/assets/2c276e11-8168-4a71-b744-6996c26f31bc"
/>

After (FSE, monokernels on), one decode step: 
<img width="2087" height="1006" alt="image"
src="https://github.com/user-attachments/assets/a6618313-922f-43aa-a721-d7e842eea9eb"
/>



## 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.
- [ ] A new model adds one line to `.github/CODEOWNERS` that names its
owner. (N/A: `main` already has `**/*qwen38_a95b_mxfp4* @omirosh
@yichiche @chuyeh-amd`.)

## 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]>
yichiche pushed a commit to sgl-project/sgl-amd-mono that referenced this pull request Nov 19, 2026
…gl-project/sglang#43839 (#92)

Part 5 of 5 of the split of
[sgl-amd-mono#16](#16).
[sgl-amd-mono#83](#83),
[sgl-amd-mono#88](#88),
[sgl-amd-mono#89](#89)
and
[sgl-amd-mono#90](#90)
have merged. This PR is on `main` at `56669ca`. It has four commits: the
code commit `5516f20`, the README commit `262dd24`, the refusal commit
`8975393` and the comment commit `a4c94bb`.

## Motivation

Since sgl-project/sglang#43839, SGLang quantizes in_proj_qkvz and
out_proj of the 69 GDN layers to MXFP4 while it loads. This is on by
default with `SGLANG_USE_AITER=1` on gfx950
(`SGLANG_ROCM_GDN_ONLINE_MXFP4`). The weights go through
`shuffle_weight` (16, 16), and the scales through `shuffle_scale`.

The earlier PRs of this split read these projections in bf16 and refuse
the MXFP4 ones at startup. A user must set
`SGLANG_ROCM_GDN_ONLINE_MXFP4=0`. This PR adds the `qq` variant of K1
and the `oq` variant of K2 from sgl-project/sglang#43516, so the spec
serves SGLang's default.

With this PR, the plugin has all the kernel variants of the port of
sgl-project/sglang#43516.

## Modifications

| Area | Change |
| --- | --- |
| `qwen38_a95b_mxfp4/gfx950/gdn.py` | Adds the `qq` build flag. With
`qq`, the in_proj_qkvz tasks read the MXFP4 weight and its scales
(`w_qkvzs`). They quantize the input rows to MXFP4 (RCEIL), as SGLang's
GEMM quantizes its input. in_proj_ba stays bf16, on the rows before the
quantization. |
| `qwen38_a95b_mxfp4/gfx950/layer.py` | Adds the `oq` build flag. With
`oq`, K2 reads the MXFP4 out_proj and its scales (`w_os`), and quantizes
the core rows to MXFP4 (RCEIL). The FP4 GEMV helpers (`fp4_gemv`,
`fp4_gemv_loads`, `quant_x`) come back, and K1 imports them from K2. |
| `qwen38_a95b_mxfp4/spec.py` | Builds K1 for each in_proj_qkvz dtype
and K2 for each out_proj and o_proj dtype that the model has. Accepts
bf16 or MXFP4 for in_proj_qkvz and out_proj. Removes the MXFP4 refusal.
The refusal commit refuses an MXFP4 projection with the Hadamard
rotation (see below). |
| `test/e2e/qwen38_a95b_mxfp4_server.py` | The test servers do not set
`SGLANG_ROCM_GDN_ONLINE_MXFP4=0` now. All the e2e tests run the MXFP4
projections. They set `SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0`. |
| `test/e2e/test_qwen38_a95b_mxfp4_server.py` | The check-mode test
checks that SGLang logs "Online MXFP4 GDN in_proj_qkvz,out_proj: N
projections". |
| `test/kernels/qwen38_a95b_mxfp4/check_k1.py`, `check_k2.py`,
`check_port.py`, `inputs.py` | The compile checks also build the `qq`
and `oq` keys. The port test also compares `qq` and `oq` with
sgl-project/sglang#43516, bit for bit. |
| `test/unit/test_qwen38_a95b_mxfp4_spec.py` | Checks that MXFP4
projections give no refusal, and that a rotated or unknown quant method
state gives one. |
| `README.md` | The requirements and the usage command drop
`SGLANG_ROCM_GDN_ONLINE_MXFP4=0`. |
| `sgl_amd_mono/qwen38_a95b_mxfp4/README.md` | The README commit adds
the MXFP4 GDN projections to the folder README. It removes
`SGLANG_ROCM_GDN_ONLINE_MXFP4=0` from the start command and the
limitations. The refusal commit adds the Hadamard refusal to its list. |

**Refusals.** This PR removes the MXFP4 refusal. The spec still refuses
a GDN layer whose in_proj_qkvz or out_proj is neither bf16 nor MXFP4.

The commit `8975393` adds one refusal.
[sglang#46059](sgl-project/sglang#46059) (open,
default on) rotates the MXFP4 in_proj_qkvz and out_proj weights by
Hadamard-32, and SGLang rotates the activation before its quant. K1 and
K2 do not rotate the activation, so the output would be wrong with no
error. The spec now accepts an MXFP4 projection only when
`vars(quant_method)` is `{}` (SGLang before that PR) or `{"hadamard":
False, "quant_kwargs": {}}` (`SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0`).
It refuses each other state, so a renamed flag gives a refusal, not a
wrong output. The e2e servers set
`SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0`. `pytest
test/unit/test_qwen38_a95b_mxfp4_spec.py`: 18 passed. The results below
ran before this commit. On their SGLang builds, the new check accepts
each projection.

With the MXFP4 projections and the test CUDA graphs, each rank logs
"Qwen3.8 monokernel: 8 K1 and 8 K2 launches (widths [1, 2, 4, 8],
decode)". All 8 K1 kernels are `qq` builds. The K2 kernels are `oq`
builds for the GDN layers and bf16 builds for the o_proj of the 23
attention layers. With NEXTN 3/1/4, each rank logs "0 K1 and 4 K2
launches (widths [4, 8], verify)". SGLang logs "Online MXFP4 GDN
in_proj_qkvz,out_proj: 138 projections".

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

## Accuracy Tests

All the results below use this setup:

| 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
sgl-project/sglang#41899 and 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`, so the GDN projections are
MXFP4. Add `--enforce-shared-experts-fusion` where a test or arm says
FSE. The monokernel-on servers add `--monokernel-backend amd`. |
| Branch commit | `536efa2` (tag `q38v3-tested/5-mxfp4`). The code
commit `5516f20` is rebased onto `main` at `56669ca`, which has
[sgl-amd-mono#90](#90).
Its model code and tests are the same as at `5d328f2`, the code commit
before the rebases. They differ from the tested commit only in the text
of a docstring and a skip message. The test runs used the old base
`0aa9749`, before
[sgl-amd-mono#76](#76)
changed `PeerBuffer.close()`. |

The port test (`check_port.py`) compares K1 and K2 with the original
kernels of sgl-project/sglang#43516 at `51b0c592b2`. That PR is not
merged, so the test run mounts its two kernel folders (`k3_mono_flydsl`
and `qwen3_5_mono_flydsl`) read-only into SGLang's tree in the
container. No SGLang code imports them. Only the port test does.

### GSM8K with FSE and MXFP4 GDN projections, monokernels on and off

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. Both arms use `--enforce-shared-experts-fusion`
and the MXFP4 GDN projections. The test sends 8 concurrent requests, so
the decode steps take the K1 and K2 path. Each arm starts a fresh
server. Each question has the same `prompt_hash` in both arms.

| Filter | Monokernels off | Monokernels on | Right only off | Right
only on | McNemar's p (exact) |
| --- | --- | --- | --- | --- | --- |
| flexible-extract | 1286 (0.9750) | 1289 (0.9773) | 9 | 12 | 0.664 |
| strict-match | 1179 (0.8939) | 1186 (0.8992) | 79 | 86 | 0.641 |

The arms differ by 3 questions on flexible-extract and by 7 on
strict-match. McNemar's test finds no accuracy difference on either
filter.

Strict-match needs a `#### N` line. Of the answers that flexible-extract
finds right, strict-match fails 108 in the off arm and 104 in the on
arm. Of these, 107 and 104 have no `#### N` line, and about half end in
`**Answer: N**` instead (58 and 57). The other one, in the off arm, ends
in `#### $21`, and strict-match does not take the dollar sign. So the
strict-match gap is in the answer format, not in the answers.

Both arms have a higher strict-match than the arms of #90 (0.8052 off
and 0.8165 on), because fewer right answers have no `#### N` line (226
and 208 in #90). The off arm runs no monokernel, so this change comes
with SGLang's MXFP4 GDN projections, not with K1 or K2.

### GPQA Diamond and SWE-bench Pro with FSE and MXFP4 GDN projections,
monokernels on and off

These runs use the code commit `5d328f2` in one image, with the flags of
the GSM8K and speed servers plus `--default-chat-template-kwargs
'{"reasoning_effort": "xhigh"}'`. Claude Code sends the effort `high`,
which the chat template refuses. With this flag, the template renders
its default effort, xhigh, for every request. Both arms use
`--enforce-shared-experts-fusion` and the MXFP4 GDN projections. 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 8 concurrent requests.

| | Monokernels off | Monokernels on | Model card |
| --- | --- | --- | --- |
| avg@4, with the 95% interval over the questions | 92.05 ± 3.43 | 92.68
± 3.26 | 92.6 |

Over the 198 paired questions, on minus off is +0.63 points, with a 95%
interval of ±1.55. Ten questions score higher with the monokernels on,
and nine with them off. The sign test gives p 1.000 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. With the monokernels
off, 6 of the 792 samples stop at the 131072-token cap, and 2 do with
them on.

#### SWE-bench Pro

The test runs 50 tasks of [SWE-bench Pro
V2](https://github.com/scaleapi/SWE-bench_Pro-os/tree/66f92766bba642462d4bbe5479e83f91f9211862/v2),
Scale's validated set of 642 tasks. The 50 tasks come from 11 repos.
`random.Random(20261105).sample(sorted(ids), 50)` picks them from the
642 task names in `v2/tasks`. Harbor 0.23.0 runs Claude Code with the
`locked_claude_code` agent of V2, 8 tasks at a time. Each task gets 50
minutes, network access only to the model server, and no WebFetch or
WebSearch. Each turn can have 32768 output tokens and 31999 thinking
tokens. The server samples with the defaults of the checkpoint
(temperature 1.0, top-p 0.95, top-k 20). Each decode batch in the server
log of the on arm has 1 to 8 running requests, so the decode steps take
the K1 and K2 path. After the run, `patch_replay` grades each patch
again on a fresh task image, and the table gives that grade.

| | Monokernels off | Monokernels on |
| --- | --- | --- |
| Resolved | 46 of 50 (92%) | 46 of 50 (92%) |
| Agent timeouts | 2 | 2 |

Over the 50 paired tasks, 2 pass only with the monokernels on, and 2
only with them off. McNemar's exact test gives p 1.000 and finds no
difference. In 3 of these 4 tasks, the agent of the failing arm ended
without an error, and its patch failed the tests. In the fourth, the
agent of the on arm reached the 50-minute limit, and the task failed.

The saved results name a task by the first 32 characters of its name,
and the 3 protonmail tasks have the same 32 characters. Each arm fails 1
of them. If the two arms fail different protonmail tasks, the counts are
3 and 3, and p is 1.000.

Fifty tasks find only a large change. The 95% interval of the resolved
rate is ±7.6 points in both arms. We did not run the other 592 tasks of
V2.

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

| Check | Result |
| --- | --- |
| Compile every K1 build key (widths 1 to 8, first layer or not, f32 or
bf16 state, bf16 or MXFP4 in_proj_qkvz) | All 64 keys compile |
| Compile every K2 build key (widths 1 to 8, with and without `fse`,
bf16 or MXFP4 out_proj) on every rank | All 32 keys compile |
| Port test: K1 against the sgl-project/sglang#43516 `gdn_pre` kernel |
34 cases (widths 1 to 8 with f32 and bf16 state and with and without
`qq`, and the first layer at 1 and 8 rows) are bit for bit equal |
| Port test: K2 against the sgl-project/sglang#43516 kernels, on every
rank | 17 cases (widths 1 to 8, and `fse`, `oq` and both at 1, 4 and 8
rows) are bit for bit equal |

Each run also repeats the K1 and K2 checks of #90, with the same
results. 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

All the e2e tests of this PR run the MXFP4 GDN projections.

| 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 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | 14 passed | 6 passed | 6 passed | 0.980 | 0.985 | 0.0195 | 0 and 0
of 3956 | 0.999561, 0.999918 |
| 2 | 14 passed | 6 passed | 6 passed | 0.975 | 0.980 | 0.0232 | 0 and 0
of 3956 | 0.999225, 0.999695 |
| 3 | 14 passed | 6 passed | 6 passed | 0.985 | 0.985 | 0.0203 | 1 and 0
of 3956 | 0.999860, 0.999796 |

Each check-mode test has 1104 K1 checks and 1472 K2 checks. In all runs,
the lowest `k1.core.cosine` is 0.999972, the lowest `k1.state.cosine` is
0.999986, and `k2.res_out.cosine` rounds to 1.000000.

The e2e tests are the six tests of #90. The check-mode test without FSE
also checks that SGLang logs the MXFP4 quantization of the GDN
projections.

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

## Speed Tests and Profiling

The test uses `sglang.bench_serve` with random prompts of 8192 input and
1024 output tokens (range ratio 0.8). Each arm starts a fresh server, in
the order off, on, on, off. The servers use the flags and environment of
`test/e2e/qwen38_a95b_mxfp4_server.py` (so the GDN projections are
MXFP4), plus `--enforce-shared-experts-fusion`, `--tool-call-parser
qwen3_coder` and `--watchdog-timeout 12000`.

| 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 | 9.32, 9.31 | 5.16, 5.16 | 107.4, 193.8 | 1.81× | 0.1% |
| 2 | 10.14, 10.12 | 6.69, 6.69 | 98.7, 149.5 | 1.51× | 0.2% |
| 4 | 12.23, 12.20 | 8.66, 8.66 | 81.9, 115.5 | 1.41× | 0.2% |
| 8 | 15.08, 15.08 | 12.85, 12.84 | 66.3, 77.9 | 1.17× | 0.1% |
| 16 (past the largest width) | 21.07, 21.07 | 21.09, 21.09 | 47.5, 47.4
| 1.00× | 0.0% |

- The speedup uses the mean of the two rounds.
- The spread is the largest difference between the two rounds of one
arm.
- At concurrency 16, most steps have more than 8 rows and run SGLang's
path. There, the on arm is 0.02 ms (0.1%) slower in both rounds.
- The arms of #90 ran on the same node with bf16 GDN projections.
Against them, the MXFP4 projections make the off arm 1.03× to 1.06×
faster, and the on arm 1.05× to 1.24× faster.

### All 5 PRs on the v0.5.23 nightly, monokernels off and on

These arms compare the 5 PRs of the split
([sgl-amd-mono#83](#83),
[sgl-amd-mono#88](#88),
[sgl-amd-mono#89](#89),
[sgl-amd-mono#90](#90)
and this PR) with no monokernel, on a current SGLang nightly.

| Item | Value |
| --- | --- |
| Image |
`rocm/sgl-dev:v0.5.23-rocm10-mi35x-20261116@sha256:5e6d56215545c865e2ab50ae7206edbdbf7bc00143170f853d54a289053cbba6`
|
| SGLang | `074aeaf67499d06cc61300971fae90bcf4297670` (2026-11-16),
which has
[sglang#41899](sgl-project/sglang#41899) and
[sglang#43839](sgl-project/sglang#43839) |
| AITER | `285579b6211b0da30f35b91a890c29c823597cd1`, the same as in the
20261028 nightly |
| Plugin | `262dd24` of this PR. The monokernel-on servers also have the
fix of
[sgl-amd-mono#147](#147).
[sglang#46980](sgl-project/sglang#46980) removed
the pool method that K1 reads, so without the fix the first decode step
stops with an `AttributeError`. The monokernel-off servers do not run
K1. |
| Server flags | The flags of the table above. The NEXTN servers add
`--speculative-algorithm NEXTN` with 3 steps, top-k 1 and 4 draft
tokens, and `--enable-linear-replayssm-spec`. |

Each arm starts a fresh server. With NEXTN, the order is off, on, on,
off. Without MTP, the order is off, off, on, on, because the first two
on arms stopped on the removed method and ran again with the fix.

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.82, 8.83 | 5.15, 5.14 | 113.3, 194.3 | 1.72× | 0.3% |
| 2 | 9.62, 9.65 | 6.68, 6.64 | 103.8, 150.1 | 1.45× | 0.6% |
| 4 | 11.77, 11.80 | 8.52, 8.55 | 84.9, 117.1 | 1.38× | 0.3% |
| 8 | 14.62, 14.69 | 12.60, 12.70 | 68.2, 79.0 | 1.16× | 0.8% |
| 16 (past the largest width) | 20.58, 20.53 | 20.53, 20.60 | 48.7, 48.6
| 1.00× | 0.3% |

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 | 3.17, 3.19 | 2.62, 2.62 | 314.4, 382.0 | 1.21× | 0.4% |
| 2 | 3.79, 3.83 | 3.52, 3.46 | 262.3, 286.4 | 1.09× | 1.5% |
| 4 (past the largest width) | 5.43, 5.36 | 5.37, 5.38 | 185.5, 186.2 |
1.00× | 1.3% |
| 8 (past the largest width) | 7.21, 7.29 | 7.28, 7.28 | 137.9, 137.4 |
1.00× | 1.0% |
| 16 (past the largest width) | 10.33, 10.29 | 10.46, 10.38 | 97.0, 96.0
| 0.99× | 0.8% |

- The speedup uses the mean of the two rounds. The spread is the largest
difference between the two rounds of one arm.
- Without MTP, each rank logs "Qwen3.8 monokernel: 8 K1 and 8 K2
launches (widths [1, 2, 4, 8], decode)". At concurrency 16, most steps
have more than 8 rows and run SGLang's path.
- With NEXTN, each rank logs "Qwen3.8 monokernel: 0 K1 and 4 K2 launches
(widths [4, 8], verify)". Only the verify steps of 1 and 2 requests take
K2. Concurrency 4, 8 and 16 have verify steps of 16, 32 and 64 rows, and
both arms run SGLang's path. At concurrency 16, the on arm is 0.09 to
0.13 ms (1.1%) slower in both rounds, a little more than the spread.
- On this nightly, SGLang's path (the off arm) is 1.03× to 1.06× faster
than in the table above, and the on arm is 1.00× to 1.03× faster. So the
speedup at concurrency 1 without MTP is 1.72× here, against 1.81× above.

GSM8K, round 1 of each arm, with the setup of the GSM8K test above (all
1,319 questions, 5-shot, temperature 0). Without MTP, the test sends 8
concurrent requests, so the decode steps take K1 and K2. With NEXTN, it
sends 2, so the verify steps have 8 rows and take K2.

| Mode | Filter | Monokernels off | Monokernels on | Right only off |
Right only on | McNemar's p (exact) |
| --- | --- | --- | --- | --- | --- | --- |
| No MTP | flexible-extract | 1288 (0.9765) | 1291 (0.9788) | 7 | 10 |
0.629 |
| No MTP | strict-match | 1186 (0.8992) | 1185 (0.8984) | 79 | 78 |
1.000 |
| NEXTN 3/1/4 | flexible-extract | 1290 (0.9780) | 1287 (0.9757) | 10 |
7 | 0.629 |
| NEXTN 3/1/4 | strict-match | 1197 (0.9075) | 1182 (0.8961) | 81 | 66 |
0.248 |

McNemar's test finds no accuracy difference in either mode or filter.

**Registers.** The tables come from a compile-only build of the K1 `qq`
and the K2 `oq` build keys at `26699aa` (the head before the rebase,
with the same kernel code) 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 builds of one width
differ, a cell gives the range.

K1 `qq` (32 keys: first layer or not, f32 or bf16 state):

| Width | VGPR | VGPR spill | SGPR spill | LDS (bytes) | Scratch (bytes)
|
| --- | --- | --- | --- | --- | --- |
| 1 | 149 to 150 | 0 | 0 | 24656 | 0 |
| 2 | 140 to 144 | 0 | 0 | 41056 | 0 |
| 3 | 140 to 148 | 0 | 0 | 57456 | 0 |
| 4 | 142 to 146 | 0 | 0 | 73856 | 0 |
| 5 | 142 to 145 | 0 | 0 to 2 | 90256 | 0 |
| 6 | 142 to 144 | 0 | 0 | 106656 | 0 |
| 7 | 141 to 146 | 0 | 8 to 35 | 123056 | 0 |
| 8 | 147 to 148 | 0 | 1 to 2 | 139456 | 0 |

K2 `oq` (16 keys: with and without `fse`):

| Width | VGPR | VGPR spill | SGPR spill | LDS (bytes) | Scratch (bytes)
|
| --- | --- | --- | --- | --- | --- |
| 1 | 197 to 207 | 0 | 14 to 19 | 27664 to 27680 | 0 |
| 2 | 197 to 211 | 0 | 20 to 94 | 46224 to 46240 | 0 |
| 3 | 203 to 213 | 0 | 16 to 23 | 62704 to 62736 | 0 |
| 4 | 213 to 215 | 0 | 21 to 79 | 79184 to 79216 | 0 |
| 5 | 213 to 216 | 0 | 16 to 23 | 95664 to 95712 | 0 |
| 6 | 217 to 221 | 0 | 20 to 98 | 112144 to 112192 | 0 |
| 7 | 213 to 220 | 0 | 14 to 23 | 128624 to 128688 | 0 |
| 8 | 221 to 223 | 0 | 21 to 24 | 145104 to 145168 | 0 |

- No `qq` or `oq` build spills a VGPR or uses scratch. The SGPR spills
go to VGPR lanes.
- No build uses AGPRs.
- The `qq` builds use about 60 fewer VGPRs than the bf16 K1 builds (205
to 214).
- LDS is at most 145,168 of gfx950's 163,840 bytes (K2 `fse` at 8 rows).

**Kernels before and after.** The table compares one decode step at
batch 1 in two TP-0 profiles with the MXFP4 GDN projections and
`--enforce-shared-experts-fusion`: monokernels off and monokernels on.
Both servers ran the head `5d328f2` on one node with 8× MI355X. The
prompt has 8192 tokens, and the output has 100 tokens. The counts come
from the `step[DECODE bs=1]` slices on the GPU stream. All 89 decode
steps after the first 10 have the same counts. Each time is the mean of
these 89 steps.

| Part of the GDN layer | Before: SGLang kernel | Calls per step | Time
per call (µs) | After |
| --- | --- | --- | --- | --- |
| The residual add and the input norm |
`_gemma_fused_add_rmsnorm_kernel`; `_gemma_rmsnorm_kernel` on layer 0 |
68 + 1 | 4.4 | One K1 `qq` launch for each GDN layer:
`qwen38_mono_k1_s1_f0_b1_q1` (68 calls per step, 12.8 µs each) and
`qwen38_mono_k1_s1_f1_b1_q1` (layer 0, 12.9 µs) |
| The MXFP4 quantization of the in_proj_qkvz input |
`aiter::dynamic_per_group_scaled_quant_kernel<bf16, fp4>` | 69 | 4.3 |
In K1 |
| in_proj_qkvz (MXFP4) | `_gemm_afp4wfp4_preshuffle_kernel`
(`BLOCK_SIZE_N_64`) | 69 | 4.2 | In K1 |
| The split-K reduction of in_proj_qkvz | `_gemm_afp4wfp4_reduce_kernel`
(`ACTUAL_KSPLIT_4`) | 69 | 4.2 | In K1 |
| in_proj_ba (bf16) | `aiter::wv_splitk_small_fp16_bf16_kernel` | 69 |
4.4 | In K1 |
| The split of the projection output |
`fused_qkvzba_split_reshape_cat_contiguous_kernel` | 69 | 4.4 | In K1 |
| The conv update | `_causal_conv1d_update_kernel` | 69 | 4.4 | In K1 |
| The gated delta rule |
`fused_recurrent_gated_delta_rule_packed_decode_kernel` | 69 | 4.4 | In
K1 |
| The gated norm | `_layer_norm_fwd_1pass_kernel` | 69 | 4.2 | In K1 |
| The MXFP4 quantization of the out_proj input |
`aiter::dynamic_per_group_scaled_quant_kernel<bf16, fp4>` | 69 | 4.4 |
One K2 `oq` launch for each GDN layer: `qwen38_mono_k2_s1_f1_o1_a0` (69
calls per step, 30.0 µs each) |
| out_proj (MXFP4) | `_gemm_afp4wfp4_preshuffle_kernel`
(`BLOCK_SIZE_N_32`) | 69 | 5.4 | In K2 |
| The all-reduce after out_proj | `aiter::ar_ll_gfx9` | 69 | 7.8 | In K2
|
| The post-attention norm, the router, the top-k, the shared expert
gate, the experts and the MoE all-reduce | The 6 kernels of the FSE tail
in #90 | 69 each | 52.3 for the 6 | In K2 |
| The step epoch of the K2 waits | None | | | One
`CUDAFunctorOnSelf_add<int>` per step |

- The 9 kernels of a GDN front take 38.9 µs together. K1 `qq` takes 12.8
µs. The bf16 K1 of #89 takes 27.8 µs on the same node.
- The 9 kernels of a GDN tail take 69.9 µs together. K2 `oq` takes 30.0
µs.
- The 23 attention layers keep bf16 o_proj. As in #90, their 8 tail
kernels (68.4 µs) run as one `qwen38_mono_k2_s1_f1_o0_a0` launch (34.2
µs).
- The step falls from 1669 to 405 kernels, and from 10.71 to 5.41 ms of
kernel time.
- Each screenshot selects one `step[DECODE bs=1]` slice and shows only
its kernels (filter `Category = kernel`).

Before (MXFP4 GDN projections, monokernels off), one decode step: 
<img width="2087" height="1175" alt="image"
src="https://github.com/user-attachments/assets/5a6edac0-b3d6-4dc1-b1d7-ba80c66c631c"
/>


After (MXFP4 GDN projections, monokernels on), one decode step:
<img width="2087" height="1014" alt="image"
src="https://github.com/user-attachments/assets/d5f10efd-76ed-4faf-96f6-0ec4b258acc8"
/>


## 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.
- [ ] A new model adds one line to `.github/CODEOWNERS` that names its
owner. (N/A: `main` already has `**/*qwen38_a95b_mxfp4* @omirosh
@yichiche @chuyeh-amd`.)

## 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 Nov 19, 2026
…shared expert

LayerBuild gets the field fse (default True, the build of
sgl-project/sglang#41899). With fse False, the
16-row layer_block runs the bf16 shared expert with the numbers of K2
and SGLang:

- CTAs 96 to 223 run the shared gate | up: 32 row groups, each over the
  4 K quarters of x, as the router of
  vllm-project/vllm#67421. Part 0 puts the bf16
  rows to SGU.
- load_h makes h = bf16(silu(g) u) in LDS, as K2.
- The down stage adds bf16(bf16(h . w_sd) x SGATE) to the routed rows,
  as K2.
- SGATE is bf16 after the sigmoid. The route has no expert 512 slot.
  The early shared tasks and the split down stay FSE only.

Without FSE, layer_block takes 16 rows only. The FSE build keeps its
scratch layout and its kernel name. Its kernel gets the two unused
pointers w_sgu and w_sd.

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

LayerBuild gets the field fse (default True, the build of
sgl-project/sglang#41899). With fse False, the
16-row layer_block runs the bf16 shared expert with the numbers of K2
and SGLang:

- CTAs 96 to 223 run the shared gate | up: 32 row groups, each over the
  4 K quarters of x, as the router of
  vllm-project/vllm#67421. Part 0 puts the bf16
  rows to SGU.
- load_h makes h = bf16(silu(g) u) in LDS, as K2.
- The down stage adds bf16(bf16(h . w_sd) x SGATE) to the routed rows,
  as K2.
- SGATE is bf16 after the sigmoid. The route has no expert 512 slot.
  The early shared tasks and the split down stay FSE only.

Without FSE, layer_block takes 16 rows only. The FSE build keeps its
scratch layout and its kernel name. Its kernel gets the two unused
pointers w_sgu and w_sd.

Co-authored-by: Cursor <[email protected]>
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
…shared expert

LayerBuild gets the field fse (default True, the build of
sgl-project/sglang#41899). With fse False, the
16-row layer_block runs the bf16 shared expert with the numbers of K2
and SGLang:

- CTAs 96 to 223 run the shared gate | up: 32 row groups, each over the
  4 K quarters of x, as the router of
  vllm-project/vllm#67421. Part 0 puts the bf16
  rows to SGU.
- load_h makes h = bf16(silu(g) u) in LDS, as K2.
- The down stage adds bf16(bf16(h . w_sd) x SGATE) to the routed rows,
  as K2.
- SGATE is bf16 after the sigmoid. The route has no expert 512 slot.
  The early shared tasks and the split down stay FSE only.

Without FSE, layer_block takes 16 rows only. The FSE build keeps its
scratch layout and its kernel name. Its kernel gets the two unused
pointers w_sgu and w_sd.

Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants