[feat] support aiter pa for Qwen3.5 GA module in decode phase#241
[feat] support aiter pa for Qwen3.5 GA module in decode phase#241At1a8 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for using the AMD aiter paged-attention backend specifically in the decode phase for hybrid-linear (full-attn + linear-attn) models (notably Qwen3.5), and fixes an aiter KV loader incompatibility for certain hybrid layouts.
Changes:
- Extend
HybridLinearAttnBackendto optionally use a separate full-attention backend for decode. - In
attn_backend_wrapper, selectAiterAttnBackendfor full-attention decode whenSGLANG_USE_AITER_PA=1. - Adjust
AiterAttnBackendv-head-dim detection for some hybrid-linear model runners.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
python/sglang/srt/layers/attention/hybrid_linear_attn_backend.py |
Adds an optional decode-only full-attn backend and routes decode calls accordingly. |
python/sglang/srt/layers/attention/attention_registry.py |
Enables env-var-based selection of aiter paged attention for decode in hybrid-linear models. |
python/sglang/srt/layers/attention/aiter_backend.py |
Tweaks v-head-dim retrieval to avoid hybrid KV pool layer-id assumptions in some cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if self.full_attn_decode_backend is not None: | ||
| return self.full_attn_decode_backend.forward_decode( | ||
| q, k, v, layer, forward_batch, save_kv_cache, **kwargs | ||
| ) |
There was a problem hiding this comment.
full_attn_decode_backend.forward_decode(..., **kwargs) can raise TypeError when the decode backend doesn’t accept extra keyword args. For example, AiterAttnBackend.forward_decode currently has no **kwargs parameter, so any forwarded args like q_rope/k_rope/sinks will break decode. Consider making the decode backend interface-compatible (accept and ignore **kwargs), or filter kwargs before calling the decode backend.
| if get_bool_env_var("SGLANG_USE_AITER_PA"): | ||
| from sglang.srt.layers.attention.aiter_backend import AiterAttnBackend | ||
| return HybridLinearAttnBackend( | ||
| full_attn_backend, linear_attn_backend, full_attn_layers, AiterAttnBackend(runner) | ||
| ) |
There was a problem hiding this comment.
The new SGLANG_USE_AITER_PA path can select AiterAttnBackend on systems where aiter isn’t installed / supported, leading to a later runtime failure (the aiter_backend module swallows ImportError and continues). Add an explicit availability check here (e.g., import aiter in a try/except and raise a clear error) and/or hardware gating so enabling this env var fails fast with an actionable message.
| if ( | ||
| model_runner.hybrid_gdn_config is not None | ||
| or model_runner.kimi_linear_config is not None | ||
| ): | ||
| # For hybrid linear models, layer_id = 0 may not be full attention | ||
| self.v_head_dim = model_runner.token_to_kv_pool.get_v_head_dim() | ||
| else: | ||
| self.v_head_dim = model_runner.token_to_kv_pool.get_value_buffer(0).shape[ | ||
| -1 | ||
| ] |
There was a problem hiding this comment.
This v_head_dim selection is based on specific model configs (hybrid_gdn_config/kimi_linear_config), but the underlying issue is whether token_to_kv_pool.get_value_buffer(0) is valid (it can raise for HybridLinearKVPool when layer 0 isn’t a full-attention layer). To avoid reintroducing the same loader failure for other hybrid models (e.g., NemotronH / other mambaish configs), prefer a capability-based check like hasattr(token_to_kv_pool, "get_v_head_dim") (or isinstance(..., HybridLinearKVPool)) and use get_v_head_dim() when available.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Motivation
Support page attention ragged in decode phase
Modifications
Accuracy Tests
root@smci355-ccs-aus-n12-13:/mnt/raid0/fangyuan/qwen3.5# SGLANG_USE_AITER_PA=1 python3 /opt/sglang/benchmark/gsm8k/bench_sglang.py --port 8000
Downloading from https://raw.githubusercontent.com/openai/grade-school-math/master/grade_school_math/data/test.jsonl to /tmp/test.jsonl
/tmp/test.jsonl: 732kB [00:00, 31.0MB/s]
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 200/200 [00:26<00:00, 7.57it/s]
Accuracy: 0.945
Invalid: 0.005
Latency: 26.430 s
Output throughput: 1195.773 token/s
Benchmarking and Profiling
Checklist