[Bugfix][KV Connector] MooncakeStore: exclude non-prefix-cacheable (QSA ring) groups; fix align-mode check (#55027)
Signed-off-by: Zhewen Li <zhewenli@inferact.ai> Co-authored-by: Zhewen Li <zhewenli@inferact.ai> Co-authored-by: OpenAI Codex <codex@openai.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Zhewen Li
OpenAI Codex
Claude Fable 5.1
parent
fe49665eb3
commit
58d45fd767
@@ -132,20 +132,22 @@ class MooncakeStoreConnector(KVConnectorBase_V1, SupportsHMA):
|
||||
from vllm.v1.kv_cache_interface import CrossAttentionSpec, MambaSpec
|
||||
|
||||
unsupported: list[str] = []
|
||||
cache_block_size = vllm_config.cache_config.block_size
|
||||
for g_idx, g in enumerate(kv_cache_config.transfer_groups):
|
||||
spec = g.kv_cache_spec
|
||||
store_group_ids = kv_cache_config.prefix_cacheable_group_ids
|
||||
if not store_group_ids:
|
||||
raise ValueError(
|
||||
"MooncakeStore requires at least one prefix-cacheable KV cache group"
|
||||
)
|
||||
for group_id in store_group_ids:
|
||||
spec = kv_cache_config.kv_cache_groups[group_id].kv_cache_spec
|
||||
if isinstance(spec, CrossAttentionSpec):
|
||||
unsupported.append(f"group {g_idx}: CrossAttentionSpec")
|
||||
# Enforce Mamba align mode
|
||||
if isinstance(spec, MambaSpec) and spec.block_size != cache_block_size:
|
||||
unsupported.append(f"group {group_id}: CrossAttentionSpec")
|
||||
if isinstance(spec, MambaSpec) and spec.mamba_cache_mode != "align":
|
||||
unsupported.append(
|
||||
f"group {g_idx}: MambaSpec with block_size="
|
||||
f"{spec.block_size} != cache_config.block_size="
|
||||
f"{cache_block_size} (mamba_cache_mode != 'align')"
|
||||
f"group {group_id}: mamba_cache_mode="
|
||||
f"{spec.mamba_cache_mode!r} != 'align'"
|
||||
)
|
||||
pcp = vllm_config.parallel_config.prefill_context_parallel_size
|
||||
if len(kv_cache_config.transfer_groups) > 1 and pcp > 1:
|
||||
if len(store_group_ids) > 1 and pcp > 1:
|
||||
unsupported.append(f"PCP > 1 (pcp={pcp}) with hybrid attention")
|
||||
if unsupported:
|
||||
raise ValueError(
|
||||
|
||||
@@ -452,7 +452,7 @@ def _unwrap_spec(spec: KVCacheSpec) -> KVCacheSpec:
|
||||
|
||||
|
||||
def partial_hash_hits_enabled(
|
||||
kv_cache_groups: list[KVCacheGroupSpec],
|
||||
kv_cache_groups: Sequence[KVCacheGroupSpec],
|
||||
hash_block_size: int,
|
||||
dcp_world_size: int = 1,
|
||||
) -> bool:
|
||||
|
||||
@@ -71,19 +71,27 @@ class MooncakeStoreScheduler:
|
||||
)
|
||||
self.client = LookupKeyClient(vllm_config)
|
||||
self.kv_cache_config = kv_cache_config
|
||||
self._store_group_ids = kv_cache_config.prefix_cacheable_group_ids
|
||||
# Map scheduler group IDs to store group indices. Groups outside the
|
||||
# store projection, such as the QSA ring, map to None and are skipped.
|
||||
self._store_group_id_by_kv_cache_group_id = {
|
||||
group_id: store_group_id
|
||||
for store_group_id, group_id in enumerate(self._store_group_ids)
|
||||
}
|
||||
store_groups = kv_cache_config.prefix_cacheable_groups
|
||||
|
||||
# Align with the engine's own scheduler_block_size and hash_block_size.
|
||||
self._block_size, self._hash_block_size = resolve_kv_cache_block_sizes(
|
||||
kv_cache_config, vllm_config
|
||||
)
|
||||
self.enable_partial_hash_hits = partial_hash_hits_enabled(
|
||||
kv_cache_config.kv_cache_groups,
|
||||
store_groups,
|
||||
self._hash_block_size,
|
||||
vllm_config.parallel_config.decode_context_parallel_size,
|
||||
)
|
||||
mamba_groups = {
|
||||
group_id: group.kv_cache_spec
|
||||
for group_id, group in enumerate(kv_cache_config.kv_cache_groups)
|
||||
for group_id, group in enumerate(store_groups)
|
||||
if isinstance(group.kv_cache_spec, MambaSpec)
|
||||
}
|
||||
assert all(
|
||||
@@ -173,8 +181,8 @@ class MooncakeStoreScheduler:
|
||||
"""Update state after block allocation."""
|
||||
local_block_ids: tuple[list[int], ...] = ()
|
||||
if num_external_tokens > 0:
|
||||
local_block_ids = self.kv_cache_config.select_transfer_block_ids(
|
||||
blocks.get_block_ids()
|
||||
local_block_ids = blocks.get_block_ids(
|
||||
group_ids=self._store_group_ids,
|
||||
)
|
||||
|
||||
self._unfinished_requests[request.request_id] = (request, local_block_ids)
|
||||
@@ -239,10 +247,7 @@ class MooncakeStoreScheduler:
|
||||
request_real = request_tuple[0] # type: ignore[index]
|
||||
|
||||
unfolded_block_ids = tuple(
|
||||
blocks.copy()
|
||||
for blocks in self.kv_cache_config.select_transfer_block_ids(
|
||||
request.block_ids
|
||||
)
|
||||
request.block_ids[group_id].copy() for group_id in self._store_group_ids
|
||||
)
|
||||
|
||||
prefill_tokens = _new_req_prefill_tokens(request)
|
||||
@@ -278,8 +283,8 @@ class MooncakeStoreScheduler:
|
||||
for i, req_id in enumerate(cached_reqs.req_ids):
|
||||
new_block_ids = cached_reqs.new_block_ids[i]
|
||||
if new_block_ids:
|
||||
new_block_ids = self.kv_cache_config.select_transfer_block_ids(
|
||||
new_block_ids
|
||||
new_block_ids = tuple(
|
||||
new_block_ids[group_id] for group_id in self._store_group_ids
|
||||
)
|
||||
|
||||
req_meta = None
|
||||
@@ -438,7 +443,9 @@ class MooncakeStoreScheduler:
|
||||
assert block_ids is not None, (
|
||||
f"Missing current block table for store request {req_meta.req_id}"
|
||||
)
|
||||
req_meta.block_ids = block_ids
|
||||
req_meta.block_ids = tuple(
|
||||
block_ids[group_id] for group_id in self._store_group_ids
|
||||
)
|
||||
|
||||
def _reference_save_blocks(self, meta: MooncakeStoreConnectorMetadata) -> None:
|
||||
"""Take a GPU block reference for every store job this step emits.
|
||||
@@ -509,12 +516,15 @@ class MooncakeStoreScheduler:
|
||||
return False
|
||||
|
||||
pinned_block_ids: list[int] = []
|
||||
for group_id, block_id, _ in partial_tail_offloads:
|
||||
if group_id not in self._boundary_state_group_ids:
|
||||
remapped_offloads: list[tuple[int, int, int]] = []
|
||||
for group_id, block_id, boundary in partial_tail_offloads:
|
||||
store_group_id = self._store_group_id_by_kv_cache_group_id.get(group_id)
|
||||
if store_group_id not in self._boundary_state_group_ids:
|
||||
return False
|
||||
if block_id == NULL_BLOCK_ID:
|
||||
return False
|
||||
pinned_block_ids.append(block_id)
|
||||
remapped_offloads.append((store_group_id, block_id, boundary))
|
||||
pinned_block_ids = list(dict.fromkeys(pinned_block_ids))
|
||||
|
||||
pool = self._gpu_block_pool
|
||||
@@ -530,12 +540,14 @@ class MooncakeStoreScheduler:
|
||||
self._finished_partial_tail_metas[request.request_id] = ReqMeta(
|
||||
req_id=request.request_id,
|
||||
token_len_chunk=0,
|
||||
block_ids=tuple(group.copy() for group in block_ids),
|
||||
block_ids=tuple(
|
||||
block_ids[group_id].copy() for group_id in self._store_group_ids
|
||||
),
|
||||
block_hashes=list(request.block_hashes),
|
||||
can_save=True,
|
||||
num_prompt_tokens=tracker.prefill_end_tokens,
|
||||
store_job_id=store_job_id,
|
||||
boundary_state_offloads=partial_tail_offloads,
|
||||
boundary_state_offloads=remapped_offloads,
|
||||
)
|
||||
tracker.has_pending_offload = True
|
||||
# The store job owns exact block refs, so request cleanup need not wait.
|
||||
@@ -574,9 +586,10 @@ class MooncakeStoreScheduler:
|
||||
continue
|
||||
if block_id == NULL_BLOCK_ID:
|
||||
continue
|
||||
if group_id not in self._boundary_state_group_ids:
|
||||
store_group_id = self._store_group_id_by_kv_cache_group_id.get(group_id)
|
||||
if store_group_id not in self._boundary_state_group_ids:
|
||||
continue
|
||||
accepted.append((group_id, block_id, boundary_tokens))
|
||||
accepted.append((store_group_id, block_id, boundary_tokens))
|
||||
if not accepted:
|
||||
continue
|
||||
tracker.has_pending_offload = True
|
||||
|
||||
@@ -1672,10 +1672,11 @@ class MooncakeStoreWorker:
|
||||
dataclasses.replace(
|
||||
group,
|
||||
kv_cache_spec=resolve_dcp_kv_cache_spec(
|
||||
group.kv_cache_spec, self.dcp_size
|
||||
group.kv_cache_spec,
|
||||
self.dcp_size,
|
||||
),
|
||||
)
|
||||
for group in kv_cache_config.transfer_groups
|
||||
for group in kv_cache_config.prefix_cacheable_groups
|
||||
]
|
||||
spec_cfg = getattr(vllm_config, "speculative_config", None)
|
||||
use_eagle_block_drop = bool(
|
||||
@@ -1923,10 +1924,16 @@ class MooncakeStoreWorker:
|
||||
use_group_regions = self._kv_cache_config.hisparse_host_num_blocks is not None
|
||||
|
||||
if not use_group_regions:
|
||||
store_layer_names = {
|
||||
layer_name
|
||||
for group in self._kv_cache_groups
|
||||
for layer_name in group.layer_names
|
||||
}
|
||||
seen_storage_ptrs: set[int] = set()
|
||||
cache_tensors = [
|
||||
group_kernel_blocks(_repr_tensor(cache), self.num_blocks)
|
||||
for cache in kv_caches.values()
|
||||
for layer_name, cache in kv_caches.items()
|
||||
if layer_name in store_layer_names
|
||||
]
|
||||
for cache in cache_tensors:
|
||||
cache_storage = cache.untyped_storage()
|
||||
|
||||
Reference in New Issue
Block a user