HiSparse local KV offload architecture¶
Status: experimental
The short version¶
There are three different jobs:
- The normal KV cache system manages GPU block pools and tables.
HiSparseCoordinatormanages logical host blocks, host-prefix identity, and host/GPU residency transitions.HiSparseConnectorcarries residency work between scheduler and worker;HiSparseConnectorWorkercoordinates transfers, while per-cacheHiSparseRuntimeobjects own host/hot views and GPU replacement state.
Neither worker-side object allocates or frees logical blocks. HMA provides the GPU allocation shared by the device and hot groups; it does not manage CPU memory or KV identity.
request ────► HiSparseCoordinator ── host blocks + residency policy
│
├──► KV cache manager ── device/hot GPU leases (HMA)
│
└──► HiSparseConnector ── host bytes + copies + GPU LRU
This is a local KV connector. When P/D or another offload connector is also
configured, MultiConnector composes it with HiSparseConnector.
host_pool_gib is configured on HiSparseConnector and is the usable
host-cache capacity per data-parallel replica, not a node-wide memory budget.
MLA tensor-parallel ranks hold replicated views of that logical cache, using
private per-rank backing or one shared physical allocation. QSA stores full K/V
heads in private per-rank pools, with each rank writing its own shard. Its
logical capacity counts each unique K/V head once; heads replicated when TP
exceeds the K/V head count still consume physical memory in each rank's pool.
Padding also contributes to physical allocation, not logical capacity. Physical
host memory consumption is therefore topology- and implementation-dependent. The
realized capacity may be slightly smaller because the budget is rounded down
to complete host blocks.
Startup logs report two concurrency bounds at max_model_len. The generic
Maximum concurrency line charges each request its full admission footprint,
including the in-flight window of every device group. The HiSparse
steady-state maximum concurrency line charges running requests that read from
host only their active tail pages, plus one request being admitted at its full
footprint. Host-pool metrics are listed in
Metrics.
Nomenclature¶
| Term | Meaning |
|---|---|
| Host block / host page | A block of the separate CPU pool and the KV page it holds. The host pages are the authoritative copy of a request's sparse-attention KV. |
| Host group | The cache group whose blocks come from the host pool (HiSparseHostManager, host_resident=True). |
| Host leader | The TP rank that creates, writes and imports into a node's shared host pool (get_hisparse_host_leader_rank); its peers only read it. |
| Device page / device group | A request's KV page held in a GPU block, and the cache group holding those blocks (HiSparseDeviceManager). Hot rows are also in GPU memory but are not device pages. |
| Device pool groups | Every GPU group sharing the device pool: the indexer, device and hot groups, plus ordinary groups. |
| Indexer group | The indexer's KV (KVCacheGroupRole.HISPARSE_INDEXER). It stays in an ordinary prefix-cacheable GPU group; HiSparse never offloads it. |
| Hot cache | The GPU cache group, and its tensor, that holds every request's hot buffer. |
| Hot buffer / hot row | A request's fixed set of GPU blocks that hold host pages fetched for attention, and one row within it. |
| Write-back | Copying a device page to its host page. Happens eagerly, not only under memory pressure. |
| Page transfer | One tracked write-back or restore of a page, identified by its transfer ID. |
| Mirror | Copying each step's newly written KV rows to their host pages, rather than waiting to write back whole pages. |
| Durable | A page whose write-back (or import) has completed, so its device block can be released. |
| Publish | Registering durable host pages in the prefix cache so later requests can hit them. |
| Resolve residency | Mapping attention's top-k positions to physical rows: device pages directly, hot rows on a hit, and host rows copied into the hot buffer on a miss (resolve_residency). |
| Prefill staging | Gathering a prefill's selected rows from device pages and host pages into a contiguous buffer before attention (HiSparsePrefillStagingPlan). |
| Group prefetch | The indexer layer resolving top-k once for every layer sharing it and queuing their host misses ahead of their attention. |
| Restore | Copying a host page back into a device page. |
| Import | KV arriving from a P/D prefill node into host pages. |
| Promote | Restoring an import's earlier pages into new device pages while the pool has room above the read-from-host watermark. |
| Import reservation | Host pages held back for an admitted import's remaining sequence, so later admissions cannot take them. |
| Pin / release | Holding or dropping a device page's allocation reference. Releasing (BlockPool.unpin_blocks in core) keeps the block readable until the pool evicts it. |
| Lease / free | An extra block reference a page transfer or pending publication holds (BlockPool.touch) so the block outlives the copy, and dropping it (BlockPool.free_blocks). |
| Active tail | The last ACTIVE_TAIL_PAGES pages of a request, which stay pinned because an in-flight step may still write them. |
| Read-from-host watermark | The free device-pool block count below which requests ask for a hot buffer, so they can read from host and release their durable pages (read_from_host_watermark). |
| GPU copy | A durable device page whose reference was released but whose contents stay readable until the pool evicts its block. |
| Revive | A host-prefix hit taking back a released GPU copy the pool has not yet evicted, re-pinning it instead of reading the page from host. |
| Evict | The pool handing a released block to another allocation, which destroys any GPU copy it held. |
| Residency update | The scheduler telling the worker which GPU block, if any, each of a request's pages is read from (take_residency_updates). The block table stays append-only. |
QSA models¶
For Qwen4Exp QSA models, configure HiSparseConnector to offload the main K/V
cache.
vllm serve QSA_MODEL \
--kv-transfer-config '{"kv_connector":"HiSparseConnector","kv_role":"kv_both","kv_connector_extra_config":{"host_pool_gib":8}}'
The device layout resolves to BLNHC, so one copy row holds a token's K and V
for every local K/V head. HiSparse leaves compressed indexer keys, raw-key rings
and recurrent state in their normal GPU cache groups. With prefix caching,
prefixes are reused at whole scheduler-page boundaries; matching tokens past
the boundary are recomputed.
QSA does not yet implement decode context parallelism, even without HiSparse. The current HiSparse configuration also rejects DCP.
QSA P/D with HiSparse requires a separate NIXL integration for mixed host/GPU cache registration and transfer-group mapping across P and D. It is not yet supported by this implementation.
Ownership¶
| Thing | Owner | What “owner” means |
|---|---|---|
| HiSparse host-prefix identity | HiSparseCoordinator |
maps tokens to logical host blocks |
| Device block leases | normal KV cache manager | allocates and frees HMA blocks |
| Device block tables | normal KV cache manager | append-only record of a request's device allocations |
| Per-page residency | HiSparseCoordinator |
decides which pages attention reads from GPU and sends residency updates |
| Residency transitions | HiSparseCoordinator |
plans write-back-before-release transactions |
| Logical host block allocation | HiSparseCoordinator |
owns the separate CPU block pool and its lifecycle |
| Pinned host-pool lifecycle | HiSparseHostPool |
per-process backing, registration and teardown, shared by the node's TP ranks when the pool is shared |
| Per-cache host view and hot contents | HiSparseRuntime |
binds host/hot storage and fills cache-manager-provided hot leases |
| Hot row map and LRU | HiSparseRuntime |
resolves hits and chooses victims on GPU |
| Device-cache route | HiSparseCacheHandle |
exposes device or host/hot resolution to attention |
| Sparse attention | attention backend | consumes a device cache and physical row IDs |
| HMA | allocator | provides GPU capacity; owns no KV meaning |
The key distinction is logical allocation versus contents. HiSparseCoordinator
owns host block IDs and their request/prefix associations.
HiSparseConnectorWorker and its per-cache runtimes own the corresponding
bytes. The normal cache manager sees only device pools.
The host group has block_pool_id=None; device-pool consumers must narrow it
before indexing, so host ownership cannot masquerade as a numeric GPU pool.
For MLA with MP tensor parallelism, every TP worker on a node maps the same pinned host pool and uses the same block and layer offsets. MLA KV is replicated across TP ranks, so this stores one physical copy per node instead of one copy per rank. The host leader, the lowest TP rank on each node, writes that node's pool; its peers wait on its IPC events before reading it. Other executor and parallel layouts retain private per-rank pools.
The shared layout backs the per-replica logical capacity with one physical pool per node; the private layout allocates one physical pool per rank. Physical pool size includes block-stride alignment.
Code boundary¶
scheduler process worker process
HiSparseConnector HiSparseConnector
└─ HiSparseCoordinator └─ HiSparseConnectorWorker
│ │
│ connector metadata ├─ host bytes
│ - page transfers ├─ copy scheduling
│ - residency updates └─ per-layer hot state
└───────────────────────────────────────────────►│
◄──────── connector worker metadata ─────────────┘
enqueued and completed transfer IDs
The command travels in kv_connector_metadata; transfer updates return in
KVConnectorOutput.kv_connector_worker_meta. The model runner does not
interpret page transfers. Enqueue acknowledgements let the scheduler free
device leases in stream order; completion acknowledgements make the copied
pages durable and publish them.
Device pages¶
Device pages are intentionally outside HiSparseRuntime.
KV-cache initialization binds cache-manager allocations to the attention-facing
HiSparseCacheHandle before constructing HiSparseConnectorWorker. That same
handle's runtime retains the device group index needed by a transfer plan.
There is no second device object or registration wrapper.
KV cache setup
│
├─ bind device allocation ──► HiSparseCacheHandle
│ cache + block table + slot mapping
│
├─ bind host/hot allocation ──► HiSparseRuntime
│ host + hot + GPU LRU
│
└─ register cache handles ────► HiSparseConnectorWorker
step-level transfers
HiSparseConnectorWorker registers the same HiSparseCacheHandle objects directly
Attention construction links each layer to the most recent layer that actually owns an indexer. This releases a follower's duplicate LRU tensors before GPU memory profiling. Cache binding only attaches storage; it does not infer semantic groups from the physical packed-tensor order. The construction cursor is discarded with the worker's pinned state.
Every HiSparse decode batch uses the same fused resolver. It checks device pages first, then hot rows, then pinned host memory. A device hit exits inside the kernel before hot-LRU lookup or host copying; there is no framework-level residency route or separate CUDA graph. No CPU decision is added to the decode path. The resolver consumes the existing graph-stable request mapping from attention metadata; neither the worker nor individual cache handles keep a duplicate mapping.
Speculative decoding resolves all verification rows of a request in one pass: one block resolves the union of the rows' top-k against the request's hot-buffer state, so rows that select the same host row share its hot row and no row evicts a hot row another row of the step still reads. Draft layers write their rows after the target forward, so their host mirror runs at the start of the next step, after the drafter, and the step's page transfers are submitted behind it.
P/D import target¶
For supported P/D configurations, NIXL and Mooncake import offloaded main KV into the host tier; under a shared host pool, each node's host leader receives it. Admission reserves the import's host pages for its full sequence. After an import completes, the coordinator restores the tail page and promotes earlier imported pages using free GPU blocks above the read-from-host watermark. Promoted pages keep their host backing and follow the normal residency policy. A cancelled import still publishes its host prefix but restores nothing. Indexer KV is transferred to its GPU cache group.
Indexer KV offloading¶
HiSparse does not keep a private CPU copy of indexer KV. The indexer remains a
normal prefix-cacheable GPU cache group. If OffloadingConnector is configured
with HiSparse, it stores and restores that group through the generic KV
offloading path; HiSparse continues to own only the main sparse-attention host tier.
The two prefix sources can have different hit lengths. When the HiSparse host
prefix extends beyond the device indexer prefix, the scheduler asks
OffloadingConnector to restore only the missing indexer suffix, capped at the
host prefix boundary. If that suffix is unavailable, all groups fall back to
the shorter prefix they share.
Write-back transaction¶
A device page cannot be released until its write-back has completed.
HiSparseCoordinator HiSparseConnectorWorker
│ │
│ lease device and host blocks │
│── HiSparsePageTransfer ────────────►│
│ │ enqueue GPU-to-host copy
│◄── enqueued transfer ID ────────────│
│ free device leases │
│ │ copy reaches its event
│◄── completed transfer ID ───────────│
│ mark page durable │
│ release it if the request can │
│ read from host │
│ free host lease; publish │
“Enqueued” means the copy has entered the worker stream. Stream ordering makes it safe to free the device leases, since later GPU work cannot overtake the copy, but the page is not yet durable. “Completed” means the worker has observed the copy's event; only then does the coordinator mark the page durable, release its device block once the request can read from host, publish the host page for prefix reuse and free its host lease. A host-write event separately protects direct CPU readers from writes already queued on the accelerator.
The worker transfer contains only its transfer ID and physical copy coordinates. Request identity and logical page state remain in the scheduler.
Hot lookup and LRU¶
Speculative decode group prefetch¶
HiSparse prefetches historical KV for layers sharing an indexer during pure decode batches, including multi-token verification with speculative decoding such as MTP. It uses the existing speculative-decoding configuration and swap capacity; no additional switch or backend capability flag is required.
The index-producing layer resolves the current top-k once and queues each layer's missing rows on the group's copy stream. Each layer waits on its own completion event before consuming those rows, allowing later layers' copies to overlap earlier layers' computation. Prefill and mixed prefill/decode batches retain per-layer staging.
This prefetch eligibility is separate from single-token device-write and host mirror policy. Current verification tokens remain in device pages, are excluded from the historical host-row swap plan, and are written by each layer before its attention runs. Prefetching does not publish rejected draft tokens as durable host KV. The benefit depends on host misses, shared-index group size, and how much copy work can overlap computation.
The CUDA compact gather uses at most 64 thread blocks per launch. Workers loop over additional rows when verification expands the batch beyond that limit; the existing column parallelism is retained for smaller batches. This bounds copy-kernel occupancy while later layers are prefetched, without reading miss counts back to the CPU or launching a separate compaction kernel. Actual copy bandwidth and end-to-end latency must be measured together, since bounding the grid can trade peak copy throughput for compute overlap.
Row resolution¶
The NVIDIA CUDA path keeps replacement entirely on the accelerator:
top-K logical positions
│
▼
device page? ── yes ──► device physical row
│ no
▼
hot row? ──────── yes ──► existing hot physical row + update GPU LRU
│ no
▼
choose GPU LRU victim ──► copy pinned host row ──► hot physical row
Device operations are selected by Platform.get_hisparse_backend_cls(). The base
platform returns None; CUDA selects CUDAHiSparseBackend in platforms/cuda.py.
Hardware plugins can provide a HiSparseBackend for host registration, cache
operations, IPC events, capture queries, and transfers while reusing the common
runtime and connector. HiSparse validates availability and cache formats before
allocation. Streams, ordinary events, current-stream queries, and synchronization
use torch.Stream, torch.Event, and torch.accelerator directly. The backend
provides IPC event creation/import/export only for shared host pools.
Without HiSparse, sparse attention keeps its normal stream and event path.
ROCm does not currently provide a HiSparse backend.
Main classes¶
| Class | Inherits / implements | Responsibility |
|---|---|---|
HiSparseCoordinator |
plain scheduler component | host allocation, host prefixes, device leases, and page-transfer state machine |
HiSparseConnector |
KVConnectorBase_V1, SupportsHMA |
scheduler/worker metadata and lifecycle boundary |
HiSparseHostManager |
FullAttentionManager |
host-group allocation from the private host pool and prefix publication once durable |
HiSparseDeviceManager |
SingleTypeKVCacheManager |
normal block-pool bookkeeping with host-backed holes |
HiSparseHotManager |
SingleTypeKVCacheManager |
allocates a request's hot buffer once it must read from host |
PagedCacheView |
immutable data object | shared device/hot HMA tensor binding |
HiSparseConnectorWorker |
connector-owned worker component | worker-wide transfer scheduling |
HiSparseHostPool |
plain worker component | pinned host backing and its registration |
HiSparseBackend |
platform plugin | host registration, cache operations, IPC events and transfers |
HiSparseRuntime |
plain worker-owned component | per-cache host/hot tensors, GPU LRU, and fused resolution |
HiSparseCacheHandle |
plain attention component | device view and fused cache resolution |
HiSparseTransferCommand |
dataclass | opaque scheduler-to-worker work |
Performance invariants¶
- Device hits bypass hot-LRU lookup and host copies inside the fused resolver.
- Hot lookup, victim selection, and LRU updates stay on the GPU.
- A hot miss still copies directly from registered pinned host memory.
- Top-K resolution stays inside the attention invocation and remains graph capturable.
- Compatible layers still share one miss plan.
- Index-sharing followers release their private LRU state before memory sizing.
- Indexer KV is untouched by HiSparse unless a generic KV offloader is configured.
- Device and hot leases can still share one packed HMA allocation.
- No device scalar readback or CPU/device metadata round trip is added.
- The abstraction wraps the fused kernel; it does not add another kernel launch.
- When HiSparse is disabled, the scheduler does not construct an offload command or empty update table.
What remains platform-specific¶
The command/result and attention-layer boundaries can be shared. The host
allocator, copy implementation, hot layout, and replacement policy should stay
platform-specific. NVIDIA uses the current accelerator LRU and fused host/hot
kernel. Other accelerators can implement HiSparseBackend and return its class
path from their platform override without changing the shared control flow.