Skip to content

[Perf] [AMD] qwen3.5: Run each Qwen3.8 decode layer as two persistent FlyDSL launches on MI355X - #43516

Closed
omirosh wants to merge 14 commits into
sgl-project:mainfrom
omirosh:rocm/qwen3-5-mono-decode
Closed

omirosh wants to merge 14 commits into
sgl-project:mainfrom
omirosh:rocm/qwen3-5-mono-decode

Conversation

@omirosh

@omirosh omirosh commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

This PR speeds up Qwen3.8 (Qwen3_5MoeForCausalLM) decode on MI355X with ROCm. In a decode step of 8 rows or fewer, each of the 92 decoder layers runs as two persistent FlyDSL launches, ported from vllm-project/vllm#60833. Today each layer takes about a dozen kernel launches and two all-reduces, so small decode steps wait on launches and syncs. On one 8x MI355X node on main, TP8, no MTP, at 8k/1k, median TPOT drops 37% at concurrency 1, with 56% more output tok/s. At concurrency 4 it drops 29%, with 40% more output tok/s. With NEXTN MTP, the second launch alone on the verify steps gives 31% more output tok/s at concurrency 1.

The change is off by default, and SGLANG_QWEN3_5_MONO_DECODE=1 turns it on. A step it does not cover keeps the existing path. These are prefill and mixed steps, steps of more than 8 rows, PP, and any setup other than TP8 on gfx950. With the flag unset, only qwen3_5.py changes on the default path. Its attention and GDN forwards now call attention_core() or core(), then o_proj or out_proj. These are the same ops in the same order.

Stacked on #43481. That PR adds the Kimi-K3 mono framework, k3_mono_flydsl/common and stages/gemv.py. The Qwen kernels import it unchanged, so this PR does not carry a second copy. Only the commits after #43481 are new here. I will rebase once #43481 lands.

Modifications

  • kernels/ops/moe/qwen3_5_mono_flydsl/ has the K1 and K2 kernels of #60833 at 3346929b27 and their layout module, with the imports changed to k3_mono_flydsl. One change is new. K1 also takes a bf16 SSM state. It widens the state to fp32 for the recurrence and rounds it on store, as the stock GDN kernel does. The dtype is part of the K1 build key.
    • K1 (gdn_pre, 69 GDN layers) runs the residual add and input norm, in_proj_qkvz and in_proj_ba, conv1d, the gated delta rule and the gated norm. It writes the input of out_proj.
    • K2 (layer_post, all 92 layers) runs out_proj or o_proj with an in-kernel TP all-reduce, the residual add and post norm, the top-10 router over 512 experts, the MXFP4 experts, the sigmoid-gated shared expert and the MoE all-reduce.
  • srt/layers/moe/qwen3_5_mono_decode.py binds the kernels to SGLang's state. It reads the GDN state from the mamba pool of the hybrid backend, with mamba_cache_indices, conv (slots, dim, 3) and SSM (slots, HV, V, K) in fp32 or bf16. The weight-layout options of #60833 stay off. These are the fused shared expert, MXFP4 o_proj, out_proj and in_proj_qkvz, and the output gate in K2. SGLang loads those weights as bf16 and applies the gate in attention_core(). The kernels skip pad rows, marked -1, and the reserved slot 0. The glue checks the weights once at the first decode step. When it turns itself off, it logs the reason.
  • models/qwen3_5.py splits self_attention, so attention_core() returns the input of o_proj. The 23 full-attention layers keep SGLang's fused HIP front and attention, then run K2. The GDN layer's forward splits the same way, and core() returns the input of out_proj. The text model's forward hands covered decode and target-verify steps to the mono path. The decode CUDA graph captures that path at widths 1, 2, 4 and 8.
  • environ.py adds SGLANG_QWEN3_5_MONO_DECODE.
  • The docs add the flag to docs/references/environment_variables.mdx.

The glue checks these requirements at runtime: TP8, gfx950 and --disable-shared-experts-fusion, because K2 runs the shared expert itself. Without speculative decoding, K1 also needs an fp32 or bf16 SSM state and no ReplaySSM ring. The glue also turns mono off on a GPU with fewer than 256 CUs, because a partitioned GPU cannot keep all 256 spinning CTAs resident. It does the same with HiCache or LMCache, because their copy kernels on another stream can hold CUs that those CTAs wait on. The launch argument checks raise ValueError instead of using assert, so python -O keeps them. Both changes follow the current #60833 head.

This PR has a known problem on ROCm 10 images. The peer buffer uses aiter's UncachedIpcHeap, and its load_hip_runtime() opens libamdhip64.so by name. With _rocm_sdk_devel/lib on LD_LIBRARY_PATH, that maps the devel HIP runtime next to the core copy that torch loads. This brings back the bug that #39513 fixed. vattn_asm binds to the first libamdhip64 in /proc/self/maps, and #39513 assumed that this is always the copy of torch. Graph capture can then fail with this error.

RuntimeError: vattn_asm: hipModuleLaunchKernel failed: 709 (context is destroyed)

The failure needs all of these:

  • A ROCm 10 image with _rocm_sdk_devel/lib on LD_LIBRARY_PATH. rocm720 and rocm724 images map one runtime, so they are not affected.
  • Mono decode on, so the peer buffer imports UncachedIpcHeap.
  • vattn_asm in use. That needs gfx950, the aiter backend, --page-size 16, head dim 256, and SGLANG_ASM_VERIFY_ATTN at its default of 1. Since [AMD] gfx950 assembly attention for EAGLE verify, draft extend and decode  #37465, vattn_asm runs plain q_len 1 decode (forward_decode calls unified_attention_3d_mtp_decode_func) as well as MTP target verify and draft extend. So non-MTP runs hit it too. Other page sizes do not use vattn_asm.

The failure is intermittent. It broke two of three non-MTP server starts here, in the decode graph capture. ROCm/aiter#6398 makes load_hip_runtime() bind to the copy that is already mapped. With that file mounted, no later start failed, with or without MTP. smallm_moe_gfx950 looks up HIP the same way, so it is exposed too, but I have not seen it fail. #43481 imports the same peer_memory.py, so it also maps the second runtime on ROCm 10.

Accuracy Tests

The GSM8K, GPQA and NIAH results in this section used the earlier kernels, #60833 f3c2ec988b. GSM8K and NIAH for the head kernels are in the speed section.

GSM8K, 5-shot, all 1319 questions, lm_eval local-completions at concurrency 8. Flag on and flag off ran on the same image and node.

flexible-extract strict-match
SGLang, mono on (this PR) 0.8506 +- 0.0098 0.8287 +- 0.0104
SGLang, mono off (stock) 0.8446 0.8302

An exact per-question McNemar test, mono on against off, finds no difference. For flexible-extract, 87 questions are right only with mono and 79 only without, p = 0.59. For strict-match the counts are 81 and 83, p = 0.94. RULER niah_single_2 at 128k scores 0.992 with mono on.

With MTP, K2 runs only on the verify steps, as the MTP section below describes. GSM8K at concurrency 2 against the same MTP server with the flag off shows no difference. Flexible-extract is 0.8582 against 0.8461, with 85 questions right only with mono and 69 only without, p = 0.23. Strict-match is 0.8446 against 0.8370, p = 0.47.

GPQA Diamond and RULER niah_single_2 ran at concurrency 8, so every decode step is in the mono range. Flag on and flag off use the same server config.

flag off flag on
GPQA Diamond, thinking, temperature 1.0 (2 runs each) 0.884, 0.924 (mean 0.904) 0.894, 0.934 (mean 0.914)
NIAH 64k (500 questions) 0.994, 0.996 (2 runs) 0.996
NIAH 128k (500 questions) 0.996, 1.000 (2 runs) 0.992

GPQA samples at temperature 1.0, and the two runs of one arm differ by 4 points, so the 1-point gap is noise. NIAH is greedy. Paired per question, mono against each flag-off run gives p = 0.63 and 0.13 at 128k and p = 1.0 at 64k. The two flag-off runs also disagree with each other on 2 to 5 questions. No difference.

The unit tests in test/registered/amd/test_qwen3_5_mono_decode.py run on 1 GPU. They check that every fp4 byte and e8m0 scale of SGLang's gfx950 expert layout is where K2 reads it. K1 runs at widths 1, 4 and 8 against SGLang's pool layout. It writes the live rows and leaves pad rows and other slots unchanged. With a bf16 state, K1 gives the same core output and conv state as with the widened fp32 state. Its new state equals the new fp32 state rounded to bf16. The tests pass on MI355X in the v0.5.21-based image and on main, here the ROCm nightly of 2026-10-09 with this branch's files. The file has not run in CI yet.

The batch-invariance test in test/registered/amd/test_qwen3_5_mono_batch_invariance.py runs K1 on 1 GPU and K2 on 8 GPUs. It keeps one probe row fixed and changes the other rows of the step. The probe outputs must be bitwise the same at widths 1 to 8, and equal to the probe run alone. It passes on MI355X on the ROCm 10 main nightly.

Speed Tests and Profiling

The numbers in this section are for the head kernels, #60833 3346929b27. amd/Qwen3.8-2.4T-A95B-Quark-MXFP4 ran on one 8x MI355X node, TP8, on main, here the ROCm nightly of 2026-10-09 with this branch's files mounted in both arms. The load is bench_serving random, range ratio 0.8, with the same seeds in both arms and one short warm-up cell first. Both servers use the aiter attention backend at page size 16, FSE off and a bf16 SSM state, and only the flag differs. They ran on the same node, back to back.

Cell (prompts) Median TPOT off / on (ms) Change Output tok/s off / on Change
8k/1k c1 (8) 10.88 / 6.86 -37.0% 89.3 / 139.2 +56.0%
8k/1k c2 (16) 12.10 / 8.21 -32.1% 158.2 / 230.4 +45.6%
8k/1k c4 (32) 14.42 / 10.20 -29.3% 265.9 / 372.7 +40.2%
8k/1k c8 (64) 17.08 / 14.37 -15.9% 446.8 / 530.4 +18.7%
8k/1k c16 (96), 16 rows: stock path 23.59 / 23.55 -0.1% 650.7 / 655.4 +0.7%
60k/600 c4 (32) 25.77 / 21.52 -16.5% 132.1 / 154.0 +16.6%

c16 decode steps have more than 8 rows, so they take the stock layers, and that row is the noise floor. TTFT does not change, because prefill is stock.

GSM8K on the same servers, 5-shot, all 1319 questions, lm_eval local-completions at concurrency 8, shows no difference. Flexible-extract is 0.8491 off against 0.8582 on, paired McNemar p = 0.36. Strict-match is 0.8370 against 0.8476. RULER niah_single_2 at concurrency 8 scores 0.994 / 0.996 off and 0.992 / 0.998 on, at 64k / 128k.

By default on main, this checkpoint runs without shared-expert fusion and with an fp32 SSM state, so a default server meets the K2 requirements as it is. These runs set --mamba-ssm-dtype bfloat16 in both arms.

MTP

With speculative decoding on, K1 is off and K2 runs alone on the target-verify steps. GDN layers run SGLang's own input projection and core, then K2 runs out_proj and the MoE. K1 cannot run there, because it has no per-draft-token state for the SSM rollback. NEXTN runs 3 draft steps with top-k 1, so a verify step has 4 rows per request, one for each of the 4 draft tokens. Mono covers only c1 with 4 rows and c2 with 8 rows. The K1 requirements on the SSM state dtype and the ReplaySSM ring do not apply then.

The MTP A/B uses the same setup plus --speculative-num-steps 3 --speculative-eagle-topk 1 --speculative-num-draft-tokens 4, so the reference is the same server without the flag.

Cell (prompts) Median TPOT off / on (ms) Change Output tok/s off / on Change
8k/1k c1 (8) 3.87 / 2.88 -25.7% 237.8 / 312.1 +31.2%
8k/1k c2 (16) 4.64 / 3.82 -17.7% 391.2 / 463.9 +18.6%
8k/1k c4 (32), 16 rows: stock path 6.27 / 6.27 flat 590.3 / 591.9 +0.3%
60k/600 c1 (8) 3.95 / 2.97 -24.9% 114.4 / 129.3 +13.0%

The accept length is the same in both arms, 3.62-3.68. GSM8K at concurrency 2 on the same servers shows no difference. Flexible-extract is 0.8597 off against 0.8567 on, paired McNemar p = 0.82. Strict-match is 0.8438 against 0.8446.

Earlier kernels

The first A/Bs used the #60833 f3c2ec988b kernels. Their tables stay here for reference.

The table below compares the first kernels, f3c2ec988b, with the next #60833 kernels, 6a1c13b2fc. Both arms ran on one MI355X node on main, the ROCm nightly of 2026-10-09 with this branch's files, with a bf16 SSM state and the flag on.

Cell Median TPOT earlier / new kernels (ms) Change Output tok/s earlier / new Change
8k/1k c1 7.77 / 6.88 -11.5% 123.4 / 138.0 +11.8%
8k/1k c2 9.29 / 8.26 -11.1% 203.6 / 227.6 +11.8%
8k/1k c4 12.04 / 10.33 -14.2% 317.0 / 368.5 +16.3%
8k/1k c8 16.56 / 14.50 -12.4% 443.0 / 516.9 +16.7%
8k/1k c16, stock path 23.90 / 23.88 flat 643.3 / 645.7 flat
60k/600 c4 23.93 / 22.16 -7.4% 139.9 / 148.8 +6.4%
MTP 8k/1k c1 3.26 / 2.90 -11.0% 277.8 / 308.3 +10.9%
MTP 8k/1k c2 4.30 / 3.78 -12.1% 418.9 / 469.5 +12.1%

The whole gain is in K2. In a profile at one row, a K2 launch takes 39.2 us against 50.0 us before. K1 alone measures the same as before. GSM8K paired per question, earlier against new kernels, shows no difference. Flexible-extract is 0.8423 / 0.8537 (p = 0.26) without MTP and 0.8393 / 0.8506 (p = 0.27) with MTP. Strict-match gives p = 0.88 and 0.94.

The first A/Bs ran on a v0.5.21-based ROCm image with the same change and the f3c2ec988b kernels. That image has identical glue, and the qwen3_5.py hunks on its v0.5.21 file. I repeated both A/Bs on main, and the results agree.

amd/Qwen3.8-2.4T-A95B-Quark-MXFP4, 8x MI355X, TP8, no MTP, bench_serving random, range ratio 0.8, the same seeds in both arms. Both servers have FSE off and an fp32 SSM state, and only the flag differs. They ran on the same node, back to back.

Cell (prompts) Median TPOT off / on (ms) Change Output tok/s off / on Change
8k/1k c1 (8) 10.66 / 7.65 -28.2% 91.2 / 125.9 +38.0%
8k/1k c2 (16) 11.68 / 9.12 -21.9% 163.8 / 208.3 +27.2%
8k/1k c4 (32), first cell 14.20 / 11.97 -15.7% 265.8 / 265.7 flat, see below
8k/1k c4 (32), warm server 14.18 / 11.91 -16.0% 270.6 / 321.4 +18.8%
8k/1k c8 (64) 17.51 / 16.39 -6.4% 437.6 / 469.1 +7.2%
8k/1k c16 (96), 16 rows: stock path 23.34 / 23.13 -0.9% 656.9 / 664.3 +1.1%
60k/600 c4 (32) 25.34 / 23.07 -9.0% 134.1 / 145.5 +8.5%

c16 decode steps have more than 8 rows, so they take the stock layers, and that row is the noise floor. TTFT does not change, because prefill is stock.

The first c4 cell is flat because of a one-time stall that this PR does not cause. Every server pays 15-40 s on its first prefills, flag on or off. The flag-off server happened to pay it during its startup warm-up request. The stall lines up with first-use JIT compiles on the GDN prefill path. The warm-server row runs one short c4 warm-up cell first. There, Max ITL is 726 ms off and 721 ms on, and the throughput gain matches the TPOT gain.

The same A/B on main ran on the same node as above, with the ROCm nightly of 2026-10-09, this branch's files mounted in both arms and one warm-up cell first.

Cell (prompts) Median TPOT off / on (ms) Change Output tok/s off / on Change
8k/1k c1 (8) 10.99 / 7.76 -29.4% 88.5 / 123.6 +39.7%
8k/1k c2 (16) 12.25 / 9.25 -24.5% 156.4 / 205.7 +31.5%
8k/1k c4 (32) 14.63 / 12.05 -17.6% 262.3 / 317.6 +21.1%
8k/1k c8 (64) 17.30 / 16.48 -4.7% 441.2 / 466.6 +5.7%
8k/1k c16 (96), 16 rows: stock path 23.84 / 23.92 +0.3% 643.9 / 644.1 flat
60k/600 c4 (32) 25.95 / 23.38 -9.9% 131.2 / 143.8 +9.5%

GSM8K on main with the same servers shows no difference. Flexible-extract is 0.8582 off against 0.8605 on, with 88 questions right only with mono and 85 only without, p = 0.88. Strict-match is 0.8408 against 0.8415, p = 1.0.

MTP with the earlier kernels

Both arms ran on the same node with FSE off and --speculative-num-steps 3 --speculative-eagle-topk 1 --speculative-num-draft-tokens 4, so the reference is the same server without the flag.

Cell Median TPOT off / on (ms) Output tok/s off / on Change
8k/1k c1 3.77 / 3.21 244.5 / 283.3 +15.9%
8k/1k c2 4.56 / 4.39 400.2 / 413.0 +3.2%
8k/1k c4 (16 rows: stock path) 6.05 / 6.01 608.5 / 606.7 flat
60k/600 c1 3.85 / 3.29 117.3 / 125.2 +6.7%

The accept length is the same in both arms, 3.62-3.69. Stock MTP with FSE on gets 3.37 / 4.21 / 5.70 / 3.45 ms TPOT. Its accept length on this random dataset is 3.96-4.00, so its TPOT is not comparable per token. Per verify step, which is TPOT times accept length, K2 saves 14-15% at c1 and 4% at c2 against both.

The same A/B on main ran on the same node, with the ROCm nightly of 2026-10-09 and this branch's files mounted in both arms. The accept length is 3.62-3.69 in both.

Cell Median TPOT off / on (ms) Output tok/s off / on Change
8k/1k c1 3.88 / 3.25 236.9 / 279.7 +18.0%
8k/1k c2 4.62 / 4.29 391.0 / 419.0 +7.1%
8k/1k c4 (16 rows: stock path) 6.31 / 6.28 588.0 / 589.3 flat
60k/600 c1 3.97 / 3.33 114.0 / 123.3 +8.1%

GSM8K at concurrency 2 on main shows no difference. Flexible-extract is 0.8506 off against 0.8499 on, p = 1.0. Strict-match is 0.8385 against 0.8324, p = 0.57.

Checklist

Review and Merge Process

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

CI States

Latest PR Test (Base): ❌ Missing run-ci label -- add it to run CI tests.
Latest PR Test (Extra): ❌ Blocked -- run-ci is required first.
Latest PR Test (AMD ROCm 10): ➖ No AMD PR run found for this commit.

billishyahao and others added 2 commits October 10, 2026 03:26
…layer on MI355X

Port the vllm-project/vllm#60833 kernels. A decode step of at most 8 rows
runs each layer as K1 (GDN front) and K2 (o_proj/out_proj, in-kernel TP
all-reduces, norm, router, MXFP4 experts, shared expert). The full-attention
layers keep SGLang's fused HIP front through a new attention_core().

Builds on the Kimi-K3 mono framework (k3_mono_flydsl common/ and stages/).
Off by default: SGLANG_QWEN3_5_MONO_DECODE=1.

Co-authored-by: Cursor <[email protected]>
Change the launch asserts to need() checks. python -O does not remove them.
Refuse GPUs with fewer than 256 compute units.
Refuse the hierarchical cache and LMCache. Their copy kernels can hold CUs.

Co-authored-by: Cursor <[email protected]>
omirosh and others added 2 commits October 10, 2026 16:34
With speculative decoding, run K2 only on target-verify steps of 8 rows or fewer.
K1 has no per-draft-token state for the rollback, so GDN layers run their own core.
Split the GDN forward into core() and out_proj for this.
Skip the K1 checks under speculative decoding, so the ReplaySSM ring and a bf16 SSM state are allowed.

Co-authored-by: Cursor <[email protected]>
Add the flag to the AMD and ROCm table of the environment variables.
Add a tip to the AMD section of the Qwen3.8 cookbook.

Co-authored-by: Cursor <[email protected]>
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 11, 2026
omirosh and others added 3 commits October 12, 2026 08:43
K1 loads a bf16 state, widens it to fp32 for the recurrence, and
rounds it to bf16 on store. This is what the stock GDN kernel does.
The dtype is part of the K1 build key. The glue passes it and no
longer refuses --mamba-ssm-dtype bfloat16.

Add a test: the bf16 kernel gives the same core, residual and conv
state as the fp32 kernel on the widened state, and the fp32 kernel's
new state rounded to bf16.

Co-authored-by: Cursor <[email protected]>
Copy gdn.py, layer.py and layout.py from vllm-project/vllm#60833 at
6a1c13b2fc. Keep the bf16 SSM state in K1.

The glue passes the per-width speed flags (tuned) to both kernels and
sizes the scratch with them. The weights stay as SGLang loads them:
bf16 dense layers, an unfused shared expert, and the output gate in the
attention layer. So fse, oq, qq and og stay off.

The K1 pad-row test now runs each case with and without the speed
flags and checks that the outputs are bitwise equal.

Co-authored-by: Cursor <[email protected]>
K1 now takes an fp32 or a bf16 SSM state. Say so in the environment variable table and the cookbook. Drop the old advice to remove --mamba-ssm-dtype bfloat16.

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

jhinpan commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

MI355X verification of d9945f4a4c (TP8, no MTP)

Mono decode engages on all 8 ranks. Median TPOT drops 36% at 8k/1k c1, and GSM8K does not change (exact McNemar p = 0.71). Up to c8, flag-off TPOT is within 2% of the description's main table, and flag-on TPOT is within 4% of its new-kernel numbers (those used a bf16 state).

Setup

  • Image rocm/sgl-dev:v0.5.21-rocm720-mi35x-20261009 (sha256:3d9129547126…), with /sgl-workspace/sglang (editable install) checked out at d9945f4a4c. ROCm 7.2.0, torch 2.9.1+rocm7.2.0, Triton 3.7.0 (git89002410), aiter e7d2453f25, flydsl 0.3.4.1.
  • One 8x MI355X node (gfx950, 256 CUs per GPU), host amdgpu 6.16.13. One server on the node at a time, with 8/8 GPUs idle over 30 one-second amd-smi samples before each server.
  • amd/Qwen3.8-2.4T-A95B-Quark-MXFP4, --tp-size 8 --trust-remote-code --mem-fraction-static 0.9 --disable-shared-experts-fusion in both arms. The SSM state is fp32 (the checkpoint's mamba_ssm_dtype), attention is aiter with page size 1, and there is no MTP. Only SGLANG_QWEN3_5_MONO_DECODE=1 differs between arms.

Unit tests: test/registered/amd/test_qwen3_5_mono_decode.py passes 5/5 on one MI355X.

Engagement: all 8 ranks log Qwen3.8 mono decode on for decode steps of <= 8 rows, then step at width 1, 2, 4 and 8 during decode graph capture. No off or skips a decode step message and no error appeared.

Speed: sglang.benchmark.serving, random 8k/1k, range ratio 0.8, seed 1, one warm-up row first. One round: flag off, then flag on, then the default server, back to back on the same node.

Cell (prompts) Median TPOT off / on (ms) Change Output tok/s off / on Change Median TTFT off / on (ms) Median TPOT stock default (ms) Mono vs default
8k/1k c1 (8) 11.21 / 7.13 −36.4% 87.4 / 136.0 +55.5% 170 / 162 11.22 −36.5%
8k/1k c2 (16) 12.30 / 8.29 −32.6% 157.9 / 232.1 +47.0% 328 / 319 12.33 −32.8%
8k/1k c4 (32) 14.35 / 10.05 −30.0% 265.8 / 378.0 +42.2% 332 / 336 14.34 −29.9%
8k/1k c8 (64) 17.47 / 14.27 −18.3% 439.9 / 540.9 +23.0% 388 / 382 17.44 −18.2%
8k/1k c16 (96), wider than 8 rows 22.13 / 22.14 +0.1% 670.7 / 675.5 +0.7% 349 / 357 22.13 +0.0%

The default server (no --disable-shared-experts-fusion, no flag) logs Qwen3.5: shared-expert fusion not supported for this checkpoint (multi-streaming #25885 still applies). Shared experts fusion optimization is disabled. and keeps the fp32 SSM state. It therefore matches the flag-off server within 0.3% on every row, and the flag-on server is faster than the default up to c8. The c8 and c16 cost in the description's "stock default" table (FSE on, bf16 SSM state) does not appear at this branch's base, where the default server already meets both preconditions.

Accuracy: GSM8K, 5-shot, all 1319 questions, greedy, parallel 8, with sglang.test.few_shot_gsm8k rather than lm_eval, so absolute scores differ from the description's: 0.936 with the flag off and 0.939 with it on. Per question, 35 are right only with mono and 31 only without; the exact McNemar p is 0.71. 151/1319 generations are byte-identical. This PR does not claim bit-exactness with the stock path, so I compared per-question correctness instead.

Not covered: MTP (K2 on target-verify steps), the bf16 SSM state end to end (only the unit test covers it), and the ROCm 10 vattn_asm issue: this image is ROCm 7.2 and page size 1 keeps vattn_asm out of the path, so ROCm/aiter#6398 was not exercised.

omirosh and others added 4 commits October 15, 2026 16:41
…0833

Copy K1 and K2 from vllm#60833 3346929b27. Each width and weight layout
now has one schedule. The options that won at every width are always on.
The losing and debug-only paths are removed. The outputs are bitwise the
same as 6a1c13b2fc. The kernel code is about 670 lines shorter.

Keep the bf16 SSM state option in K1. The glue no longer passes tuned().

Co-authored-by: Cursor <[email protected]>
The test keeps one probe row and changes only the other rows of the step.
The probe outputs must be bit-identical at widths 1 to 8, and equal to
the probe alone. ROCm/ATOM#2485 found this fault in the MiniMax-M3 K4.

Co-authored-by: Cursor <[email protected]>
A shared scratch is the vllm#60397 race. It can fail the probe for the
wrong reason.

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

Torch rejects an index write whose source is a view of the same tensor.
@kevin-mii

Copy link
Copy Markdown
Collaborator

Thanks! Since #44353 landed, model monokernels live in sgl-project/sgl-amd-mono and are selected with --monokernel-backend amd, so this should become a Qwen3.8 spec there instead of the SGLANG_QWEN3_5_MONO_DECODE switch and the glue in qwen3_5.py. sgl-project/sgl-amd-mono#6 (GLM-5.3-Flash) is the template.

@omirosh omirosh changed the title [ROCm][Perf] Qwen3.8 mono decode: two persistent FlyDSL launches per layer on MI355X [Perf] [AMD] qwen3.5: Run each Qwen3.8 decode layer as two persistent FlyDSL launches on MI355X Oct 16, 2026
@omirosh

omirosh commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @kevin-mii, agreed. We will port this to sgl-amd-mono as a Qwen3.8 spec, and drop SGLANG_QWEN3_5_MONO_DECODE and the hooks in qwen3_5.py. Thanks also @jhinpan for the independent MI355X run.

The plan for the spec:

Questions:

  1. The forward needs the out_proj / o_proj input. This PR splits Qwen3_5GatedDeltaNet.forward into core() + out_proj, and Qwen3_5AttentionDecoderLayer.self_attention into attention_core() + o_proj, with no behavior change. Is a small SGLang refactor PR with only that split OK? The other way is for the spec to rebuild both cores from _prepare_qkv_gate, attn and the GDN internals, which means more names in SGLANG_READS.
  2. Shared FlyDSL code: our kernels also need stages/gemv.py, sync.shift, plan.KernelAbi, ops.wave_sum, ops.wave_max and ops.block_excl_scan from [AMD] integrate kimi k3 monokernel #43481, which sgl_amd_mono/common does not have yet. Should these go into common/ in one PR before the three specs? We can send it, after we agree with @billishyahao and @vorapolsiloai, and check it against the DeepSeek-V4.1 plugin PRs that @amd-pedghazi plans.
  3. Layout: one qwen38/ package with the MoE and dense specs on shared gfx950/ stages (as vllm#60833 now does with MoeDims / GdnDims), or one package per spec?

amd-oshkarav added a commit to amd-oshkarav/sglang that referenced this pull request Oct 27, 2026
The pull request is stacked on the Kimi-K3 mono framework, which is not on main, so that framework comes with it. Main has since replaced the K3 attention-residual forward, so the MoE launch is hooked into the current forward and the old K1/K2 dispatch is not brought back.

Co-authored-by: Cursor <[email protected]>
amd-oshkarav added a commit to amd-oshkarav/sglang that referenced this pull request Oct 27, 2026
The pull request is stacked on the Kimi-K3 mono framework, which is not on main, so that framework comes with it. Main has since replaced the K3 attention-residual forward, so the MoE launch is hooked into the current forward and the old K1/K2 dispatch is not brought back.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Oct 29, 2026
…glang#43839

Since sglang#43839, SGLang quantizes in_proj_qkvz and out_proj of the GDN
layers to MXFP4 while it loads (SGLANG_ROCM_GDN_ONLINE_MXFP4, on by default
with SGLANG_USE_AITER=1 on gfx95x). The weights go through shuffle_weight
(16, 16), and the scales through shuffle_scale.

- K1 qq reads the MXFP4 in_proj_qkvz (ABI arg w_qkvzs).
- K2 oq reads the MXFP4 out_proj (ABI arg w_os). It quantizes the core rows
  to MXFP4 (RCEIL), as SGLang's GEMM quantizes its input.
- The FP4 GEMV helpers fp4_gemv, fp4_gemv_loads and quant_x come back. K1
  imports them from K2.

The spec builds K1 and K2 for each projection dtype that the model has. It
does not refuse the MXFP4 GDN projections now. Thus the test server and the
README command do not set SGLANG_ROCM_GDN_ONLINE_MXFP4=0. The check-mode
e2e test asserts that SGLang quantized the projections.

With this commit, the kernels have all the variants of the port of
sgl-project/sglang#43516.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Oct 30, 2026
…glang#43839

Since sglang#43839, SGLang quantizes in_proj_qkvz and out_proj of the GDN
layers to MXFP4 while it loads (SGLANG_ROCM_GDN_ONLINE_MXFP4, on by default
with SGLANG_USE_AITER=1 on gfx95x). The weights go through shuffle_weight
(16, 16), and the scales through shuffle_scale.

- K1 qq reads the MXFP4 in_proj_qkvz (ABI arg w_qkvzs).
- K2 oq reads the MXFP4 out_proj (ABI arg w_os). It quantizes the core rows
  to MXFP4 (RCEIL), as SGLang's GEMM quantizes its input.
- The FP4 GEMV helpers fp4_gemv, fp4_gemv_loads and quant_x come back. K1
  imports them from K2.

The spec builds K1 and K2 for each projection dtype that the model has. It
does not refuse the MXFP4 GDN projections now. Thus the test server and the
README command do not set SGLANG_ROCM_GDN_ONLINE_MXFP4=0. The check-mode
e2e test asserts that SGLang quantized the projections.

With this commit, the kernels have all the variants of the port of
sgl-project/sglang#43516.

Co-authored-by: Cursor <[email protected]>
@omirosh omirosh closed this Nov 4, 2026
HaiShaw pushed a commit to sgl-project/sgl-amd-mono that referenced this pull request Nov 12, 2026
…ne K2 launch (#83)

Part 1 of 5 of the split of #16.

## Motivation

Qwen3.8-2.4T-A95B (`amd/Qwen3.8-2.4T-A95B-Quark-MXFP4`) has 92 decoder
layers. Each layer has attention or Gated DeltaNet (GDN, a linear
attention), then a sparse MoE. The MoE has a router that picks 10 of 512
MXFP4 experts, and one bf16 shared expert. In a decode step of 1 to 8
rows, SGLang runs the layer tail after the attention as many small
launches and two TP all-reduces. At these batch sizes, the launches and
the waits take most of the step time.

This PR runs the tail of each layer as one persistent launch, K2, on
each of the 8 ranks. The kernels are the K2 kernels of
sgl-project/sglang#43516 (at `51b0c592b2`), which adapts them from
vllm-project/vllm#60833. This PR moves them into the plugin (RFC
sgl-project/sglang#43949), with two differences:

- Each wait on another workgroup or GPU has a deadline. A failed wait
stops the launch on every rank, and the server stops without tokens from
that step.
- This PR leaves out the fused shared expert (`fse`) and MXFP4 out_proj
(`oq`) variants. The spec refuses those configurations at startup.

Since sgl-project/sglang#43839, SGLang quantizes the GDN projections to
MXFP4 by default. K2 reads out_proj in bf16, so start the server with
`SGLANG_ROCM_GDN_ONLINE_MXFP4=0`.

Later PRs add the MTP verify steps, K1 (the attention and GDN front of a
layer), the fused shared expert and the MXFP4 GDN projections.

## Modifications

| Area | Change |
| --- | --- |
| `qwen38_a95b_mxfp4/spec.py` | Adds the spec, its forward and its
refusals. The spec covers the decode steps of 1 to 8 rows at TP8 on
gfx950. SGLang runs the input norm and the attention or GDN, up to the
projection input. Then one K2 launch runs the rest of the layer:
out_proj (o_proj on the attention layers) and its all-reduce, the
post-attention norm, the router, the shared and routed experts, and the
MoE all-reduce. Other steps run SGLang's path. |
| `qwen38_a95b_mxfp4/gfx950/` | Adds the K2 kernels (`layer.py`), the
Kimi-K3 helpers that they use (`_k3.py`, by way of
sgl-project/sglang#43481) and the MoE weight layout (`layout.py`). Each
of the 8 build keys (widths 1 to 8) builds one kernel. A server builds
only the widths of its CUDA graphs. With the test flags, these are 1, 2,
4 and 8. |
| `qwen38_a95b_mxfp4/check.py` | Adds check mode
(`SGLANG_AMD_MONO_CHECK=1`). Check mode runs SGLang's own layer code
next to each K2 launch and compares the outputs. The spec's `NUMERICS`
threshold is `k2.out.cosine` ≥ 0.99. |
| `sgl_amd_mono/__init__.py` | Registers the spec in `SPECS`. |
| Tests | Adds the model's tests in `test/unit`, `test/kernels` and
`test/e2e` (results below). |
| `README.md`, `NOTICE` | `README.md` adds the model row, the design
text, the `SGLANG_ROCM_GDN_ONLINE_MXFP4=0` requirement and a usage
command. `NOTICE` names the origins of the adapted code. |

**Refusals.** The server stops at startup, with the reason in the log,
for each of these configurations:

- the fused shared expert (`--enforce-shared-experts-fusion`);
- the MXFP4 GDN projections (`SGLANG_ROCM_GDN_ONLINE_MXFP4` not `0`);
- speculative decoding, such as MTP (the spec does not accept the
feature, so SGLang's monokernel guard refuses it);
- a model config that does not match Qwen3.8 in `HF_CONFIG` (the hidden
size, the GDN heads, the experts, the top-k, the expert sizes or SiLU);
- a config without `norm_topk_prob`;
- more layers than the mailbox tags hold;
- a layer whose norm, router, shared expert, o_proj or out_proj is not
bf16;
- routed experts that are not MXFP4 in AITER's shuffled layout;
- an image without FlyDSL.

The kernels read SGLang's weights in place and make no weight copies.
Each rank allocates one peer buffer, and one scratch buffer for each
width.

K2 does not replace SGLang's attention, GDN, embedding, final norm or
logits processor. 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#43839, with no unmerged SGLang PR |
| AITER, FlyDSL | `285579b6211b0da30f35b91a890c29c823597cd1`, 0.4.0 |
| Model revision | `13dc9676cdd9e2374c3efb50389d3392b975acae` |
| Server flags | `test/e2e/qwen38_a95b_mxfp4_server.py`. The
monokernel-on servers add `--monokernel-backend amd`. |
| Branch commit | `b0c3818` (tag `q38v3-tested/1-k2`). The head
`3daea98` is rebased onto `main` at `b10f3b7`. Its model code and tests
differ from that commit only in the text of a comment, a docstring and a
skip message. The test runs used the old base `0aa9749`, before #76
changed `PeerBuffer.close()`. |

The port test (`check_port.py`) compares 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, 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. It sends 8 concurrent requests, so the decode
steps take the 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 | 1291 (0.9788) | 1289 (0.9773) | 10 | 8 | 0.815 |
| strict-match | 1141 (0.8650) | 1143 (0.8666) | 103 | 105 | 0.945 |

The arms differ by 2 questions on each filter, and McNemar's test finds
no accuracy difference. Strict-match scores lower in both arms because
of the answer format. In the off arm, all 151 questions that pass
flexible-extract and fail strict-match have no `#### N` line. Their
answers end in other forms, such as `**Answer: 45**`.

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

These runs use `3daea98` 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. 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 its own 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 | 93.43 ± 3.20 | 92.68
± 3.24 | 92.6 |

Over the 198 paired questions, on minus off is -0.76 points, with a 95%
interval of ±1.10. Five questions score higher with the monokernels on,
and nine with them off. The sign test gives p 0.424 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 5 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
logs has 1 to 8 running requests, so the decode steps take the 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%) | 48 of 50 (96%) |
| Agent timeouts | 3 | 0 |
| Median agent time per task | 18.2 min | 15.1 min |

Over the 50 paired tasks, 3 pass only with the monokernels on and 1 only
with them off. McNemar's exact test gives p 0.625 and finds no
difference. One of the 3 is an infrastructure failure in the off arm.
There, `docker compose` failed in the environment setup, and the agent
did not start. In the task that passes only with the monokernels off,
the `claude` process of the on arm was killed ("Killed") and left no
patch.

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

### Kernel checks (`test/kernels`, 8 GPUs, TP8)

| Check | Result |
| --- | --- |
| The MoE weight layout (the w13 and w2 tiles and the scales) | Equal to
SGLang's layout |
| Compile every build key (widths 1 to 8) on every rank | All 8 keys
compile |
| Batch invariance on random TP8 shards. A row's `out` and `res_out` do
not change with the other rows or the width. | 57 cases pass, and the
ranks agree |
| Graph replay of widths 8, 1, 3, 8, 2, 5 in one graph on one peer
buffer | 200 replays are bit for bit equal to eager mode, and the ranks
agree |
| Fault: rank 3 stalls at its first wait | Rank 3 sets its deadline
flag, the flag reaches every rank, and the launch returns in 0.52 s |
| Port test: `out` and `res_out` against the sgl-project/sglang#43516
kernels, at widths 1 to 8 on every rank | Bit for bit equal |

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 (200, the e2e test) | Highest mean
KL (2, 3, 7, 8 rows) | Rows that check mode skipped | Lowest
`k2.out.cosine` |
| --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | 12 passed | 5 passed | 4 passed | 0.970 | 0.0118 | 1 of 3956 |
0.999897 |
| 2 | 12 passed | 5 passed | 4 passed | 0.975 | 0.0179 | 0 of 3956 |
0.998428 |
| 3 | 12 passed | 5 passed | 4 passed | 0.975 | 0.0107 | 0 of 3956 |
0.999738 |

Each run gave the kernel check results above. `k2.res_out.cosine` is 1
in all 4416 checks (3 runs of 1472).

The e2e tests are:

- GSM8K: 200 questions at 12 concurrent requests, with thinking, at
temperature 1.0. The batch grows past 8 rows as it fills, and drops
below 8 rows as it drains.
- Prefill match: at 2, 3, 7 and 8 rows, the KL divergence of the decode
logprobs against prefill is below 0.06.
- Check mode: each K2 layer output is within `NUMERICS`.
- Fault injection: after 100 steps, rank 1 stalls at its first wait. At
the deadline, every rank stops, and the server returns no tokens from
that step.

The check-mode test runs without CUDA graphs, at 1, 3 and 8 rows, with
1472 checks in each run. In rare rows, K2 and SGLang pick a different
10th expert, because two experts score within one bf16 step. Check mode
skips those rows for the layer output and counts them. The test fails if
it skips more than 1% of the rows.

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 GSM8K and speed servers use the flags
and environment of `test/e2e/qwen38_a95b_mxfp4_server.py`, plus
`--tool-call-parser qwen3_coder` and `--watchdog-timeout 12000`. On each
rank, the monokernel-on servers log "Qwen3.8 monokernel: 4 K2 launches
(widths [1, 2, 4, 8])".

| 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 | 11.06, 11.04 | 7.46, 7.46 | 90.5, 134.0 | 1.48× | 0.2% |
| 2 | 11.61, 11.58 | 8.69, 8.69 | 86.2, 115.1 | 1.33× | 0.3% |
| 4 | 13.79, 13.76 | 10.41, 10.41 | 72.6, 96.1 | 1.32× | 0.2% |
| 8 | 17.38, 17.34 | 14.91, 14.89 | 57.6, 67.1 | 1.17× | 0.2% |
| 16 (past the largest width) | 23.39, 23.35 | 23.34, 23.39 | 42.8, 42.8
| 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.
- 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.

**Registers.** The table comes from a compile-only build of the 8 K2
build keys at `7c038cb` (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
`stop=True / stop=False`.

| Width | VGPR | VGPR spill | SGPR spill | LDS (bytes) | Scratch (bytes)
|
| --- | --- | --- | --- | --- | --- |
| 1 | 203 | 0 | 22 / 123 | 27616 | 0 |
| 2 | 203 / 205 | 0 | 65 / 26 | 46176 | 0 |
| 3 | 209 | 0 | 23 / 27 | 62656 | 0 |
| 4 | 213 | 0 | 26 / 29 | 79136 | 0 |
| 5 | 209 | 0 | 22 / 27 | 95616 | 0 |
| 6 | 219 | 0 | 23 / 27 | 112096 | 0 |
| 7 | 213 | 0 | 23 / 28 | 128576 | 0 |
| 8 | 221 | 0 | 26 | 145056 | 0 |

- No 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,056 of gfx950's 163,840 bytes at 8
rows.

**Kernels before and after.** The table compares one decode step at
batch 1 in two TP-0 profiles: monokernels off and monokernels on. Both
servers ran the head `3daea98` 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.

### Kernel Replacement (layer tail, decode bs=1)
| 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.0 | One
`qwen38_mono_k2_s1_a0` launch for each layer: 92 calls per step, 39.8 µs
each |
| The all-reduce after out_proj | `aiter::ar_ll_gfx9` | 92 | 7.6 | In K2
|
| The post-attention norm | `_gemma_fused_add_rmsnorm_kernel` | 92 | 4.3
| In K2 |
| The shared expert gate_up | `aiter::wv_splitk_small_fp16_bf16_kernel`
| 92 | 8.0 | In K2 |
| The shared expert SiLU and mul |
`sgl_hip::activation::act_and_mul_kernel` | 92 | 4.3 | In K2 |
| The shared expert down | `_gemm_a16_w16_kernel`
(`SPLITK_BLOCK_SIZE_256`) | 92 | 4.1 | In K2 |
| The router | `aiter::wv_splitk_small_fp16_bf16_kernel` | 92 | 8.0 | In
K2 |
| The top-k | `vllm::moe::topkGatingSoftmax` | 92 | 9.8 | In K2 |
| The routed experts |
`aiter::fmoe_bf16_pertokenMXfp4_g1u1_flat_vs_silu_16x32` | 92 | 19.2 |
In K2 |
| The shared expert gate, sigmoid and add |
`_fused_gate_sigmoid_mul_add_kernel` | 92 | 4.2 | In K2 |
| The MoE all-reduce | `aiter::ar_ll_gfx9` | 92 | 6.8 | In K2 |
| The step epoch of the K2 waits | None | | | One
`CUDAFunctorOnSelf_add<int>` per step (`self.epoch[:1].add_(1)` in
`spec.py`) |

| Before | Time (us) | After | Time (us) |
| --- | ---: | --- | ---: |
| `_gemm_a16_w16_kernel` (SPLITK_BLOCK_SIZE_2048, out_proj / o_proj,
×92) | 8.0 | `qwen38_mono_k2_s1_a0` (×92) | 39.8 |
| `aiter::ar_ll_gfx9` (all-reduce after out_proj, ×92) | 7.6 | (in K2) |
-- |
| `_gemma_fused_add_rmsnorm_kernel` (×92) | 4.3 | (in K2) | -- |
| `aiter::wv_splitk_small_fp16_bf16_kernel` (shared expert gate_up, ×92)
| 8.0 | (in K2) | -- |
| `sgl_hip::activation::act_and_mul_kernel` (×92) | 4.3 | (in K2) | -- |
| `_gemm_a16_w16_kernel` (SPLITK_BLOCK_SIZE_256, shared expert down,
×92) | 4.1 | (in K2) | -- |
| `aiter::wv_splitk_small_fp16_bf16_kernel` (router, ×92) | 8.0 | (in
K2) | -- |
| `vllm::moe::topkGatingSoftmax` (×92) | 9.8 | (in K2) | -- |
| `aiter::fmoe_bf16_pertokenMXfp4_g1u1_flat_vs_silu_16x32` (×92) | 19.2
| (in K2) | -- |
| `_fused_gate_sigmoid_mul_add_kernel` (×92) | 4.2 | (in K2) | -- |
| `aiter::ar_ll_gfx9` (MoE all-reduce, ×92) | 6.8 | (in K2) | -- |
| | | `CUDAFunctorOnSelf_add<int>` (×1 per step) | -- |
| **Total** | **84.3** | **Total** | **39.8 (52.8% reduce)** |

- The 11 kernels of a layer tail take 84.3 µs together. K2 takes 39.8
µs.
- The step falls from 1669 to 750 kernels, and from 12.14 to 8.11 ms of
kernel time.
- SGLang still runs the embedding and its all-reduce, the input norms,
the GDN or attention, the final norm, the LM head and the sampling.
- Each screenshot selects one `step[DECODE bs=1]` slice and shows only
its kernels (filter `Category = kernel`).

Before (monokernels off), one decode step:
<img width="1928" height="1172" alt="image"
src="https://github.com/user-attachments/assets/977c336a-1228-4c3a-b711-e49b525828ce"
/>


After (monokernels on), one decode step: 
<img width="1928" height="1172" alt="image"
src="https://github.com/user-attachments/assets/ccac7f6b-a326-4b25-b354-cf741bc899f8"
/>

E2E: 12.14 ms => 8.103 ms,33.3% reduce


## 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 16, 2026
)

Part 2 of 5 of the split of
[sgl-amd-mono#16](#16).
[sgl-amd-mono#83](#83)
merged, and this PR is rebased onto `main`. The diff shows only the code
commit `22c7f25` and the README commit `cac4a8e`.

## Motivation

Qwen3.8-2.4T-A95B has an MTP layer, and SGLang runs it as NEXTN
speculative decoding. With NEXTN, each decode step of the target model
is a verify step. A verify step scores the last accepted token and the
draft tokens of each request. With 3 draft steps, a verify step has 4
rows for each request.

#83 runs each decoder layer's tail as one K2 launch in decode steps of 1
to 8 rows. Its spec does not accept speculative decoding, so SGLang
refuses `--monokernel-backend amd` with NEXTN.

This PR lets the spec serve the verify steps of 1 and 2 requests (4 and
8 rows) with the same K2 launch. The K2 kernels do not change. K2 takes
1 to 8 rows, and a draft token is one row, like a decode token.

## Modifications

| Area | Change |
| --- | --- |
| `qwen38_a95b_mxfp4/spec.py` | Accepts the `SPECULATIVE_DECODING`
feature. A verify step runs the same way as a decode step, on its draft
tokens. Adds a refusal for a draft that is not one chain (see below).
Adds the four speculative server args to `SGLANG_READS`. |
| `test/e2e/qwen38_a95b_mxfp4_server.py` | Adds `NEXTN`, the NEXTN flags
as benchmarked: 3 steps, top-k 1, 4 draft tokens and
`--enable-linear-replayssm-spec`. |
| `test/e2e/test_qwen38_a95b_mxfp4_server.py` | Adds
`TestMonokernelVerify`. It runs GSM8K at 4 concurrent requests on a
NEXTN server. The verify steps then have 4 to 16 rows, and K2 serves the
steps of up to 8 rows. |
| `test/unit/test_qwen38_a95b_mxfp4_spec.py` | Checks that NEXTN 3/1/4
gives no refusal, and that top-k 4 gives the one-chain refusal. |
| `README.md` | The model row names the NEXTN verify steps. |
| `sgl_amd_mono/qwen38_a95b_mxfp4/README.md` | The README commit adds
the NEXTN verify steps to the folder README of #83. |

**Refusal.** The server stops at startup if `--speculative-eagle-topk`
is not 1, or if `--speculative-num-draft-tokens` is not
`--speculative-num-steps` + 1. K2's verify step takes one chain of draft
tokens for each request, not a draft tree.

With NEXTN 3/1/4 and the test CUDA graphs, each rank builds two K2
kernels, for widths 4 and 8. Each rank logs "Qwen3.8 monokernel: 2 K2
launches (widths [4, 8])". The draft model (`Qwen3_5ForCausalLMMTP`) has
no spec, so it runs SGLang's path.

This PR does not change the K2 kernels, check mode, `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#43839, with no unmerged SGLang PR |
| AITER, FlyDSL | `285579b6211b0da30f35b91a890c29c823597cd1`, 0.4.0 |
| Model revision | `13dc9676cdd9e2374c3efb50389d3392b975acae` |
| Server flags | `ARGS` and `NEXTN` of
`test/e2e/qwen38_a95b_mxfp4_server.py`. The monokernel-on servers add
`--monokernel-backend amd`. |
| Branch commit | `2dd4b2c` (tag `q38v3-tested/2-verify`). The head
`cac4a8e` is rebased onto `main` at `572ddf1`, the merge of
[sgl-amd-mono#83](#83).
Its model code and tests differ from that commit only in the text of a
comment, 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 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 NEXTN, 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. It sends 2 concurrent requests, so the verify
steps have 4 or 8 rows and take the 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 | 1285 (0.9742) | 1286 (0.9750) | 8 | 9 | 1.000 |
| strict-match | 1138 (0.8628) | 1114 (0.8446) | 114 | 90 | 0.107 |

The arms differ by 1 question on flexible-extract, and McNemar's test
finds no accuracy difference. Strict-match is 24 questions lower with
the monokernels on (p 0.107, not significant).

Strict-match needs a `#### N` line. Of the answers that flexible-extract
finds right, 173 have no `#### N` line in the on arm, and 147 in the off
arm. Most of them end in `**Answer: N**` instead (94 and 81), for
example `**Answer: 20**`. So the strict-match gap is in the answer
format, not in the answers.

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

These runs use the code commit `bd756b1` 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. 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.

A verify step has 4 rows for each request, so both tests send at most 2
requests at a time. In the server logs, each decode batch has 1 or 2
running requests, so the verify steps have 4 or 8 rows and take the K2
path. The mean accept length in the server logs is 2.75 in both GPQA
arms. In the SWE-bench arms, it is 3.17 with the monokernels off and
3.19 with them on.

#### 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 2 concurrent requests.

| | Monokernels off | Monokernels on | Model card |
| --- | --- | --- | --- |
| avg@4, with the 95% interval over the questions | 91.92 ± 3.50 | 92.80
± 3.24 | 92.6 |

Over the 198 paired questions, on minus off is +0.88 points, with a 95%
interval of ±1.18. Ten questions score higher with the monokernels on,
and five with them off. The sign test gives p 0.302 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, 2 of the 792 samples stop at the 131072-token cap, and 1 does 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, 2 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). 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%) | 45 of 50 (90%) |
| Agent timeouts | 0 | 1 |

Over the 50 paired tasks, 2 pass only with the monokernels off, and none
only with them on. McNemar's exact test gives p 0.500 and finds no
difference. In both of these tasks, the agent of the on arm ended
without an error, and its patch failed the tests. The task with the
timeout passes in both arms.

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
3 and 1, and p is 0.625.

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

### Three runs of all tests

This PR changes no kernel. The kernel checks of #83 run again in each
run below.

| Run | unit | kernels | e2e | GSM8K decode (200) | GSM8K NEXTN (200) |
Highest mean KL (2, 3, 7, 8 rows) | Rows that check mode skipped |
Lowest `k2.out.cosine` |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | 12 passed | 5 passed | 5 passed | 0.975 | 0.975 | 0.0172 | 0 of
3956 | 0.999613 |
| 2 | 12 passed | 5 passed | 5 passed | 0.985 | 0.980 | 0.0122 | 0 of
3956 | 0.999874 |
| 3 | 12 passed | 5 passed | 5 passed | 0.980 | 0.985 | 0.0144 | 4 of
3956 | 0.999136 |

`k2.res_out.cosine` is at least 0.999999 in all 4416 checks (3 runs of
1472).

The e2e tests are the four tests of #83 and `TestMonokernelVerify`:

- GSM8K decode: 200 questions at 12 concurrent requests, without NEXTN.
- GSM8K NEXTN (`TestMonokernelVerify`): 200 questions at 4 concurrent
requests, with NEXTN 3/1/4. The verify steps have 4 to 16 rows.
- Prefill match: at 2, 3, 7 and 8 rows, the KL divergence of the decode
logprobs against prefill is below 0.06.
- Check mode: each K2 layer output is within `NUMERICS`. The test fails
if check mode skips more than 1% of the rows.
- Fault injection: after 100 steps, rank 1 stalls at its first wait. At
the deadline, every rank stops, and the server returns no tokens from
that step.

The prefill-match, check-mode and fault tests use servers without NEXTN.
Only the NEXTN GSM8K test and the GSM8K comparison above run verify
steps through K2.

The tests do not cover TP4 or MI350X, because the spec serves only TP8
on MI355X. They do not cover a draft tree (top-k above 1), because the
spec refuses it.

## 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` with `NEXTN`, plus
`--tool-call-parser qwen3_coder` and `--watchdog-timeout 12000`.

A verify step has 4 rows for each request, so K2 serves concurrency 1
and 2. Concurrency 4 and up is past the largest width.

| 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 | Accept
length, off and on | Speedup | Spread between rounds |
| --- | --- | --- | --- | --- | --- | --- |
| 1 | 3.66, 3.65 | 2.79, 2.81 | 273.6, 357.1 | 4.00, 4.00 | 1.31× | 0.7%
|
| 2 | 4.47, 4.50 | 3.83, 3.83 | 223.0, 261.1 | 3.99, 3.99 | 1.17× | 0.7%
|
| 4 (past the largest width) | 6.06, 6.04 | 6.06, 6.06 | 165.3, 165.0 |
3.99, 3.99 | 1.00× | 0.3% |
| 8 | 8.11, 8.12 | 8.14, 8.14 | 123.2, 122.9 | 3.97, 3.97 | 1.00× | 0.1%
|
| 16 | 11.38, 11.44 | 11.39, 11.44 | 87.6, 87.6 | 3.98, 3.98 | 1.00× |
0.5% |

- The speedup uses the mean of the two rounds.
- The spread is the largest difference between the two rounds of one
arm.
- The accept length comes from the round 2 servers. Round 1 runs GSM8K
after the first cell, and the bench's accept length counts from the
server start.
- The monokernels do not change the accept length.
- At concurrency 8, the on arm is 0.3% slower than the off arm, more
than the 0.1% spread. At concurrency 4 and 16, the difference (0.2% and
0.0%) is inside the spread. These steps run SGLang's path.
- On each rank, the monokernel-on servers log "Qwen3.8 monokernel: 2 K2
launches (widths [4, 8])".

**Registers.** Not applicable: this PR changes no kernel. A compile-only
build of the K2 build keys at `0e3c283` (the head before the rebase,
with the same kernel code) gives the same VGPR, spill, LDS and scratch
numbers as #83.

**Kernels before and after.** The table compares one verify step of 1
request (4 rows) in two TP-0 profiles: monokernels off and monokernels
on. Both servers ran the head `bd756b1` with `NEXTN` on one node with 8×
MI355X. The prompt has 8192 tokens, and the output has 100 tokens. The
counts come from the `step[VERIFY bs=1]` slices on the GPU stream. All
16 verify steps after the first 10 have the same counts. Each time is
the mean of these 16 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.3 | One
`qwen38_mono_k2_s4_a0` launch for each layer: 92 calls per step, 55.2 µs
each |
| The all-reduce after out_proj | `aiter::ar_ll_gfx9` | 92 | 9.9 | In K2
|
| The post-attention norm | `_gemma_fused_add_rmsnorm_kernel` | 92 | 4.5
| In K2 |
| The shared expert gate_up | `Cijk_Alik_Bljk_…_MT16x16x128_…`, then
`Cijk_SB_BiasS_HAS_ScaleAlphaVec_PostGSU8_VW1` | 92 + 92 | 4.4 + 4.3 |
In K2 |
| The shared expert SiLU and mul |
`sgl_hip::activation::act_and_mul_kernel` | 92 | 4.4 | In K2 |
| The shared expert down | `_gemm_a16_w16_kernel`
(`SPLITK_BLOCK_SIZE_256`) | 92 | 4.4 | In K2 |
| The router | `Cijk_Alik_Bljk_…_MT16x16x128_…`, then
`Cijk_SB_BiasS_HAS_ScaleAlphaVec_PostGSU8_VW1` | 92 + 92 | 4.4 + 4.3 |
In K2 |
| The top-k | `vllm::moe::topkGatingSoftmax` | 92 | 9.1 | In K2 |
| The routed experts |
`aiter::fmoe_bf16_pertokenMXfp4_g1u1_flat_vs_silu_16x32` | 92 | 29.8 |
In K2 |
| The shared expert gate, sigmoid and add |
`_fused_gate_sigmoid_mul_add_kernel` | 92 | 4.5 | In K2 |
| The MoE all-reduce | `aiter::ar_ll_gfx9` | 92 | 8.5 | In K2 |
| The step epoch of the K2 waits | None | | | One
`CUDAFunctorOnSelf_add<int>` per step (`self.epoch[:1].add_(1)` in
`spec.py`) |

- At 4 rows, SGLang runs the shared expert gate_up and the router as a
hipBLASLt GEMM and its split-K reduction. At 1 row (#83), it runs
`aiter::wv_splitk_small_fp16_bf16_kernel`.
- The 13 kernels of a layer tail take 100.8 µs together. K2 takes 55.2
µs.
- The verify step falls from 1872 to 769 kernels, and from 14.19 to
10.01 ms of kernel time.
- A full NEXTN cycle falls from 2110 to 1007 kernels, and from 15.93 to
11.79 ms of kernel time. A cycle is one `scheduler.run_batch` slice: the
3 draft steps, the verify step and the draft extend. The draft steps run
SGLang's path in both servers.
- Each screenshot selects one `step[VERIFY bs=1]` slice and shows only
its kernels (filter `Category = kernel`).

Before (monokernels off), one verify step: 
<img width="2089" height="1172" alt="image"
src="https://github.com/user-attachments/assets/2085206e-425b-42e2-b9a0-d45cd8a8eeb6"
/>


After (monokernels on), one verify step: 
<img width="2089" height="1172" alt="image"
src="https://github.com/user-attachments/assets/2e32c4af-9913-4f94-b89e-c252d6712445"
/>



## 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 16, 2026
…glang#43839

Since sglang#43839, SGLang quantizes in_proj_qkvz and out_proj of the GDN
layers to MXFP4 while it loads (SGLANG_ROCM_GDN_ONLINE_MXFP4, on by default
with SGLANG_USE_AITER=1 on gfx95x). The weights go through shuffle_weight
(16, 16), and the scales through shuffle_scale.

- K1 qq reads the MXFP4 in_proj_qkvz (ABI arg w_qkvzs).
- K2 oq reads the MXFP4 out_proj (ABI arg w_os). It quantizes the core rows
  to MXFP4 (RCEIL), as SGLang's GEMM quantizes its input.
- The FP4 GEMV helpers fp4_gemv, fp4_gemv_loads and quant_x come back. K1
  imports them from K2.

The spec builds K1 and K2 for each projection dtype that the model has. It
does not refuse the MXFP4 GDN projections now. Thus the test server and the
README command do not set SGLANG_ROCM_GDN_ONLINE_MXFP4=0. The check-mode
e2e test asserts that SGLang quantized the projections.

With this commit, the kernels have all the variants of the port of
sgl-project/sglang#43516.

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

Since sglang#43839, SGLang quantizes in_proj_qkvz and out_proj of the GDN
layers to MXFP4 while it loads (SGLANG_ROCM_GDN_ONLINE_MXFP4, on by default
with SGLANG_USE_AITER=1 on gfx95x). The weights go through shuffle_weight
(16, 16), and the scales through shuffle_scale.

- K1 qq reads the MXFP4 in_proj_qkvz (ABI arg w_qkvzs).
- K2 oq reads the MXFP4 out_proj (ABI arg w_os). It quantizes the core rows
  to MXFP4 (RCEIL), as SGLang's GEMM quantizes its input.
- The FP4 GEMV helpers fp4_gemv, fp4_gemv_loads and quant_x come back. K1
  imports them from K2.

The spec builds K1 and K2 for each projection dtype that the model has. It
does not refuse the MXFP4 GDN projections now. Thus the test server and the
README command do not set SGLANG_ROCM_GDN_ONLINE_MXFP4=0. The check-mode
e2e test asserts that SGLang quantized the projections.

With this commit, the kernels have all the variants of the port of
sgl-project/sglang#43516.

Co-authored-by: Cursor <[email protected]>
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]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 16, 2026
…glang#43839

Since sglang#43839, SGLang quantizes in_proj_qkvz and out_proj of the GDN
layers to MXFP4 while it loads (SGLANG_ROCM_GDN_ONLINE_MXFP4, on by default
with SGLANG_USE_AITER=1 on gfx95x). The weights go through shuffle_weight
(16, 16), and the scales through shuffle_scale.

- K1 qq reads the MXFP4 in_proj_qkvz (ABI arg w_qkvzs).
- K2 oq reads the MXFP4 out_proj (ABI arg w_os). It quantizes the core rows
  to MXFP4 (RCEIL), as SGLang's GEMM quantizes its input.
- The FP4 GEMV helpers fp4_gemv, fp4_gemv_loads and quant_x come back. K1
  imports them from K2.

The spec builds K1 and K2 for each projection dtype that the model has. It
does not refuse the MXFP4 GDN projections now. Thus the test server and the
README command do not set SGLANG_ROCM_GDN_ONLINE_MXFP4=0. The check-mode
e2e test asserts that SGLang quantized the projections.

With this commit, the kernels have all the variants of the port of
sgl-project/sglang#43516.

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]>
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 jit-kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants