Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
16c7d27
[kv_offload] Emit secondary-tier BlockStored presence events
Change72 Jun 23, 2026
c3ac1f4
[kv_offload] Use stable wire medium names for offload tiers
Change72 Jun 24, 2026
f32d355
[kv_offload] Use MEDIUM_GPU constant in GPULoadStoreSpec.medium()
Change72 Jun 24, 2026
4655f21
[kv_offload] Make secondary tier events opt-in via medium()
Change72 Jun 25, 2026
4f373a5
[kv_offload] Fix stale medium() comments and test fs/obj opt-in
Change72 Jun 25, 2026
ef01110
Merge origin/main into feat/tiering-secondary-presence-events
Change72 Jun 25, 2026
ce13f90
[kv_offload] Clarify OffloadingManager.medium() docstring
Change72 Jun 26, 2026
b8239bc
[kv_offload] Restore merged base.py and clarify medium() docstring
Change72 Jun 26, 2026
44376af
[kv_offload] Move Stored KV event emission to the connector
Change72 Jun 28, 2026
c7246bd
[kv_offload] Gate Stored-event metadata capture; de-scope follow-up bits
Change72 Jun 28, 2026
4bdb089
[kv_offload] Review fixes: evaluate medium once; pin event uses retur…
Change72 Jun 28, 2026
6753237
[kv_offload] Reuse one _stored_event_medium helper for capture and emit
Change72 Jun 29, 2026
b323dda
Merge branch 'main' into feat/tiering-secondary-presence-events
Change72 Jun 30, 2026
c88be84
[kv_offload] Restore tier-owned KV event responsibility
Change72 Jul 6, 2026
c891bab
[kv_offload] Preserve tiering event configuration
Change72 Jul 6, 2026
7135538
Revert "[kv_offload] Preserve tiering event configuration"
Change72 Jul 6, 2026
c492bf4
[kv_offload] Test eviction event ordering
Change72 Jul 6, 2026
af1ac90
Merge branch 'main' into feat/tiering-secondary-presence-events
orozery Jul 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from tests.v1.kv_connector.unit.utils import create_vllm_config
from vllm.config import KVEventsConfig, KVTransferConfig
from vllm.distributed.kv_events import BlockRemoved, BlockStored
from vllm.distributed.kv_events import MEDIUM_CPU, BlockRemoved, BlockStored
from vllm.distributed.kv_transfer.kv_connector.v1.offloading.events import (
OffloadingEventGroupSpec,
OffloadingEventsTracker,
Expand All @@ -28,10 +28,9 @@
OffloadKey,
make_offload_key,
)
from vllm.v1.kv_offload.cpu.common import CPULoadStoreSpec
from vllm.v1.kv_offload.tiering.spec import TieringOffloadingSpec

_CPU_MEDIUM = CPULoadStoreSpec.medium()
_CPU_MEDIUM = MEDIUM_CPU
_FULL_ATTENTION_EVENT_SPEC = OffloadingEventGroupSpec(
kv_cache_spec_kind=KVCacheSpecKind.FULL_ATTENTION.value,
kv_cache_spec_sliding_window=None,
Expand Down
4 changes: 0 additions & 4 deletions tests/v1/kv_connector/unit/offloading_connector/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ class MockLoadStoreSpec(LoadStoreSpec):
def __init__(self, offload_keys: Iterable[OffloadKey]):
self.offload_keys: list[OffloadKey] = list(offload_keys)

@staticmethod
def medium() -> str:
return "Mock"

def __repr__(self) -> str:
return repr(self.offload_keys)

Expand Down
22 changes: 21 additions & 1 deletion tests/v1/kv_offload/cpu/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
import pytest

from vllm.distributed.kv_events import MEDIUM_CPU
from vllm.v1.kv_offload.base import (
LoadStoreSpec,
LookupResult,
Expand Down Expand Up @@ -99,7 +100,7 @@ def verify_events(
stores: list[set[OffloadKey]] = []
evictions: list[set[OffloadKey]] = []
for event in events:
assert event.medium == CPULoadStoreSpec.medium()
assert event.medium == MEDIUM_CPU
if event.removed:
evictions.append(set(event.keys))
else:
Expand All @@ -114,6 +115,25 @@ def to_key_sets(
assert tuple(stores) == to_key_sets(expected_stores)


def test_cpu_eviction_removed_precedes_stored():
"""An eviction is announced before the store that reuses its capacity."""
manager = make_cpu_manager(num_blocks=2, enable_events=True)

manager.prepare_store(to_keys([1, 2]), _EMPTY_REQ_CTX)
manager.complete_store(to_keys([1, 2]), _EMPTY_REQ_CTX)
list(manager.take_events())

manager.prepare_store(to_keys([3]), _EMPTY_REQ_CTX)
manager.complete_store(to_keys([3]), _EMPTY_REQ_CTX)

events = list(manager.take_events())
removed_idx = [i for i, event in enumerate(events) if event.removed]
stored_idx = [i for i, event in enumerate(events) if not event.removed]
assert removed_idx and stored_idx, events
assert max(removed_idx) < min(stored_idx)
assert all(event.medium == manager.medium for event in events)


@pytest.mark.parametrize("eviction_policy", ["lru", "arc"])
def test_already_stored_block_not_evicted_during_prepare_store(eviction_policy):
"""
Expand Down
19 changes: 19 additions & 0 deletions tests/v1/kv_offload/tiering/test_tiering_offloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from vllm.v1.kv_offload.base import (
LookupResult,
OffloadingCounterMetadata,
OffloadingEvent,
OffloadKey,
OffloadPolicy,
ReqContext,
Expand Down Expand Up @@ -242,6 +243,24 @@ def _start_request(self, req_context: ReqContext = _CTX):
if req_context.req_id not in self.manager._req_state:
self.manager.on_new_request(req_context)

def test_take_events_aggregates_tier_owned_events(self, manager_setup):
primary_event = OffloadingEvent(to_keys([1]), "CPU", removed=False)
secondary_event1 = OffloadingEvent(to_keys([2]), "tier-1", removed=False)
secondary_event2 = OffloadingEvent(to_keys([3]), "tier-2", removed=True)

self.primary_tier.take_events = MagicMock(return_value=[primary_event])
self.secondary_tier1.take_events = MagicMock(return_value=[secondary_event1])
self.secondary_tier2.take_events = MagicMock(return_value=[secondary_event2])

assert list(self.manager.take_events()) == [
primary_event,
secondary_event1,
secondary_event2,
]
self.primary_tier.take_events.assert_called_once_with()
self.secondary_tier1.take_events.assert_called_once_with()
self.secondary_tier2.take_events.assert_called_once_with()

def test_basic_store_to_primary(self, manager_setup):
"""Test basic store operation to primary tier."""
blocks = to_keys(range(3))
Expand Down
1 change: 1 addition & 0 deletions vllm/distributed/kv_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class KVCacheEvent(


MEDIUM_GPU = "GPU"
MEDIUM_CPU = "CPU"


class BlockStored(KVCacheEvent):
Expand Down
23 changes: 6 additions & 17 deletions vllm/v1/kv_offload/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -313,6 +303,10 @@ def take_events(self) -> Iterable[OffloadingEvent]:
"""
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.
"""
Expand Down Expand Up @@ -392,11 +386,6 @@ def __init__(
self.group_sizes: Sequence[int] = group_sizes
self.block_indices: Sequence[int] = block_indices

@staticmethod
@override
def medium() -> str:
return "GPU"


@dataclass
class CanonicalKVCacheTensor:
Expand Down
7 changes: 0 additions & 7 deletions vllm/v1/kv_offload/cpu/common.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -15,8 +13,3 @@ class CPULoadStoreSpec(BlockIDsLoadStoreSpec):
"""
Spec for loading/storing a KV block to CPU memory.
"""

@staticmethod
@override
def medium() -> str:
return "CPU"
3 changes: 2 additions & 1 deletion vllm/v1/kv_offload/cpu/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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,
)
Expand Down Expand Up @@ -51,7 +52,7 @@ def __init__(
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] = []
Expand Down
5 changes: 5 additions & 0 deletions vllm/v1/kv_offload/tiering/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from vllm.v1.kv_offload.base import (
LookupResult,
OffloadingEvent,
OffloadingMetricMetadata,
OffloadKey,
ReqContext,
Expand Down Expand Up @@ -208,6 +209,10 @@ def has_pending_work(self) -> bool:
"""
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.
Expand Down
16 changes: 5 additions & 11 deletions vllm/v1/kv_offload/tiering/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ def __init__(
self,
primary_tier: CPUPrimaryTierOffloadingManager,
secondary_tiers: list[SecondaryTierManager] | None = None,
enable_events: bool = False,
):
"""
Initialize the TieringOffloadingManager.
Expand All @@ -179,14 +178,11 @@ def __init__(
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)
Expand Down Expand Up @@ -539,7 +535,7 @@ def complete_store(
keys: Collection[OffloadKey],
req_context: ReqContext,
success: bool = True,
):
) -> None:
"""
Mark blocks as done storing from GPU to primary tier.

Expand Down Expand Up @@ -707,16 +703,14 @@ def has_pending_work(self) -> bool:

@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:
Expand Down
1 change: 0 additions & 1 deletion vllm/v1/kv_offload/tiering/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ def get_manager(self) -> OffloadingManager:
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(
Expand Down
Loading