LongRoPE2: Near-Lossless LLM Context Window Scaling
LongRoPE2通过优化RoPE缩放算法和混合上下文窗口训练,实现了LLM上下文窗口的无损扩展,同时保持了短上下文性能。
更新于 2025-07-09。作者:Ning Shang、Li Lyna Zhang、Siyuan Wang、Gaokai Zhang、Gilsinia Lopez、Fan Yang、Weizhu Chen、Mao Yang。
中文摘要
LongRoPE2是一种新颖的方法,它将预训练的大型语言模型(LLMs)的有效上下文窗口扩展到目标长度,同时保持了在原始较短上下文窗口上的性能。这是通过以下三个贡献实现的:(1)一个假设,即在高RoPE维度上的训练不足是导致现有方法中观察到的持续分布外(OOD)问题的主要原因;(2)一个有效的RoPE缩放算法,该算法采用“针驱动”困惑度引导的进化搜索来解决训练不足的问题;(3)一种混合上下文窗口训练方法,该方法微调模型权重,以采用缩放后的RoPE进行长上下文序列的训练,同时使用原始RoPE保持短上下文性能。在LLaMA3-8B和Phi3-mini-3.8B上进行的广泛实验在各种基准测试中验证了这一假设,并展示了LongRoPE2的有效性。值得注意的是,LongRoPE2将LLaMA3-8B的有效上下文长度扩展到128K,同时保留了超过98.5%的短上下文性能,仅使用了10B个标记——比Meta的方法少80倍,而Meta的方法未能达到目标的有效上下文长度。代码将在https://github.com/microsoft/LongRoPE上提供。
英文摘要
LongRoPE2 is a novel approach that extends the effective context window of pre-trained large language models (LLMs) to the target length, while preserving the performance on the original shorter context window. This is achieved by three contributions: (1) a hypothesis that insufficient training in higher RoPE dimensions contributes to the persistent out-of-distribution (OOD) issues observed in existing methods; (2) an effective RoPE rescaling algorithm that adopts evolutionary search guided by "needle-driven" perplexity to address the insufficient training problem; (3) a mixed context window training approach that fine-tunes model weights to adopt rescaled RoPE for long-context sequences while preserving the short-context performance with the original RoPE. Extensive experiments on LLaMA3-8B and Phi3-mini-3.8B across various benchmarks validate the hypothesis and demonstrate the effectiveness of LongRoPE2. Remarkably, LongRoPE2 extends LLaMA3-8B to achieve a 128K effective context length while retaining over 98.5% of short-context performance, using only 10B tokens -- 80x fewer than Meta's approach, which fails to reach the target effective context length. Code will be available at https://github.com/microsoft/LongRoPE.
解读
一句话总结
LongRoPE2通过优化RoPE缩放算法和混合上下文窗口训练,实现了LLM上下文窗口的无损扩展,同时保持了短上下文性能。
问题1:这篇论文想要解决什么具体问题?
- 问题背景:在扩展预训练LLM的上下文窗口时,RoPE的分布外(OOD)问题导致性能下降,且现有方法往往无法达到目标上下文长度,同时牺牲了短上下文性能。
- 现有方案不足:RoPE缩放方法无法充分解决OOD问题,且现有方法在扩展上下文窗口时通常会牺牲短上下文性能。
- 研究目标:提出LongRoPE2,以实现LLM上下文窗口的无损扩展,同时保持短上下文性能。
问题2:论文的核心创新点是什么?
- 技术创新:提出了一种基于进化搜索的RoPE缩放算法,通过“needle-driven”困惑度评估来识别关键RoPE维度和最优缩放因子。
- 方法改进:引入了混合上下文窗口训练方法,同时训练预训练上下文窗口和长上下文窗口,以保持短上下文性能。
- 优势:与现有方法相比,LongRoPE2在保持短上下文性能的同时,实现了更长的上下文窗口。
问题3:实验结果如何验证了方法的有效性?
- 关键实验:在LLaMA3-8B和Phi3-mini-3.8B上进行了广泛的实验,包括RULER、Needle in a Haystack、LOFT、InfiniteBench和LongBench等基准测试。
- 性能提升:LongRoPE2将LLaMA3-8B扩展到128K有效上下文长度,同时保持了超过98.5%的短上下文性能,而Meta的方法未能达到目标有效上下文长度。
- 对比结果:LongRoPE2在所有基准测试中都优于基线方法,同时在保持短上下文性能方面也表现出色。
问题4:这个研究的实际应用价值是什么?
- 应用场景:文档摘要、科学研究和需要长上下文理解的任何任务。
- 实施建议:使用LongRoPE2进行LLM上下文窗口的无损扩展,以提高模型在长上下文任务上的性能。
- 局限与展望:LongRoPE2可以进一步扩展到无损耗和无限上下文窗口扩展,以处理更长的上下文。
来源
机器可读索引:llms.txt