From d33e9b783219ec96df153bfd6383b78a7fc48961 Mon Sep 17 00:00:00 2001 From: Or Ozeri Date: Thu, 26 Nov 2026 09:11:22 +0200 Subject: [PATCH] Revert "[KV Offload] Return pending work, events and stats from on_schedule_end (#68962)" This reverts commit 27053d0137005f5d5e55077314fa40d22b16d7fb. #68962 moved the step-end report into on_schedule_end(), which runs before the forward pass. Completions only reach the manager in update_connector_output(), so events and stats produced by a finished transfer are now reported one step later, and an idle engine takes one extra step to flush them. Reverting restores same-step reporting: get_stats() and take_events() are read after update_connector_output() and therefore see the step's completions. Item 4 of #68678 is intended to re-land as a single batched complete_transfers() call that returns the post-completion StepResult. Co-Authored-By: Claude Code Signed-off-by: Or Ozeri --- .../offloading_connector/test_scheduler.py | 97 ++++++------------- .../unit/offloading_connector/utils.py | 3 +- tests/v1/kv_offload/cpu/test_manager.py | 38 -------- .../v1/kv_offload/tiering/p2p/test_manager.py | 14 --- tests/v1/kv_offload/tiering/test_fs_tier.py | 7 +- .../tiering/test_tiering_offloading.py | 15 +-- .../kv_connector/v1/offloading/scheduler.py | 72 +++++--------- vllm/v1/kv_offload/base.py | 48 ++++----- vllm/v1/kv_offload/cpu/manager.py | 9 -- vllm/v1/kv_offload/tiering/manager.py | 12 +-- 10 files changed, 99 insertions(+), 216 deletions(-) diff --git a/tests/v1/kv_connector/unit/offloading_connector/test_scheduler.py b/tests/v1/kv_connector/unit/offloading_connector/test_scheduler.py index d50ea98fc26c..7c9266705bb4 100644 --- a/tests/v1/kv_connector/unit/offloading_connector/test_scheduler.py +++ b/tests/v1/kv_connector/unit/offloading_connector/test_scheduler.py @@ -117,7 +117,6 @@ OffloadPolicy, ReqContext, RequestOffloadingContext, - StepResult, StoreTrigger, get_offload_block_hash, get_offload_group_idx, @@ -2537,27 +2536,6 @@ def test_cache_reset_without_in_flight_jobs_holds_nothing(): scheduler.shutdown() -def test_cascade_after_the_last_store_keeps_engine_stepping(): - """The last store's report cascades it to a secondary tier after - on_schedule_end(), so the engine keeps stepping until that job is done.""" - scheduler, manager = _make_tiering_engine_scheduler([{"type": "example"}]) - try: - stored = _store_in_flight(scheduler) - output = scheduler.schedule() - _report_jobs(scheduler, output, stored) - assert manager.has_pending_work() - - for _ in range(10): - if not scheduler.has_requests(): - break - output = scheduler.schedule() - scheduler.update_from_output(output, create_model_runner_output([])) - assert not scheduler.has_requests() - assert not manager.has_pending_work() - finally: - scheduler.shutdown() - - def test_cache_reset_twice_before_a_step_still_flushes(): """A second reset before the engine steps must not assert: RL loops call reset_prefix_cache(reset_connector=True) every iteration, and EngineCore @@ -3010,11 +2988,12 @@ def test_step_releases_the_manager_before_the_model_runs(request_runner): assert lock.__enter__.call_count == lock.__exit__.call_count -def test_has_pending_push_work_follows_the_step_result(request_runner): - """It reads the last StepResult and never enters the manager. +def test_has_pending_push_work_does_not_open_the_step_region(request_runner): + """It must take a short region, never the step-scoped one. - The engine asks this before schedule(), so entering the manager here could - leave the step-scoped region open on an idle engine. + The engine asks this before schedule() and returns early when the answer is + False, so a step-scoped acquire here would never reach the release in + build_connector_meta and would hold the manager for good. """ runner = request_runner( block_size=4, @@ -3022,49 +3001,38 @@ def test_has_pending_push_work_follows_the_step_result(request_runner): async_scheduling=False, ) scheduler = runner.connector_scheduler - lock = runner.manager.lock - # No step has reported yet. - assert scheduler.has_pending_push_work() is True - - runner.manager.on_schedule_end.return_value = StepResult(pending=True) - runner.scheduler.schedule() - entered = lock.__enter__.call_count - assert scheduler.has_pending_push_work() is True + runner.manager.has_pending_work.return_value = False - runner.manager.on_schedule_end.return_value = StepResult() - runner.scheduler.schedule() assert scheduler.has_pending_push_work() is False - assert lock.__enter__.call_count == entered + 1 + assert scheduler._step_region is None + lock = runner.manager.lock assert lock.__enter__.call_count == lock.__exit__.call_count -def test_step_result_events_and_stats_are_reported_once(request_runner): - """Results of several steps accumulate until take_events() and - get_stats() drain them, as with async scheduling.""" +def test_take_events_drains_the_manager_inside_the_region(request_runner): + """take_events must not hold the manager across its own iteration. + + manager.take_events() is a generator whose backing list is cleared once + exhausted, so draining it lazily would both pin the manager for as long as + the consumer takes and lose events appended in the meantime. + """ runner = request_runner( block_size=4, num_gpu_blocks=10, async_scheduling=False, ) scheduler = runner.connector_scheduler - keys = [make_offload_key(bytes([i]) * 32, 0) for i in range(2)] - for key in keys: - stats = OffloadingConnectorStats() - stats.increase_counter(_ConnectorMetricName.ALLOCATION_FAILURE) - runner.manager.on_schedule_end.return_value = StepResult( - events=[OffloadingEvent(keys=[key], medium=Medium.CPU, removed=True)], - stats=stats, - ) - runner.scheduler.schedule() + runner.manager.take_events.return_value = iter(()) + runner.manager.reset_mock() events = list(scheduler.take_events()) - assert len(events) == 2 - assert all(isinstance(event, BlockRemoved) for event in events) - assert list(scheduler.take_events()) == [] - stats = scheduler.get_stats() - assert stats is not None - assert stats.reduce()[_ConnectorMetricName.ALLOCATION_FAILURE] == 2 - assert scheduler.get_stats() is None + + assert events == [] + assert runner.manager.take_events.call_count == 1 + assert scheduler._step_region is None + lock = runner.manager.lock + assert lock.__enter__.call_count == 1 + assert lock.__exit__.call_count == 1 def test_scheduler_reports_lookup_async_delay_on_resolve(request_runner): @@ -3094,6 +3062,7 @@ def test_max_offload_tokens_zero_does_not_record_pending_lookups(request_runner) async_scheduling=False, ) runner.manager.lookup.return_value = LookupResult.RETRY + runner.manager.take_events.return_value = [] runner.manager.prepare_store.side_effect = lambda keys, req_context, trigger: ( generate_store_output(keys) ) @@ -3127,13 +3096,12 @@ def test_abort_before_hit_uses_placeholder_then_later_hit_heals_removal( ) raw_events: list[OffloadingEvent] = [] - def on_schedule_end(context): - events = list(raw_events) + def take_raw_events(): + yield from raw_events raw_events.clear() - return StepResult(events=events) runner.manager.lookup.return_value = LookupResult.RETRY - runner.manager.on_schedule_end.side_effect = on_schedule_end + runner.manager.take_events.side_effect = take_raw_events runner.manager.prepare_store.side_effect = lambda keys, req_context, trigger: ( generate_store_output([]) ) @@ -3152,7 +3120,6 @@ def on_schedule_end(context): assert not tracker._pending_event_metadata raw_events.append(OffloadingEvent(keys=[key], medium=Medium.CPU, removed=False)) - runner.scheduler.schedule() events = list(runner.connector_scheduler.take_events()) assert len(events) == 1 assert isinstance(events[0], BlockStored) @@ -3174,7 +3141,6 @@ def on_schedule_end(context): assert key in tracker._pending_event_metadata raw_events.append(OffloadingEvent(keys=[key], medium=Medium.CPU, removed=True)) - runner.scheduler.schedule() [event] = runner.connector_scheduler.take_events() assert isinstance(event, BlockRemoved) assert event.medium == MEDIUM_CPU @@ -3212,13 +3178,12 @@ def lookup(key, req_context): raw_events.append(OffloadingEvent(keys=[key], medium=Medium.CPU, removed=False)) return LookupResult.HIT - def on_schedule_end(context): - events = list(raw_events) + def take_raw_events(): + yield from raw_events raw_events.clear() - return StepResult(events=events) runner.manager.lookup.side_effect = lookup - runner.manager.on_schedule_end.side_effect = on_schedule_end + runner.manager.take_events.side_effect = take_raw_events runner.manager.prepare_store.side_effect = lambda keys, req_context, trigger: ( generate_store_output([]) ) diff --git a/tests/v1/kv_connector/unit/offloading_connector/utils.py b/tests/v1/kv_connector/unit/offloading_connector/utils.py index f7e97e57285d..cebbef8beb80 100644 --- a/tests/v1/kv_connector/unit/offloading_connector/utils.py +++ b/tests/v1/kv_connector/unit/offloading_connector/utils.py @@ -66,7 +66,6 @@ OffloadKey, PrepareStoreOutput, RequestOffloadingContext, - StepResult, TransferResult, make_offload_key, ) @@ -224,7 +223,7 @@ def __init__(self, config: OffloadingConfig): self.manager.lookup.return_value = LookupResult.MISS self.manager.prepare_store.return_value.keys_to_retry = [] self.manager.get_load_source.return_value = CacheHitSource.EXTERNAL_UNSPECIFIED - self.manager.on_schedule_end.return_value = StepResult() + self.manager.get_stats.return_value = None self.manager.config_info.return_value = [{}] self.manager.on_new_request.return_value = RequestOffloadingContext() diff --git a/tests/v1/kv_offload/cpu/test_manager.py b/tests/v1/kv_offload/cpu/test_manager.py index 1d07b820ccb3..336673e3a1f8 100644 --- a/tests/v1/kv_offload/cpu/test_manager.py +++ b/tests/v1/kv_offload/cpu/test_manager.py @@ -16,7 +16,6 @@ OffloadKey, PrepareStoreOutput, ReqContext, - ScheduleEndContext, StoreTrigger, make_offload_key, ) @@ -171,43 +170,6 @@ def test_cpu_stored_event_carries_request_context(): assert event.req_context is req_context -def test_cpu_schedule_end_reports_events_and_stats_once(): - manager = make_cpu_manager(num_chunks=2, enable_events=True) - manager.prepare_store(to_keys([1]), _EMPTY_REQ_CTX, trigger=StoreTrigger.ON_COMPUTE) - manager.complete_store( - to_keys([1]), _EMPTY_REQ_CTX, trigger=StoreTrigger.ON_COMPUTE - ) - context = ScheduleEndContext(new_req_ids=(), preempted_req_ids=()) - - result = manager.on_schedule_end(context) - - assert not result.pending - verify_events(result.events, expected_stores=({1},)) - assert result.stats is not None - assert CPUOffloadingMetrics.CPU_CACHE_USAGE_PERC in result.stats.reduce() - assert manager.on_schedule_end(context).events == [] - - -def test_reset_drops_undrained_stored_events(): - manager = make_cpu_manager(num_chunks=2, enable_events=True) - manager.prepare_store( - to_keys([1, 2]), _EMPTY_REQ_CTX, trigger=StoreTrigger.ON_COMPUTE - ) - manager.complete_store( - to_keys([1, 2]), _EMPTY_REQ_CTX, trigger=StoreTrigger.ON_COMPUTE - ) - list(manager.take_events()) - # Evicts chunk 1, then stores chunk 3; neither event is drained yet. - manager.prepare_store(to_keys([3]), _EMPTY_REQ_CTX, trigger=StoreTrigger.ON_COMPUTE) - manager.complete_store( - to_keys([3]), _EMPTY_REQ_CTX, trigger=StoreTrigger.ON_COMPUTE - ) - - manager.reset_cache() - - verify_events(manager.take_events(), expected_evictions=({1},)) - - def test_cpu_eviction_removed_precedes_stored(): """An eviction is announced before the store that reuses its capacity.""" manager = make_cpu_manager(num_chunks=2, enable_events=True) diff --git a/tests/v1/kv_offload/tiering/p2p/test_manager.py b/tests/v1/kv_offload/tiering/p2p/test_manager.py index c19f4fbf3745..69a504a6c4b9 100644 --- a/tests/v1/kv_offload/tiering/p2p/test_manager.py +++ b/tests/v1/kv_offload/tiering/p2p/test_manager.py @@ -1317,7 +1317,6 @@ def test_B2_idle_manager_does_not_keep_engine_busy(self): from vllm.distributed.kv_transfer.kv_connector.v1.offloading.scheduler import ( OffloadingConnectorScheduler, - _ManagerStepState, ) from vllm.distributed.kv_transfer.kv_connector.v1.offloading_connector import ( OffloadingConnector, @@ -1344,12 +1343,6 @@ def test_B2_idle_manager_does_not_keep_engine_busy(self): connector_scheduler.manager = manager connector_scheduler._job_statuses = {} connector_scheduler._reset_fence = {} - connector_scheduler._step_state = _ManagerStepState() - connector_scheduler._step_state.update( - manager.on_schedule_end( - ScheduleEndContext(new_req_ids=(), preempted_req_ids=()) - ) - ) connector = object.__new__(OffloadingConnector) connector.connector_scheduler = connector_scheduler scheduler = object.__new__(Scheduler) @@ -1381,7 +1374,6 @@ def test_B2_no_poll_thread_keeps_engine_busy(self): from vllm.distributed.kv_transfer.kv_connector.v1.offloading.scheduler import ( OffloadingConnectorScheduler, - _ManagerStepState, ) from vllm.distributed.kv_transfer.kv_connector.v1.offloading_connector import ( OffloadingConnector, @@ -1410,12 +1402,6 @@ def test_B2_no_poll_thread_keeps_engine_busy(self): connector_scheduler.manager = manager connector_scheduler._job_statuses = {} connector_scheduler._reset_fence = {} - connector_scheduler._step_state = _ManagerStepState() - connector_scheduler._step_state.update( - manager.on_schedule_end( - ScheduleEndContext(new_req_ids=(), preempted_req_ids=()) - ) - ) connector = object.__new__(OffloadingConnector) connector.connector_scheduler = connector_scheduler scheduler = object.__new__(Scheduler) diff --git a/tests/v1/kv_offload/tiering/test_fs_tier.py b/tests/v1/kv_offload/tiering/test_fs_tier.py index 1a4dad2ad55f..f420e7aab424 100644 --- a/tests/v1/kv_offload/tiering/test_fs_tier.py +++ b/tests/v1/kv_offload/tiering/test_fs_tier.py @@ -1190,8 +1190,8 @@ def test_events_require_global_kv_events_flag(tmp_path): def test_cascade_store_emits_fs_event_through_tiering_manager(tmp_path): - """A GPU->CPU->fs cascade surfaces the tier-owned FS stored event in the - TieringOffloadingManager's aggregated StepResult.""" + """A GPU->CPU->fs cascade surfaces the tier-owned FS stored event via the + TieringOffloadingManager's aggregated take_events().""" from vllm.v1.kv_offload.tiering.manager import ( CPUPrimaryTierOffloadingManager, TieringOffloadingManager, @@ -1225,7 +1225,8 @@ def test_cascade_store_emits_fs_event_through_tiering_manager(tmp_path): ctx = ScheduleEndContext(new_req_ids=[], preempted_req_ids=()) deadline = time.monotonic() + 5.0 while time.monotonic() < deadline and not events: - events.extend(manager.on_schedule_end(ctx).events) + manager.on_schedule_end(ctx) + events.extend(manager.take_events()) time.sleep(0.01) fs_events = [e for e in events if e.medium == Medium.STORAGE] diff --git a/tests/v1/kv_offload/tiering/test_tiering_offloading.py b/tests/v1/kv_offload/tiering/test_tiering_offloading.py index 7233ba805142..179228a61996 100644 --- a/tests/v1/kv_offload/tiering/test_tiering_offloading.py +++ b/tests/v1/kv_offload/tiering/test_tiering_offloading.py @@ -39,7 +39,6 @@ OffloadPolicy, ReqContext, ScheduleEndContext, - StepResult, StoreTrigger, TierFilter, TierMatcher, @@ -359,12 +358,11 @@ def manager_setup(self): secondary_tiers=[self.secondary_tier1, self.secondary_tier2], ) - def _simulate_on_schedule_end( - self, new_req_ids: list[str] | None = None - ) -> StepResult: + def _simulate_on_schedule_end(self, new_req_ids: list[str] | None = None): """Simulate end of scheduler step: lifecycle flush + drain events.""" ctx = ScheduleEndContext(new_req_ids=new_req_ids or [], preempted_req_ids=()) - return self.manager.on_schedule_end(ctx) + self.manager.on_schedule_end(ctx) + list(self.manager.take_events()) def _start_request(self, req_context: ReqContext = _CTX): if req_context.req_id not in self.manager._req_state: @@ -641,7 +639,9 @@ def submit_load(job_metadata): self._simulate_on_schedule_end() # End of step 2: processes the completed promotion jobs - stats = self._simulate_on_schedule_end().stats + self._simulate_on_schedule_end() + + stats = self.manager.get_stats() assert stats is not None reduced = stats.reduce() assert ( @@ -935,7 +935,8 @@ def test_lookup_does_not_report_async_delay_for_promotion(self, manager_setup): assert self.manager.lookup(chunk, _CTX) is LookupResult.HIT_PENDING # Promotion is not treated as unresolved secondary lookup time. - stats = self._simulate_on_schedule_end(new_req_ids=[_CTX.req_id]).stats + self._simulate_on_schedule_end(new_req_ids=[_CTX.req_id]) + stats = self.manager.get_stats() assert stats is not None reduced = stats.reduce() assert ( diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/offloading/scheduler.py b/vllm/distributed/kv_transfer/kv_connector/v1/offloading/scheduler.py index e29604b1e973..067d4757b0f2 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/offloading/scheduler.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/offloading/scheduler.py @@ -50,7 +50,6 @@ Locality, LookupResult, Medium, - OffloadingEvent, OffloadingManager, OffloadingSpec, OffloadKey, @@ -58,7 +57,6 @@ ReqContext, RequestOffloadingContext, ScheduleEndContext, - StepResult, StoreTrigger, TierFilter, TierMatcher, @@ -177,35 +175,6 @@ def _create_req_context( ) -@dataclass(slots=True) -class _ManagerStepState: - """What the connector keeps from the manager's StepResults between steps.""" - - # The latest StepResult.pending; True until the first step reports. - pending: bool = True - # Events from every StepResult since take_events() last drained them. - events: list[OffloadingEvent] = field(default_factory=list) - # Set when a finished transfer reaches the manager after the latest - # on_schedule_end(). - _stale: bool = field(default=False, init=False) - - def update(self, result: StepResult) -> None: - self.pending = result.pending - self.events.extend(result.events) - self._stale = False - - def mark_stale(self) -> None: - self._stale = True - - @property - def is_stale(self) -> bool: - return self._stale - - def take_events(self) -> list[OffloadingEvent]: - events, self.events = self.events, [] - return events - - class _StoreJobSink: """The store-job intake of one handler in one scheduler step.""" @@ -293,7 +262,6 @@ def __init__( # it cannot write. self.access_mode: OffloadAccessMode = spec.access_mode self._connector_stats = OffloadingConnectorStats() - self._step_state = _ManagerStepState() self.num_hash_lookahead_tokens = vllm_config.num_hash_lookahead_tokens # The static config facts ride on the first stats payload of this @@ -1479,10 +1447,7 @@ def _build_connector_meta( # on_request_finished above. on_schedule_end is documented as running at # the end of the step, and callers rely on that to bound the step's # exclusive access to the manager. - result = self.manager.on_schedule_end(schedule_end_context) - self._step_state.update(result) - if result.stats is not None: - self._connector_stats.aggregate(result.stats) + self.manager.on_schedule_end(schedule_end_context) return meta def has_pending_push_work(self) -> bool: @@ -1491,19 +1456,19 @@ def has_pending_push_work(self) -> bool: While True, build_connector_meta() and update_connector_output() continue to be called even when no requests are scheduled. - Answers from the latest StepResult, without entering the manager. A - transfer that finishes after it may give the manager more work, so the - engine keeps stepping until the next StepResult. + Must use a short region, never the step-scoped one. The engine asks this + before schedule() and returns early when the answer is False, so a + step-scoped acquire here would never reach build_connector_meta's + release and would hold the manager for good -- which is precisely the + state an idle engine settles into. A cache reset fence also keeps it stepping: the flush must reach the workers and their reports come back before on_reset_flushed(). """ - return bool( - self._job_statuses - or self._reset_fence - or self._step_state.pending - or self._step_state.is_stale - ) + if self._job_statuses or self._reset_fence: + return True + with self._manager_locked(): + return self.manager.has_pending_work() def update_connector_output(self, connector_output: KVConnectorOutput): """Update KVConnector state from worker-side connectors output. @@ -1585,7 +1550,6 @@ def _update_connector_output(self, connector_output: KVConnectorOutput): if job_status.pending_count > 0: continue assert job_status.pending_count == 0 - self._step_state.mark_stale() req_status = self._req_status[job_status.req_id] if job_status.is_store: @@ -1637,6 +1601,14 @@ def get_stats(self) -> OffloadingConnectorStats | None: stats = self._connector_stats self._connector_stats = OffloadingConnectorStats() + with self._manager_locked(): + manager_stats = self.manager.get_stats() + if manager_stats is not None: + if stats is None: + stats = manager_stats + else: + stats.aggregate(manager_stats) + if not self._info_sent: if stats is None: stats = OffloadingConnectorStats() @@ -1714,7 +1686,13 @@ def take_events(self) -> Iterable[KVCacheEvent]: the underlying `OffloadingEvent` stream. """ - manager_events = self._step_state.take_events() + # Drain the manager eagerly, inside the region. manager.take_events() is + # itself a generator whose backing list is cleared once exhausted, so + # iterating it lazily would both hold the manager for as long as the + # consumer takes and let a concurrent writer append events that the + # clear then discards unpublished. + with self._manager_locked(): + manager_events = list(self.manager.take_events()) # Still a generator, so callers testing the result for truthiness keep # seeing a non-empty object the way they do today. yield from self._events_tracker.take_events(manager_events) diff --git a/vllm/v1/kv_offload/base.py b/vllm/v1/kv_offload/base.py index 1978c7b5d5c2..b660001c5b25 100644 --- a/vllm/v1/kv_offload/base.py +++ b/vllm/v1/kv_offload/base.py @@ -3,7 +3,7 @@ """Core abstractions for KV cache offloading in vLLM v1.""" from abc import ABC, abstractmethod -from collections.abc import Collection, Mapping, Sequence +from collections.abc import Collection, Iterable, Mapping, Sequence from contextlib import AbstractContextManager, nullcontext from dataclasses import dataclass, field, fields from enum import Enum, auto @@ -228,19 +228,6 @@ class OffloadingEvent: req_context: ReqContext | None = field(default=None, repr=False, compare=False) -@dataclass(frozen=True, slots=True) -class StepResult: - """What the manager reports to the connector once per step.""" - - # Whether the engine must keep stepping with no requests scheduled. Read - # only here, so a manager cannot raise it between steps. - pending: bool = False - # Events collected since the previous step, in emission order. - events: list[OffloadingEvent] = field(default_factory=list) - # Metrics collected since the previous step, or None if disabled. - stats: "OffloadingConnectorStats | None" = None - - """ OffloadingManager class for managing KV data offloading in vLLM v1 @@ -503,7 +490,20 @@ def on_request_finished(self, req_context: ReqContext) -> None: """ return - def on_schedule_end(self, context: ScheduleEndContext) -> StepResult: + 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. + + """ + return () + + def on_schedule_end(self, context: ScheduleEndContext) -> None: """Called once at the end of each scheduler step. This is the last manager call of a step: every lookup(), prepare_load(), @@ -512,16 +512,16 @@ def on_schedule_end(self, context: ScheduleEndContext) -> StepResult: Managers may override this to flush deferred work accumulated during the step (e.g., batched promotions). + """ + return - A tier manager reports 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. - - Returns: - Everything the connector reads from the manager for this step. + def has_pending_work(self) -> bool: + """Whether this manager needs the engine to keep stepping. + While True, on_schedule_end() and get_finished_jobs() continue + to be called even when no requests are scheduled. """ - return StepResult() + return False def reset_cache(self) -> None: """Evict all tracked blocks and reset internal state.""" @@ -532,6 +532,10 @@ def on_reset_flushed(self) -> None: reset_cache(); blocks it freed are no longer written by them.""" return + def get_stats(self) -> "OffloadingConnectorStats | None": + """Return collected metrics since last call, or None if disabled.""" + return None + def config_info(self) -> Sequence[ConfigInfoMapping]: """Return the info metric labels, one mapping for each series. diff --git a/vllm/v1/kv_offload/cpu/manager.py b/vllm/v1/kv_offload/cpu/manager.py index 6b8749db1b8b..46c75e0d6f86 100644 --- a/vllm/v1/kv_offload/cpu/manager.py +++ b/vllm/v1/kv_offload/cpu/manager.py @@ -21,8 +21,6 @@ PrepareStoreOutput, ReqContext, RequestOffloadingContext, - ScheduleEndContext, - StepResult, StoreTrigger, get_offload_group_idx, ) @@ -540,15 +538,8 @@ def reset_cache(self) -> None: self._free_list.clear() self._num_allocated_chunks = 0 - if self.events is not None: - # A stored event drained after the reset would announce a chunk - # it dropped. - self.events = [event for event in self.events if event.removed] @override - def on_schedule_end(self, context: ScheduleEndContext) -> StepResult: - return StepResult(events=list(self.take_events()), stats=self.get_stats()) - def take_events(self) -> Iterable[OffloadingEvent]: if self.events is None: return diff --git a/vllm/v1/kv_offload/tiering/manager.py b/vllm/v1/kv_offload/tiering/manager.py index 21a05c1cd639..8807d2e89feb 100644 --- a/vllm/v1/kv_offload/tiering/manager.py +++ b/vllm/v1/kv_offload/tiering/manager.py @@ -44,7 +44,6 @@ ReqContext, RequestOffloadingContext, ScheduleEndContext, - StepResult, StoreTrigger, ) from vllm.v1.kv_offload.cpu.common import CPULoadStoreSpec, CPUOffloadingInfo @@ -1216,7 +1215,7 @@ def _maybe_finalize_request( del self._req_state[req_id] @override - def on_schedule_end(self, context: ScheduleEndContext) -> StepResult: + def on_schedule_end(self, context: ScheduleEndContext) -> None: """End-of-schedule hook: process finished jobs, flush deferred promotions, and reset the per-step gate. @@ -1250,12 +1249,7 @@ def on_schedule_end(self, context: ScheduleEndContext) -> StepResult: continue self._metrics.on_request_allocated(state.req_context) - return StepResult( - pending=self.has_pending_work(), - events=list(self.take_events()), - stats=self.get_stats(), - ) - + @override def has_pending_work(self) -> bool: """Report whether outstanding work needs an engine step to finish. @@ -1276,6 +1270,7 @@ def has_pending_work(self) -> bool: or any(tier.has_pending_work() for tier in self.secondary_tiers) ) + @override def take_events(self) -> Iterable[OffloadingEvent]: """Yield events owned by the primary and secondary tiers. @@ -1354,6 +1349,7 @@ def reset_cache(self) -> None: def on_reset_flushed(self) -> None: self._promotions_held = False + @override def get_stats(self) -> OffloadingConnectorStats | None: stats = self.primary_tier.get_stats()