Add AITER GDN prefill and decode backends - #9
Conversation
bf2896e to
3b8d46f
Compare
Integrate ROCm HIP and FlyDSL kernels through the canonical VK dispatcher while preserving Triton fallbacks for graph capture, padding, and unsupported configurations.
Use FlyDSL by default and reserve HIP for Qwen3.5-397B TP8 graph batches at or above 24 based on direct kernel crossover measurements.
14a8cc3 to
7d7de24
Compare
sammysun0711
left a comment
There was a problem hiding this comment.
@IzacharyI for APC function mamba cache support with linear attention.
Please update following patch:
diff --git a/python/sglang/srt/arg_groups/overrides.py b/python/sglang/srt/arg_groups/overrides.py
index 9439b6da4..dc5443bfa 100644
--- a/python/sglang/srt/arg_groups/overrides.py
+++ b/python/sglang/srt/arg_groups/overrides.py
@@ -999,7 +999,9 @@ def supports_mamba_cache_extra_buffer(view: Any, model_arch: str) -> bool:
"""Whether ``model_arch`` supports the extra_buffer strategy on the
configured linear-attention backend (pure read)."""
if model_arch in _MAMBA_EXTRA_BUFFER_ARCHS:
- return view.linear_attn_backend == "triton"
+ return view.linear_attn_backend == "triton" or (
+ is_hip() and view.linear_attn_backend == "aiter"
+ )
return False
There was a problem hiding this comment.
Pull request overview
This PR adds an AITER-based GDN linear-attention backend on ROCm, integrating AITER HIP + FlyDSL kernels into the existing GDN dispatcher while keeping Triton as the fallback for unsupported shapes/modes and for ReplaySSM.
Changes:
- Add
aiteras a selectableLinearAttnKernelBackendand CLI choice, and wire it intoGDNKernelDispatcherfor decode/prefill. - Introduce
AiterGDNKernelwith runtime guards and fallback routing (HIP vs FlyDSL vs Triton), plus graph-padding aware decode handling viaactive_batch_size. - Improve Mamba state tracking/scatter paths with direct-copy helpers and add/expand AMD-focused tests for AITER GDN and state-copy correctness.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/registered/unit/test_model_overrides.py | Extends override tests to cover aiter + ROCm gating for mamba extra buffer support. |
| test/registered/unit/layers/test_mamba_state_scatter_triton.py | Adds unit tests for new extend-state copy flag derivation and copy behavior (incl. overlap). |
| test/registered/attention/test_gdn_aiter_backend.py | New AMD CI suite validating AITER backend registration, routing, graph padding behavior, and parity vs Triton. |
| python/sglang/srt/server_args.py | Adds aiter to linear-attention backend CLI choices. |
| python/sglang/srt/layers/attention/mamba/mamba2_metadata.py | Adds trusted/disjoint flags to forward metadata and threads them through prepare helpers. |
| python/sglang/srt/layers/attention/mamba/mamba_state_scatter_triton.py | Adds trusted/disjoint derivation plus a Triton row-copy kernel and extend-row copy helper. |
| python/sglang/srt/layers/attention/linear/utils.py | Registers LinearAttnKernelBackend.AITER and helper predicate. |
| python/sglang/srt/layers/attention/linear/kernels/gdn_aiter.py | New AITER GDN kernel implementation with HIP/FlyDSL decode and VK/low-level prefill paths plus Triton fallback. |
| python/sglang/srt/layers/attention/linear/gdn_backend.py | Integrates AITER into kernel dispatch and adds decode conv-split + active-batch handling hooks. |
| python/sglang/srt/layers/attention/hybrid_linear_attn_backend.py | Uses new trusted/disjoint flags and direct-copy helper for extend-state tracking; minor formatting changes. |
| python/sglang/srt/layers/attention/fla/l2norm.py | Adds fused Q/K L2Norm Triton kernels and fused_l2norm_qk helper. |
| python/sglang/srt/arg_groups/overrides.py | Allows mamba extra buffer on ROCm when linear_attn_backend == "aiter". |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| split_qkv = None | ||
| if layer.q_dim == layer.k_dim: | ||
| split_qkv = self.kernel_dispatcher.decode_conv_split( | ||
| mixed_qkv, | ||
| conv_states, | ||
| layer.conv_weights, | ||
| bias=layer.bias, | ||
| activation=layer.activation, | ||
| conv_state_indices=cache_indices, | ||
| key_dim=layer.k_dim, | ||
| value_dim=layer.v_dim, | ||
| num_k_heads=layer.num_k_heads, | ||
| num_v_heads=layer.num_v_heads, | ||
| head_k_dim=layer.head_k_dim, | ||
| head_v_dim=layer.head_v_dim, | ||
| active_batch_size=self._aiter_decode_active_batch_size, | ||
| ) |
There was a problem hiding this comment.
@IzacharyI do you think it has out of bound read risk?
There was a problem hiding this comment.
I checked the actual AITER Gluon conv-split kernel. It explicitly returns when conv_state_indices is PAD_SLOT_ID (-1), before calculating or accessing the state address, so padded rows cannot modify conv_state[-1].
The proposed Python guard would not protect CUDA Graph replay because it is evaluated only during graph capture, not again when the active batch changes during replay.
I added a regression test that captures with valid indices, replays after changing one index to -1, and verifies that valid Q/K/V match the reference and the last cache row is unchanged. So, may the fused fast path is kept enabled.




Integrate ROCm HIP and FlyDSL kernels through the canonical VK dispatcher while preserving Triton fallbacks for graph capture, padding, and unsupported configurations.
Related AITER PR: ROCm/aiter#4540
Motivation
The existing GDN backend relies on Triton kernels on ROCm even when optimized AITER HIP and FlyDSL implementations are available.
This PR integrates those kernels without changing the canonical GDN state layout or scheduler interfaces. AITER is selected only for validated workloads, while Triton remains the correctness fallback for unsupported shapes, dependencies, padding, graph configurations, and execution modes.
Modifications
Modifications
aiteras an independent linear-attention decode and prefill backend.AiterGDNKernelthrough the existingLinearAttnKernelBaseandGDNKernelDispatcherinterfaces.--linear-attn-backend aiter--linear-attn-decode-backend aiter--linear-attn-prefill-backend aiterflydsl_gdr_decode.(HK, HV)=(2, 8), batch>=24: HIP.[slot, HV, V, K]recurrent-state layout without introducing state transposes or legacy bitmap management.Accuracy Tests
5-shot GSM8K evaluation using 100 examples, temperature 0, top-p 1, and maximum output length 4096:
Focused correctness tests:
Speed Tests and Profiling
Environment:
702aacd62b008d42d8521d3ec5a4052e13320d623356e187fKernel profiling
End-to-end concurrency benchmark
The 397B TP8 prefill path remains on Triton by default because controlled 8K end-to-end measurements showed a 0.81% mean TTFT regression. The AITER prefill path remains available through an explicit threshold override.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ci