{"slug": "basinkv-drop-in-ram-nvme-kv-offloading-for-llama-cpp-sglang-vllm", "title": "BasinKV, Drop-In RAM/NVMe KV Offloading for Llama.cpp, SGLang, vLLM", "summary": "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.", "body_md": "# BasinKV: Long Context Without the KV Cache Tax\n\n- Published\n- Authors\n- Zellige\n- Reading time\n- 8 min\n\n- #inference\n- #kv-cache\n- #long-context\n- #systems\n- #open-source\n\nDrop-in sparse KV offloading 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.\n\n## Contents6\n\n**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](https://zellige.ai/research/basinkv).\n\nLong-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.\n\n**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**.\n\n## Flat decode throughput and bounded VRAM\n\nOn 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:\n\nThat 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).\n\n## Results across llama.cpp, SGLang, and vLLM V1\n\n| Engine & workload | Hardware | Stock baseline | **BasinKV** | Quality check | \n|---|---|---|---|---|\n| **llama.cpp**`Qwen3.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** | \n| **llama.cpp**`Qwen3.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 | \n| **llama.cpp**`Qwen3-8B` Q4_K_M @ 128K | A100-80GB PCIe | 54.28 tok/s | **124.29 tok/s (2.29x)** | 16/18 coding ( `W = 4,096` ) | \n| **SGLang**`Qwen3.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 | \n| **SGLang**`Qwen3.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 | \n| **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) | \n| **vLLM V1** zero-fork`OKVP1` 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 | \n\nIn 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`).\n\nIn 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:\n\n## Try it\n\n*(Repository paths and CLI flags in v0.1 retain the `oasiskv` namespace.)*\n\nClone BasinKV, then run the steps below from inside its folder:\n\n```\ngit clone https://github.com/zellige-ai/basinkv && cd basinkv\n```\n\n### 1. `llama.cpp`\n\n```\ngit clone https://github.com/ggml-org/llama.cpp\ngit -C llama.cpp checkout ca123ba76311290ec6ab041dd2058fed8d9f03d2\npython3 integrations/llamacpp/apply_llamacpp_wiring.py llama.cpp\ncmake -S llama.cpp -B llama.cpp/build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=\"86;89\"\ncmake --build llama.cpp/build --target llama-server llama-bench -j\n\n./llama.cpp/build/bin/llama-server -m Qwen3.6-35B-A3B-UD-Q4_K_M.gguf \\\n  -ngl 99 -c 262144 -b 1024 -ub 1024 -fa on -np 1 \\\n  --oasiskv --oasiskv-resident 2048 --oasiskv-cap 8 \\\n  --oasiskv-index quest --oasiskv-alpha 0.25 --oasiskv-kv-quant int8\n```\n\n### 2. SGLang\n\n```\npip install -e .\ngit clone https://github.com/sgl-project/sglang.git /tmp/sglang\ngit -C /tmp/sglang checkout a3f0bff5babfe18d3862e134449cd8fd11fcb84a\npip install -e /tmp/sglang/python\npython3 integrations/sglang/apply_wiring.py /tmp/sglang integrations/sglang\n\npython3 -m sglang.launch_server \\\n  --model-path Qwen/Qwen3.8-27B-FP8 --context-length 262144 \\\n  --enable-oasiskv --attention-backend oasiskv --disable-radix-cache --page-size 16 \\\n  --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}' \\\n  --speculative-algorithm NEXTN --speculative-num-steps 3 \\\n  --speculative-eagle-topk 1 --speculative-num-draft-tokens 4 \\\n  --enable-linear-replayssm-spec\n```\n\n### 3. vLLM V1 (zero-fork prefix cache)\n\n```\nvllm serve Qwen/Qwen3-8B --kv-transfer-config '{\n  \"kv_connector\": \"OasisKVConnector\",\n  \"kv_connector_module_path\": \"integrations.vllm.oasiskv_connector\",\n  \"kv_role\": \"kv_both\",\n  \"kv_connector_extra_config\": {\n    \"cache_mode\": \"mixed\",\n    \"pcie_quant\": \"int8\",\n    \"prefix_cache_dir\": \"/tmp/basinkv_cache\",\n    \"prefix_cache_ram_gb\": 4.0,\n    \"prefix_cache_nvme_gb\": 32.0\n  }\n}'\n```\n\n*(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.)*\n\n## Five technical pieces behind the numbers\n\n1. **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 BF16`Qwen/Qwen3.8-27B` , the non-rotary box radius averages`2.70x` the midpoint magnitude (`1.898` vs`0.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 to`alpha = 0.25` raises per-step Top-8 recall from`82.5%` (OasisKV Eq. 3`alpha = 0.50` sum) to`95.5%` (`93.2%` under GQA max) and restores`5/5` RULER with`48/48` greedy prefix parity.\n2. **`SphereIndex` (136 bytes/block, `7.53x` smaller than BF16 min/max).** Instead of storing per-block BF16 min/max bounds (`1,024 B/blk` at`D = 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` ). At`D = 256` , Top-8 salient-event recall improves from`61.8%` to`70.2%` while cutting index memory`7.53x` .\n3. **`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 error`3.9x` vs naive INT4 and doubling host concurrency and NVMe cache density at equal decode speed.\n4. **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 hybrid`NEXTN` MTP, direct-to-host streaming prefill, an optional fused Triton block-sparse prefill kernel (`-10.50 s` at 240K), and atomic CRC32-checked`OKVP1` /`OKVS1` prefix snapshots (including recurrent states for hybrids).\n5. **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 block`b` without`b + 1` flips induction-head logits by +30 to +40 nats (`30%` to`60%` failure rate at offsets 14 or 15 vs`0/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).\n\n## Quality and practical notes\n\n- **Quality parity on hybrids:**`100%` retrieval/QA on 64K to 128K RULER,`18/18` on 128K to 192K 3-turn iterative coding,`7/10` vs`7/10` on 128K/224K RepoPatch-LC,`45.0%` vs`42.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).\n- **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 why`int8` + Quest`INT8` (`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), whereas`wht_int4` compresses tail margins by ~5 nats (`+7.75` to`+7.88` nats). Under 4-token`NEXTN` MTP at 199K, Quest`INT8` (`alpha = 0.25` ) also avoids occasional`SphereIndex` centroid-dilution spikes (`-0.06` mean /`+1.50` worst nat delta vs`+2.44` /`+4.87` under`wht_int4` +`sphere_int4` , and`+6.12` worst even under BF16 +`sphere_int4` ). Reach for`wht_int4` +`sphere_int4` when host RAM, NVMe footprint, or peak concurrency is the binding constraint (as in our`24 GB` L4 and`1.02M` -token SGLang throughput runs above).\n- **When full KV already fits in HBM:** Stock full-HBM serving is still faster when there is no memory pressure. On H100`Qwen3.6-35B-A3B-FP8` at`B = 16 x 64K` (where all 20 GiB of BF16 KV fits comfortably in HBM), stock decodes`20.1%` faster (`1,141.2` vs`950.2 tok/s` ), while BasinKV holds resident KV near`2 GiB` so concurrency and context can keep scaling past the HBM wall (details in §5.8 of the[technical paper](https://zellige.ai/research/basinkv) ).\n- **Tuning pure-attention models:** Deep 36-layer pure-attention models (`Qwen3-8B` ) compound per-layer misses more steeply than interleaved hybrids; use`W = 4,096` instead of`2,048` .\n- **Global counting at sub-1% budgets:** Unkeyed global counting tasks like 240K RULER`cwe` (finding the 10 most common words scattered across ~300 blocks) drop from`50%` to`0%` under a`0.83%` resident window (`W = 2,048` of 245K); see §6.1 of the[technical paper](https://zellige.ai/research/basinkv) for the full depth breakdown and sampling analysis.\n\n## Read more\n\n- **Full technical paper (19 tables, methodology, roofline analysis):**[BasinKV Technical Paper](https://zellige.ai/research/basinkv)\n- **Practical tuning recipes and flag reference:**[Tinkering & Tuning Guide](https://github.com/zellige-ai/basinkv/blob/main/docs/TINKERING_AND_TUNING.md)\n- **Raw measurements and commands:**[Benchmark Log](https://github.com/zellige-ai/basinkv/blob/main/docs/summaries/benchmark-track-a-oasiskv.md)", "url": "https://wpnews.pro/news/basinkv-drop-in-ram-nvme-kv-offloading-for-llama-cpp-sglang-vllm", "canonical_source": "https://zellige.ai/research/basinkv-launch", "published_at": "2026-12-02 16:05:33+00:00", "updated_at": "2026-12-02 16:17:08.110583+00:00", "lang": "en", "topics": ["ai-infrastructure", "large-language-models", "ai-research", "mlops", "ai-tools"], "entities": ["Zellige", "BasinKV", "llama.cpp", "SGLang", "vLLM", "OasisKV", "NVIDIA L4", "Qwen3.6-35B-A3B"], "also_reported_by": [], "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.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/basinkv-drop-in-ram-nvme-kv-offloading-for-llama-cpp-sglang-vllm", "markdown": "https://wpnews.pro/news/basinkv-drop-in-ram-nvme-kv-offloading-for-llama-cpp-sglang-vllm.md", "text": "https://wpnews.pro/news/basinkv-drop-in-ram-nvme-kv-offloading-for-llama-cpp-sglang-vllm.txt", "jsonld": "https://wpnews.pro/news/basinkv-drop-in-ram-nvme-kv-offloading-for-llama-cpp-sglang-vllm.jsonld"}}