A model trained on sequences up to length 8 gets handed a prompt of length 64. Every RoPE rotation angle past position 8 is one it has never seen produced during training. Retraining on longer sequences fixes it, but that's expensive — is there a way to reuse the same weights and just reinterpret the positions?
Push the scaling factor up and watch two numbers: the fast dimension's effective position never budges, but the slow dimension's collapses back down toward the trained range. The two frequencies aren't treated the same way at all — and that asymmetry is the entire idea.
YaRN checks each RoPE frequency's wavelength — how many positions it takes to complete one full rotation — against the length the model was actually trained on, and only rescales the ones that need it:
- — the token's true position in the (extended) sequence.
- — which frequency this is; .
- — the original trained context length.
- — the scaling factor: how many times longer the new context is meant to be.
- A fast dimension has already lapped the trained range many times
If its wavelength is shorter than , it completed full rotations inside training. One more turn past looks, geometrically, exactly like turns it already learned from — safe to extrapolate as-is.
- A slow dimension never even finished one turn during training
Its wavelength exceeds , so every angle past is new territory. Dividing its position by before rotating maps the extended range of positions back down into the angles the model actually trained on.
- Real YaRN ramps smoothly between the two, this demo snaps
Production YaRN blends interpolation and extrapolation across a band of intermediate wavelengths so there's no hard seam. With only two frequencies here, the boundary is exact and hand-checkable — the idea is identical either way.
The dashed line is the fast dimension: flat, because it's never rescaled. The bold curve is the slow dimension's effective position at position 64 as the scaling factor slides from 1x (no rescaling — the raw, unsafe extrapolation) to 8x. By 8x it lands exactly on 8 — the length the model actually trained on.
Trained context ; extended position (an 8x-longer sequence); fast rate , slow rate (so wavelengths and ):
- No scaling (s = 1): the slow dimension extrapolates raw
Angle radians. The largest slow-dimension angle seen in training is at : . Ratio: larger than any slow-dimension angle seen in training.
- Scale by 8x: divide position by 8 before rotating
Effective position . Angle — precisely the boundary angle the model trained up to.
- The fast dimension is untouched throughout
Angle radians regardless of — it already completed more than 10 full turns inside the trained range, so extrapolating further changes nothing about how familiar the angle looks.
At position 64, find the scaling factor, among the candidates, that brings the slow dimension's effective position back down to within 0.5 of the trained context length (8).
YaRN stretches a trained context window without touching a single weight, by rescaling positions rather than the model — and only for the RoPE frequencies whose wavelength is long enough that extrapolation would otherwise land them in angles never seen during training. Fast-rotating dimensions are left alone because they've already lapped the trained range many times over. It's a purely inference-time fix for the mismatch RoPE creates once a prompt runs longer than training — but it says nothing about the cost of actually processing that longer prompt, which is where the next chapter picks up.