Support vectorized_5d kv cache for HybridLinearKVPool in Qwen3.5 - #24
Support vectorized_5d kv cache for HybridLinearKVPool in Qwen3.5#24apinge wants to merge 4 commits into
Conversation
Signed-off-by: apinge <tong.qiu2@amd.com>
There was a problem hiding this comment.
🟡 Changes recommended
Composite-pool detection misclassifies unified-memory buffers, and hybrid prefix reads bypass layer-transfer synchronization.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds vectorized 5D KV-cache support for Qwen3.5’s HybridLinearKVPool.
Changes:
- Resolves wrapped MHA sub-pools and layer mappings.
- Recursively detects vectorized 5D layouts.
- Supplies
query_scaleto AITER decode.
File summaries
| File | Description |
|---|---|
python/sglang/srt/layers/attention/aiter_utils.py |
Adds hybrid sub-pool resolution and updates decode arguments. |
python/sglang/srt/layers/attention/aiter_backend.py |
Detects vectorized layouts through composite pools. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| for child_name in ("full_kv_pool", "swa_kv_pool"): | ||
| child = getattr(pool, child_name, None) | ||
| if child is not None and _pool_is_vec5d(child): | ||
| return True |
There was a problem hiding this comment.
--enable-unified-memory conflicts with the 5d KV cache layout.
SGLANG_AITER_KV_CACHE_LAYOUT=vectorized_5d requires the MHA KV cache to use a true 5D physical tensor layout:
K: (num_blocks, H, D // X, page_size, X)
V: (num_blocks, H, page_size // X, D, X)
However, under --enable-unified-memory, UnifiedMHATokenToKVPool exposes only a 4d page-major view rather than a true 5d layout. In other words, it may inherit the kv_cache_layout="vectorized_5d" string, but the actual k_buffer /v_buffer are not 5D.
Therefore, --enable-unified-memory and vectorized_5d are currently incompatible.
I added an extra check to reject the 5d layout in this case.
I also add warning in server_args.py
| if hasattr(pool, "layers_mapping"): | ||
| sub_layer_id, sub_is_swa = pool.layers_mapping[layer.layer_id] | ||
| return pool.swa_kv_pool if sub_is_swa else pool.full_kv_pool, sub_layer_id | ||
|
|
||
| if hasattr(pool, "full_attention_layer_id_mapping") and hasattr( | ||
| pool, "full_kv_pool" | ||
| ): | ||
| return pool.full_kv_pool, pool.full_attention_layer_id_mapping[layer.layer_id] |
There was a problem hiding this comment.
Makes sense, I've applied the fix. As Copilot noted, this issue occurs during async kv cache transfers when --enable-hierarchical-cache and --enable-lmcache are enabled. Although we aren't using these options right now, it's better to fix it proactively.
Signed-off-by: apinge <tong.qiu2@amd.com>
Motivation
This PR functionally supports
vectorized_5dforHybridLinearKVPoolin Qwen3.5 by usingexport SGLANG_AITER_KV_CACHE_LAYOUT=vectorized_5d.Currently Dflash speculative decoding cannot work with this feature.
Modifications
Accuracy Tests
gsm8k
Speed Tests and Profiling
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ci