arXiv:2506.15704cs.LGcs.AI2025-06

利用历史注意力模式预测关键索引,显著加速长文本生成。

Learn from the Past: Fast Sparse Indexing for Large Language Model Decoding

  • 基于历史注意力趋势动态生成候选索引,减少重复计算。
  • 在RTX 4090上比全量注意力快22.8倍,单核CPU快9.6倍。
  • 适合长上下文生成任务,尤其对资源受限场景友好。

随着大语言模型支持更长的上下文,解码过程中的键值(KV)缓存内存需求急剧增长,成为显存容量和PCIe带宽的关键瓶颈。稀疏注意力通过仅对选定的键值对计算注意力权重缓解此问题,但其索引计算通常需遍历所有键向量,带来显著的计算与数据传输开销。现有方法常将每步解码视为独立过程,未能利用历史解码信息中的时间相关性。为此,我们提出LFPS(Learn From the Past for Sparse Indexing),一种基于历史注意力模式动态构建稀疏索引候选的方法。LFPS捕捉解码器注意力中两种常见模式——垂直模式(固定位置关注)和斜线模式(相对位置关注),并引入位置扩展策略,有效预测当前步骤的Top-k索引。我们在LongBench-RULER等长上下文基准上以Llama-3.1-8B-Instruct为基线模型验证了该方法。实验结果表明,LFPS在RTX 4090 GPU上相较全量注意力实现最高22.8倍加速,在单个Xeon Gold 6430 CPU核心上相较精确的Top-k检索实现9.6倍加速,同时保持生成准确性。这些结果证明,LFPS为长上下文大模型推理中的解码优化提供了实用高效的解决方案。

原文摘要 · Abstract (English)

As large language models (LLMs) continue to support increasingly longer contexts, the memory demand for key-value (KV) caches during decoding grows rapidly, becoming a critical bottleneck in both GPU memory capacity and PCIe bandwidth. Sparse attention mechanisms alleviate this issue by computing attention weights only for selected key-value pairs. However, their indexing computation typically requires traversing all key vectors, resulting in significant computational and data transfer overhead. To reduce the cost of index retrieval, existing methods often treat each decoding step as an independent process, failing to exploit the temporal correlations embedded in historical decoding information. To this end, we propose LFPS(Learn From the Past for Sparse Indexing), an acceleration method that dynamically constructs sparse indexing candidates based on historical attention patterns. LFPS captures two prevalent trends in decoder attention -vertical patterns (attending to fixed positions) and slash patterns (attending to relative positions) -and incorporates a positional expansion strategy to effectively predict the Top-k indices for the current step. We validate LFPS on challenging long-context benchmarks such as LongBench-RULER, using Llama-3.1-8B-Instruct as the base model. Experimental results show that LFPS achieves up to 22.8$\times$ speedup over full attention and 9.6$\times$ speedup over exact Top-k retrieval on an RTX 4090 GPU and a single CPU core of a Xeon Gold 6430, respectively, while preserving generation accuracy. These results demonstrate that LFPS offers a practical and efficient solution for decoding optimization in long-context LLM inference.

长文本生成稀疏注意力推理加速缓存优化

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