arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2512.09238cs.CL
收藏

无需训练的上下文自适应注意力:用于高效长上下文建模

Training-free Context-adaptive Attention for Efficient Long Context Modeling

School of Future Technology, South China University of Technology, Guangzhou, China(未来技术学院,华南理工大学,广州,中国);Pengcheng Laboratory, Shenzhen, China(鹏城实验室,深圳,中国);School of Software Engineering, South China University of Technology, Guangzhou, China(软件学院,华南理工大学,广州,中国);Harbin Institute of Technology, Shenzhen, China(哈尔滨工业大学,深圳,中国)

Zeng You, Yaofo Chen, Shuhai Zhang, Zhijie Qiu, Tingyu Wu, Yingjian Li, Yaowei Wang, Mingkui Tan

AI总结:

本文提出无需训练的上下文自适应注意力机制,通过轻量级阶段实现高效长上下文推理,减少内存占用并提升速度。

摘要:

大型语言模型(LLMs)在各种自然语言处理任务中展现出了显著的能力。这些能力主要源于自注意力机制,该机制能够建模长距离依赖。然而,自注意力机制与序列长度的二次复杂性带来了显著的计算和内存挑战,尤其是在序列长度扩展到极端时。尽管已经提出了各种稀疏注意力和KV缓存压缩方法来提高效率,但它们往往存在固有模式依赖、无法处理预填充和解码阶段或需要额外训练的局限性。在本文中,我们提出了无需训练的上下文自适应注意力(TCA-Attention),这是一种无需训练的稀疏注意力机制,能够选择性地关注信息量大的token,以实现高效的长上下文推理。我们的方法包括两个轻量级阶段:i)一个离线校准阶段,通过单次前向传递确定每个head的稀疏性预算;ii)一个在线token选择阶段,利用轻量级冗余度度量适配性地保留核心上下文token。TCA-Attention提供了一个统一的解决方案,加速了预填充和解码,同时减少了KV缓存内存占用,无需参数更新或架构更改。理论分析表明,我们的方法保持了有界的近似误差。广泛的实验表明,TCA-Attention在128K上下文长度下实现了2.8倍的速度提升,将KV缓存减少了61%,同时在各种基准测试中保持了与全注意力相当的性能,提供了一个实用的即插即用解决方案,用于高效的长上下文推理。

英文摘要:

Large Language Models (LLMs) have demonstrated remarkable capabilities across a wide range of natural language processing tasks. These capabilities stem primarily from the self-attention mechanism, which enables modeling of long-range dependencies. However, the quadratic complexity of self-attention with respect to sequence length poses significant computational and memory challenges, especially as sequence length extends to extremes. While various sparse attention and KV cache compression methods have been proposed to improve efficiency, they often suffer from limitations such as reliance on fixed patterns, inability to handle both prefilling and decoding stages, or the requirement for additional training. In this paper, we propose Training-free Context-adaptive Attention (TCA-Attention), a training-free sparse attention mechanism that selectively attends to only the informative tokens for efficient long-context inference. Our method consists of two lightweight phases: i) an offline calibration phase that determines head-specific sparsity budgets via a single forward pass, and ii) an online token selection phase that adaptively retains core context tokens using a lightweight redundancy metric. TCA-Attention provides a unified solution that accelerates both prefilling and decoding while reducing KV cache memory footprint, without requiring parameter updates or architectural changes. Theoretical analysis shows that our approach maintains bounded approximation error. Extensive experiments demonstrate that TCA-Attention achieves a 2.8$\times$ speedup and reduces KV cache by 61% at 128K context length while maintaining performance comparable to full attention across various benchmarks, offering a practical plug-and-play solution for efficient long-context inference.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑