YaRN (Yet another RoPE extensioN method) extends the context window of a pretrained language model that uses RoPE. It scales the rotation angle differently for each dimension pair and also adjusts the temperature of the attention scores. It was proposed in 2023 by Peng, Quesnelle, Fan, and Shippole. The authors extended the context of Llama 2 from 4096 to 128k (131072) tokens and report that fine-tuning needed 10× fewer tokens and 2.5× fewer steps than previous methods.
The earlier Position Interpolation uniformly scales position indices by (where is the extension factor). This is equivalent to slowing down the rotation of every RoPE pair by the same amount. The YaRN paper points out two problems with this uniform scaling.
- It also scales the fast-rotating pairs: The fast-rotating pairs encode the fine-grained order of adjacent words. Slowing them down makes it harder to distinguish the order of nearby words.
- Attention becomes blurred over long contexts: Extending the context changes the distribution of attention scores. The paper found that scaling the scores by a constant factor before the softmax lowers perplexity uniformly.
YaRN leaves the fast-rotating pairs unchanged, scales only the slow-rotating pairs by as in Position Interpolation, and connects the two smoothly in between (an interpolation called NTK-by-parts). Combined with the temperature adjustment of the scores, this is YaRN.
The left side of the figure at the top of this article shows where positional information is injected. It has the same layout as the figures in the RoPE and Position Interpolation articles; only the scaling of the rotation angle and the factor applied to queries and keys differ. The top right shows the per-pair rotation-speed ratio, computed in the same frame as for Position Interpolation. The bottom right shows the size of the temperature adjustment for each extension factor.

