[Paper Review] Scaling Laws of RoPE-based Extrapolation
This paper proposes a unified theoretical framework—Scaling Laws of RoPE-based Extrapolation—that explains how adjusting the rotary base (both smaller and larger than 10,000) and fine-tuning context length enhances extrapolation in RoPE-based LLMs. It demonstrates that fine-tuning with a base of 500 or 1,000,000 on 16K context length enables LLaMA2 7B and 13B models to extrapolate to 1 million tokens, with the base value and tuning length showing a critical periodic relationship that governs performance beyond training length.
The extrapolation capability of Large Language Models (LLMs) based on Rotary Position Embedding is currently a topic of considerable interest. The mainstream approach to addressing extrapolation with LLMs involves modifying RoPE by replacing 10000, the rotary base of $θ_n={10000}^{-2n/d}$ in the original RoPE, with a larger value and providing longer fine-tuning text. In this work, we first observe that fine-tuning a RoPE-based LLM with either a smaller or larger base in pre-training context length could significantly enhance its extrapolation performance. After that, we propose extbf{ extit{Scaling Laws of RoPE-based Extrapolation}}, a unified framework from the periodic perspective, to describe the relationship between the extrapolation performance and base value as well as tuning context length. In this process, we also explain the origin of the RoPE-based extrapolation issue by extbf{ extit{critical dimension for extrapolation}}. Besides these observations and analyses, we achieve extrapolation up to 1 million context length within only 16K training length on LLaMA2 7B and 13B.
Motivation & Objective
- To investigate the counterintuitive phenomenon that both smaller and larger rotary base values improve RoPE-based LLM extrapolation beyond the standard 10,000 base.
- To identify the underlying mechanism of RoPE extrapolation failure and its resolution through periodicity and critical dimension analysis.
- To establish a unified theoretical framework linking rotary base, fine-tuning context length, and extrapolation performance.
- To validate the framework empirically on LLaMA2 7B and 13B, achieving 1M context length extrapolation with only 16K fine-tuning.
Proposed method
- Proposes a periodic perspective to model RoPE's behavior beyond training length, analyzing how angular resolution and periodicity affect attention stability.
- Introduces the concept of 'critical dimension for extrapolation' to explain the performance drop when base and context length are mismatched.
- Derives a mathematical scaling law relating rotary base, fine-tuning context length, and extrapolation limit using trigonometric properties of RoPE.
- Empirically tests base values from 500 to 1,000,000 across 4K and 16K fine-tuning lengths on LLaMA2 models.
- Validates the framework using perplexity evaluation on Books3 dataset and analyzes attention score dynamics.
- Demonstrates that base reduction enhances extrapolation by improving angular resolution, while large bases extend the effective range via phase wrapping.
Experimental results
Research questions
- RQ1Is 10,000 the worst base value for RoPE-based extrapolation in fine-tuning, and why does performance degrade at this value?
- RQ2Is there a mathematical relationship between rotary base, fine-tuning context length, and the upper limit of extrapolation?
- RQ3Can both smaller and larger bases improve extrapolation, and what explains this dual-directional improvement?
- RQ4What is the origin of the RoPE extrapolation problem, and how does it relate to attention score stability and periodicity?
- RQ5Can the proposed scaling laws explain the success of existing methods like Dynamic NTK and Code LLaMA?
Key findings
- Fine-tuning with a smaller base (e.g., 500) or a larger base (e.g., 1,000,000) on the original 4K context length significantly improves extrapolation performance compared to the standard 10,000 base.
- The model achieves 1 million context length extrapolation on LLaMA2 7B and 13B using only 16K fine-tuning context with a base of 1,000,000.
- The performance degradation at base=10,000 is attributed to a critical mismatch in angular resolution and periodicity, making it the worst-performing base in the tested range.
- Base reduction enhances extrapolation by increasing angular resolution, delaying phase wrapping and maintaining attention stability.
- The framework explains the success of Code LLaMA (1M base, 16K fine-tuning) by showing that the combination of large base and long context enables stable phase progression over long sequences.
- The study identifies an upper bound on extrapolation performance for very large bases, confirming theoretical limits of phase-based generalization in RoPE.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.