vllm.v1.kv_offload.tiering.base
¶
Abstract interfaces and data types for the secondary tiering layer.
Classes:
-
JobResult–Result of an async transfer job.
-
ParentManager–Interface for secondary tiers to call back into the tiering manager.
-
SecondaryTierManager–Abstract interface for managing a single non-primary offloading tier.
-
SecondaryTierRequestContext–Per-request offloading preferences of a secondary tier.
-
TieringOffloadingMetrics–Metric names for TieringOffloadingManager.
-
TransferJob–Metadata for an in-flight async transfer job.
JobResult
dataclass
¶
Result of an async transfer job.
ParentManager
¶
Bases: ABC
Interface for secondary tiers to call back into the tiering manager.
Passed to secondary tiers via serve_external_requests() each step. The _SecondaryTierFacingParent wrapper implements this, automatically excluding the calling tier from fan-out operations.
Required call sequence for each remote request
- on_new_request(req_context) — set up per-request state
- lookup(key, req_context) — check chunk availability (repeat per chunk)
- create_store_job(keys, req_context) — pin chunks and get a job handle
- on_request_finished(req_context) — clean up per-request state
Steps 2-3 may be interleaved. Step 4 must be called even if no chunks were found, to avoid leaking async lookup state (e.g. in the fs tier's AsyncLookupManager).
Methods:
-
on_demand–A consumer demanded these keys at local monotonic time
at.
on_demand(keys, at)
abstractmethod
¶
A consumer demanded these keys at local monotonic time at.
Call it while the keys are pinned: when the demand arrives, or from report_demand().
SecondaryTierManager
¶
Bases: ABC
Abstract interface for managing a single non-primary offloading tier.
Secondary tiers cannot directly access GPU memory. All data transfers must go through the CPU (primary) tier: - Store: GPU → CPU (primary) → secondary (cascade) - Load: secondary → CPU (primary) → GPU (promotion)
IMPORTANT: All methods run in the Scheduler process and must be lightweight and non-blocking. submit_load() and submit_store() submit async jobs; get_finished_jobs() polls for completion.
Methods are called under the tiering manager's lock, so they are never entered concurrently -- but not always from the same thread. A tier that sets tolerates_off_thread_polling is also serviced from the manager's tier-poll thread, and any tier can be reached from there via ParentManager fan-out. Keep per-thread assumptions out of tier state.
Methods:
-
__init__–Args:
-
build_metric_definitions–Return Prometheus metric definitions emitted by this tier.
-
config_info–Return the info metric labels of this tier, for its one series.
-
config_info_keys–Return the info metric label names of this tier.
-
drain_jobs–Block until every submitted load/store job has completed or failed.
-
get_finished_jobs–Return all jobs (loads and stores) that completed since the last call.
-
get_stats–Return and reset metric observations collected by this tier.
-
has_pending_work–Whether this tier needs the engine to keep stepping.
-
lookup–Check whether a chunk exists in this secondary tier.
-
on_new_request–Called when a new request is first seen by the scheduler.
-
on_request_finished–Called when a request has finished.
-
on_schedule_end–Called once at the end of each scheduler step.
-
report_demand–Report demand seen outside serve_external_requests() to the parent.
-
serve_external_requests–Process remotely-originated requests using the parent manager.
-
shutdown–Release resources held by this tier (threads, connections, etc.).
-
submit_load–Submit an async job to load chunks from this secondary tier to the
-
submit_store–Submit an async job to store chunks from the primary tier to this
-
take_events–Take KV events for storage state owned by this tier.
__init__(offloading_spec, primary_kv_view, tier_type, backpressure_detector=None, access_mode=OffloadAccessMode.READWRITE)
¶
Args:
offloading_spec: Offloading configuration.
primary_kv_view: Memoryview of the primary tier's CPU KV cache.
tier_type: Tier type identifier, set by SecondaryTierFactory
from the registered tier type.
backpressure_detector: Optional BackpressureDetector.
access_mode: Direction(s) in which this tier may transfer data. The
tiering manager skips stores to a tier whose access_mode cannot
write, and lookups of a tier whose access_mode cannot read.
build_metric_definitions(extra_config)
classmethod
¶
Return Prometheus metric definitions emitted by this tier.
config_info()
¶
Return the info metric labels of this tier, for its one series.
TieringOffloadingManager adds TIER_LABEL. See ConfigInfo.
config_info_keys(tier_config)
classmethod
¶
drain_jobs()
abstractmethod
¶
Block until every submitted load/store job has completed or failed.
After this returns, no tier I/O is touching the primary memoryview,
and every submitted job's result is available from get_finished_jobs()
(yielded by a prior call or queued for the next one). Used by
TieringOffloadingManager.reset_cache to release primary slots
without racing with in-flight transfers.
Implementations must not abort a mid-flight transfer: a partial copy
would corrupt either the primary memoryview or the secondary backing
store. Queued (not-yet-started) transfers may be cancelled, but their
failure result must still appear in get_finished_jobs().
Likewise, every JobResult.deferred_release event must be set
before this returns, so the tier must bound how long it can defer a
release.
get_finished_jobs()
abstractmethod
¶
get_stats()
¶
Return and reset metric observations collected by this tier.
has_pending_work()
¶
Whether this tier 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.
lookup(key, req_context)
abstractmethod
¶
Check whether a chunk exists in this secondary tier.
Parameters:
-
(key¶OffloadKey) –Offload key to look up.
-
(req_context¶ReqContext) –per-request context (e.g. kv_transfer_params).
Returns:
-
LookupResult–HIT if the chunk is present and ready,
-
LookupResult–MISS if not found,
-
LookupResult–or RETRY if the chunk is being transferred (retry later).
on_new_request(req_context)
¶
Called when a new request is first seen by the scheduler.
Returns a SecondaryTierRequestContext expressing this tier's preference for how chunks should be offloaded for this request.
Parameters:
-
(req_context¶ReqContext) –Per-request context.
on_request_finished(req_context)
¶
Called when a request has finished.
By the time this is called, all per-request calls for this request (submit_store, submit_load) have already been issued, and none will follow. Note this does NOT imply the tier's transfers have completed: jobs already submitted may still be in flight and will report via get_finished_jobs(). This is the right place to release per-request bookkeeping.
Parameters:
-
(req_context¶ReqContext) –per-request context.
on_schedule_end(context)
¶
Called once at the end of each scheduler step.
Parameters:
-
(context¶ScheduleEndContext) –Per-step context from the scheduler.
report_demand(parent)
¶
Report demand seen outside serve_external_requests() to the parent.
Called after get_finished_jobs() and before the primary pins of the finished jobs are released, so a demanded chunk is still cached.
serve_external_requests(parent)
¶
Process remotely-originated requests using the parent manager.
Called once per scheduler step, BEFORE _flush_pending_promotions(), and additionally once per tier-poll round for tiers that set tolerates_off_thread_polling. The _flush_pending_promotions() ordering holds only for the per-step call: a promotion this method initiates from a tier-poll round is submitted at the next on_schedule_end().
The parent handle is valid only for the duration of this call, and the caller holds the manager lock throughout it -- so a lookup() HIT taken here stays valid until this call pins it. An implementation must not release that lock partway through.
Tiers that don't serve external requests leave this as a no-op. A tier that overrides it without setting tolerates_off_thread_polling is served once per step only.
shutdown()
¶
Release resources held by this tier (threads, connections, etc.).
submit_load(job_metadata)
abstractmethod
¶
Submit an async job to load chunks from this secondary tier to the primary tier.
This method must be lightweight and non-blocking: mark chunks as in-flight and submit the transfer, but do NOT perform the data copy on the calling thread.
Preconditions (guaranteed by the framework):
- job_metadata.chunk_ids are allocated primary-tier slots
ready to receive data.
The implementation must copy data from this tier into the
primary-tier slots identified by chunk_ids.
Report completion via get_finished_jobs().
Parameters:
-
(job_metadata¶TransferJob) –Job metadata including job_id, keys, and chunk_ids identifying the primary-tier slots to write into.
submit_store(job_metadata)
abstractmethod
¶
Submit an async job to store chunks from the primary tier to this secondary tier.
This method must be lightweight and non-blocking: allocate metadata and submit the transfer, but do NOT perform the data copy on the calling thread.
Preconditions (guaranteed by the framework):
- job_metadata.chunk_ids are valid primary-tier slots, pinned
(ref-counted) for the duration of the transfer.
The implementation is responsible for
- Filtering out chunks already present in this tier
- Evicting chunks if capacity is needed
- Allocating space in this tier
- Submitting the async transfer (read from primary via chunk_ids)
Report completion via get_finished_jobs().
Parameters:
-
(job_metadata¶TransferJob) –Job metadata including job_id, keys, and chunk_ids identifying the primary-tier slots to read from.
take_events()
¶
Take KV events for storage state owned by this tier.
SecondaryTierRequestContext
dataclass
¶
Bases: RequestOffloadingContext
Per-request offloading preferences of a secondary tier.
TieringOffloadingMetrics
¶
Metric names for TieringOffloadingManager.
TransferJob
dataclass
¶
Metadata for an in-flight async transfer job.