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

周期性RoPE:面向无限上下文的大型语言模型

Periodic and Harmonic Periodic RoPE for Length Extrapolation in LLMs

Shanghai Jiao Tong University(上海交通大学)

Simin Huo, Ning Li

AI总结:

提出周期性RoPE(P-RoPE)位置编码机制,结合滑动窗口注意力和无位置编码的全局注意力,避免位置耗尽,理论上支持无限上下文窗口。

摘要:

处理超长上下文的能力对于大型语言模型(LLMs)执行长期任务至关重要。尽管最近的努力已将上下文窗口扩展到1M及以上,但当序列长度超过位置编码(如RoPE)的预训练范围时,模型性能会下降,即位置耗尽。必须克服这一基本限制才能实现真正的无限上下文。为此,我们提出了周期性RoPE(P-RoPE),一种旨在避免这种耗尽的位置编码机制。它与滑动窗口注意力(SWA)协同工作,以捕获每个窗口内的局部依赖和相对位置。然后,这一局部层由无位置编码(NoPE)的全局注意力层补充,使得整个序列上的无界交互成为可能,而不受位置限制。通过堆叠这两类层,模型避免了位置外推以泛化更长的序列,并理论上支持无限的上下文窗口。实验结果表明,我们的模型MiniWin在长上下文效率和稳定性上优于采用标准GPT架构的MiniMInd。我们的工作为LLMs实现真正的无限上下文理解提供了一条可能的路径。代码可在\href{https://github.com/Cominder/miniwin}{https://github.com/Cominder/miniwin}获取。

英文摘要:

The ability to process long contexts is crucial for large language models (LLMs) to perform long-horizon tasks. Rotary position embedding (RoPE) gives every token a new rotation angle, so a model eventually meets angles it never saw in training, i.e., position exhaustion. We propose Periodic RoPE (P-RoPE), a positional encoding mechanism that operates in conjunction with sliding window attention. It repeats the first sliding-window-size \(W\) angles of the RoPE table, so the model needs only \(W\) distinct angles. P-RoPE works but introduces a wrap error at the window boundary. We further propose Harmonic Periodic RoPE (HP-RoPE), which removes the error by choosing frequencies that complete whole turns in \(W\) tokens. We compare models that share the same architecture, data, and schedule and differ only in the window-layer position encoding: standard RoPE, P-RoPE, and HP-RoPE. The results show that P-RoPE and HP-RoPE keep perplexity nearly flat from the training length \(768\) to \(16\)k, while RoPE, NTK, and YaRN rise. In a format-free Passkey test at \(16\)k, they remain at \(99\)--\(100\%\), against \(11\)--\(37\%\) for those RoPE interpolations. The code is available at \href{https://github.com/Cominder/miniwin}{https://github.com/Cominder/miniwin}.

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

↑