AttnCache: Accelerating Self-Attention Inference for LLM Prefill via Attention Cache

Dinghong Song, Yuan Feng, Yiwei Wang, Shangye Chen, Cyril Guyot +4 more
10/29/2025
cs.CLcs.LG

No official code found. Best implementation: dinghongsong/AttnCache (0 stars, MIT, last commit 2025-10-29).

Abstract

Large Language Models (LLMs) are widely used in generative applications such as chatting, code generation, and reasoning. However, many realworld workloads such as classification, question answering, recommendation, and text embedding rely solely on the prefill stage of inference, where the model encodes input sequences without performing autoregressive decoding. In these prefill only scenarios, the self-attention computation becomes the primary performance bottleneck due to its quadratic complexity with respect to sequence length. In this paper, we observe that semantically different sentences often produce similar attention maps across layers and heads. Building on this insight, we propose AttnCache, a framework that accelerates the prefill stage of LLM inference by retrieving and reusing similar attention maps. Based on an attention map memorization database, AttnCache employs efficient caching and similarity search techniques to identify and reuse pre-cached attention maps during inference, thereby reducing the computational overhead of self-attention. Experimental results show that AttnCache achieves an average of 1.2x end-to-end and 2x attention speedup on CPU, and 1.6x end-to-end and 3x attention speedup on GPU, with negligible accuracy degradation.

View on arXivView PDF

Code Implementations(1)

MIT

AttnCache: Accelerating Self-Attention Inference for LLM Prefill via Attention Cache

00Shell, PythonMay 20, 202511 months agoMIT

Similar Papers

Cite this paper

@article{song2025attncache,
  title  = {AttnCache: Accelerating Self-Attention Inference for LLM Prefill via Attention Cache},
  author = {Dinghong Song and Yuan Feng and Yiwei Wang and Shangye Chen and Cyril Guyot and Filip Blagojevic and Hyeran Jeon and Pengfei Su and Dong Li},
  year   = {2025},
  eprint = {2510.25979},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2510.25979v3}
}

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.25979.svg)](https://codeofpaper.com/paper/2510.25979)

Discussion