arXiv:2502.15734cs.DCcs.AI2025-02中稿 · SIGMOD 2025被引 46

通过复用文本块缓存,显著降低RAG生成的冗余计算。

Cache-Craft: Managing Chunk-Caches for Efficient Retrieval-Augmented Generation

  • 设计可复用的分块缓存机制,解决重复文本在不同上下文中无法重用的问题。
  • 相比顶尖方法减少51%冗余计算,吞吐量提升1.6倍,延迟降低50%。
  • 适合高并发RAG系统,尤其对大模型部署有显著性能提升。

检索增强生成(RAG)常用于将领域知识或用户特定信息注入大语言模型(LLM)。在RAG中,给定用户查询,检索器从知识库中提取相关文本块,并将其作为输入提示的一部分发送给LLM。通常,同一文本块会多次出现在不同查询中。然而,当前方法在每次查询时都会重复计算注意力层的键值对(KVs),因为现有技术无法在任意位置和上下文中重用已有的KV缓存。直接重用会导致输出质量下降。这造成了昂贵GPU上的冗余计算和响应延迟增加。本文提出Cache-Craft,一个用于管理并重用对应于文本块的预计算KV缓存(称为分块缓存)的系统。我们展示了如何识别可重用的分块缓存,如何进行少量重新计算以修复缓存并保持输出质量,以及如何高效存储和淘汰分块缓存,以最大化重用率并隐藏开销。在真实生产负载及合成数据集上,Cache-Craft相比最先进前缀缓存技术减少51%的冗余计算,相比完全重新计算减少75%。此外,在真实生产工作负载上采用连续批处理,相较于前缀缓存,吞吐量提升1.6倍,端到端响应延迟减少50%,同时保持输出质量,适用于LLaMA-3-8B和LLaMA-3-70B模型。

原文摘要 · Abstract (English)

Retrieval-Augmented Generation (RAG) is often used with Large Language Models (LLMs) to infuse domain knowledge or user-specific information. In RAG, given a user query, a retriever extracts chunks of relevant text from a knowledge base. These chunks are sent to an LLM as part of the input prompt. Typically, any given chunk is repeatedly retrieved across user questions. However, currently, for every question, attention-layers in LLMs fully compute the key values (KVs) repeatedly for the input chunks, as state-of-the-art methods cannot reuse KV-caches when chunks appear at arbitrary locations with arbitrary contexts. Naive reuse leads to output quality degradation. This leads to potentially redundant computations on expensive GPUs and increases latency. In this work, we propose Cache-Craft, a system for managing and reusing precomputed KVs corresponding to the text chunks (we call chunk-caches) in RAG-based systems. We present how to identify chunk-caches that are reusable, how to efficiently perform a small fraction of recomputation to fix the cache to maintain output quality, and how to efficiently store and evict chunk-caches in the hardware for maximizing reuse while masking any overheads. With real production workloads as well as synthetic datasets, we show that Cache-Craft reduces redundant computation by 51% over SOTA prefix-caching and 75% over full recomputation. Additionally, with continuous batching on a real production workload, we get a 1.6X speed up in throughput and a 2X reduction in end-to-end response latency over prefix-caching while maintaining quality, for both the LLaMA-3-8B and LLaMA-3-70B models.

RAG缓存优化大模型推理效率提升

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。