[5/N][KV-Cache Layout Refactor] Backend-published KV packing via customize_spec (#51704)

Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Lucas Wilkinson
2026-08-14 09:47:55 -04:00
committed by GitHub
co-authored by Claude
parent 63a9a5010a
commit 57bd0ed441
18 changed files with 204 additions and 219 deletions
+10 -11
View File
@@ -2766,21 +2766,20 @@ def test_unify_kv_cache_page_size_padding_requires_backend_support():
kv_cache_utils.unify_kv_cache_spec_page_size(specs)
def test_unpadded_page_size_without_quant_matches_real_page():
# Without quantization the offload transfer width is just the raw page.
spec = new_kv_cache_spec()
assert spec.unpadded_page_size_bytes == spec.real_page_size_bytes
assert spec.page_size_bytes == spec.unpadded_page_size_bytes
def test_unpadded_page_size_includes_per_token_head_scales():
# Per-token-head quant carries inline fp32 scales that are carved from the
# raw KV allocation, so they must be budgeted into the offload width.
spec = new_kv_cache_spec(
dtype=torch.uint8, kv_quant_mode=KVQuantMode.FP8_PER_TOKEN_HEAD
# raw KV allocation, so they must be budgeted into the offload width. The
# packing is published by the owning backend's customize_spec hook.
from vllm.v1.attention.backends.triton_attn import TritonAttentionBackend
dense = new_kv_cache_spec(dtype=torch.uint8)
spec = TritonAttentionBackend.customize_spec(
new_kv_cache_spec(
dtype=torch.uint8, kv_quant_mode=KVQuantMode.FP8_PER_TOKEN_HEAD
)
)
scales = 2 * spec.block_size * spec.num_kv_heads * 4
assert spec.unpadded_page_size_bytes == spec.real_page_size_bytes + scales
assert spec.unpadded_page_size_bytes == dense.unpadded_page_size_bytes + scales
assert spec.page_size_bytes == spec.unpadded_page_size_bytes