AutoCache: 291x Agentic Prefix & Hybrid KV-Cache Compression

AutoCache (arXiv:2612.03651, Cornell & Meta) is an agentic program-search framework that automatically synthesizes prefix-cache compressors and reconstructors tailored to hybrid LLM architectures. On RULER-32K with Qwen3.5-9B (GDN + GQA), AutoCache discovers a 6-stage compressor achieving 291.1x KV-cache compression and 222.6x whole-cache compression—18x denser than the 16x baseline.
AutoCache: 291x Agentic Prefix & Hybrid KV-Cache Compression: AutoCache (arXiv:2612.03651, Cornell & Meta) is an agentic program-search framework that automatically synthesizes prefix-cache compressors and reconstructors tailored to hybrid LLM architectures. On RULER-32K with Qwen3.5-9B (GDN + GQA), AutoCache discovers a 6-stage compressor achieving 291.1x KV-cache compression and 222.6x whole-cache compression—18x denser than the 16x baseline. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- 291.1x KV-Cache Compression: Compresses 1,399.82 GB of Qwen3.5-9B RULER-32K KV state down to 3.846 GB payload (4.81 GB total including metadata and workspace).
- 16x Compression With 99.5% Retention: Joint cross-layer K+V projection with per-layer standardization and key-norm restoration holds 95.5% accuracy vs. 96.0% uncompressed.
- Hybrid Recurrent State Support: Compresses Gated DeltaNet, Mamba2, KDA, and sliding-window states alongside attention KV caches (222.6x whole-cache ratio).
- Automatic Architecture Discovery: Tailors compressors separately for Qwen3.5-9B, Nemotron-3.5-L-30B, Ling-3.0-tiny, and Gemma-4-12B under a strict bandwidth gate.
import { createAgent } from '@smoke-monkey/harness';// Serving-optimization agent synthesizing & verifying AutoCache prefix-compression policiesconst agent = createAgent({agentId: 'autocache-serving-architect',provider: 'openai-compatible',baseUrl: 'http://127.0.0.1:8000/v1',model: 'Qwen/Qwen3.5-9B',workspacePath: process.cwd(),permissions: {read_file: 'allow',write_file: 'allow',run_command: 'ask',},});async function main() {const result = await agent.run('Profile prefix KV + recurrent state bytes per 32K prompt, enforce the decompression bandwidth gate, and emit a compression config.');console.log('AutoCache profile:', result.summary);}main().catch(console.error);
Watch: Related Video Guides
How KV Cache Speeds Up LLMs for Faster AI Models on GPUs
The KV Cache: Memory Usage in Transformers
What Is AutoCache and Why Hybrid Models Need It?
AutoCache is an automated search controller developed by researchers at Cornell University and Meta that writes, benchmarks, and refines Python/CUDA prefix-cache compression programs against a target accuracy floor and decompression bandwidth gate. Modern hybrid LLMs—such as Qwen3.5-9B (GDN + GQA), Nemotron-3.5-L-30B (Mamba2 + GQA), Ling-3.0-tiny (KDA + MLA), and Gemma-4-12B (SWA + global MQA)—store recurrent and convolutional states in addition to attention KV tensors, breaking standard KV-only compressors.
| Compression Method (16x Budget, Qwen3.5-9B RULER-32K) | Accuracy (%) | Retained vs. Uncompressed (96.0%) |
|---|---|---|
| xKV (4 layers, keys and values separate) | 46.7 | 48.7% |
| Joint low-rank (8 layers, keys and values joined) | 86.5 | 90.1% |
| + Per-layer K/V centering and scaling | 92.0 | 95.9% |
| + Key-norm restoration (AutoCache recipe) | 95.5 | 99.5% |
Exact Byte Accounting of the 291.1x Qwen3.5-9B Compressor
AutoCache measures compression ratios strictly against all stored bytes—including per-prefix metadata, shared projection matrices, and decompression workspace—avoiding misleading payload-only math:
| Cache Component (RULER-32K Sum) | Uncompressed (GB) | AutoCache Stored (GB) | Effective Ratio |
|---|---|---|---|
| Full-attention KV tensors | 1,399.82 | 3.846 | 364.0x (payload only) |
| Recurrent GDN state | 70.87 | 0.145 | 488.8x |
| Convolution state (lossless) | 1.66 | 1.661 | 1.0x |
| Metadata + shared tensors + workspace | — | 0.963 | Included in denominator |
| Total Whole Cache | 1,472.35 | 6.616 | 222.6x Whole / 291.1x KV |
- Standardize Before SVD: Centering and scaling each layer's keys and values before joint 8-layer K+V projection prevents large-norm layers from dominating the low-rank basis (+5.4% accuracy).
- Key-Norm Restoration: Rescaling reconstructed key vectors back to original L2 norms preserves softmax attention temperature (+3.5% accuracy).
- Outlier Token Patching: Saving exact high-saliency "needle" tokens alongside low-rank residuals recovers long-context retrieval at extreme compression.
Enforce the Decompression Bandwidth Gate
Overly complex entropy decoders can become CPU- or memory-bandwidth bound during TTFT prefill restoration. AutoCache rejects any candidate program whose decompression time exceeds raw prefix recompute.
Reproducible Prefix Standardization and Joint Projection Script
Prototype AutoCache's core centering, joint K+V low-rank projection, and key-norm restoration transform in PyTorch before registering it in your serving cache:
import torch
def compress_kv_block(k: torch.Tensor, v: torch.Tensor, rank: int = 64):
# k, v shape: [layers, tokens, head_dim]
k_mean, k_std = k.mean(dim=1, keepdim=True), k.std(dim=1, keepdim=True).clamp_min(1e-6)
v_mean, v_std = v.mean(dim=1, keepdim=True), v.std(dim=1, keepdim=True).clamp_min(1e-6)
k_norms = k.norm(dim=-1, keepdim=True)
kn = ((k - k_mean) / k_std).permute(1, 0, 2).reshape(k.shape[1], -1)
vn = ((v - v_mean) / v_std).permute(1, 0, 2).reshape(v.shape[1], -1)
joint = torch.cat([kn, vn], dim=-1) # [tokens, 2 * layers * head_dim]
u, s, vh = torch.linalg.svd(joint, full_matrices=False)
coeffs = u[:, :rank] * s[:rank]
basis = vh[:rank, :]
return coeffs, basis, (k_mean, k_std, v_mean, v_std, k_norms)
k_sample = torch.randn(8, 1024, 128)
v_sample = torch.randn(8, 1024, 128)
coeffs, basis, stats = compress_kv_block(k_sample, v_sample, rank=64)
print("Compressed coeffs shape:", coeffs.shape, "Basis shape:", basis.shape)Frequently Asked Questions
Q:How does AutoCache achieve 291.1x KV compression without destroying RULER accuracy?
AutoCache's search agent combines per-layer K/V standardization, joint cross-layer factorization, key-norm restoration, cross-token residual prediction, entropy coding, and selective patching of high-saliency outlier tokens.
Q:Does AutoCache work on recurrent hybrid architectures like Qwen3.5 and Nemotron 3.5?
Yes. AutoCache compresses both full-attention KV caches and low-rank recurrent states (Gated DeltaNet, Mamba2, KDA), achieving 222.6x whole-cache compression on Qwen3.5-9B while keeping convolution states lossless.
Q:Why is key-norm restoration critical after low-rank KV compression?
Low-rank truncation shrinks vector magnitudes, distorting dot-product attention logits. Restoring per-token key L2 norms lifted Qwen3.5-9B RULER accuracy at 16x compression from 92.0% to 95.5% (99.5% of uncompressed).
Q:Does AutoCache require retraining the base LLM?
No. AutoCache searches over training-free compression and reconstruction programs at the prefix cache layer.
Related Alternatives & Comparisons
Related Architecture Guides
View all guidesBest Open Source Coding Agents in 2026: Free, Local & Fully Hackable Harnesses
MCP Server Security Best Practices: Hardening Model Context Protocol Agents in 2026
Open Source Coding Agent Harness: Build a Forkable, Local AI Engineering Runtime
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.