Skip to content
Starchaser1024Public

About

Zero-Fork vLLM V1 Lossless Bit-Plane Compression & 3-Tier KV Cache Engine (C++17 Pinned Slabs + Read-Preemptive io_uring + Triton + cuMemcpyBatchAsync)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

PrismKV

Zero-Fork vLLM V1 Bit-Exact Lossless 3-Tier KV Cache Engine (GPU HBM ↔ Pinned Host DRAM ↔ Linux io_uring NVMe) with 48-Layer Contiguous Super-Block cuMemcpyBatchAsync & Tri-Mode Entropy @triton.jit Codec

Python 3.10+ vLLM V1 C++17 + Triton + io_uring Lossless Bijection


1. Production Motivation: Why Multi-Turn Agents Break Standard Prefix Caching

Modern Coding, SQL, and Computer-Use Agents exhibit a burst-pause-resume execution pattern that breaks single-turn LLM serving assumptions:

  1. HBM Eviction Thrashing During Tool Pauses: An agent accumulates 8K–64K context tokens across multi-step reasoning, emits a tool_call (bash test suite, SQL query, browser navigation), and pauses for 2–15s. Under concurrent traffic, GPU HBM evicts the paused session's KV blocks; when the tool returns, the engine must recompute the entire historical prefill from scratch, causing multi-second TTFT spikes and wasting GPU FLOPs.
  2. PCIe Root-Complex Contention & Host DRAM Bloat: Naive raw BF16 CPU offloading transfers 100% of raw KV bytes across PCIe and burns tens of gigabytes of pinned host RAM. Worse, per-layer fragmented slabs generate $O(L \cdot B)$ DMA/IOPS storms (1.38M ops for 48-layer 14B workloads), while synchronous wait_for_save() hooks or background NVMe writeback head-of-line blocking stall vLLM V1's overlapped execution pipeline.
  3. Zero-Tolerance for Lossy KV Drift & Silent Disk Corruption: Lossy KV quantization (INT4/FP4) accumulates logit drift over multi-turn tool trajectories, breaking strict JSON schemas, SQL identifiers, or code diffs; meanwhile, multi-terabyte NVMe caches require hardware checksums and automatic self-healing against silent bit-rot.

PrismKV (v0.4) solves all three problems as a zero-fork vLLM V1 plugin (KVConnectorBase_V1 + SupportsHMA):

  • Rate-Optimal Tri-Mode @triton.jit Lossless BF16 Bit-Plane Codec (3-bit + 4-bit + Raw): Exploits BF16 exponent concentration with auto-calibrated per-subchunk exponent windows (e_base=0, immune to 120× attention-sink massive activations), selecting per 2,048-element subchunk the tightest representation among 3-bit bit-planes (7 bins + 1B prefix-sum escape), 4-bit nibbles (14 bins + dedicated zero + 1B escape), and raw BF16 fallback. Reaches 1.4161× lossless compression (-29.38% bytes, 93.30% of the BF16 Shannon Exponent-Entropy Limit 1.5178×, max_uint16_xor == 0), 13,876× faster than CPU zlib-6 with 325.64 GB/s single-pass barrier-free scatter-decode on NVIDIA A100.
  • Multi-Layer Contiguous Super-Block Packing & Zero-Copy cuMemcpyBatchAsync: Coalesces all L (48) Transformer layers of each KV block on GPU into 1 contiguous ~2.25 MiB Super-Block and transfers directly between C++ pinned slabs and GPU buffers via CUDA Driver cuMemcpyBatchAsync (0 host memcpy), slashing DMA descriptors, hash lookups, and io_uring IOPS by 48× while running 4-thread parallel SSE4.2 CRC-32C on D2H commits.
  • Read-Preemptive C++17 Linux io_uring NVMe Tier + Self-Healing Quarantine: Direct <linux/io_uring.h> async NVMe engine (1,399.6 MiB/s spill write, 2,726.7 MiB/s promote read + CRC-32C on A100) featuring front-of-queue read preemption (push_front), SQE background-write throttling, and flush_reads() decoupling so background writeback never blocks active KV restoration; optional O_DIRECT supported, with automatic corrupted-slot quarantine and vLLM V1 block recomputation (get_block_ids_with_load_errors()).
  • True vLLM V1 Overlapped Async Load (load_kv_async=True), Multi-Bucket Triton Warmup & Prewarm Proxy: Overlaps external KV restoration behind GPU compute (WAITING_FOR_REMOTE_KVS) while preserving FULL_AND_PIECEWISE CUDA Graphs, exports native vllm:prismkv_* Prometheus metrics, and pairs with an OpenAI SSE proxy for tool_calls demotion and proactive prewarm.

2. System Architecture

flowchart TB
    subgraph ClientLayer["Multi-Turn Agent Runtime & OpenAI SSE Proxy (prismkv.proxy)"]
        Agent["Coding / SQL / Browser Agent"]
        Proxy["PrismKV FastAPI SSE Proxy<br/>• Auto-detects finish_reason='tool_calls' → tool_wait<br/>• Prewarms spilled sessions (POST /v1/kv/prewarm)"]
        Agent <-->|"OpenAI /v1/chat/completions"| Proxy
    end

    subgraph VLLMEngine["vLLM V1 Engine (v0.34.0 Zero-Fork Plugin via --kv-transfer-config)"]
        Sched["PrismKVSchedulerManager (SCHEDULER + SupportsHMA)<br/>• Prefix-chained 128-bit Blake2b block keys<br/>• Async KV Load (load_kv_async=True, WAITING_FOR_REMOTE_KVS)<br/>• O(N) Append-Only Dirty-Delta save planner<br/>• Native vllm:prismkv_* Prometheus exporter"]
        Compute["GPU Forward & FULL_AND_PIECEWISE CUDA Graphs<br/>• Overlapped with async KV transfers (A100 14B ITL P50 = 26.74 ms)"]
        LoadPipe["Zero-Copy Super-Block Load Pipeline (load_stream)<br/>• 1 cuMemcpyBatchAsync per 48-layer Super-Block (48x fewer DMA ops)<br/>• Single-pass barrier-free @triton.jit scatter-decode (325.6 GB/s)"]
        SavePipe["4-Wave Overlapped Super-Block Save Pipeline (save_stream + d2h_stream)<br/>• Tri-Mode (3-bit/4-bit/Raw) @triton.jit gather-encode + GPU coalescing<br/>• Background cuMemcpyBatchAsync + 4-thread SSE4.2 CRC-32C"]
    end

    subgraph NativeStorage["C++17 Native Storage Extension (prismkv._prismkv_C)"]
        Slab["Tier-2: PinnedSlabPool (CUDA Pinned Host DRAM)<br/>• Page-aligned Super-Block slabs + pin_count DMA guard<br/>• Zero-copy prepare_multilayer_h2d / prepare_multilayer_d2h<br/>• Session-aware LRU demotion"]
        Uring["Tier-3: UringNvmeTier (Read-Preemptive Linux io_uring)<br/>• Priority read queue + SQE write throttling + flush_reads()<br/>• SSE4.2 CRC-32C check + silent bit-rot quarantine"]
        Slab <-->|"Watermark Spill & Async Prewarm"| Uring
    end

    Proxy -->|"Forward + session_id"| Sched
    Proxy -.->|"Unix Domain Sideband IPC"| Slab
    Sched -->|"Async Load / Save Plan"| LoadPipe
    Sched -->|"Dirty-Delta Save Plan"| SavePipe
    LoadPipe -->|"Zero-Copy Scatter"| Compute
    Compute -->|"Post-Forward Stream Event"| SavePipe
    Slab -->|"cuMemcpyBatchAsync H2D (-27.7%)"| LoadPipe
    SavePipe -->|"cuMemcpyBatchAsync D2H (-27.7%)"| Slab
Loading

3. Verified Real-Hardware Benchmarks

Full benchmark ledgers, design deep-dives, and reproduction scripts are documented in docs/BENCHMARK_REPORT.md, docs/ARCHITECTURE.md, benchmarks/run_live_benchmark.py, and benchmarks/bench_codec_and_uring.py.

PrismKV v0.4 A100 14B Verification

3.1 Datacenter Tier: NVIDIA A100-SXM4-40GB + Qwen2.5-Coder-14B-Instruct (48 Layers, ~84 GiB KV Traffic)

Workload: 12 interleaved multi-turn Coding/SQL Agent sessions × 4 turns = 48 turns (bfloat16, max_model_len=16384, --num-gpu-blocks-override 1920 = 30,720 HBM tokens, 1.8s external tool pause, max_num_seqs=6, max_inflight_llm=3, temperature=0.0 greedy SSE streaming).

Arm Configuration Resume TTFT Mean Resume TTFT P50 Resume TTFT P95 Decode ITL P50 Throughput (turns/min) Wall Time Offload Parity
1. Native vLLM V1 (HBM Evict-Recompute) 3291.3 ms 3120.1 ms 5297.8 ms 26.78 ms 36.43 79.06 s Baseline
2. vLLM Official SimpleCPUOffload (34 GiB Raw BF16) 1401.8 ms (-57.4%) 1525.5 ms (-51.1%) 1983.9 ms (-62.6%) 26.66 ms 64.12 (+76.0%) 44.92 s 100.0%
3. PrismKV v0.4 (48L Super-Block + Tri-Mode Codec) 1400.9 ms (-57.4%) 1357.1 ms (-56.5%) 1997.8 ms (-62.3%) 26.74 ms 65.46 (+79.7%) 44.00 s 100.0% (48/48)
4. PrismKV v0.4 3-Tier (~15.9 GiB DRAM + io_uring + Prewarm) 1801.4 ms (-45.3%) 1613.8 ms (-48.3%) 4315.2 ms (-18.5%) 26.73 ms 57.38 (+57.5%) 50.19 s 100.0% (48/48)
  • Headline Datacenter Result: At 14B (48-layer) scale on NVIDIA A100-SXM4-40GB, PrismKV v0.4 beats vLLM's official uncompressed SimpleCPUOffloadConnector on both median resume TTFT (1,357.1 ms vs 1,525.5 ms, -11.0% faster) and total wall-clock throughput (44.00 s vs 44.92 s, +79.7% over Native vLLM V1), while saving 23.33 GiB (23,885.3 MiB, 1.3836× live lossless ratio) of PCIe bus traffic with 100.0% (48/48 turns) greedy token-for-token parity against uncompressed SimpleCPUOffloadConnector! Under < 50% host DRAM budget (~15.9 GiB), 3-tier read-preemptive io_uring NVMe tiering seamlessly spills 7,844 and promotes 15,417 Super-Blocks (0 CRC errors) with +57.5% higher throughput than Native vLLM V1.

3.2 Kernel, PCIe DMA & Linux io_uring Micro-Benchmarks (A100-SXM4-40GB & RTX 3060)

Subsystem Metric NVIDIA A100-SXM4-40GB NVIDIA RTX 3060 12 GiB
Lossless Compression Ratio (max_uint16_xor == 0) 1.4161× (93.30% of BF16 Shannon Limit 1.5178×, 13,876× faster than zlib-6) 1.3244× (v0.2) / 1.4161× (v0.4)
Paged Gather + Bit-Plane Encode (@triton.jit) 133.01 GB/s (0.126 ms / 16 MiB) 69.69 GB/s
Paged Single-Pass Unpack + Scatter (@triton.jit) 325.64 GB/s (0.051 ms / 16 MiB) 140.57–166.40 GB/s
Single-Transfer Pinned PCIe H2D (16 MiB KV Batch) Raw 1.362 ms → PrismKV 1.022 ms (1.333× faster) Raw 1.999 ms → PrismKV 1.685 ms (1.186× faster)
C++17 Linux io_uring NVMe Async Spill / Promote+CRC32C 1,399.6 MiB/s write / 2,726.7 MiB/s read (0 CRC err) 1,089.0 MiB/s write / 2,039.2 MiB/s read

4. Quickstart

Build & Diagnostics

uv pip install --no-build-isolation -e .
prismkv doctor
# Verifies CUDA HostRegister pinning, cuMemcpyBatchAsync driver support, io_uring ring & SSE4.2 CRC-32C

Launch Zero-Fork vllm serve with PrismKVConnector

KV_CFG=$(prismkv kv-config \
  --codec bitplane \
  --dram-slabs 240000 \
  --nvme-path /var/tmp/prismkv_tier3.bin \
  --nvme-slots 520000 \
  --sideband-sock /tmp/prismkv_sideband.sock)

vllm serve Qwen/Qwen2.5-Coder-14B-Instruct \
  --enable-prefix-caching \
  --kv-transfer-config "$KV_CFG"

5. Honest Engineering Boundaries

  • Data Type Scope: The @triton.jit tri-mode lossless bit-plane codec targets bfloat16 KV caches (8-bit exponent concentration). Models running FP8 (E4M3) KV caches have lower exponent redundancy and can set "codec": "raw" to use PrismKV's C++17 PinnedSlabPool + read-preemptive io_uring NVMe tiering directly.
  • Single-Engine TP=1 Verification Scope: Current end-to-end benchmarks target single-GPU (TP=1) vLLM V1 serving (A100 40GB 14B and RTX 3060 12GB 1.5B); multi-GPU tensor parallelism (TP>1) embeds tp_sz into prefix keys and requires per-rank slab pools.
  • FlashAttention Reduction Tree Determinism vs Codec Bijection: Uncached varlen full-prefill (native_recompute) and paged prefix-cached suffix-prefill (SimpleCPUOffloadConnector / PrismKV) use different FlashAttention-2 tile reduction trees on sm_80, yielding 77.1% greedy match against uncached recompute for both uncompressed and compressed offload, while PrismKV achieves 100.0% (48/48) exact token parity against uncompressed SimpleCPUOffloadConnector and max_uint16_xor == 0 bitwise KV reconstruction.

License

Apache License 2.0 — see LICENSE.

About

Zero-Fork vLLM V1 Lossless Bit-Plane Compression & 3-Tier KV Cache Engine (C++17 Pinned Slabs + Read-Preemptive io_uring + Triton + cuMemcpyBatchAsync)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages