The RoPE Base Frequency
One hyperparameter, written as 10000 in the original RoFormer code and 500000 in Llama 3, sets the entire wavelength spectrum of rotary position embedding and puts a hard ceiling on the context length the model can actually discriminate.
Llama 2 and Llama 3 share an attention implementation almost line for line. One number differs: the RoPE base went from 10,000 to 500,000 (Grattafiori et al., 2024, The Llama 3 Herd of Models, arXiv:2407.21783). That single constant is the difference between a model that loses track of a fact 6,000 tokens back and one that retrieves it at 32,000. It is worth understanding what the number actually controls, because almost every long-context recipe is a manipulation of it.
Base sets a spectrum, not a scale
Rotary position embedding splits each head's dimension into \(d/2\) coordinate pairs and rotates pair \(i\) by an angle proportional to the absolute position \(m\):
Here \(b\) is the base. Because the dot product of two rotated vectors depends only on the angle difference, attention between positions \(m\) and \(n\) sees \((m-n)\theta_i\) — absolute rotation in, relative position out (Su et al., 2021, RoFormer, arXiv:2104.09864).
The useful way to read \(\theta_i\) is as a wavelength, the token distance over which that pair completes one full turn:
With \(b = 10^4\) and a 128-dimensional head, the fastest pair (\(i=0\)) has \(\lambda_0 = 2\pi \approx 6.3\) tokens and the slowest (\(i=63\)) has \(\lambda_{63} \approx 54{,}400\) tokens. Raising the base to 500,000 leaves \(\lambda_0\) untouched at 6.3 tokens and stretches the slow end to roughly 2.56 million. The base does not shift the spectrum, it fans it out from a fixed high-frequency anchor.
The critical dimension
During pretraining at length \(L\), a pair with \(\lambda_i < L\) sweeps through complete periods and sees every angle on the circle. A pair with \(\lambda_i > L\) only ever sees one short arc. At inference beyond \(L\), those slow pairs are asked for angles they have never observed, which is the out-of-distribution failure behind naive length extrapolation. Liu et al. name the boundary between the two regimes the critical dimension and derive the extrapolation limit from it (Liu et al., 2023, Scaling Laws of RoPE-based Extrapolation, arXiv:2310.05209).
Count it for Llama 2: with \(b = 10^4\), \(d = 128\), \(L = 4096\), the pairs satisfying \(2\pi b^{2i/d} \le L\) are those with \(i \le 45\). Forty-six of sixty-four pairs are fully trained; eighteen are not.
The lower bound nobody expected
The obvious inference is that a small base is safer, since it puts every pair inside the training window. Men et al. show the opposite constraint binds harder. Define \(B_{m,\theta} = \sum_i \cos(m\theta_i)\), the model's ability to score a similar token above a random one at distance \(m\). Once \(B_{m,\theta}\) goes negative, random tokens win, and no amount of training repairs it. Solving numerically for the smallest base that keeps \(B_{m,\theta} \ge 0\) across a target length gives an absolute floor (Men et al., 2024, Base of RoPE Bounds Context Length, arXiv:2405.14591):
| Target context | Minimum base |
|---|---|
| 1k | 4.3 × 10³ |
| 4k | 2.7 × 10⁴ |
| 8k | 8.4 × 10⁴ |
| 32k | 6.4 × 10⁵ |
| 128k | 7.8 × 10⁶ |
| 1M | 5.1 × 10⁸ |
Llama 3's 500,000 sits just under the 32k row, and Llama 3's own paper says the value was validated "for context lengths up to 32,768". Two independent methods, one from attention geometry and one from ablation, land on the same number.
When it breaks
Below the bound, the failure is invisible in the metric teams usually watch. Men et al. fine-tuned at 32k with an insufficient base and got healthy perplexity from a model that could not retrieve a planted fact at a distance of 1k. Perplexity is dominated by local tokens, so a model that has lost all long-range discrimination still predicts the next word well. Retrieval evaluation is the only thing that catches it, which is part of why RULER exists (Hsieh et al., 2024, RULER, arXiv:2404.06654).
Above the bound, the cost lands on the fast end. Barbero et al. show that the highest RoPE frequencies are what let a head build a sharp diagonal or previous-token pattern, something provably unavailable without positional information, and they find models prefer the lowest frequencies for carrying semantics rather than for decay (Barbero et al., 2024, Round and Round We Go, arXiv:2410.06205). Stretching the spectrum blunts the local machinery in exchange for range, which is why a base raised without any long-context training usually degrades short-prompt quality first.
There is also a scope trap. The base is a training-time property. Changing it on a released checkpoint rotates every key already in the KV cache differently from the keys the model learned on, which is why the deployment-time methods are interpolation schemes such as Position Interpolation (Chen et al., 2023, arXiv:2306.15595) and YaRN (Peng et al., 2023, arXiv:2309.00071) rather than a bare edit of \(b\), and why any change needs at least a short fine-tune at the target length.
12 flashcards for this concept
Click a card to reveal the answer.