vllm.v1.hisparse.coordinator
¶
Classes:
-
HiSparseCoordinator–Own HiSparse host allocation, host publication, spills, and GPU residency.
Functions:
-
get_hisparse_coordinator–Return the coordinator shared by a KV cache manager's HiSparse groups.
HiSparseCoordinator
¶
Own HiSparse host allocation, host publication, spills, and GPU residency.
GPU-resident pages are a write-back cache of the host tier. Once a page's
host copy is durable and its owner can read from host (it has, or has
asked for, a hot region), the page's allocation reference is released with
BlockPool.unpin_blocks: the block keeps being read, but the pool counts
it as free and may hand it out, at which point the owner stops reading it.
Residency changes reach the worker through take_residency_updates, not
the block table, which stays append-only.
Methods:
-
advance_scheduled–Run the per-step residency work for each scheduled request.
-
all_context_pages_resident–Return whether every scheduled request can read only resident KV.
-
build_offload_command–Package residency decisions for the worker connector.
-
build_row_mirrors–Map scheduled rows to scheduler-owned resident and host blocks.
-
commit_computed_blocks–Account for a prefix hit on host pages the request now references.
-
complete_host_import–Publish externally populated host pages after connector completion.
-
free–Detach the request; its clean pages stay readable copies in the pool.
-
get_num_reclaimable_blocks–Clean resident blocks a hot-first allocation can release immediately.
-
has_pending_reclamation–Whether an in-flight spill will free GPU or host blocks on completion.
-
plan_prefix_materialization–Eagerly write back every sealed page that has no host copy yet.
-
publish_when_ready–Publish host-source hashes of the pages that are already durable.
-
record_pending_host_import–Note a prefix an external load is populating in host pages.
-
release_completed_host_copies–Release the endpoints of host copies the worker reports having run.
-
size_import–Note the full-sequence host pages of an import being admitted.
-
take_host_block_copies–Drain host copy-on-write work, retaining both endpoints.
-
take_residency_updates–Resident block ids the worker lacks for the scheduled requests:
-
try_preallocate_hot–Fund this allocation only if Hot fits and reclaim covers the shortfall.
-
update_residency–Per-step residency policy for a scheduled request.
Attributes:
-
reserved_import_pages(int) –Host pages admitted imports still need for their sequence.
reserved_import_pages
property
¶
Host pages admitted imports still need for their sequence.
_adopt_copies(request_id, state, host_blocks)
¶
Point null prefix pages at readable GPU copies of their contents.
Runs after the hit length is fully reconciled, so copy hits and misses can be scattered per page without affecting the prefix hit.
_apply_enqueued_spills()
¶
Drop the GPU pins once every worker has completed the transfer.
_can_read_from_host(request_id)
¶
Whether resident pages may be dropped under the request.
_fills_admission_window(request_id)
¶
Whether the request holds the resident pages admission reserved.
Admission caps a request's resident pages at the in-flight window, assuming older pages move to host; keeping them pinned past it lets a chunked prefill outgrow the pool it was admitted into.
_iter_unpinnable_pages(request_id, state, page_indices)
¶
Select complete, durable pages outside the active tail.
_plan_page_transfers(request_id, page_indices, budget, *, restore=False)
¶
Plan up to budget transfers for the pages, in the given order.
_promote_imported_pages(request_id, num_pages)
¶
Back an import's first num_pages host pages with new GPU pages.
Imports land in the host tier. While the GPU pool has room above the transition watermark, the imported pages are restored into resident pages too, so decode reads them like a locally computed prefix. They are clean copies of durable host pages: the residency policy unpins them.
Promotion takes only blocks that hold no cached prefix: a host prefix hit also needs its prefix-cached indexer blocks, and a promoted page costs one block per resident group.
_publish_host_blocks_if_ready(request_id)
¶
Publish the durable prefix of the pending publication.
Host writes trail a long prefill by about a chunk, so waiting for the whole computed prefix would publish nothing until the prefill ends, and a prefill preempted before then would recompute from the start.
_record_copies(request_id, num_computed_tokens)
¶
Index the GPU copies of just-published host blocks for later hits.
_unpin_pages(request_id, state, page_indices)
¶
Release the pages' resident blocks to the pool, in the given order.
advance_scheduled(requests)
¶
Run the per-step residency work for each scheduled request.
requests pairs a request id with the number of tokens computed
once the step completes. Multi-module MTP may still rewrite the last
num_reprefillable_tokens, so they are not written back yet.
all_context_pages_resident(requests)
¶
Return whether every scheduled request can read only resident KV.
build_offload_command()
¶
Package residency decisions for the worker connector.
build_row_mirrors(requests)
¶
Map scheduled rows to scheduler-owned resident and host blocks.
commit_computed_blocks(request_id, num_host_pages)
¶
Account for a prefix hit on host pages the request now references.
complete_host_import(request_id, num_computed_tokens, *, restore=True)
¶
Publish externally populated host pages after connector completion.
free(request_id)
¶
Detach the request; its clean pages stay readable copies in the pool.
get_num_reclaimable_blocks(request_id)
¶
Clean resident blocks a hot-first allocation can release immediately.
has_pending_reclamation()
¶
Whether an in-flight spill will free GPU or host blocks on completion.
plan_prefix_materialization(request_id, num_computed_tokens)
¶
Eagerly write back every sealed page that has no host copy yet.
publish_when_ready(request, num_computed_tokens, retention_interval, *, replay_boundaries)
¶
Publish host-source hashes of the pages that are already durable.
record_pending_host_import(request_id, num_tokens)
¶
Note a prefix an external load is populating in host pages.
release_completed_host_copies(dst_block_ids)
¶
Release the endpoints of host copies the worker reports having run.
size_import(request_id, num_pages)
¶
Note the full-sequence host pages of an import being admitted.
The admission gate runs in the same allocate_slots call as the
allocation, so the next record_pending_host_import is this
request's if it is admitted; a size left by a rejected admission is
discarded.
take_host_block_copies()
¶
Drain host copy-on-write work, retaining both endpoints.
The worker runs the copies in the step that carries them, so the endpoints are released when that step's output comes back.
take_residency_updates(request_ids)
¶
Resident block ids the worker lacks for the scheduled requests: stale pages plus pages appended since the last update.
Requests that are not scheduled keep their changes until they are: only a scheduled request's residency is read.
try_preallocate_hot(request_id, shortfall, available)
¶
Fund this allocation only if Hot fits and reclaim covers the shortfall.
update_residency(request_id)
¶
Per-step residency policy for a scheduled request.
A request that can read from host releases every clean sealed page to the pool. One that cannot keeps its pages pinned until the shared pool runs low, or until it holds the resident pages admission reserved for it, then asks for a hot region. Pages remain pinned until that region is allocated on a subsequent scheduling pass.
_HiSparseRequestState
dataclass
¶
Residency bookkeeping for one request.
A resident page moves through three states: dirty (only the GPU copy
exists), clean (valid_pages: the host copy is complete) and unpinned
(unpinned_pages: clean, and its allocation reference was released so
the pool may reuse it). pinned_clean tracks clean pages still holding
their reference, which only happens before the request can read from host.
get_hisparse_coordinator(kv_cache_manager, *, import_step_tokens=None, num_reprefillable_tokens=None)
¶
Return the coordinator shared by a KV cache manager's HiSparse groups.
Built on first call and memoised on the HiSparse managers it binds itself to. Must run before the first request is admitted.