feat(kvcache): host-RAM KV tier for sparse-attention models (--kv-host-pages) - #499
Open
alvarorsouza-arch wants to merge 1 commit into
Open
alvarorsouza-arch wants to merge 1 commit into
alvarorsouza-arch wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an opt-in second KV tier in pinned host RAM for models whose attention only re-reads a small selected subset of pages per step (Qwen3.8-Flash-Next QSA:
indexer_budget=2048). The pinned mirror is the backing store; the GPU pool becomes an LRU cache of physical slots over the logical page space.New flag:
--kv-host-pages N(default 0 = off; zero behavior change when off).Why this works for sparse attention
Every attend step first runs the indexer (top-k block selection over a compressed slab, fully GPU-resident) and only then reads the selected pages. Pages are fetched host→device after selection, bounded at ~34-520 pages/request/layer (fixed shape, CUDA-graph safe). Cold pages never cross PCIe; selected pages do, once.
Design
store_kvis mirrored to a pinnedHostBankover UVA, so a GPU slot is always drop-clean; eviction is a pure rebind (no write-back, no dirty tracking)lru_ensure(device-side LRU, fixed shapes, graph-safe) +fast_index_copy_multi_jit(one launch copies K+V of a page across all 12 QSA layers)qsa_sparse_paged_attentionruns unmodifiedensure_write_pagesuses a single fixed-shape Triton launch (stride samples + one boundary sample per request run). The first version used boolean-mask indexing andtorch.unique, both data-dependent shapes that hide device-to-host syncs per layer and serialize the prefill-overlap pipeline (the same pattern later found inmoe/offload_cache.py)compact_selected_pagesgained a drop counter;max_sel_pagessized from2*block_topk + 8instead of the contiguous-selection estimateMeasured (RTX 4070 Ti SUPER 16 GB, EPYC 7K62, 251 GB RAM, PCIe gen4)
Config A (fp8 KV via #354 composed):
--memory-ratio 0.92 --max-prefill-length 4096 --moe-cache-size 1024 --ple-backend pinned --max-running-requests 1 --enable-special-token-ckpt --kv-cache-dtype fp8 --kv-host-pages 5000 --num-pages 1635Composes with #354 (fp8 KV): fp8 pages halve fetch bytes and double the resident pool.
Known limitations
dsv4_sparseFiles
kvcache/kv_host_offload.py,kernel/triton/qsa/offload.pyattention/qsa_sparse.py,kvcache/qsa_pool.py,kvcache/__init__.py,core.py,engine/config.py,engine/engine.py,server/args.pyTest protocol
All numbers measured end-to-end over the OpenAI API. The quality suite (40 known-answer QA + 30 cloze at temperature 0) scored identical to the non-offload baseline on the same server. Happy to add unit tests for the offloader where maintainers prefer.