[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
-11
View File
@@ -34,7 +34,6 @@ from vllm.v1.kv_cache_interface import (
SinkFullAttentionSpec,
SlidingWindowMLASpec,
SlidingWindowSpec,
TQFullAttentionSpec,
UniformTypeKVCacheSpecs,
get_kv_cache_spec_kind,
)
@@ -85,7 +84,6 @@ class _TrulyUnregisteredSpec(KVCacheSpec):
spec_manager_map: dict[type[KVCacheSpec], type[SingleTypeKVCacheManager]] = {
FullAttentionSpec: FullAttentionManager,
TQFullAttentionSpec: FullAttentionManager,
MLAAttentionSpec: FullAttentionManager,
HiddenStateCacheSpec: FullAttentionManager,
SlidingWindowSpec: SlidingWindowManager,
@@ -98,7 +96,6 @@ spec_manager_map: dict[type[KVCacheSpec], type[SingleTypeKVCacheManager]] = {
spec_uniform_base_map: dict[type[KVCacheSpec], type[KVCacheSpec]] = {
FullAttentionSpec: FullAttentionSpec,
TQFullAttentionSpec: FullAttentionSpec,
MLAAttentionSpec: FullAttentionSpec,
HiddenStateCacheSpec: FullAttentionSpec,
SlidingWindowSpec: SlidingWindowSpec,
@@ -113,13 +110,6 @@ spec_args_map: dict[type[KVCacheSpec], dict[str, Any]] = {
FullAttentionSpec: dict(
block_size=64, num_kv_heads=8, head_size=128, dtype=torch.bfloat16
),
TQFullAttentionSpec: dict(
block_size=64,
num_kv_heads=8,
head_size=128,
dtype=torch.bfloat16,
tq_slot_size=256,
),
MLAAttentionSpec: dict(
block_size=64, num_kv_heads=1, head_size=128, dtype=torch.bfloat16
),
@@ -262,7 +252,6 @@ class TestKVCacheSpecRegistry:
def test_full_attention_family_specs_are_uniform(self):
specs = [
make_spec(FullAttentionSpec),
make_spec(TQFullAttentionSpec),
make_spec(MLAAttentionSpec),
make_spec(HiddenStateCacheSpec),
make_spec(SinkFullAttentionSpec),
@@ -93,6 +93,7 @@ def test_dsv4_packed_zeroer_geometry():
cache_dtype_str="fp8_ds_mla",
alignment=576,
model_version="deepseek_v4",
state_content_bytes=584, # >576 to allocate room for scales at back of page
)
for _ in layer_names
]