Skip to content

[feat] support aiter pa for Qwen3.5 GA module in decode phase#241

Open
At1a8 wants to merge 2 commits into
Qwen3.5_v0.5.9from
fangyuan/qwen3.5_aiter_pa
Open

[feat] support aiter pa for Qwen3.5 GA module in decode phase#241
At1a8 wants to merge 2 commits into
Qwen3.5_v0.5.9from
fangyuan/qwen3.5_aiter_pa

Conversation

@At1a8

@At1a8 At1a8 commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Support page attention ragged in decode phase

Modifications

  • fix weight loader issue in aiter attn backend to make it compatible with hybrid linear models (self attention module + gated delta net)
  • load aiter backend when specify SGLANG_USE_AITER_PA=1, it will help Qwen3.5 use aiter page attention in decode stage

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

image

Checklist

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 HybridLinearAttnBackend to optionally use a separate full-attention backend for decode.
  • In attn_backend_wrapper, select AiterAttnBackend for full-attention decode when SGLANG_USE_AITER_PA=1.
  • Adjust AiterAttnBackend v-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.

Comment on lines +1651 to +1654
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
)

Copilot AI Apr 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +225 to +229
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)
)

Copilot AI Apr 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +127 to +136
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
]

Copilot AI Apr 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread python/sglang/srt/layers/attention/attention_registry.py Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

2 participants