Up nextNext guide
Position Interpolation for Context Extension
Language AI
Technical GUIDE
YaRN (Yet another RoPE extensioN) is an efficient technique for stretching a model's usable context window far beyond what it was trained on.
Listen to this guideAI-narrated · ~2 min
It cleverly rescales rotary position embeddings so a model trained on, say, 4K tokens can handle 32K or more with minimal fine-tuning.
Most modern LLMs encode token positions with RoPE (Rotary Position Embeddings), which rotate query and key vectors by angles tied to position. When you feed sequences longer than training length, these rotations enter unseen ranges and the model breaks down. YaRN, introduced in 2023 by Bowen Peng and collaborators, fixes this with NTK-aware interpolation applied per frequency: it leaves high-frequency dimensions (which capture local, short-range relationships) mostly untouched while interpolating low-frequency dimensions (which track long-range position). YaRN also adds a temperature adjustment to attention to counter the entropy changes that come from longer contexts. The result is strong long-context performance after fine-tuning on only a tiny fraction of the data and steps that naive approaches require.
Extending an open 4K-context model to 32K or 128K for long-document question answering with brief fine-tuning
Enabling retrieval-augmented systems to ingest many concatenated passages without truncation
Powering code assistants that need an entire large repository file or multiple files in one prompt
Adapting a base model for long multi-turn conversations that accumulate large chat histories
Context extension is now standard practice: open models routinely ship YaRN-extended variants reaching 128K tokens or beyond. Research is moving toward methods that extend context with zero or near-zero fine-tuning, combine RoPE rescaling with attention-pattern tricks, and maintain quality across the full window rather than just the ends. Expect tighter integration of these techniques into pretraining so long context is native rather than retrofitted.
Free newsletter
One short email each weekday with the three AI stories that actually matter. Free forever, no ads.
One email each weekday. Unsubscribe in one click. We never sell or share your address.
Test yourself
Instant feedback on every answer, and a shareable certificate with a verifiable ID once you pass a course.
Support free AI education. AI Understanding is a 501(c)(3) nonprofit — no ads, no paywall, ever. Make a donation
YaRN (Yet another RoPE extensioN) is an efficient technique for stretching a model's usable context window far beyond what it was trained on. It cleverly rescales rotary position embeddings so a model trained on, say, 4K tokens can handle 32K or more with minimal fine-tuning.
YaRN, whose name means Yet another RoPE extensioN, rescales the rotary position embeddings used in most modern LLMs.
Positions beyond training produce rotation angles the model never saw, so attention behavior degrades sharply.
YaRN uses an NTK-by-parts ramp that interpolates long-wavelength low-frequency dims and leaves short-range high-frequency dims mostly intact.
YaRN adds a temperature scaling to attention logits to counteract entropy shifts that occur as context grows.
YaRN achieves strong long-context quality after fine-tuning on a small fraction of the data naive methods require.
Keep learning
More guides picked for this topic
Up nextNext guide
Position Interpolation for Context Extension
Language AI