arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2510.25979cs.CLcs.LG
收藏

AttnCache:通过注意力缓存加速LLM预填充阶段的自注意力推理

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

Dinghong Song, Yuan Feng, Yiwei Wang, Shangye Chen, Cyril Guyot, Filip Blagojevic, Hyeran Jeon, Pengfei Su, Dong Li

AI总结:

针对仅依赖LLM预填充阶段的工作负载中自注意力计算的性能瓶颈,提出AttnCache框架,通过复用相似注意力图实现CPU端平均1.2倍端到端加速、GPU端1.6倍端到端加速,精度损失可忽略。

摘要:

大型语言模型(LLMs)广泛应用于聊天、代码生成和推理等生成式应用中。然而,分类、问答、推荐和文本嵌入等许多实际工作负载仅依赖推理的预填充阶段,即模型在不进行自回归解码的情况下对输入序列进行编码。在这些仅预填充的场景中,由于自注意力计算的复杂度与序列长度呈二次关系,其成为主要的性能瓶颈。本文观察到,语义不同的句子在不同层和注意力头上往往会产生相似的注意力图。基于这一见解,我们提出AttnCache框架,通过检索和复用相似的注意力图来加速LLM推理的预填充阶段。基于注意力图记忆数据库,AttnCache采用高效的缓存和相似性搜索技术,在推理过程中识别并复用预缓存的注意力图,从而降低自注意力的计算开销。实验结果表明,AttnCache在CPU上实现了平均1.2倍的端到端加速和2倍的注意力加速,在GPU上实现了1.6倍的端到端加速和3倍的注意力加速,且精度下降可忽略不计。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑