Skip to content

vllm.v1.kv_offload.tiering.base

Abstract interfaces and data types for the secondary tiering layer.

Classes:

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
  1. on_new_request(req_context) — set up per-request state
  2. lookup(key, req_context) — check chunk availability (repeat per chunk)
  3. create_store_job(keys, req_context) — pin chunks and get a job handle
  4. 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

Return the info metric label names of this tier.

TieringOffloadingSpec merges the names of all tiers and adds TIER_LABEL, so a tier must not declare it. See ConfigInfo.

Parameters:

  • tier_config

    (dict[str, Any]) –

    Configuration dict of this tier.

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

Return all jobs (loads and stores) that completed since the last call.

The framework uses these results to release resources and finalize transfers.

Returns:

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:

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:

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:

on_schedule_end(context)

Called once at the end of each scheduler step.

Parameters:

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
  1. Filtering out chunks already present in this tier
  2. Evicting chunks if capacity is needed
  3. Allocating space in this tier
  4. 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.