arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2504.15364cs.AI
收藏

KeyDiff: 基于键相似性的KV缓存淘汰方法用于资源受限环境中的长上下文LLM推理

KeyDiff: Key Similarity-Based KV Cache Eviction for Long-Context LLM Inference in Resource-Constrained Environments

Qualcomm AI Research(高通人工智能研究)

Junyoung Park, Dalton Jones, Matthew J Morse, Raghavv Goel, Mingu Lee, Chris Lott

AI总结:

KeyDiff是一种基于键相似性的KV缓存淘汰方法,能够在资源受限环境下高效处理长上下文LLM推理,减少缓存占用并提升响应效率。

摘要:

我们证明在LLM推理过程中,几何上具有显著差异的键倾向于具有较高的注意力分数。基于这一现象,我们提出KeyDiff,一种无需训练的KV缓存淘汰方法,仅基于键相似性。与其他KV缓存淘汰方法不同,KeyDiff能够在严格资源限制下处理任意长的提示,并高效生成响应。我们通过将键多样性与注意力分数联系起来,为KeyDiff提供了理论基础。这些结果表明,KeyDiff能够有效识别最需要保留的令牌。值得注意的是,KeyDiff不依赖于注意力分数,允许使用优化的注意力机制,如FlashAttention。在严格的内存限制下,我们通过在LongBench上对Llama和Qwen模型家族进行测试,展示了KeyDiff的有效性,在8K缓存预算下(约23%的KV缓存减少)与非淘汰基线相比,性能差距小于0.04%。我们还观察到在Math500推理基准上接近基线的性能,并且与其它令牌淘汰方法相比,端到端推理延迟可降低高达30%。

英文摘要:

We demonstrate that geometrically distinctive keys during LLM inference tend to have high attention scores. Based on the phenomenon we propose KeyDiff, a training-free KV cache eviction method based solely on key similarity. Unlike other KV cache eviction methods, KeyDiff can process arbitrarily long prompts within strict resource constraints and efficiently generate responses. We provide a theoretical basis for KeyDiff by relating key diversity with attention scores. These results imply KeyDiff can efficiently identify the most important tokens to retain. Notably KeyDiff does not rely on attention scores, allowing the use of optimized attention mechanisms like FlashAttention. Under a strict memory allowance, we demonstrate the effectiveness of KeyDiff for the Llama and Qwen model families by observing a performance gap of less than 0.04% with 8K cache budget ($\sim$23% KV cache reduction) from the non-evicting baseline on LongBench for Llama 3.1-8B and Llama 3.2-3B. We also observe near baseline performance for Deepseek-R1-Distill-Llama-8B on the Math500 reasoning benchmark and decrease end-to-end inference latency by up to 30% compared to the other token-eviction methods.

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

↑