[论文解读] LongRoPE: Extending LLM Context Window Beyond 2 Million Tokens
LongRoPE 引入一种非均匀、进化引导的 RoPE 重新缩放策略,将 LLM 的上下文窗口扩展到 2048k 令牌,采用高效的两阶段过程与最小微调。它在短上下文性能上保持,并且适用于 RoPE 基模型如 LLaMA2 和 Mistral。
Large context window is a desirable feature in large language models (LLMs). However, due to high fine-tuning costs, scarcity of long texts, and catastrophic values introduced by new token positions, current extended context windows are limited to around 128k tokens. This paper introduces LongRoPE that, for the first time, extends the context window of pre-trained LLMs to an impressive 2048k tokens, with up to only 1k fine-tuning steps at within 256k training lengths, while maintaining performance at the original short context window. This is achieved by three key innovations: (i) we identify and exploit two forms of non-uniformities in positional interpolation through an efficient search, providing a better initialization for fine-tuning and enabling an 8x extension in non-fine-tuning scenarios; (ii) we introduce a progressive extension strategy that first fine-tunes a 256k length LLM and then conducts a second positional interpolation on the fine-tuned extended LLM to achieve a 2048k context window; (iii) we readjust LongRoPE on 8k length to recover the short context window performance. Extensive experiments on LLaMA2 and Mistral across various tasks demonstrate the effectiveness of our method. Models extended via LongRoPE retain the original architecture with minor modifications to the positional embedding, and can reuse most pre-existing optimizations.
研究动机与目标
- 激发对大幅增大 LLM 上下文窗口的需求,并识别扩展到 ~128k 令牌以上的障碍。
- 提出 LongRoPE,一种利用两种形式的非均匀 RoPE 插值以及高效搜索以在无需大量微调的情况下将上下文扩展到 2048k 的方法。
- 在短上下文设定下,展示 LongRoPE 在 LLaMA2 和 Mistral 上在困惑度、passkey 检索和标准基准测试中的有效性。
提出的方法
- 识别 RoPE 在不同维度和 token 位置上的两种非均匀性。
- 开发一个进化搜索,用于优化每个维度的 RoPE 重新缩放因子以及插值的起始 token 阈值。
- 提出一个渐进式扩展策略:先在 RoPE 重新缩放下扩展到 256k/128k 并进行短暂微调,然后在对微调模型进行第二次 RoPE 插值的基础上扩展到 2048k。
- 在短上下文长度下重新调整 RoPE 以恢复短上下文性能。
- 实现从 4k 扩展到 2048k,最少微调(1k 步)与第二阶段的 256k 训练长度。
实验结果
研究问题
- RQ1是否可以通过对每个维度进行非均匀重新缩放来优化 RoPE 插值,超越现有的 PI/NTK/YaRN 策略?
- RQ2是否存在一个无插值的最佳起始 token 数量,以在扩展过程中保留关键早期 token 信息?
- RQ3是否存在一种渐进式、有限微调的工作流,在不产生过高训练成本的情况下实现 2048k 上下文?
- RQ4在超长上下文扩展后,LongRoPE 是否仍能维持短上下文基准的性能?
主要发现
- 非均匀 RoPE 的维度与 token 位置显示出不同的插值需求,对每维度重新缩放因子的优化在 8k–16k 上下文的困惑度上有所提升。
- 具有单调性约束的进化搜索在扩展上下文时给出比 PI、NTK 或 YaRN 更好的 RoPE 重新缩放因子。
- 渐进式扩展方法在不进行直接长文本微调的情况下实现到 2048k 上下文,只在中间尺度需要简短的微调步骤。
- 扩展到 2048k 时初始会降低短上下文性能,但通过重新调整短长度的 RoPE 因子可以缓解。
- LongRoPE-2048k 模型在书籍数据集和长文档评估中的困惑度和 passkey 检索精度具有竞争力,优于若干基线在 256k 上下文内的表现。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。