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

CacheBlend:基于缓存知识融合的RAG快速大语言模型服务

CacheBlend: Fast Large Language Model Serving for RAG with Cached Knowledge Fusion

University of Chicago(芝加哥大学);CUHK Shenzhen(香港中文大学(深圳));Stanford University(斯坦福大学);Microsoft Research(微软研究院)

Jiayi Yao, Hanchen Li, Yuhan Liu, Siddhant Ray, Yihua Cheng, Qizheng Zhang, Kuntai Du, Shan Lu, Junchen Jiang

AI总结:

本文提出CacheBlend方案,通过选择性地重计算少量token的KV值来融合非前缀文本块的预计算KV cache,在RAG场景下实现与全量预填充相当的生成质量,同时显著降低TTFT并提升推理吞吐量。

摘要:

大语言模型(LLM)通常在其输入中包含多个文本块以提供必要的上下文。为了加速长LLM输入的预填充,可以预计算文本的KV cache,并在上下文作为另一个LLM输入的前缀被重用时复用该KV cache。然而,被重用的文本块并不总是输入前缀,这使得预计算的KV cache无法直接使用,因为它们忽略了文本与前面文本的交叉注意力。因此,复用KV cache的益处在很大程度上仍未实现。本文仅解决一个挑战:当LLM输入包含多个文本块时,如何快速组合它们的预计算KV cache,以实现与昂贵的全量预填充(即不复用KV cache)相同的生成质量?这一挑战自然出现在检索增强生成(RAG)中,其输入通过补充多个检索到的文本作为上下文。我们提出了CacheBlend,这是一种复用预计算KV cache的方案,无论是否为前缀,它都选择性地重新计算一小部分token的KV值,以部分更新每个重用的KV cache。同时,重新计算部分token带来的少量额外延迟可以与同一作业内KV cache的检索进行流水线化,使CacheBlend能够将KV cache存储在具有更大存储容量的较慢设备上,同时在不增加推理延迟的情况下进行检索。通过在不同大小的三个开源LLM和不同任务的四个流行基准数据集上比较CacheBlend与最先进的KV cache复用方案,我们表明CacheBlend将首个token的生成时间(TTFT)减少了2.2-3.3倍,并在不牺牲生成质量的情况下,通过避免全量KV重计算将推理吞吐量提升了2.8-5倍。代码可在 https://github.com/LMCache/LMCache 获取。

英文摘要:

Large language models (LLMs) often incorporate multiple text chunks in their inputs to provide the necessary contexts. To speed up the prefill of the long LLM inputs, one can pre-compute the KV cache of a text and re-use the KV cache when the context is reused as the prefix of another LLM input. However, the reused text chunks are not always the input prefix, which makes precomputed KV caches not directly usable since they ignore the text's cross-attention with the preceding texts. Thus, the benefits of reusing KV caches remain largely unrealized. This paper tackles just one challenge: when an LLM input contains multiple text chunks, how to quickly combine their precomputed KV caches in order to achieve the same generation quality as the expensive full prefill (i.e., without reusing KV cache)? This challenge naturally arises in retrieval-augmented generation (RAG) where the input is supplemented with multiple retrieved texts as the context. We present CacheBlend, a scheme that reuses the precomputed KV caches, regardless prefix or not, and selectively recomputes the KV values of a small subset of tokens to partially update each reused KV cache. In the meantime, the small extra delay for recomputing some tokens can be pipelined with the retrieval of KV caches within the same job, allowing CacheBlend to store KV caches in slower devices with more storage capacity while retrieving them without increasing the inference delay. By comparing CacheBlend with the state-of-the-art KV cache reusing schemes on three open-source LLMs of various sizes and four popular benchmark datasets of different tasks, we show that CacheBlend reduces time-to-first-token (TTFT) by 2.2-3.3x and increases the inference throughput by 2.8-5x from full KV recompute without compromising generation quality. The code is available at https://github.com/LMCache/LMCache.

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

↑