[kv_offload] Establish tier-owned KV event handling (#46544)

Signed-off-by: Change72 <changg@nvidia.com>
Signed-off-by: Chang Guo <changg@nvidia.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Or Ozeri <oro@il.ibm.com>
This commit is contained in:
Chang Guo
2026-07-07 16:55:20 +03:00
committed by GitHub
co-authored by Claude Opus 4.8 Or Ozeri
parent 65dcde1695
commit c46ced1ee3
11 changed files with 61 additions and 45 deletions
+1
View File
@@ -43,6 +43,7 @@ class KVCacheEvent(
MEDIUM_GPU = "GPU"
MEDIUM_CPU = "CPU"
class BlockStored(KVCacheEvent):
+6 -17
View File
@@ -12,7 +12,6 @@ from typing import TYPE_CHECKING, Any, NamedTuple, NewType
import numpy as np
import torch
from typing_extensions import override
from vllm.logger import init_logger
from vllm.v1.core.kv_cache_utils import resolve_kv_cache_block_sizes
@@ -85,21 +84,12 @@ class ScheduleEndContext(NamedTuple):
preempted_req_ids: Collection[str]
class LoadStoreSpec(ABC):
class LoadStoreSpec:
"""
Abstract metadata that encapsulates information allowing a worker
Metadata that encapsulates information allowing a worker
to load, and optionally also to store, blocks of KV data.
"""
@staticmethod
@abstractmethod
def medium() -> str:
"""
Returns a string representation of the medium type
this store/load targets.
"""
pass
@dataclass
class PrepareStoreOutput:
@@ -313,6 +303,10 @@ class OffloadingManager(ABC):
"""
Take the offloading events from the manager.
A tier manager emits only events for storage state it owns. A
composing manager may aggregate child event streams, but should not
synthesize events on behalf of a child tier.
Yields:
New OffloadingEvents collected since the last call.
"""
@@ -392,11 +386,6 @@ class GPULoadStoreSpec(BlockIDsLoadStoreSpec):
self.group_sizes: Sequence[int] = group_sizes
self.block_indices: Sequence[int] = block_indices
@staticmethod
@override
def medium() -> str:
return "GPU"
@dataclass
class CanonicalKVCacheTensor:
-7
View File
@@ -1,7 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from typing_extensions import override
from vllm.v1.kv_offload.base import BlockIDsLoadStoreSpec
@@ -15,8 +13,3 @@ class CPULoadStoreSpec(BlockIDsLoadStoreSpec):
"""
Spec for loading/storing a KV block to CPU memory.
"""
@staticmethod
@override
def medium() -> str:
return "CPU"
+2 -1
View File
@@ -6,6 +6,7 @@ from typing import Literal
from typing_extensions import override
from vllm.distributed.kv_events import MEDIUM_CPU
from vllm.distributed.kv_transfer.kv_connector.v1.offloading.metrics import (
OffloadingConnectorStats,
)
@@ -51,7 +52,7 @@ class CPUOffloadingManager(OffloadingManager):
store_threshold: int = 1,
max_tracker_size: int = 64_000,
):
self.medium: str = CPULoadStoreSpec.medium()
self.medium: str = MEDIUM_CPU
self._num_blocks: int = num_blocks
self._num_allocated_blocks: int = 0
self._free_list: list[int] = []
+5
View File
@@ -13,6 +13,7 @@ import numpy as np
from vllm.v1.kv_offload.base import (
LookupResult,
OffloadingEvent,
OffloadingMetricMetadata,
OffloadKey,
ReqContext,
@@ -208,6 +209,10 @@ class SecondaryTierManager(ABC):
"""
return False
def take_events(self) -> Iterable[OffloadingEvent]:
"""Take KV events for storage state owned by this tier."""
return ()
def touch(self, keys: Collection[OffloadKey], req_context: ReqContext):
"""
Mark blocks as recently used for eviction policy.
+5 -11
View File
@@ -170,7 +170,6 @@ class TieringOffloadingManager(OffloadingManager):
self,
primary_tier: CPUPrimaryTierOffloadingManager,
secondary_tiers: list[SecondaryTierManager] | None = None,
enable_events: bool = False,
):
"""
Initialize the TieringOffloadingManager.
@@ -179,14 +178,11 @@ class TieringOffloadingManager(OffloadingManager):
primary_tier: The primary tier manager (CPU-based).
secondary_tiers: List of secondary tier managers (e.g., Storage,
Network). Can be None or empty list.
enable_events: Whether to track offloading events
"""
self.primary_tier: CPUPrimaryTierOffloadingManager = primary_tier
self.secondary_tiers = secondary_tiers or []
self._job_id_counter: int = 0
self.events: list[OffloadingEvent] | None = [] if enable_events else None
# Job tracking: maps job_id to metadata for all in-flight transfers.
# JobMetadata.is_promotion distinguishes direction:
# True: secondary → primary (promotion)
@@ -539,7 +535,7 @@ class TieringOffloadingManager(OffloadingManager):
keys: Collection[OffloadKey],
req_context: ReqContext,
success: bool = True,
):
) -> None:
"""
Mark blocks as done storing from GPU to primary tier.
@@ -707,16 +703,14 @@ class TieringOffloadingManager(OffloadingManager):
@override
def take_events(self) -> Iterable[OffloadingEvent]:
"""Yield offloading events collected since the last call.
"""Yield events owned by the primary and secondary tiers.
Yields:
New OffloadingEvents collected since the last call.
New OffloadingEvents collected by each tier since the last call.
"""
if self.events is not None:
yield from self.events
self.events.clear()
yield from self.primary_tier.take_events()
for tier in self.secondary_tiers:
yield from tier.take_events()
@override
def reset_cache(self) -> None:
-1
View File
@@ -168,7 +168,6 @@ class TieringOffloadingSpec(CPUOffloadingSpec):
tiering_manager = TieringOffloadingManager(
primary_tier=primary_tier,
secondary_tiers=secondary_tiers,
enable_events=self.kv_events_config.enable_kv_cache_events,
)
if int(self.extra_config.get("store_threshold", 0)) >= 2:
raise ValueError(