Length Extrapolation
PremiumNTK-aware Scaling, YaRN, and other methods to let RoPE handle longer sequences
Get code accessThe Rotation View: Understanding Extrapolation
Suppose the model is trained with max_seq_len = 4096. What happens if inference length is 8192?
A common intuition is “the position index is out of range, so it is OOD.” But that is imprecise. The position index is unbounded, while RoPE position embeddings are bounded trigonometric functions. The model interacts with embeddings, not indices. To understand OOD, we must analyze the embeddings.
Rotating on the Unit Circle
Recall the dot product after RoPE (complex form):
The key is . By Euler’s formula, it is a point on the unit circle. As relative distance grows, this point rotates around the circle. Larger rotates faster; smaller rotates slower.
This is the core of the “rotation view”: whether is OOD is not important; what matters is whether the unit-circle points have been sufficiently covered during training.
High Frequency vs Low Frequency: Coverage Differences
Assume training length , then . For each dimension , the number of rotations during training is:
- High-frequency dims ( large, small): fast rotation, many turns during training, covering the circle. At test time, even larger just keeps rotating on already covered points → no OOD
- Low-frequency dims ( small, large): slow rotation, may not complete one full circle during training, covering only a small arc. When test-time exceeds that arc, we enter unseen territory → true OOD
Concrete numbers (, , ):
# Highest-frequency dim (i=0): θ₀ = 1.0
# Rotations: 1.0 × 4096 / (2π) ≈ 651 turns → full coverage, safe
# Lowest-frequency dim (i=63): θ₆₃ ≈ 0.00011
# Rotations: 0.00011 × 4096 / (2π) ≈ 0.07 turns → tiny arc, high OOD riskThe core issue is not “the rotation angle is too large,” but insufficient unit-circle coverage in low-frequency dimensions. High-frequency dims are the safest.
From Rotation to Solutions
With this view, the solution becomes clear:
- Dims with enough rotations (high frequency) → no change, extrapolate directly
- Dims with insufficient rotations (low frequency) → compress out-of-range angles back into the trained arc (position interpolation)
- Middle range → smoothly transition between the two
All methods below are variations of how to compress and how much.
Log in to continue reading
This is premium content. Please log in to access the full article.
CookLLM Docs