vllm.v1.hisparse.coordinator
¶
Classes:
-
HiSparseCoordinator–Own HiSparse host allocation, publication, page transfers, and GPU residency.
Functions:
-
get_hisparse_coordinator–Return the coordinator shared by a KV cache manager's HiSparse groups.
HiSparseCoordinator
¶
Own HiSparse host allocation, publication, page transfers, and GPU residency.
Device pages are a write-back cache of the host tier. Once a page's
host copy is durable and its request can read from host (it has, or has
asked for, a hot buffer), 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 request 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_on_device–Return whether every scheduled request can read only device KV.
-
build_row_mirrors–Map scheduled rows to scheduler-owned device and host blocks.
-
build_transfer_command–Package residency decisions for the worker connector.
-
finish_host_import–Publish externally populated host pages after connector completion.
-
free–Detach the request; its durable pages stay readable GPU copies.
-
free_completed_host_cow_copies–Free the endpoints of host copies the worker reports having run.
-
get_num_releasable_blocks–Durable device blocks a hot-first allocation can release immediately.
-
has_pending_block_frees–Whether an in-flight transfer will free GPU or host blocks on completion.
-
plan_write_backs–Eagerly write back every sealed page that has no host copy yet.
-
publish_when_durable–Publish host hashes of the pages that are already durable.
-
record_host_prefix_hit–Account for a prefix hit on host pages the request now references.
-
record_pending_host_import–Note a prefix an external load is populating in host pages.
-
size_import–Note the full-sequence host pages of an import being admitted.
-
take_host_cow_copies–Drain host copy-on-write work, retaining both endpoints.
-
take_residency_updates–Device block ids the worker lacks for the scheduled requests:
-
try_preallocate_hot–Fund this allocation only if the hot buffer fits and releasing covers
-
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.
_apply_enqueued_transfers()
¶
Free the GPU leases once every worker has completed the transfer.
_can_read_from_host(request_id)
¶
Whether device pages may be dropped under the request.
_fills_admission_window(request_id)
¶
Whether the request holds the device pages admission reserved.
Admission caps a request's device 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_releasable_pages(request_id, state, page_indices)
¶
Select complete, durable pages outside the active tail.
_plan_page_transfers(request_id, page_indices, budget, *, is_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 read-from-host watermark, the imported pages are restored into device pages too, so decode reads them like a locally computed prefix. They are durable GPU copies of host pages: the residency policy releases 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 device group.
_publish_if_durable(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_gpu_copies(request_id, num_computed_tokens)
¶
Index the GPU copies of just-published host pages for later hits.
_release_pages(request_id, state, page_indices)
¶
Release the pages' device blocks to the pool, in the given order.
_revive_gpu_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.
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_on_device(requests)
¶
Return whether every scheduled request can read only device KV.
build_row_mirrors(requests)
¶
Map scheduled rows to scheduler-owned device and host blocks.
build_transfer_command()
¶
Package residency decisions for the worker connector.
finish_host_import(request_id, *, failed, restore=True)
¶
Publish externally populated host pages after connector completion.
Without restore, the import was cancelled: its host prefix is still
published, but nothing is restored to the GPU.
free(request_id)
¶
Detach the request; its durable pages stay readable GPU copies.
free_completed_host_cow_copies(dst_block_ids)
¶
Free the endpoints of host copies the worker reports having run.
get_num_releasable_blocks(request_id)
¶
Durable device blocks a hot-first allocation can release immediately.
has_pending_block_frees()
¶
Whether an in-flight transfer will free GPU or host blocks on completion.
plan_write_backs(request_id, num_computed_tokens)
¶
Eagerly write back every sealed page that has no host copy yet.
publish_when_durable(request, num_computed_tokens, retention_interval, *, replay_boundaries)
¶
Publish host hashes of the pages that are already durable.
record_host_prefix_hit(request_id, num_host_pages)
¶
Account for a prefix hit on host pages the request now references.
record_pending_host_import(request_id, num_tokens)
¶
Note a prefix an external load is populating in host pages.
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_cow_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 freed when that step's output comes back.
take_residency_updates(request_ids)
¶
Device 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 the hot buffer fits and releasing covers the shortfall.
update_residency(request_id)
¶
Per-step residency policy for a scheduled request.
A request that can read from host releases every durable sealed page to the pool. One that cannot keeps its pages pinned until the shared pool runs low, or until it holds the device pages admission reserved for it, then asks for a hot buffer. Pages remain pinned until that buffer is allocated on a subsequent scheduling pass.
_HiSparseRequestState
dataclass
¶
Residency bookkeeping for one request.
A device page moves through three states: not yet durable (only the GPU
copy exists), durable (durable_pages: its host copy is complete) and
released (released_pages: durable, and its allocation reference was
released so the pool may evict it). pinned_durable_pages tracks durable
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.