Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

CompilerKV: Retaining 1.56% KV Cache Boosts Decode Throughput 2.45x for Long-Context LLMs

CompilerKV introduces an offline experience compilation framework that compresses KV cache to 1.56% of original size while maintaining near-full accuracy on LongBench and RULER benchmarks, achieving 2.45x decode throughput improvement on A100-80GB through two lightweight lookup tables for head reliability and risk-adaptive thresholds.

As LLM context windows expand, KV cache memory becomes a critical bottleneck. A 7B model at 128K context can exceed 100GB for KV cache alone. Researchers from Chinese Academy of Sciences, UESTC, CUHK-Shenzhen, Tianjin University, and University of Science and Technology Beijing propose CompilerKV, a risk-adaptive KV cache compression method based on offline experience compilation.

Core Insight: Single Prompt Is the Wrong Statistical Unit

The team found that two key signals — per-head reliability and prompt-level compression sensitivity — have extremely low signal-to-noise ratio within a single prompt but exhibit strong cross-prompt regularity. When measuring head reliability rankings independently on academic corpora (arXiv + PubMed) and conversational corpora (ShareGPT + UltraChat), the average Spearman rank correlation across mainstream models reached ρ = 0.90 (0.89–0.91). This indicates that which heads handle long-range retrieval vs. local windows is a portable architectural prior, not input-dependent. Recomputing these priors online per prompt wastes compute and causes catastrophic mis-deletion in extreme long-context or high-noise scenarios.

CompilerKV: Two-Stage Offline Compilation + Online O(1) Lookup

CompilerKV restructures KV compression into offline experience compilation and online O(1) table lookup, with three components targeting three error sources in prefill compression:

1. Stabilized Token Utility (Parameter-Free)

During online phase, standard observation window scanning aggregates attention quality combined with Value vector norm normalization. This parameter-free step smooths instantaneous attention spikes from individual query positions, providing a clean base signal for scoring.

2. Head Heterogeneity Table (Offline Compiled)

Using ~50K calibration samples, the team applies Conservative Q-Learning (CQL) regularized offline reward regression to compile a continuous reliability weight table W_head for every layer and attention head. For GQA architectures, weights are indexed at the finer Query Head granularity, with weighted max-pooling within layers. This ensures that if any query head in a GQA group deems a token critical for long-range retrieval, it can override other local heads' averaging tendency — a "one-vote veto" mechanism preserving key memories.

3. Risk-Adaptive Threshold LUT

Different prompts have vastly different compression tolerance: loose chat text tolerates 90% cache removal while dense multi-hop reasoning collapses if wrong tokens are dropped. CompilerKV compiles a risk threshold table indexed by layer, attention entropy, local perplexity, and layer budget. At inference, a single O(1) lookup based on current input's entropy and perplexity dynamically adjusts retention thresholds: raise thresholds for simple low-risk text to aggressively prune redundancy; lower thresholds for high-risk complex text, with CQL's out-of-distribution conservative regularization providing a safety net against tail collapse. The compiled tables are tiny: <100 KB for 32-layer 8B models, <1 MB even for 72B models.

Experimental Evaluation: 1.56% Cache Retention Enables 128K Context and Batch-16 Inference

Validated on LLaMA-3, Qwen2, Mistral, InternLM-2.5, and Qwen3-8B:

LongBench SOTA: At 512-token cache budget, CompilerKV achieves best compression scores across all four base models, averaging +1.67 points over strongest prefill-only baseline (95% CI [+1.08, +2.37]). On Qwen3-8B, 512-token budget scores 49.67, surpassing all compression baselines (48.93) and even slightly exceeding FullKV (49.46).

128K Stress Test: At fixed 1.56% retention (512/32K) extrapolated to 128K RULER benchmark, SnapKV drops to 38 points while CompilerKV maintains ~73 points, approaching FullKV's 79. On 32K Needle-in-a-Haystack (NIAH), retrieval accuracy reaches 0.89 vs. SnapKV's 0.42 — 2.1x improvement.

Memory & Throughput: At 32K input, FullKV OOMs at Batch-16 while CompilerKV supports stable Batch-16 service. In 32K input + 8K output scenario, end-to-end latency drops 2.48x, generation throughput jumps from 11.65 to 28.50 tokens/s (2.45x).

Engineering Deployment: One-Time Compilation Pays Back in Days, Native SGLang Integration

Compilation Cost: On single A100-80GB, full offline compilation takes ~20 GPU-hours for 8B, ~169 GPU-hours for 72B (96%+ is frozen model forward passes for statistics; actual table fitting <3 hours). With 2.45x online decode throughput gain, compilation cost amortizes in days of continuous serving. Tables also transfer across same-scale architectures with only 0.4–0.8 LongBench point drop.

SGLang Native: No decoder kernel changes needed. Only a single KV-slot remapping at prefill-decode boundary: selected 512 physical KV blocks copied to compact space, freeing remaining paged memory, while decoupling logical sequence length (32,768) from physical cache length (512). This preserves correct rotary position encoding and lets attention kernels scan only 512 entries, natively compatible with production inference engines.

CompilerKV demonstrates that many dynamic heuristic decisions in LLM inference are essentially repeated inefficient re-estimation of fixed architectural priors. By offline compiling head reliability and risk sensitivity into sub-100KB static lookup tables, it achieves robust accuracy at extreme compression ratios and high-concurrency throughput, paving a clean, practical engineering path for low-cost deployment of ultra-long-context LLMs.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

Offline CompilationLong-Context LLMKV Cache CompressionNeurIPS 2026Attention Head ReliabilityCQL RegularizationRisk-Adaptive ThresholdingSGLang Integration

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion