Skip to main content
QUICK REVIEW

[论文解读] Accelerating Inference of Retrieval-Augmented Generation via Sparse Context Selection

Yun Zhu, Jia-Chen Gu|arXiv (Cornell University)|May 25, 2024
Domain Adaptation and Few-Shot LearningComputer Science被引用 3
一句话总结

本文提出稀疏RAG(Sparse RAG),一种通过在解码过程中仅关注最相关的检索文档来加速检索增强生成(RAG)的方法。通过使用大语言模型(LLM)利用控制标记评估文档相关性,并仅加载高质量的键值缓存,稀疏RAG在不牺牲性能的前提下降低了延迟并提升了生成质量,在短文本与长文本任务中均实现了最先进水平的效率与效果。

ABSTRACT

Large language models (LLMs) augmented with retrieval exhibit robust performance and extensive versatility by incorporating external contexts. However, the input length grows linearly in the number of retrieved documents, causing a dramatic increase in latency. In this paper, we propose a novel paradigm named Sparse RAG, which seeks to cut computation costs through sparsity. Specifically, Sparse RAG encodes retrieved documents in parallel, which eliminates latency introduced by long-range attention of retrieved documents. Then, LLMs selectively decode the output by only attending to highly relevant caches auto-regressively, which are chosen via prompting LLMs with special control tokens. It is notable that Sparse RAG combines the assessment of each individual document and the generation of the response into a single process. The designed sparse mechanism in a RAG system can facilitate the reduction of the number of documents loaded during decoding for accelerating the inference of the RAG system. Additionally, filtering out undesirable contexts enhances the model's focus on relevant context, inherently improving its generation quality. Evaluation results of two datasets show that Sparse RAG can strike an optimal balance between generation quality and computational efficiency, demonstrating its generalizability across both short- and long-form generation tasks.

研究动机与目标

  • 解决因多个检索文档导致的长输入序列所引发的检索增强生成(RAG)高推理延迟问题。
  • 在短文本与长文本生成任务中,提升计算效率而不降低生成质量。
  • 通过将上下文评估与生成整合到单一统一流程中,消除对外部分类器或独立检索排序模型的需求。
  • 通过减少解码过程中的键值缓存加载,实现在资源受限设备上的高效、低延迟推理。

提出的方法

  • 稀疏RAG采用两阶段流程:大规模预填充阶段,所有检索文档并行编码以生成完整的键值缓存;选择性解码阶段,仅关注相关文档。
  • 通过特殊控制标记引导大语言模型(LLM)评估每篇检索文档的相关性,并决定是否在解码阶段包含该文档。
  • 模型在解码过程中动态丢弃低质量或无关文档,减少键值缓存加载次数,降低内存与计算开销。
  • 将文档相关性评估与响应生成整合到单一自回归过程中,避免使用独立的排序模型。
  • 原生支持仅解码器架构的大语言模型(LLM),无需修改模型架构即可兼容现代大语言模型。
  • 该方法对基础模型尺寸具有高度兼容性,支持从小型模型(如Gemini XS)到大型模型(如Gemini XXS)的广泛应用。
Figure 1 : An overview of Sparse RAG at inference. Each of the retrieved documents will be assessed by LLMs to decide whether to keep or drop by estimating a relevance score. Then, load the documents that are considered to keep for generation.
Figure 1 : An overview of Sparse RAG at inference. Each of the retrieved documents will be assessed by LLMs to decide whether to keep or drop by estimating a relevance score. Then, load the documents that are considered to keep for generation.

实验结果

研究问题

  • RQ1在RAG中采用稀疏注意力机制是否能在保持或提升生成质量的同时降低解码延迟?
  • RQ2将相关性评估与生成整合到单一流程中,对推理效率与输出质量有何影响?
  • RQ3稀疏RAG在不同模型尺寸下,能在多大程度上减少键值缓存加载而不降低性能?
  • RQ4当提供完美文档级别相关性标签时,稀疏RAG的性能上限是多少?
  • RQ5在多样化生成任务中,稀疏RAG与密集RAG(dense-RAG)及PCW-RAG相比,在延迟与生成质量方面表现如何?

主要发现

  • 在生成不同长度响应时,稀疏RAG相比基线密集RAG实现了52%至超过55%的端到端延迟降低。
  • 在PopQA数据集上,稀疏RAG在Gemini XS模型上仅使用6.27次键值缓存加载,即实现了68.26的EM与72.26的F1,优于RAG与PCW-RAG在质量和效率上的表现。
  • 在Biography数据集上,稀疏RAG在Gemini XXS模型上实现了67.17的EM与71.16的F1,表明其在不同模型尺寸下均保持一致的性能提升。
  • 当提供黄金标准的上下文级别标签时,稀疏RAG的F1提升至26.76,DS为21.16,表明在理想评估条件下具备巨大潜力。
  • 该方法显著降低了计算开销,每秒处理令牌数(t/s)相比密集RAG大幅提升,尤其在大上下文窗口下优势明显。
  • 稀疏RAG在短文本与长文本生成任务中均保持高性能,证明了其良好的泛化能力。
(a) Decoding speed with different number of memories
(a) Decoding speed with different number of memories

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。