[AMD][Perf] Fuse QK RMSNorm + gate extraction Triton kernel for Qwen3.5 on HIP - #27656
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the documentation to feature a new blog post on MoRI and AMD Instinct MI355X, and introduces a fused Triton kernel (fused_qk_gemma_rmsnorm_with_gate) to optimize the attention forward pass for Qwen 3.5 on AMD GPUs (HIP). The reviewer provided valuable performance optimization feedback to avoid an expensive memory copy of the non-contiguous k tensor by passing it as a 3D tensor and utilizing stride-based indexing directly inside the Triton kernel.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
737a836 to
e650d78
Compare
e650d78 to
a6e0834
Compare
2bba1b0 to
698c8e0
Compare
|
@amd-bot ci-status |
CI Status for PR #27656Merge verdict: No failures are caused by this PR — all 6 leaf-job failures are in unrelated code paths (aiter all-reduce, NPU diffusion/quant perf, a CPU missing-module, and a HuggingFace 429 rate-limit). The PR's new Triton kernel helper is well-tested and green on AMD (113 unit cases passed). Warning Coverage is partial. The kernel math in Changed files: AMD: 2 failures (0 related) · Others: 4 failures (0 related) — all 169 checks completed, none pending. AMD CI Failures
Other CI Failures
The 4 Details / what to do before merge
Generated by amd-bot using Claude Code CLI |
|
This broke lint on main |
Motivation
In Qwen3.5's attention layers on HIP, the
forward_preparepath for models withattn_output_gateruns three separate kernels to deinterleave q/gate from the QKV projection output and normalize q/k:elementwise_kernel-- copy q from interleaved buffer (4.5 us)elementwise_kernel-- copy gate from interleaved buffer (4.8 us)_fused_qk_gemma_rmsnorm_kernel-- normalize q and k (4.5 us)This PR fuses all three operations into a single Triton kernel (
_fused_qk_gemma_rmsnorm_gate_kernel) that reads q and gate from the interleaved[q_h0, gate_h0, q_h1, gate_h1, ...]layout, normalizes q/k with GemmaRMSNorm, and writes contiguous q, k, and gate outputs -- eliminating 2 kernel launches per attention layer.Modifications
python/sglang/srt/models/utils.py: Add_fused_qk_gemma_rmsnorm_gate_kernelTriton kernel andfused_qk_gemma_rmsnorm_with_gate()Python wrapper. The kernel handles the interleaved q_gate layout with stride-based access (no intermediate copies), performs GemmaRMSNorm on q and k, and extracts gate to a contiguous output.python/sglang/srt/models/qwen3_5.py: Addforward_prepare_hip()method toQwen3_5AttentionDecoderLayerthat uses the fused kernel. Dispatch to it when_is_hip and self.attn_output_gatein theforward_attention()method.Accuracy Tests
Model: Qwen3.5-397B-A17B-MXFP4, TP=2, MI355x
Benchmarking and Profiling
Kernel-level (per attention layer, decode, TP=2, MI355x)
elementwise_kernel(q deinterleave)elementwise_kernel(gate deinterleave)_fused_qk_gemma_rmsnorm_kernel_fused_qk_gemma_rmsnorm_gate_kernel15 attention layers x 9.4 us = ~141 us savings per decode iteration.
E2E benchmark (Qwen3.5-397B-A17B-MXFP4, TP=2, ISL=8192, OSL=1024, conc=4, MI355x)
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ciCI States
Latest PR Test (Base): 🚫 Run #27216146908
Latest PR Test (Extra): ❌ Run #27216145634