feat(kv-events): emit KV cache metadata (#40984)
Signed-off-by: PeaBrane <yanrpei@gmail.com>
This commit is contained in:
@@ -48,11 +48,11 @@ class KVCacheCoordinator(ABC):
|
||||
self.enable_caching = enable_caching
|
||||
|
||||
self.block_pool = BlockPool(
|
||||
kv_cache_config.num_blocks,
|
||||
enable_caching,
|
||||
hash_block_size,
|
||||
enable_kv_cache_events,
|
||||
metrics_collector,
|
||||
num_gpu_blocks=kv_cache_config.num_blocks,
|
||||
enable_caching=enable_caching,
|
||||
hash_block_size=hash_block_size,
|
||||
enable_kv_cache_events=enable_kv_cache_events,
|
||||
metrics_collector=metrics_collector,
|
||||
)
|
||||
|
||||
# KV cache group indices that get the EAGLE last-block drop.
|
||||
|
||||
@@ -6,12 +6,16 @@ from collections.abc import Sequence
|
||||
from dataclasses import dataclass
|
||||
from typing import Literal, overload
|
||||
|
||||
from vllm.distributed.kv_events import KVCacheEvent
|
||||
from vllm.distributed.kv_events import BlockStored, KVCacheEvent
|
||||
from vllm.logger import init_logger
|
||||
from vllm.v1.core.kv_cache_coordinator import get_kv_cache_coordinator
|
||||
from vllm.v1.core.kv_cache_metrics import KVCacheMetricsCollector
|
||||
from vllm.v1.core.kv_cache_utils import KVCacheBlock
|
||||
from vllm.v1.kv_cache_interface import KVCacheConfig
|
||||
from vllm.v1.kv_cache_interface import (
|
||||
KVCacheConfig,
|
||||
get_kv_cache_spec_kind,
|
||||
get_kv_cache_spec_sliding_window,
|
||||
)
|
||||
from vllm.v1.metrics.stats import PrefixCacheStats
|
||||
from vllm.v1.request import Request
|
||||
|
||||
@@ -149,6 +153,13 @@ class KVCacheManager:
|
||||
self.num_kv_cache_groups = len(kv_cache_config.kv_cache_groups)
|
||||
self.block_pool = self.coordinator.block_pool
|
||||
self.kv_cache_config = kv_cache_config
|
||||
self.kv_cache_event_metadata = tuple(
|
||||
(
|
||||
get_kv_cache_spec_kind(group.kv_cache_spec).value,
|
||||
get_kv_cache_spec_sliding_window(group.kv_cache_spec),
|
||||
)
|
||||
for group in kv_cache_config.kv_cache_groups
|
||||
)
|
||||
|
||||
# Pre-constructed KVCacheBlocks with no blocks, callers should use this
|
||||
# via create_kv_cache_blocks instead of creating new ones to avoid GC
|
||||
@@ -502,7 +513,25 @@ class KVCacheManager:
|
||||
Returns:
|
||||
A list of KV cache events.
|
||||
"""
|
||||
return self.block_pool.take_events()
|
||||
events = self.block_pool.take_events()
|
||||
for event in events:
|
||||
if not isinstance(event, BlockStored):
|
||||
continue
|
||||
if event.group_idx is None:
|
||||
continue
|
||||
if event.group_idx < 0 or event.group_idx >= len(
|
||||
self.kv_cache_event_metadata
|
||||
):
|
||||
logger.warning(
|
||||
"Group index `%s` not in KV cache metadata", event.group_idx
|
||||
)
|
||||
continue
|
||||
# Annotate here so BlockPool can keep emitting structural cache
|
||||
# events without owning semantic KV cache spec metadata.
|
||||
kind, sliding_window = self.kv_cache_event_metadata[event.group_idx]
|
||||
event.kv_cache_spec_kind = kind
|
||||
event.kv_cache_spec_sliding_window = sliding_window
|
||||
return events
|
||||
|
||||
def get_blocks(self, request_id: str) -> KVCacheBlocks:
|
||||
"""Get the blocks of a request."""
|
||||
|
||||
Reference in New Issue
Block a user