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

一种简单有效的基于$L_2$范数的KV缓存压缩策略

A Simple and Effective $L_2$ Norm-Based Strategy for KV Cache Compression

Sapienza University of Rome(罗马第一大学);The University of Edinburgh(爱丁堡大学)

Alessio Devoto, Yu Zhao, Simone Scardapane, Pasquale Minervini

AI总结:

针对大语言模型KV缓存内存占用高的问题,提出基于键嵌入$L_2$范数的压缩策略,在多任务下实现高压缩比且无精度损失,兼容FlashAttention。

摘要:

大语言模型(LLM)的部署往往受限于键值(KV)缓存的巨大内存需求,尤其是在上下文长度增加时。现有减小KV缓存规模的方法要么通过微调模型来学习压缩策略,要么利用注意力分数缩短序列长度。我们分析了仅解码器Transformer架构模型的注意力分布,发现注意力分配模式在大多数层间保持一致。令人意外的是,我们发现缓存KV对的$L_2$范数与注意力分数之间存在明显关联:键嵌入的$L_2$范数较低时,解码阶段通常会产生较高的注意力分数。这一发现表明,KV对的影响力可能在被查询前就由键嵌入本身决定。基于该观察,我们根据键嵌入的$L_2$范数对KV缓存进行压缩。实验结果显示,这种简单策略在语言建模任务和大海捞针(needle-in-a-haystack)任务上可将KV缓存规模减小50%,在密钥检索(passkey retrieval)任务上可减小90%,且不会损失精度。此外,该方法不依赖注意力分数,仍与FlashAttention兼容,具备更广泛的适用性。

英文摘要:

The deployment of large language models (LLMs) is often hindered by the extensive memory requirements of the Key-Value (KV) cache, especially as context lengths increase. Existing approaches to reduce the KV cache size involve either fine-tuning the model to learn a compression strategy or leveraging attention scores to reduce the sequence length. We analyse the attention distributions in decoder-only Transformers-based models and observe that attention allocation patterns stay consistent across most layers. Surprisingly, we find a clear correlation between the $L_2$ and the attention scores over cached KV pairs, where a low $L_2$ of a key embedding usually leads to a high attention score during decoding. This finding indicates that the influence of a KV pair is potentially determined by the key embedding itself before being queried. Based on this observation, we compress the KV cache based on the $L_2$ of key embeddings. Our experimental results show that this simple strategy can reduce the KV cache size by 50% on language modelling and needle-in-a-haystack tasks and 90% on passkey retrieval tasks without losing accuracy. Moreover, without relying on the attention scores, this approach remains compatible with FlashAttention, enabling broader applicability.

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

↑