RoPE Scaling (Position Interpolation, NTK-aware, YaRN)
Definition
RoPE scaling is the family of methods that extend a RoPE-trained model’s usable context beyond its training length by keeping inference-time rotation angles inside the trained range. A 4k-trained model produces garbage at 100k not because of FLOPs but because its slow (low-frequency) RoPE pairs hit rotation angles they never saw in training — a positional generalization failure. Two philosophies fix it: rescale position uniformly (Position Interpolation, arXiv:2306.15595), or rescale frequencies non-uniformly (NTK-aware / YaRN, arXiv:2309.00071).
Key math / How it works
RoPE spins each 2D pair of by with , . The wavelength of pair is — tokens per full rotation. High-freq pairs () complete many rotations in training (safe to extrapolate); low-freq pairs () never complete one (go OOD at long range).
Position Interpolation (PI). With scale , linearly compress every position: . Position then maps to — the largest trained angle, so nothing is OOD. Needs only ~1000 fine-tuning steps. Flaw: it crushes all frequencies uniformly, including high-freq pairs that were fine, blurring short-range resolution (offset-1 tokens differ by an smaller angle).
NTK-aware scaling. Change the base instead of the position:
Since regardless of , the fastest pair is untouched while the slowest is interpolated by — spreading interpolation pressure across dimensions by frequency, with little or no fine-tuning.
YaRN (“NTK-by-parts”). Make the per-frequency decision explicit. With rotations-in-window and thresholds , build a ramp and set
- Many rotations () → → keep (local resolution intact).
- Fewer than one () → → use (never OOD).
YaRN also multiplies logits by a length-dependent temperature with , recovering softmax entropy as context grows. It extends further than PI with an order of magnitude less fine-tuning.
Why it matters
Positional extension is what makes a model coherent far past its training length, and it is nearly free in FLOPs — it only retunes RoPE frequencies. It is orthogonal to the systems side (flash-attention, ring-attention, kv-cache reduction via gqa-mqa/mla): YaRN can make a model coherent at 128k while it stays unaffordable without them. YaRN is the recipe behind many production long-context RoPE models.
Taught in
- 09-long-context-race — §3, deriving PI and YaRN from the wavelength argument.
See also
- rope — the base positional encoding being rescaled
- long-context — the umbrella problem (positions + systems + eval)
- ring-attention — the systems half of long context
- flash-attention · kv-cache · gqa-mqa · mla — affordability levers
- alibi · positional-encoding — alternative position schemes
- attention-mechanisms