MIT AM-OMP: Fast KV Compaction via Attention Matching — Deep Dive
Paper: Fast KV Compaction via Attention Matching Authors: Adam Zweiger, Xinghong Fu, Han Guo, Yoon Kim (MIT) arXiv: https://arxiv.org/abs/2602.16284 Code: https://github.com/adamzweiger/compaction
Key points
- AM-OMP reframes KV cache compression as a closed-form linear algebra problem rather than gradient-based optimization, cutting compaction time from GPU-hours (~5h for Cartridges) to ~30 seconds per document on a single H100.
- Core insight: an attention mixture identity — concatenated attention output decomposes into a weighted mix of local attention outputs, with weights given by Attention Mass:
Mass(q; K) = Σⱼ exp(q·Kⱼᵀ). - A per-token scalar bias β ∈ ℝᵗ (fitted via NNLS) lets retained keys represent the mass of discarded tokens, adding memory overhead of only (2d+1)/(2d).
- Three-step pipeline: OMP key selection → NNLS bias fitting → OLS value reconstruction. No gradient descent anywhere.
- Results (Qwen3-4B, QuALITY, 50x compression): AM-OMP 0.67 accuracy vs. 0.72 full cache, beating Cartridges (0.60), H2O+ (0.48), and text summarization (0.51).
- Composable with summarization for 200x total compression; supports online compaction (AIME 2025: 13/30 at effective length 8192 with physical length 2048).
- Plug-and-play: works with FlashAttention (via flat varlen KV segments), FlexAttention, PyTorch SDPA; no model weight changes.
- Non-uniform per-head budgets: sensitivity-curve calibration done once; greedy swap assigns per-head compression ratios.
- Long documents: chunked compression; MoE models cheap (Qwen3-235B costs only ~30% more than 4B).
- Adaptive compression ratios, cross-layer joint optimization, better reference query generation
- Hardware-aware and incremental/distributed compression
- Multimodal extension, retrieval synergy, task-adaptive head budgets
Technical Principles
Problem
KV caches for long contexts grow to gigabytes. Existing approaches (token eviction, merging, head sparsification) degrade sharply at compression ratios above 10x.Attention Matching
Rather than optimizing output likelihood end-to-end (e.g., Cartridges), AM-OMP directly optimizes compact Keys and Values to reproduce: 1. Local attention outputs 2. Attention Mass (via scalar bias)OMP Key Selection
Build a mass feature matrix Φ ∈ ℝⁿˣᵀ with Φᵢⱼ = exp(qᵢ·Kⱼᵀ) and target vector mᵢ = Σⱼ Φᵢⱼ. Greedily select keys maximizing residual reduction, refit weights via NNLS each iteration, then set β = log(w).Three-Step Closed-Form Solve
| Step | Algorithm | Objective | |------|-----------|-----------| | Key selection | OMP | Greedy residual reduction | | Bias fitting | NNLS | Match Attention Mass | | Value reconstruction | OLS | Match attention outputs |
Comparison with Existing Methods
| Feature | AM-OMP | Cartridges | SnapKV | H2O | |---------|--------|------------|--------|-----| | Training | None | Pretrained dictionary | None | None | | Compression | 50x (98%) | 50x (98%) | High | Medium | | Time | ~30 s | ~5 GPU-hours | Fast | Fast | | Head budget | Non-uniform | Uniform | Head-level | Uniform |
Method Family & Reference Queries
Variants trade speed for quality: AM-Highest (fastest), AM-OMP (best), AM-OMP-Batch (compromise). Reference query strategies range from context-prefill (cheapest) to repeat-prefill, self-study (synthetic interactions), random vectors, and on-policy sampling (best quality, highest cost).
Engineering & Practicality
Applications & Limitations
Use cases: long-running agents, multi-turn dialogue (replacing turn-dropping), long-document QA, real-time/streaming compression.
Limitations: depends on reference query quality; per-layer errors may accumulate; performance can drop at >100x compression; still requires extra compute.
Future Directions
Conclusion
AM-OMP turns KV compaction from an hours-long optimization into seconds of linear algebra: 50x compression with only ~5 points of accuracy loss, no training, and drop-in compatibility with standard attention kernels. Fully open-sourced.