arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2407.15176cs.CLcs.AI
收藏

ReAttention:基于有限注意力范围的免训练无限上下文方法

ReAttention: Training-Free Infinite Context with Finite Attention Scope

School of Computer Science, Fudan University(复旦大学计算机科学学院);Shanghai AI Lab(上海人工智能实验室);Shanghai Innovation Institute(上海创新研究院)

Xiaoran Liu, Ruixiao Li, Qipeng Guo, Zhigeng Liu, Yuerong Song, Kai Lv, Hang Yan, Linlin Li, Qun Liu, Xipeng Qiu

AI总结:

针对大语言模型上下文长度外推瓶颈,提出免训练的ReAttention方法,通过前置位置无关top-k注意力实现有限注意力范围下的无限上下文支持,在多个基准和主流LLM上验证了性能与效率。

摘要:

大语言模型(LLM)的长上下文能力已取得重大突破,但长度外推中支持的最大上下文长度仍是限制其实际应用的关键瓶颈。LLM的上下文长度约束源于自注意力机制,该机制无法通过有限的预训练位置信息和注意力范围,有效且高效地捕获无限长上下文中的语义关系。\n本研究提出ReAttention,这是一种免训练方法,能让基于自注意力机制的LLM在内存资源充足的条件下,以有限的注意力范围支持无限上下文。ReAttention在普通的位置感知自注意力之前,执行与位置无关的top-$k$注意力,使LLM摆脱长度外推问题。\n我们在LongBench、L-Eval和InfiniteBench上验证了ReAttention的性能,证明其效果与传统方法相当。此外,我们还将ReAttention应用于主流LLM,包括LLaMA3.1-8B和Mistral-v0.3-7B,使其能支持至少1M的上下文长度;在Needle-In-A-Haystack(大海捞针)测试中,无需进一步训练就将LLaMA3.2-3B-chat的上下文长度扩展了128$\times$,达到4M。我们还通过Triton提升了ReAttention的效率,实现了无额外开销的高效外推。代码可在https://github.com/OpenMOSS/ReAttention获取。

英文摘要:

The long-context capability of the Large Language Models (LLM) has made significant breakthroughs, but the maximum supported context length in length extrapolation remains a critical bottleneck limiting their practical applications. The constraint of context length in LLMs arises from the self-attention mechanism, which cannot effectively and efficiently capture the semantic relationships within infinitely long contexts via the limited pre-trained positional information and attention scope. In this work, we propose ReAttention, a training-free approach enabling LLM based on the self-attention mechanism to support an infinite context with a finite attention scope under sufficient memory resources. ReAttention performs the position-agnostic top-$k$ attention before the ordinary position-aware self-attention, freeing LLMs from the length extrapolation issue. We validate the performance of ReAttention on the LongBench, L-Eval, and InfiniteBench and demonstrate that it is on par with traditional methods. Furthermore, we also apply ReAttention on mainstream LLMs, including LLaMA3.1-8B and Mistral-v0.3-7B, enabling them to support context lengths of at least 1M and even expanding the context length of LLaMA3.2-3B-chat by 128$\times$ to 4M without any further training in Needle-In-A-Haystack tests. We also improve the efficiency of ReAttention with Triton and achieve an efficient extrapolation without additional overhead. The code is available at https://github.com/OpenMOSS/ReAttention.

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

↑