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

KVLink:通过高效KV缓存复用加速大语言模型

KVLink: Accelerating Large Language Models via Efficient KV Cache Reuse

Department of Computer Science UC Santa Barbara(计算机科学系 UC 圣塔芭芭拉大学);Center for Advanced AI Accenture(先进人工智能中心 江苏 Accenture)

Jingbo Yang, Bairu Hou, Wei Wei, Yujia Bao, Shiyu Chang

AI总结:

KVLink通过独立预计算文档KV缓存并在推理时拼接复用,结合位置嵌入调整和可训练特殊token恢复跨文档注意力,在7个数据集上平均提升问答准确率4%,并将首token时间最多减少96%。

摘要:

我们描述了KVLink,一种在大语言模型(LLMs)中高效复用键值(KV)缓存的方法。在许多LLM应用中,不同输入可以共享重叠的上下文,例如同一篇检索到的文档出现在多个查询中。然而,LLMs仍然需要为每个查询编码整个上下文,导致冗余计算。在本文中,我们研究了一种消除此类低效问题的新策略,其中每篇文档的KV缓存被独立预计算。在推理过程中,检索到的文档的KV缓存被拼接起来,使模型能够复用已缓存的表示,而不是重新计算它们。为了缓解使用为每篇文档独立计算的KV缓存时的性能下降,KVLink引入了两项关键技术:在推理时调整KV缓存的位置嵌入,使其匹配拼接后的全局位置;以及使用可训练的特殊token来恢复跨独立编码文档的自注意力。在7个数据集上的实验表明,KVLink将问答准确率平均提高了4%,优于最先进的方法。此外,通过利用预计算的KV缓存,我们的方法将首token时间(time-to-first-token)最多减少了96%,相比标准LLM推理,使其成为一种可扩展且高效的上下文复用解决方案。另外,KVLink可以与KV缓存压缩相结合,进一步节省缓存加载和存储开销,同时优于基线方法。

英文摘要:

We describe KVLink, an approach for efficient key-value (KV) cache reuse in large language models (LLMs). In many LLM applications, different inputs can share overlapping context, such as the same retrieved document appearing in multiple queries. However, the LLMs still need to encode the entire context for each query, leading to redundant computation. In this paper, we investigate a new strategy to eliminate such inefficiency, where the KV cache of each document is precomputed independently. During inference, the KV caches of retrieved documents are concatenated, allowing the model to reuse cached representations instead of recomputing them. To mitigate the performance degradation when using KV caches computed independently for each document, KVLink introduces two key techniques: adjusting positional embeddings of the KV cache at inference to match the global position after concatenation, and using trainable special tokens to restore self-attention across independently encoded documents. Experiments across 7 datasets demonstrate that KVLink improves question answering accuracy by an average of 4% over state-of-the-art methods. Furthermore, by leveraging precomputed KV caches, our approach reduces time-to-first-token by up to 96% compared to standard LLM inference, making it a scalable and efficient solution for context reuse. Additionally, KVLink can be combined with KV cache compression to further save cache loading and storage overhead while outperforming the baselines.

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

↑