YaRN (Yet Another RoPE eNlargement) rescales or interpolates rotary-position frequencies so models trained on short contexts can process much longer sequences without retraining. section 9.0 section 9.5.2
YaRN addresses several practical long-context problems:
- Extends context windows from earlier 2,000- or 4,000-token limits to as many as 128,000 tokens or more in model families such as Gemma 3. section 9.5.2
- Reduces the perplexity increase and loss of coherence that can occur when a model exceeds its original training length. section 9.5.2
- Improves the model's ability to locate important tokens in very long inputs, where attention can otherwise spread across many irrelevant positions. section 9.5.2
Figure 9.10 Illustration of the haystack problem. Unmitigated attention (grey) spreads probability mass almost uniformly across the sequence, making it difficult to isolate important tokens. Sharpened attention (black) produces a clear peak at the target position (dashed line), enabling retrieval even within a very long context.
Visualizes the needle-in-a-haystack problem: diffuse attention makes retrieval difficult, while sharper attention isolates the relevant position in a long sequence. section 9.5.2
