Overview
AM-OMP: Fast KV Compaction via Attention Matching is a deep-dive analysis of a paper from MIT researchers (Adam Zweiger, Xinghong Fu, Han Guo, Yoon Kim) proposing a training-free, closed-form method for compressing KV caches in long-context LLMs.
- Paper: arXiv:2602.16284
- Code: https://github.com/adamzweiger/compaction
- Problem: KV cache memory grows with context length, reaching multiple GB. Existing approaches (token eviction, token merging, head sparsification) degrade sharply at compression ratios above 10x. Prior learned methods like Cartridges work well but require hours of gradient-based optimization per document.
- Core insight: Instead of optimizing output likelihood end-to-end, AM-OMP reframes KV compaction as linear algebra: directly optimize compact keys and values to reproduce both attention outputs and attention mass, where
Mass(q; K) = Σⱼ exp(q·Kⱼᵀ). An attention mixing identity shows that concatenated attention blocks can be decomposed as a weighted mixture of local outputs, weighted by attention mass. - Scalar bias compensation: Because compressed length t ≪ original length T, subset selection alone cannot match attention mass exactly. AM-OMP introduces a per-token scalar bias β ∈ ℝᵗ (solved via NNLS) that acts as a multiplicative weight so each retained key represents the mass of discarded tokens. Memory overhead is negligible: (2d+1)/(2d), with near-zero impact on compute.
- LongHealth (60k tokens, 10x compression): ~0.70 accuracy vs ~0.80 uncompressed.
- Combined with summarization: up to 200x total compression (6,340 → 31 effective tokens), matching summarization-only accuracy (55.7% vs 55.2%).
- Online compaction (AIME 2025): physical length 2048 / effective length 8192 scored 13/30, on par with standard 8192 decoding.
- AM-Highest: fastest (highest-attention key selection), good quality
- AM-OMP: best quality, moderate speed
- AM-OMP-Batch: batched OMP selection, faster, near-best quality
- Plug-and-play: natively compatible with FlashAttention, FlexAttention (supports scalar bias), and PyTorch SDPA; no model weight changes required.
- Non-uniform per-head budgets: sensitivity curves rank head importance once; a greedy-swap algorithm assigns per-head compression ratios; varlen representations avoid padding overhead.
- Long documents: chunk-wise compression concatenated back together.
- MoE scalability: Qwen3-235B costs only ~30% more to compact than Qwen3-4B.
- Paper: https://arxiv.org/abs/2602.16284
- Code: https://github.com/adamzweiger/compaction
Key Points
The Three-Step Closed-Form Pipeline
1. Key selection — Orthogonal Matching Pursuit (OMP): greedily select keys that maximally reduce residual attention mass, using the feature matrix Φᵢⱼ = exp(qᵢ·Kⱼᵀ). 2. Bias fitting — NNLS: fit scalar biases to match attention mass. 3. Value reconstruction — OLS: solve for compacted values to match attention outputs, avoiding bias from directly reusing original values.
Because the entire pipeline uses closed-form solutions with no gradient descent, compression takes seconds instead of GPU-hours.
Performance
Qwen3-4B, QuALITY dataset, 50x compression:
| Method | Accuracy (50x) | Time (single H100) | |---|---|---| | Uncompressed cache | 0.72 | — | | AM-OMP | 0.67 | ~30 s | | Cartridges | 0.60 | ~5 GPU-hours | | H2O+ | 0.48 | — | | Text summarization | 0.51 | — |
AM-OMP is roughly two orders of magnitude faster than Cartridges while achieving higher accuracy.
Other results:
Method Family and Trade-offs
The paper describes a family of variants along a speed–quality spectrum:
Reference query strategies include context-prefill (cheapest), repeat-prefill, self-study (best), random vectors, and on-policy extraction (best but most expensive).
Engineering Practicality
Applications and Limitations
Use cases: long-running agents (e.g., persistent coding assistants), multi-turn dialogue replacing turn-dropping, long-document QA (legal, scientific), and real-time/streaming compaction during inference.
Limitations: performance depends on the quality of reference queries; per-layer compression may accumulate errors across layers; accuracy can still degrade at extreme (>100x) ratios; compaction still requires non-trivial compute.
Conclusion
AM-OMP demonstrates that KV compaction can shift from hours-long gradient optimization to seconds-long closed-form linear algebra, retaining 50x compression with only ~5 points of accuracy loss on long-document QA, while remaining training-free and drop-in compatible with standard attention kernels.