针对RAG生成中冗余计算问题,提出高效解码框架REFRAG,显著提升速度且不损失精度。
REFRAG: Rethinking RAG based Decoding
- 利用RAG上下文稀疏性,压缩-感知-扩展三步优化解码流程。
- 首词延迟加速30.85倍,相较之前工作提升3.75倍,上下文长度扩展16倍。
- 适用于长文本问答、多轮对话等场景,适合追求高效RAG部署的开发者。
大型语言模型在多轮及代理应用中通过检索增强生成(RAG)利用外部知识展现卓越能力,但长上下文处理带来显著系统延迟并占用大量键值缓存内存,导致吞吐量下降,知识丰富性与系统效率之间存在根本权衡。我们认为RAG需特殊考量:其上下文由检索到的片段拼接而成,仅小部分与查询相关,且重排序后片段间语义相似度低,形成块对角注意力模式,不同于标准LLM生成任务。基于此,我们指出解码时大部分计算为冗余,可消除而几乎不影响性能。为此提出REFRAG框架,通过压缩、感知、扩展实现高效解码。实验证明,该方法在不降低困惑度前提下,使首词延迟加速30.85倍(相较此前工作提升3.75倍),并使模型上下文长度扩展16倍。我们在多样化长上下文任务(包括RAG、多轮对话、长文档摘要)和多个数据集上进行了严格验证,结果表明,相较于LLaMA系列模型及其他先进基线,REFRAG在不同上下文长度下均实现显著提速且无准确率损失。
原文摘要 · Abstract (English)
Large Language Models (LLMs) have demonstrated remarkable capabilities in leveraging extensive external knowledge to enhance responses in multi-turn and agentic applications, such as retrieval-augmented generation (RAG). However, processing long-context inputs introduces significant system latency and demands substantial memory for the key-value cache, resulting in reduced throughput and a fundamental trade-off between knowledge enrichment and system efficiency. While minimizing latency for long-context inputs is a primary objective for LLMs, we contend that RAG require specialized consideration. In RAG, much of the LLM context consists of concatenated passages from retrieval, with only a small subset directly relevant to the query. These passages often exhibit low semantic similarity due to diversity or deduplication during re-ranking, leading to block-diagonal attention patterns that differ from those in standard LLM generation tasks. Based on this observation, we argue that most computations over the RAG context during decoding are unnecessary and can be eliminated with minimal impact on performance. To this end, we propose REFRAG, an efficient decoding framework that compresses, senses, and expands to improve latency in RAG applications. By exploiting the sparsity structure, we demonstrate a 30.85 the time-to-first-token acceleration (3.75 improvement to previous work) without loss in perplexity. In addition, our optimization framework for large context enables REFRAG to extend the context size of LLMs by 16. We provide rigorous validation of REFRAG across diverse long-context tasks, including RAG, multi-turn conversations, and long document summarization, spanning a wide range of datasets. Experimental results confirm that REFRAG delivers substantial speedup with no loss in accuracy compared to LLaMA models and other state-of-the-art baselines across various context sizes.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。