arXiv:2502.11101cs.CLcs.AI2025-02被引 2

通过动态重定位缓存,提升长文本生成效率与精度。

CacheFocus: Dynamic Cache Re-Positioning for Efficient Retrieval-Augmented Generation

  • 利用离线缓存和自适应位置分配,优化上下文缓存使用。
  • 在超长输入下仍保持高性能,4K以上长度表现优于基线。
  • 无需额外训练,适合长文本生成、问答系统等场景。

大语言模型在多种语言任务中表现优异,但受限于输入长度有限和计算成本高。现有方法如相对位置编码(如RoPE、ALiBi)和滑动窗口机制虽部分缓解问题,但仍需额外训练或在长输入时性能下降。本文提出CacheFocus,一种无需额外训练的动态缓存重定位方法,通过查询无关的离线缓存实现上下文键值缓存的高效复用。针对异常词频分布放大的问题,引入层自适应缓存剪枝策略,在预填充阶段剔除低相关性缓存,并采用自适应位置分配策略动态调整缓存位置,以最大化位置编码范围利用率。在Natural Questions和TriviaQA数据集上的实验表明,即使输入超过LLaMA-2模型4K的限制,CacheFocus仍优于其他方法,展现出对长上下文大模型的实际有效性。此外,在最大输入长度达Qwen2水平时,其性能随文档数增加保持稳定,有效支撑长文本生成且无性能退化。

原文摘要 · Abstract (English)

Large Language Models (LLMs) excel across a variety of language tasks yet are constrained by limited input lengths and high computational costs. Existing approaches\textemdash such as relative positional encodings (e.g., RoPE, ALiBi) and sliding window mechanisms\textemdash partially alleviate these issues but often require additional training or suffer from performance degradation with longer inputs. In this paper, we introduce \textbf{\textit{CacheFocus}}, a method that enhances length normalization and reduces inference latency without any further training. Our approach leverages query-independent, offline caching to efficiently reuse a Context KV Cache Store. We address the amplification of abnormal token distributions problem by re-positioning cached keys and introducing Layer-Adaptive Cache Pruning to discard low-relevance caches during pre-filling. Additionally, our Adaptive Positional Allocation Strategy dynamically reassigns cache positions to maximize the use of the available positional encoding range. Experiments on the Natural Questions and TriviaQA datasets demonstrate that CacheFocus outperforms alternative methods even when inputs exceed the $4$K limit of the \texttt{LLaMA-2} model, emphasizing its practical effectiveness for long-context LLMs. Moreover, even with large maximum input length of \texttt{Qwen2}, the performance of CacheFocus shows that it maintains consistent performance even as the number of documents increases, effectively managing long-text generation without degradation.

长文本生成缓存优化推理加速LLM

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