Repository navigation
Conversation
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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
|
Closing this together with vllm-project/vllm#58802, its only user. It gives no gain on Qwen3.8-Flash-Next, where |
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 bf16out_projGEMM as one kernel at decode. On MI355X at K = 2048 and N = 8192 (amd/Qwen3.8-2.4T-A95B-Quark-MXFP4at 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
RMSNormGatedand then the unquantizedout_projGEMM:whashead_dimvalues and is shared by all heads. The norm writesyto 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.pyis the kernel. One workgroup ownscols_per_wave * waves_per_blockoutput columns. Each wave issues the loads of its weight rows first and the loads ofxandzafter 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 withv_dot2_f32_bf16and reduces each column over the 64 lanes.yis rounded to bf16 before the multiply, as in the unfused path.aiter/ops/flydsl/gdn_gated_rmsnorm_out_proj.pyis 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__.pyexports both functions.op_tests/test_flydsl_gdn_gated_rmsnorm_out_proj.pychecks 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_dim128, bf16, contiguous tensors, and the SiLU gate. It reads the arch of the GPU in use, notGPU_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.pypasses all 27 default shapes with an error count of 0 atrtol = atol = 1e-2. AITER'svalidate-kernel-prskill 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, and2,4104,2048) on an idle MI355X, and its execution receipt shows that the calls reachedflydsl_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 intoxandz, which is at most 4159 because the LDS limit keepsnum_tokens * Kat 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.compilefollowed by vLLM's unquantized GEMM dispatch withVLLM_ROCM_USE_AITER=1. At these shapes it runswvSplitKfor 1 to 5 tokens and AITER'stgemm.mmfrom 6 tokens.Values in parentheses are measured, but
_supportedreturns False there. K = 1024 with N = 4096 isQwen/Qwen3.5-397B-A17Bat 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_a16w16time. That GEMM runs on aycomputed before timing, without the norm kernel. For 1 to 5 tokens vLLM runswvSplitKand notgemm_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 * 2bytes.End to end in vLLM: vllm-project/vllm#58802 uses this kernel in the GDN layers. On
amd/Qwen3.8-2.4T-A95B-Quark-MXFP4at 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.pyon MI355X-soption, in thevalidate-kernel-prrun