Skip to content

[FlyDSL] Fuse the GDN gated RMSNorm into the out_proj GEMM for decode - #5881

Closed
maeehart wants to merge 1 commit into
ROCm:mainfrom
maeehart:gdn-gated-rmsnorm-out-proj
Closed

maeehart wants to merge 1 commit into
ROCm:mainfrom
maeehart:gdn-gated-rmsnorm-out-proj

Conversation

@maeehart

Copy link
Copy Markdown
Contributor

Summary

Add flydsl_gdn_gated_rmsnorm_out_proj, a FlyDSL kernel for gfx950 that runs the gated RMSNorm of a Gated DeltaNet layer and the bf16 out_proj GEMM as one kernel at decode. On MI355X at K = 2048 and N = 8192 (amd/Qwen3.8-2.4T-A95B-Quark-MXFP4 at TP8) it takes 8.1 to 12.1 µs for 1 to 5 tokens inside a HIP graph, where the separate norm and GEMM take 11.6 to 16.4 µs.

Background

At decode, every Gated DeltaNet layer (Qwen3-Next, Qwen3.5, Qwen3.8) runs RMSNormGated and then the unquantized out_proj GEMM:

y[t, h, :] = bf16(x[t, h, :] * rsqrt(mean(x[t, h, :]^2) + eps) * w * silu(z[t, h, :]))
out[t, :] = y[t].flatten() @ W.T

w has head_dim values and is shared by all heads. The norm writes y to HBM and the GEMM reads it back. At 1 to 5 tokens the GEMM is bound by the weight read, so the norm kernel and the gap before the GEMM are mostly extra time.

What this PR does

  • aiter/ops/flydsl/kernels/gdn_gated_rmsnorm_out_proj.py is the kernel. One workgroup owns cols_per_wave * waves_per_block output columns. Each wave issues the loads of its weight rows first and the loads of x and z after them. The waves of the workgroup then compute the gated norm of all tokens into LDS as bf16. After one barrier, each wave computes its output columns with v_dot2_f32_bf16 and reduces each column over the 64 lanes. y is rounded to bf16 before the multiply, as in the unfused path.
  • aiter/ops/flydsl/gdn_gated_rmsnorm_out_proj.py is the wrapper. flydsl_gdn_gated_rmsnorm_out_proj(x, z, norm_weight, weight, eps) picks a tile per token count and caches the compiled kernels. flydsl_gdn_gated_rmsnorm_out_proj_supported(num_tokens, num_heads, head_dim, out_features, dtype) returns False where the kernel was not clearly faster than the separate norm and GEMM, so a caller can fall back there. It accepts K from 1024 to 4096, the measured range: up to 8 tokens at K = 1024 and up to 5 tokens at K = 2048 and K = 4096.
  • aiter/ops/flydsl/__init__.py exports both functions.
  • op_tests/test_flydsl_gdn_gated_rmsnorm_out_proj.py checks the result against a torch reference with the same bf16 rounding and times the kernel. It covers the supported token counts at K = 1024, 2048, and 4096, one N that needs the smaller fallback tile, and the path where the wrapper allocates the output.

The wrapper supports gfx950, head_dim 128, bf16, contiguous tensors, and the SiLU gate. It reads the arch of the GPU in use, not GPU_ARCHS. Other shapes and archs return False from _supported.

Validation

MI355X, ROCm 7.2.4, torch 2.10.0, FlyDSL 0.3.4.1, on top of main at 8253efc.

Correctness: python3 op_tests/test_flydsl_gdn_gated_rmsnorm_out_proj.py passes all 27 default shapes with an error count of 0 at rtol = atol = 1e-2. AITER's validate-kernel-pr skill passes on this head. It applies the patch to 8253efc, runs the op test and four more shapes (-s 4,5120,2048, 3,2560,1536, 5,6144,3584, and 2,4104,2048) on an idle MI355X, and its execution receipt shows that the calls reached flydsl_gdn_gated_rmsnorm_out_proj. Its index-width scan lists five products without 64-bit widening. The only one on the device is the vector index into x and z, which is at most 4159 because the LDS limit keeps num_tokens * K at or below 32768.

Time per call inside a HIP graph, in µs. Every call reads a different copy of the weight, at least 768 MB in total, so the weight always comes from HBM, as in a real decode step. The unfused path is the gated norm compiled by torch.compile followed by vLLM's unquantized GEMM dispatch with VLLM_ROCM_USE_AITER=1. At these shapes it runs wvSplitK for 1 to 5 tokens and AITER's tgemm.mm from 6 tokens.

Tokens K=2048, N=8192 unfused fused K=4096, N=8192 unfused fused K=1024, N=4096 unfused fused
1 11.61 8.14 18.47 13.53 6.63 4.71
2 11.83 8.53 23.29 14.35 6.79 4.85
3 12.11 9.12 19.70 16.74 7.57 5.93
4 16.38 9.66 19.46 17.57 7.34 5.21
5 12.77 12.06 20.08 19.09 8.14 6.43
6 13.34 (13.31) 19.81 (22.54) 7.85 6.88
7 13.06 (14.06) 9.46 7.25
8 13.01 (15.50) 12.08 7.23

Values in parentheses are measured, but _supported returns False there. K = 1024 with N = 4096 is Qwen/Qwen3.5-397B-A17B at TP8. In this test the unfused path is the norm kernel and the GEMM. In the vLLM server, Inductor also runs a copy of the norm output into the GEMM input, so the saving there is larger, see below.

The op test also prints a gemm_a16w16 time. That GEMM runs on a y computed before timing, without the norm kernel. For 1 to 5 tokens vLLM runs wvSplitK and not gemm_a16w16. The table above is the comparison with the path it replaces.

The final ISA from the FlyDSL dump has no VGPR or SGPR spills and no scratch in any of the 27 default kernels. At K = 2048 the kernel uses 61 to 126 VGPRs for 1 to 5 tokens. LDS is num_tokens * K * 2 bytes.

End to end in vLLM: vllm-project/vllm#58802 uses this kernel in the GDN layers. On amd/Qwen3.8-2.4T-A95B-Quark-MXFP4 at TP8, median TPOT drops by 3.5% at 1 concurrent request (14.84 to 14.31 ms), by 2.8% at 2, and by 3.6% at 4, and gsm8k does not change. At 8 concurrent requests the batch has 8 tokens, so the vLLM op runs its fallback path instead of this kernel.

Test plan

  • python3 op_tests/test_flydsl_gdn_gated_rmsnorm_out_proj.py on MI355X
  • Extra shapes through the op test's -s option, in the validate-kernel-pr run
  • CI

At decode, a Gated DeltaNet layer (Qwen3.5, Qwen3-Next) runs RMSNormGated and the bf16 out_proj GEMM as separate kernels. The norm writes its result to HBM and the GEMM reads it back. At 1 to 5 tokens the GEMM is bound by the weight read, so the norm kernel is mostly extra time.

flydsl_gdn_gated_rmsnorm_out_proj runs both as one gfx950 kernel. Each wave issues its weight loads first and the loads of x and z after them. The waves of a workgroup then compute the gated norm of all tokens into LDS as bf16, and every wave computes its output columns with v_dot2_f32_bf16. The norm result is rounded to bf16 before the multiply, as in the unfused path.

flydsl_gdn_gated_rmsnorm_out_proj_supported returns False where the kernel was measured slower than the separate norm and GEMM, so a caller can fall back there. It accepts K from 1024 to 4096, up to 8 tokens at K = 1024 and up to 5 tokens above that.

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

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
multigpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 5881 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@maeehart

Copy link
Copy Markdown
Contributor Author

Closing this together with vllm-project/vllm#58802, its only user. It gives no gain on Qwen3.8-Flash-Next, where out_proj is MXFP4 and vllm-project/vllm#59553 fuses the gated RMSNorm with the MXFP4 quant instead.

@maeehart maeehart closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant