[KV Connector] Support MooncakeStore with hybrid DCP prefix caching (#53324)

Signed-off-by: wzhao18 <wzhao18.sz@gmail.com>
Signed-off-by: wzhao18 <weizha@nvidia.com>
Signed-off-by: Yifan Qiao <yifanqiao@inferact.ai>
Co-authored-by: Yifan Qiao <yifanqiao@inferact.ai>
This commit is contained in:
Wei Zhao
2026-08-29 02:10:23 +00:00
committed by GitHub
co-authored by Yifan Qiao
parent 43196f2458
commit 7fd9cc036e
14 changed files with 560 additions and 85 deletions
+7 -7
View File
@@ -867,14 +867,14 @@ class HybridKVCacheCoordinator(KVCacheCoordinator):
if is_simple_hybrid:
break
# Truncate full attention blocks to final hit_length (if present)
first_group = self.attention_groups[0]
if isinstance(first_group.spec, FullAttentionSpec):
group_block_size = self.single_type_managers[
first_group.group_ids[0]
].block_size
# Truncate every full-attention group (target and draft) blocks
# to final hit_length.
for group in self.attention_groups:
if not isinstance(group.spec, FullAttentionSpec):
continue
group_block_size = self.single_type_managers[group.group_ids[0]].block_size
num_blocks = cdiv(hit_length, group_block_size)
for group_id in first_group.group_ids:
for group_id in group.group_ids:
if (blks := hit_blocks_by_group[group_id]) is not None:
del blks[num_blocks:]
hit_length_by_group[group_id] = hit_length
+29 -4
View File
@@ -35,6 +35,7 @@ from vllm.v1.kv_cache_interface import (
SlidingWindowSpec,
UniformTypeKVCacheSpecs,
compute_layout_strides,
iter_layer_specs,
replace_as,
)
from vllm.v1.kv_cache_spec_registry import KVCacheSpecRegistry
@@ -647,6 +648,33 @@ def hash_block_tokens(
)
def resolve_dcp_kv_block_size(spec: KVCacheSpec, dcp_world_size: int) -> int:
"""Return the token span of a cache block under DCP."""
layer_specs = iter_layer_specs(spec)
if len(layer_specs) > 0 and all(
isinstance(layer_spec, AttentionSpec) for layer_spec in layer_specs
):
return spec.block_size * dcp_world_size
return spec.block_size
def resolve_dcp_kv_cache_spec(spec: KVCacheSpec, dcp_world_size: int) -> KVCacheSpec:
"""Return a KV cache spec with block sizes adjusted for DCP."""
block_size = resolve_dcp_kv_block_size(spec, dcp_world_size)
if block_size == spec.block_size:
return spec
if isinstance(spec, UniformTypeKVCacheSpecs):
return replace(
spec,
block_size=block_size,
kv_cache_specs={
name: resolve_dcp_kv_cache_spec(layer_spec, dcp_world_size)
for name, layer_spec in spec.kv_cache_specs.items()
},
)
return replace(spec, block_size=block_size)
def resolve_kv_cache_block_sizes(
kv_cache_config: KVCacheConfig,
vllm_config: VllmConfig,
@@ -674,10 +702,7 @@ def resolve_kv_cache_block_sizes(
return bs, bs
group_block_sizes = [
g.kv_cache_spec.block_size * dcp
if isinstance(g.kv_cache_spec, AttentionSpec)
else g.kv_cache_spec.block_size
for g in groups
resolve_dcp_kv_block_size(g.kv_cache_spec, dcp) for g in groups
]
scheduler_block_size = math.lcm(*group_block_sizes)