OBCache: Optimal Brain KV Cache Pruning for Efficient Long-Context LLM Inference

Yuzhe Gu, Xiyu Liang, Jiaojiao Zhao, Enmao Diao
10/9/2025
13 citations
cs.CLcs.AI
transformer-attentionquantization-pruning

Official code: DreamSoul-AI/OBCache (1 star, Python, MIT, last commit 2025-10-10).

Abstract

Large language models (LLMs) with extended context windows enable powerful applications but impose significant memory overhead, as caching all key-value (KV) states scales linearly with sequence length and batch size. Existing cache eviction methods address this by exploiting attention sparsity, yet they typically rank tokens heuristically using accumulated attention weights without considering their true impact on attention outputs.

Show full abstract

We propose Optimal Brain Cache (OBCache), a principled framework that formulates cache eviction as a layer-wise structured pruning problem. Building upon the Optimal Brain Damage (OBD) theory, OBCache quantifies token saliency by measuring the perturbation in attention outputs induced by pruning tokens, with closed-form scores derived for isolated keys, isolated values, and joint key-value pairs. Our scores account not only for attention weights but also for information from value states and attention outputs, thereby enhancing existing eviction strategies with output-aware signals. Experiments on LLaMA and Qwen models demonstrate that replacing the heuristic scores in existing works, which estimate token saliency across different query positions, with OBCache's output-aware scores consistently improves long-context accuracy. Code is available at https://github.com/DreamSoul-AI/OBCache.

View on arXivView PDF

Code Implementations(1)

MIT

OBCache: Optimal Brain KV Cache Pruning for Efficient Long-Context LLM Inference

11Python, ShellAug 17, 20241 years agoMIT
kv-cachelarge-language-modelspruningsparsity

Similar Papers

Cite this paper

@article{gu2025obcache,
  title  = {OBCache: Optimal Brain KV Cache Pruning for Efficient Long-Context LLM Inference},
  author = {Yuzhe Gu and Xiyu Liang and Jiaojiao Zhao and Enmao Diao},
  year   = {2025},
  eprint = {2510.07651},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2510.07651v4}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2510.07651.svg)](https://codeofpaper.com/paper/2510.07651)

Discussion