TL;DR
When serving large language models (LLMs), caching the computed state of shared prefixes saves huge amounts of redundant computation—until the cache fills up and forces expensive recomputation. AutoCache uses an AI coding agent to automatically discover, implement, and refine custom cache-compression programs tailored to a specific model and workload. Instead of relying on one-size-fits-all compression, AutoCache composes techniques like low-rank projection, quantization, and entropy coding—achieving up to 291.1× KV-cache compression and 222.6× whole-cache compression on 32K-context benchmarks while preserving ~95% of the model's accuracy.
What Problem Does This Paper Address?
Modern LLM applications—chatbots, coding assistants, and agents—frequently reuse long conversation histories or system prompts. Prefix caching speeds this up by saving the model's intermediate state so subsequent requests can skip the initial "prefill" computation, slashing time-to-first-token (TTFT).
However, cache memory is finite. Once the working set outgrows available GPU and host memory, hit rates plummet and TTFT spikes. Compression can stretch that memory budget, but two major hurdles stand in the way:
- Hybrid architectures: Modern LLMs don't just use standard attention Key-Value (KV) caches. Models like Qwen3.5-9B, Nemotron-3.5-L-30B, Ling-3.0-tiny, and Gemma-4-12B mix full attention with recurrent states (like Mamba2 or Gated DeltaNet) or sliding-window attention (SWA). Existing compressors only target full-attention KV caches, leaving the rest untouched—which quickly becomes the new memory bottleneck.
- Model and workload sensitivity: A compression pipeline that works wonders on one model can flop on another. Designing a bespoke compressor by hand for every model–workload pair simply doesn't scale.
Methods
AutoCache frames cache compression as an agentic program search problem. Rather than tweaking a fixed algorithm, an LLM-powered proposer agent (Claude Code with Claude Opus 5) writes actual compress() and decompress() programs that plug directly into SGLang's cache manager.
The search loop works as follows:
- Isolated Workspace: Each proposer gets access to the target model's weights, captured cached states, and a few unlabeled development examples. It can write and run GPU scripts to inspect tensor statistics (like outliers or low-rank structure) and prototype ideas.
- Quota-Limited Feedback: Proposers get up to three development evaluations per session to test their prototypes through the real serving path and calibrate hyperparameters.
- Annealed $\epsilon$-Greedy Controller: A controller manages the search budget across 20 iterations, balancing exploration (inventing new designs from scratch) and refinement (improving candidates on the current accuracy-vs-compression Pareto frontier).
- Decompression Bandwidth Gate: To ensure compression doesn't become slower than simply recomputing the prefill, the controller enforces a strict restoration speed floor of 10 GB/s.
Datasets
AutoCache is evaluated at a 32K token context length on two complementary long-context benchmarks:
- RULER: A synthetic benchmark testing retrieval and reasoning over information scattered across a long context (e.g., needle-in-a-haystack).
- MRCR: A multi-round co-reference resolution dataset where the model must repeatedly distinguish and recover relevant details from a long conversation.
(Additionally, the authors use TraceLab multi-turn coding-agent traces to illustrate how cache capacity thresholds affect TTFT in practice.) No new benchmarks are introduced.
Key Insights and Ideas
- Co-designing across all state types is essential: Leaving recurrent or sliding-window states uncompressed caps whole-cache compression at just 19.0× on Qwen3.5-9B and 2.4× on Gemma-4-12B, no matter how aggressively you shrink the attention KV cache.
- Recurrent states are surprisingly low-rank: AutoCache discovered that each head's recurrent state in hybrid models can be reconstructed using just a few singular vectors (e.g., 90% of the energy lies in a single direction on Nemotron-3.5-L-30B, and 2–3 directions on Qwen3.5-9B and Ling-3.0-tiny). To the authors' knowledge, this is the first work to exploit this property.
- Data-specific "token protection" (and a benchmark quirk): On RULER, the agent invented a policy that keeps tokens with large low-rank projection errors at higher precision. It turns out these high-error tokens are the "needles" standing out from the repetitive "haystack"—meaning AutoCache automatically learned to spot the needle from cache statistics alone, without even seeing the query.
- Speed gates change the search: Without the 10 GB/s bandwidth gate, the agent gravitates toward ultra-compact representations that are painfully slow to decompress—sometimes slower than re-prefilling from scratch.
Key Results
Subject to retaining ~95% of each model's uncompressed accuracy:
- KV-Cache Compression: On RULER-32K, AutoCache achieves 291.1× compression on Qwen3.5-9B (vs. 16.0× for KVTC, the strongest baseline) and 91.3× on Nemotron-3.5-L-30B (vs. 8.1× for KVTC). On the harder MRCR-32K benchmark, it still leads every model, reaching 47.6× on Qwen3.5-9B and 45.5× on Gemma-4-12B.
- Whole-Cache Compression: Jointly compressing KV, recurrent, and sliding-window states boosts total cache compression from 19.0× to 222.6× on Qwen3.5-9B, 10.2× to 63.2× on Ling-3.0-tiny, and 2.4× to 119.1× on Gemma-4-12B.
Limitations and Future Work
- Synthetic benchmark limitations: AutoCache's ability to locate RULER's needle purely from cache statistics highlights a flaw in synthetic long-context benchmarks—they can be exploited in ways that don't reflect messy, real-world workloads.
- Search cost: Discovering these compressors isn't free; a 10-iteration ablation campaign took roughly 20 hours on 4 H100 GPUs, though this is a one-time offline cost per model and workload.
- Future directions: The authors view AutoCache as a step toward a new paradigm where LLM serving systems automatically tailor cache-compression algorithms to their exact hardware, model architecture, and traffic patterns.
Summary updated