cd /news/ai-infrastructure/basinkv-drop-in-ram-nvme-kv-offloadi… · home › topics › ai-infrastructure › article
[ARTICLE · art-180311] src=zellige.ai ↗ pub= topic=ai-infrastructure verified=true sentiment=↑ positive

BasinKV, Drop-In RAM/NVMe KV Offloading for Llama.cpp, SGLang, vLLM

Zellige released BasinKV, an open-source sparse KV-cache offloading system for llama.cpp, SGLang and vLLM that keeps a fixed 2,048-token working set of KV blocks per full-attention head in GPU memory and moves full history to pinned host RAM or NVMe. On a 24 GB NVIDIA L4 running Qwen3.6-35B-A3B Q4_K_M at 256K context, where stock llama.cpp hits CUDA OOM from 64K, BasinKV held the entire GPU KV cache plus index in 84.75 MiB and decoded from 69.86 tok/s at depth 0 to 67.12 tok/s at 256K with 255/256 CUDA graphs reused; on an A100-80GB it reached 141.12 tok/s versus a 95.01 tok/s stock baseline at 256K. BasinKV is an extension of the OasisKV lookahead-prefetch architecture (Xiao et al., arXiv:2608.08097), requires no retraining or new weights, and runs FlashAttention, FlashInfer and full-model CUDA graphs unmodified.

key takeaway

BasinKV caps GPU KV cache at a fixed 2,048-token working set per head and offloads history to RAM or NVMe, letting a 24 GB L4 serve 256K context at 67.12 tok/s where stock llama.cpp OOMs from 64K.

read8 min views22 publishedDec 2, 2026
BasinKV, Drop-In RAM/NVMe KV Offloading for Llama.cpp, SGLang, vLLM
Image: source
  • Published

  • Authors

  • Zellige

  • Reading time

  • 8 min

  • #inference

  • #kv-cache

  • #long-context

  • #systems

  • #open-source

Drop-in sparse KV off to RAM and NVMe for llama.cpp, SGLang, and vLLM. No retraining, no new weights, and huge concurrency headroom with unmodified attention kernels inside CUDA graphs.

Contents6 #

Published by Zellige (2026-11-30). BasinKV is our open-source implementation and extension of the OasisKV lookahead-prefetch architecture [Xiao et al., arXiv:2608.08097]. For all 19 benchmark tables, McNemar significance tests, and roofline derivations, read the full technical paper.

Long-context serving hits the same memory wall on both local workstations and datacenter GPUs: KV cache grows linearly with sequence length, forcing stock engines to OOM or serialize batches while reading gigabytes of cold history on every decoded token.

BasinKV keeps a fixed-size working set of KV blocks per full-attention head in GPU memory (2,048 tokens by default), offloads the full KV history to pinned host RAM or NVMe (INT8 by default, uncompressed BF16 when RAM is abundant, or rotated 4-bit WHT-INT4 for maximum compression), scores evicted blocks on GPU (Shrunk-Box Quest INT8 with alpha = 0.25 by default, or 136-byte SphereIndex for tightest VRAM), and prefetches newly needed blocks asynchronously over PCIe UVA behind layer compute. Because the resident GPU buffer has a static shape, FlashAttention, FlashInfer, and full-model CUDA graphs run unmodified.

Flat decode throughput and bounded VRAM #

On bare-metal A100-80GB PCIe in llama.cpp, BasinKV keeps decode throughput nearly flat through 128K and 256K while stock slows down as the KV cache grows. WHT-INT4 halves host RAM and NVMe footprint relative to INT8 with less than 0.5% difference in decode speed:

That fixed GPU footprint carries directly to tighter cards. On a 24 GB NVIDIA L4 (23,034 MiB total / 22,614 MiB ECC-usable), where Qwen3.6-35B-A3B-UD-Q4_K_M weights alone take 20.60 GiB, stock llama.cpp hits CUDA OOM starting at 64K. BasinKV keeps the entire 256K GPU KV cache plus index in 84.75 MiB (1.29 GiB in pinned host RAM), decodes flat from 69.86 tok/s (d = 0) to 67.12 tok/s ( 256K) with 255/256 CUDA graphs reused, and passes live llama-server -c 262144 passkey retrieval at 64K (59.5 tok/s, 21,327 MiB peak) and 203K (60.4 tok/s, 21,885 MiB peak).

Results across llama.cpp, SGLang, and vLLM V1 #

Engine & workload Hardware Stock baseline BasinKV Quality check
llama.cppQwen3.6-35B-A3B Q4_K_M @ 256K NVIDIA L4 (24 GB) CUDA OOM (from 64K) 67.12 tok/s ,84.8 MiB GPU KV+idx (21.4 GiB peak) Live 64K & 203K passkeys: PASS
llama.cppQwen3.6-35B-A3B Q4_K_M @ 256K A100-80GB PCIe 95.01 tok/s ( 31.5 GiB ) 141.12 tok/s (1.49x) ,22.4 GiB (-8.91 GiB ) 18/18 iterative coding; 96.2% retrieval @ 240K
llama.cppQwen3-8B Q4_K_M @ 128K A100-80GB PCIe 54.28 tok/s 124.29 tok/s (2.29x) 16/18 coding ( W = 4,096 )
SGLangQwen3.8-27B BF16,B = 16 x 64K (1.02M tok) 1x A100-80GB OOM w/ MTP (~97 no-MTP cap) 581.4 tok/s w/ native MTP,18.13 GB free 16/16 unique passkeys
SGLangQwen3.8-27B-FP8 ,B = 16 x 64K (1.02M tok) 1x H100-80GB 358.0 tok/s FP8 KV ( 264.8 s ) / 33.9 BF16 KV 470.4 tok/s (1.31x) ,130.3 s wall (2.03x vs FP8 KV) 16/16 passkeys; 5/5 64K RULER
SGLang cold block-sparse prefill @ 240K 1x H100-80GB 43.88 s dense streaming TTFT 33.38 s (-10.50 s) via fused Triton + UVA gather 40/40 RULER fields (64K to 240K)
vLLM V1 zero-forkOKVP1 prefix cache (Qwen3-8B ) A100-80GB PCIe 961.4 ms repeated request 456.5 ms RAM /702.4 ms NVMe (728.4 ms post-restart) 1.94x smaller on disk vs INT8

In SGLang on H100 with FP8 weights, Qwen3.8-27B-FP8 at B = 16 x 64K hits 470.4 tok/s and cuts batch wall time in half against stock FP8 KV (130.3 s vs 264.8 s), while keeping resident KV near 2 GiB on Qwen3.6-35B-A3B-FP8 (where stock's full 20 GiB KV still fits inside H100 HBM at B = 16).

In vLLM V1 (0.19.1), our zero-fork KVConnectorBase_V1 plugin drops directly into stock vllm serve to persist rotated 4-bit prefix caches to RAM or NVMe (OKVP1) across process restarts, cutting on-disk snapshots by 1.94x and speeding up NVMe hits by 1.36x over INT8:

Try it #

(Repository paths and CLI flags in v0.1 retain the oasiskv namespace.)

Clone BasinKV, then run the steps below from inside its folder:

git clone https://github.com/zellige-ai/basinkv && cd basinkv

1. llama.cpp

git clone https://github.com/ggml-org/llama.cpp
git -C llama.cpp checkout ca123ba76311290ec6ab041dd2058fed8d9f03d2
python3 integrations/llamacpp/apply_llamacpp_wiring.py llama.cpp
cmake -S llama.cpp -B llama.cpp/build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES="86;89"
cmake --build llama.cpp/build --target llama-server llama-bench -j

./llama.cpp/build/bin/llama-server -m Qwen3.6-35B-A3B-UD-Q4_K_M.gguf \
  -ngl 99 -c 262144 -b 1024 -ub 1024 -fa on -np 1 \
  --oasiskv --oasiskv-resident 2048 --oasiskv-cap 8 \
  --oasiskv-index quest --oasiskv-alpha 0.25 --oasiskv-kv-quant int8

2. SGLang

pip install -e .
git clone https://github.com/sgl-project/sglang.git /tmp/sglang
git -C /tmp/sglang checkout a3f0bff5babfe18d3862e134449cd8fd11fcb84a
pip install -e /tmp/sglang/python
python3 integrations/sglang/apply_wiring.py /tmp/sglang integrations/sglang

python3 -m sglang.launch_server \
  --model-path Qwen/Qwen3.8-27B-FP8 --context-length 262144 \
  --enable-oasiskv --attention-backend oasiskv --disable-radix-cache --page-size 16 \
  --oasiskv-config '{"resident_tokens":2048,"sink_blocks":4,"local_blocks":8,"transfer_cap_c":16,"pcie_quant":"int8","index_quant":"int8","quest_alpha":0.25,"successor_cofetch":true,"lazy_host_slabs":true,"streaming_prefill":true,"draft_ring_window":4096,"draft_ring_sink":64}' \
  --speculative-algorithm NEXTN --speculative-num-steps 3 \
  --speculative-eagle-topk 1 --speculative-num-draft-tokens 4 \
  --enable-linear-replayssm-spec

3. vLLM V1 (zero-fork prefix cache)

vllm serve Qwen/Qwen3-8B --kv-transfer-config '{
  "kv_connector": "OasisKVConnector",
  "kv_connector_module_path": "integrations.vllm.oasiskv_connector",
  "kv_role": "kv_both",
  "kv_connector_extra_config": {
    "cache_mode": "mixed",
    "pcie_quant": "int8",
    "prefix_cache_dir": "/tmp/basinkv_cache",
    "prefix_cache_ram_gb": 4.0,
    "prefix_cache_nvme_gb": 32.0
  }
}'

(The zero-fork vLLM V1 plugin persists host KV formats only (none, int8, or wht_int4), with no Quest or SphereIndex block index. For tight host RAM, NVMe budgets, or maximum multi-user concurrency, switch to the high-compression tier: --oasiskv-index sphere --oasiskv-beta 0.10 --oasiskv-kv-quant wht_int4 in llama.cpp, "pcie_quant": "wht_int4", "index_quant": "sphere_int4", "sphere_beta": 0.10 in SGLang, or "pcie_quant": "wht_int4" in vLLM. In SGLang and vLLM with abundant host RAM, "pcie_quant": "none" keeps uncompressed BF16.)

Five technical pieces behind the numbers #

  1. Partial-RoPE radius weight (alpha = 0.25). Qwen3.x hybrids put 64 rotary and 192 non-rotary dimensions in each full-attention head. On native BF16Qwen/Qwen3.8-27B , the non-rotary box radius averages2.70x the midpoint magnitude (1.898 vs0.704 ), drowning dot-product signal under unweighted Quest (alpha = 1.0 ,29.9% Top-8 recall,0/5 RULER at 128K). Dropping the radius weight toalpha = 0.25 raises per-step Top-8 recall from82.5% (OasisKV Eq. 3alpha = 0.50 sum) to95.5% (93.2% under GQA max) and restores5/5 RULER with48/48 greedy prefix parity.
  2. SphereIndex (136 bytes/block, 7.53x smaller than BF16 min/max). Instead of storing per-block BF16 min/max bounds (1,024 B/blk atD = 256 ), SphereIndex rotates the block centroid with a fixed randomized Walsh-Hadamard transform, quantizes it to symmetric INT4, and appends two FP16 subspace radii (r_rope ,r_nope ). AtD = 256 , Top-8 salient-event recall improves from61.8% to70.2% while cutting index memory7.53x .
  3. WHT-INT4 rotated host KV (1.97x smaller than INT8). Each offloaded K and V vector is Hadamard-rotated and quantized to symmetric 4-bit (D/2 + 4 bytes/vector), cutting synthetic outlier L2 error3.9x vs naive INT4 and doubling host concurrency and NVMe cache density at equal decode speed.
  4. Engine plumbing that respects CUDA graphs. Static fixed-shape GPU slabs, lazy host slab allocation guarded by/proc/meminfo , a ring-mapped FP8 draft KV pool for hybridNEXTN MTP, direct-to-host streaming prefill, an optional fused Triton block-sparse prefill kernel (-10.50 s at 240K), and atomic CRC32-checkedOKVP1 /OKVS1 prefix snapshots (including recurrent states for hybrids).
  5. Best-effort 1-hop successor (b + 1) co-fetch for induction heads. Running BasinKV live in coding agents exposed a block-sparse failure mode: when a multi-token cue (<tool_call>\n<function= ) straddles a 16-token block boundary, fetching blockb withoutb + 1 flips induction-head logits by +30 to +40 nats (30% to60% failure rate at offsets 14 or 15 vs0/43 aligned). Propagating each eligible block's score one hop forward (nextafter(score[b], -inf) ) before top-k selection promotes boundary-straddling pairs at zero VRAM cost (0/30 observed live boundary failures on H100).

Quality and practical notes #

  • Quality parity on hybrids:100% retrieval/QA on 64K to 128K RULER,18/18 on 128K to 192K 3-turn iterative coding,7/10 vs7/10 on 128K/224K RepoPatch-LC,45.0% vs42.5% stock on an 80-item stratified LongBench v2 subset (paired 95% CI-3.8 to+8.8 pts), and flat throughput across non-Qwen Mamba2 hybrids (IBM Granite-4.0-H-Small and NVIDIA Nemotron-Nano-9B-v2).
  • Choosing host KV and index precision: A controlled 6-arm H100 logit ablation on 66K to 199K live coding transcripts (Qwen3.8-27B-FP8 ) showed whyint8 + QuestINT8 (alpha = 0.25 ) is the cleanest default:int8 matches uncompressed BF16 runner-up logit margins on rare exact identifiers (+12.75 to+13.00 vs+12.50 to+13.12 nats), whereaswht_int4 compresses tail margins by ~5 nats (+7.75 to+7.88 nats). Under 4-tokenNEXTN MTP at 199K, QuestINT8 (alpha = 0.25 ) also avoids occasionalSphereIndex centroid-dilution spikes (-0.06 mean /+1.50 worst nat delta vs+2.44 /+4.87 underwht_int4 +sphere_int4 , and+6.12 worst even under BF16 +sphere_int4 ). Reach forwht_int4 +sphere_int4 when host RAM, NVMe footprint, or peak concurrency is the binding constraint (as in our24 GB L4 and1.02M -token SGLang throughput runs above).
  • When full KV already fits in HBM: Stock full-HBM serving is still faster when there is no memory pressure. On H100Qwen3.6-35B-A3B-FP8 atB = 16 x 64K (where all 20 GiB of BF16 KV fits comfortably in HBM), stock decodes20.1% faster (1,141.2 vs950.2 tok/s ), while BasinKV holds resident KV near2 GiB so concurrency and context can keep scaling past the HBM wall (details in §5.8 of thetechnical paper ).
  • Tuning pure-attention models: Deep 36-layer pure-attention models (Qwen3-8B ) compound per-layer misses more steeply than interleaved hybrids; useW = 4,096 instead of2,048 .
  • Global counting at sub-1% budgets: Unkeyed global counting tasks like 240K RULERcwe (finding the 10 most common words scattered across ~300 blocks) drop from50% to0% under a0.83% resident window (W = 2,048 of 245K); see §6.1 of thetechnical paper for the full depth breakdown and sampling analysis.

Read more #

── more in #ai-infrastructure 4 stories · sorted by recency
── more on @zellige 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/basinkv-drop-in-ram-…] indexed:0 read:8min 2026-12-02 · —