利用早期层筛选关键信息,实现千倍输入压缩与加速推理
Discovering the Gems in Early Layers: Accelerating Long-Context LLMs with 1000x Input Token Reduction

- 用模型早期层作为过滤器,自动挑选关键输入片段
- 在长文本任务中提速2.4倍,显存降低30%
- 无需训练、通用性强,还能让人看清选了哪些内容
大型语言模型虽能处理长上下文,但计算开销大。本研究发现,模型在生成答案前的早期层已能识别相关输入片段。基于此,提出GemFilter算法,利用早期层作为过滤器,对输入进行筛选与压缩,显著缩短后续处理的上下文长度。相比标准注意力和SnapKV/H2O等先进方法,GemFilter实现2.4×加速和30%显存减少。在Needle in a Haystack任务中表现优于标准注意力与SnapKV,LongBench任务上达到相近水平。该方法无需训练、适用广泛,并可解释性地展示被选中的输入序列。研究成果不仅提升模型部署效率,也深化了对模型内部机制的理解,为未来优化提供新思路。代码已开源。
原文摘要 · Abstract (English)
Large Language Models (LLMs) have demonstrated remarkable capabilities in handling long context inputs, but this comes at the cost of increased computational resources and latency. Our research introduces a novel approach for the long context bottleneck to accelerate LLM inference and reduce GPU memory consumption. Our research demonstrates that LLMs can identify relevant tokens in the early layers before generating answers to a query. Leveraging this insight, we propose an algorithm that uses early layers of an LLM as filters to select and compress input tokens, significantly reducing the context length for subsequent processing. Our method, GemFilter, demonstrates substantial improvements in both speed and memory efficiency compared to existing techniques, such as standard attention and SnapKV/H2O. Notably, it achieves a 2.4$\times$ speedup and 30\% reduction in GPU memory usage compared to SOTA methods. Evaluation on the Needle in a Haystack task shows that GemFilter significantly outperforms standard attention, SnapKV and demonstrates comparable performance on the LongBench challenge. GemFilter is simple, training-free, and broadly applicable across different LLMs. Crucially, it provides interpretability by allowing humans to inspect the selected input sequence. These findings not only offer practical benefits for LLM deployment, but also enhance our understanding of LLM internal mechanisms, paving the way for further optimizations in LLM design and inference. Our code is available at \url{https://github.com/SalesforceAIResearch/GemFilter}.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。