vllm.v1.hisparse.runtime
¶
HiSparse resident, host, and hot-cache data plane.
Classes:
-
HiSparseCacheHandle–Attention-facing handle for resident KV and sparse offload state.
-
HiSparseHostPool–Keep the single host backing and its exact registration range.
-
HiSparseIndexGroup–GPU index-resolution state shared by one leader and its followers.
-
HiSparsePrefillStagingPlan– -
HiSparseRuntime–Per-cache host/hot data plane and GPU replacement state.
-
HiSparseSlotInvalidator–Drop hot copies of rewritten host slots for many index groups at once.
Functions:
-
allocate_hisparse_host_pools–Allocate one host mmap shared by each node's TP ranks.
-
allocate_pinned_host_pool–Allocate and deterministically register an exact-size host KV region.
-
build_hisparse_prefill_staging_plan–Build an asynchronous layer-independent host-cache staging remap.
-
check_hisparse_host_memory–Reject a physical host-pool allocation that cannot fit in RAM.
-
get_hisparse_host_leader_rank–TP rank that creates and writes this node's shared host pool.
-
get_hisparse_host_pool–Return the engine's host pool, which outlives the profiling KV cache.
-
hisparse_prefill_staging_remap–Renumber blocks without a data-dependent CUDA output allocation.
-
initialize_hisparse_runtime_buffers–Allocate the request state shared by every HiSparse runtime.
-
is_hisparse_group_prefetch_batch–Prefetch historical KV for a pure decode batch, including verification.
-
release_pinned_state–Synchronize and release registered host KV pools.
-
update_hisparse_residency–Apply scheduled requests' residency changes.
-
use_shared_hisparse_host_pool–Whether replicated MLA host KV can share one mmap per node.
HiSparseCacheHandle
¶
Attention-facing handle for resident KV and sparse offload state.
Methods:
-
unbind_cache–Detach KV storage and per-binding metadata, retaining the index group.
unbind_cache()
¶
Detach KV storage and per-binding metadata, retaining the index group.
HiSparseHostPool
¶
Keep the single host backing and its exact registration range.
HiSparseIndexGroup
¶
GPU index-resolution state shared by one leader and its followers.
HiSparsePrefillStagingPlan
dataclass
¶
Methods:
-
ensure_gpu_sources–Resolve which staged rows can be served from the resident cache.
ensure_gpu_sources(resident_state_rows, state_indices, resident_block_size)
¶
Resolve which staged rows can be served from the resident cache.
resident_state_rows is a resident group's persistent table by
request state row and state_indices holds each staged request's
state row. Computed once per plan and resident group (every layer in
the group shares the table); non-null resident pages become
miss_mask=0 rows gathered device-to-device by gather_prefill_cache.
HiSparseRuntime
¶
Per-cache host/hot data plane and GPU replacement state.
Methods:
-
bind_hot_cache–Bind this runtime's strided view into the shared GPU HMA slab.
-
gather_prefill_cache–Gather this runtime's host cache using a shared staging plan.
-
invalidate_sorted_slots–Drop hot copies using shared, preprocessed invalidation inputs.
-
reset_hot_state–Drop all hot-buffer bookkeeping (hits become misses).
-
swap_in–Resolve once per group and ensure this layer's rows are available.
-
unbind_cache–Restore the unbound state without unregistering the host pool.
_resolve_residency(*, resident=None, req_id_per_token, num_valid_rows, block_table, topk_indices, block_size, return_valid_counts=False, shared_rows, attention_indices_out=None, valid_counts_out=None)
¶
Resolve logical top-k positions and compact rows requiring swaps.
bind_hot_cache(raw_tensor, *, byte_offset, block_stride, num_blocks, block_size, block_table, owner=None)
¶
Bind this runtime's strided view into the shared GPU HMA slab.
A cross-layer KV-sharing layer binds its target's hot rows and passes
the target as owner: both then track the rows in the owner's slot map.
gather_prefill_cache(kv_cache, plan, resident_cache=None)
¶
Gather this runtime's host cache using a shared staging plan.
invalidate_sorted_slots(sorted_slots, state_indices)
¶
Drop hot copies using shared, preprocessed invalidation inputs.
reset_hot_state()
¶
Drop all hot-buffer bookkeeping (hits become misses).
swap_in(*, resident, req_id_per_token, block_table, logical_topk_indices, block_size, num_valid_rows, return_valid_counts=False, attention_indices_out=None, valid_counts_out=None)
¶
Resolve once per group and ensure this layer's rows are available.
unbind_cache()
¶
Restore the unbound state without unregistering the host pool.
HiSparseSlotInvalidator
¶
Drop hot copies of rewritten host slots for many index groups at once.
_SharedTopKState
¶
CUDA-graph-safe residency result shared by index-sharing layers.
_check_residency_shared_memory(device, config)
¶
Reject a config whose residency resolver exceeds per-block shared memory.
allocate_hisparse_host_pools(vllm_config, tensor_sizes, num_blocks, host_block_stride)
¶
Allocate one host mmap shared by each node's TP ranks.
allocate_pinned_host_pool(size)
¶
Allocate and deterministically register an exact-size host KV region.
build_hisparse_prefill_staging_plan(block_table, seq_lens, block_size, staging_block_capacity)
¶
Build an asynchronous layer-independent host-cache staging remap.
check_hisparse_host_memory(pool_bytes)
¶
Reject a physical host-pool allocation that cannot fit in RAM.
get_hisparse_host_leader_rank(vllm_config, tp_rank=None)
¶
TP rank that creates and writes this node's shared host pool.
Parameters:
-
(vllm_config¶VllmConfig) –Engine config; its
local_world_sizesets the node size. -
(tp_rank¶int | None, default:None) –TP rank to resolve; defaults to this process's TP rank.
Returns:
-
int–The first TP rank on
tp_rank's node.
get_hisparse_host_pool(vllm_config, kv_cache_config)
¶
Return the engine's host pool, which outlives the profiling KV cache.
hisparse_prefill_staging_remap(block_table, block_size)
¶
Renumber blocks without a data-dependent CUDA output allocation.
initialize_hisparse_runtime_buffers(cache_handles, *, max_num_reqs)
¶
Allocate the request state shared by every HiSparse runtime.
is_hisparse_group_prefetch_batch(attn_metadata, max_rows)
¶
Prefetch historical KV for a pure decode batch, including verification.
release_pinned_state(pinned_host_pools, shared_host_region=None)
¶
Synchronize and release registered host KV pools.
update_hisparse_residency(residency, updates, request_ids, request_state_indices)
¶
Apply scheduled requests' residency changes.
residency is [resident groups, state rows, pages]: the GPU block of
each page, or block 0 when the page is read from the host.
use_shared_hisparse_host_pool(vllm_config)
¶
Whether replicated MLA host KV can share one mmap per node.