vllm.distributed.kv_transfer.kv_connector.v1.offloading.scheduler
¶
Classes:
-
OffloadingConnectorScheduler–Implementation of Scheduler side methods
OffloadingConnectorScheduler
¶
Implementation of Scheduler side methods
Methods:
-
get_external_cache_hit_sources–Split the accepted external hit by the tier each loaded key came from.
-
get_num_new_matched_tokens–Get number of new tokens that can be loaded beyond the
-
has_pending_push_work–Whether the engine must keep stepping.
-
on_new_request–Called when a new request is added to the scheduler.
-
request_finished–Called when a request has finished, before its blocks are freed.
-
reset_cache–Reset the offloading manager cache, evicting all stored chunks.
-
take_events–Drain pending KV cache events.
-
update_connector_output–Update KVConnector state from worker-side connectors output.
_acquire_step()
¶
Open the step-scoped region. Idempotent within a step.
_lookup_complete_chunks(req_status, max_num_new_tokens=None)
¶
Find how many tokens beyond num_locally_computed_tokens can be loaded.
Iterates full-attention groups first (prefix lookup), then sliding-window groups (suffix lookup). Each group may tighten max_hit_size_tokens, which can invalidate an earlier group's result, so the loop re-runs when that happens until num_hit_tokens converges.
Returns the number of hit tokens (None to defer) and the hit boundary the full-attention groups proved before any sliding-window/Mamba group narrowed it (None if not reached).
_lookup_partial_tail(req_status, boundary, bridge_pending)
¶
Look up every key a partial-tail hit at boundary loads.
bridge_pending is True if a complete chunk that the hit also loads
is not ready yet.
Returns (hit, pending). hit is True only if every key is ready.
pending is True if no required key missed and a required key or
bridge chunk is not ready yet.
_lookup_partial_tail_hit(req_status, complete_hit, full_attention_hit_boundary, max_num_new_tokens)
¶
Extend a complete-chunk hit with a partial tail, if supported.
_manager_locked()
¶
Hold the manager for the duration of one hook outside schedule().
None of these hooks can legitimately run inside the step-scoped region: on_new_request comes from add_request, has_pending_push_work from the engine's liveness check before schedule(), the rest from output processing or a client RPC. So finding the region open here means a previous schedule() raised between _acquire_step() and the release in build_connector_meta. Recover instead of deadlocking.
_maximal_prefix_lookup(keys, req_context, req, group_config, start_chunk_idx)
¶
Return the number of consecutive offloaded chunks from the start, or None if the backend deferred a lookup.
_maybe_register_shared_prefix_junction(req_status, boundary, num_hit_tokens)
¶
Pin a shared-prefix junction where a sparse group cut the hit, as
get_computed_blocks does for a local hit, so the recompute retains
the sliding-window/Mamba state at the full-attention hit boundary.
_num_prefix_blocks(group_idx, local_prefix_tokens)
¶
Return the number of shared prefix blocks in a full-attention group.
_release_step()
¶
Close the step-scoped region, letting other threads in.
_remove_request(req_id)
¶
Remove the state of a request, and tell each store handler.
_reserve_sync_load(req_status, num_computed_tokens, num_hit_tokens)
¶
Reserve the step's sync-load budget for a hit, if it fits.
_sliding_window_lookup(keys, sliding_window_size, req_context, initial_window_size=None)
¶
Return the end index (in keys) of the last run of
sliding_window_size consecutive hits, scanning from the end.
The first run may need a larger window for a partial rightmost chunk.
Returns 0 on miss, None if the backend deferred a lookup.
_track_store_job(req_id, keys, *, trigger, fenced_block_ids, deferred_fence_block_ids)
¶
Give a store job a job ID, track it, and return the ID.
_update_req_states(scheduler_output)
¶
Update request states from the Scheduler's output.
get_external_cache_hit_sources(request, num_external_tokens)
¶
Split the accepted external hit by the tier each loaded key came from.
Attention keys cover only their loaded token ranges; recurrent state
covers the whole reused prefix. Overlaps report the outermost tier.
Uncovered tokens, including omitted sliding-window history, are
external_unspecified.
get_num_new_matched_tokens(request, num_computed_tokens, max_num_new_tokens=None)
¶
Get number of new tokens that can be loaded beyond the num_computed_tokens.
Parameters:
-
(request¶Request) –the request object.
-
(num_computed_tokens¶int) –the number of locally computed tokens for this request
-
(max_num_new_tokens¶int | None, default:None) –cap on the number of tokens that may be loaded beyond
num_computed_tokens, if any.
Returns:
-
tuple[int | None, bool]–A tuple with the following elements: - The number of tokens that can be loaded beyond what is already computed. If None, it means that the connector needs more time to determine the number of matched tokens, and the scheduler should query for this request again later. -
Trueif tokens will be loaded asynchronously (between scheduler steps).
has_pending_push_work()
¶
Whether the engine must keep stepping.
While True, build_connector_meta() and update_connector_output() continue to be called even when no requests are scheduled.
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().
on_new_request(request)
¶
Called when a new request is added to the scheduler.
request_finished(request)
¶
Called when a request has finished, before its blocks are freed.
Returns:
-
bool–True if the request is being saved/sent asynchronously and blocks
-
dict[str, Any] | None–should not be freed until the request_id is returned from
-
tuple[bool, dict[str, Any] | None]–get_finished().
-
tuple[bool, dict[str, Any] | None]–Optional KVTransferParams to be included in the request outputs
-
tuple[bool, dict[str, Any] | None]–returned by the engine.
reset_cache()
¶
Reset the offloading manager cache, evicting all stored chunks.
take_events()
¶
Drain pending KV cache events.
Complete metadata is available only when self-describing KV events are enabled, and only for full-attention groups. Other shapes retain the previous placeholder payload so consumers can ignore them.
Yields:
-
Iterable[KVCacheEvent]–BlockStoredorBlockRemovedevents corresponding to -
Iterable[KVCacheEvent]–the underlying
OffloadingEventstream.
_StoreJobSink
¶
The store-job intake of one handler in one scheduler step.
_parse_tier_filter(raw)
¶
Parse raw kv_transfer_params tier matchers into a TierFilter.