Home Knowledge Base YaRN (Yet Another RoPE extensioN)

YaRN (Yet Another RoPE extensioN) is a state-of-the-art context length extension method for RoPE-based large language models that combines NTK-aware interpolation with attention scaling and a novel frequency-dependent interpolation strategy, achieving superior long-context performance with minimal fine-tuning. YaRN partitions RoPE dimensions into three groups based on their wavelength relative to the training context and applies different interpolation strategies to each.

Why YaRN Matters in AI/ML: YaRN provides the best quality-efficiency tradeoff for context extension, enabling models trained on 4K tokens to perform well at 64K-128K tokens with only a few hundred steps of fine-tuning, making long-context capabilities accessible without expensive full retraining.

Frequency-dependent interpolation — YaRN divides RoPE dimensions into three groups: (1) high-frequency dimensions (wavelength < L_train) are NOT interpolated (preserving local resolution), (2) low-frequency dimensions (wavelength >> L_train) are fully interpolated, (3) mid-frequency dimensions use a smooth ramp between no interpolation and full interpolation • Attention scaling — YaRN applies a temperature scaling factor to attention logits: attention = softmax(QK^T/(√d · t)) where t adjusts for the entropy increase caused by longer sequences, maintaining appropriate attention sharpness at extended lengths • NTK-aware base — The base frequency is scaled using the NTK-aware approach (base → base·α^(d/(d-2))), concentrating extension on low-frequency components while preserving high-frequency local discrimination • Minimal fine-tuning — YaRN requires only 400-1000 training steps on long-context data to adapt a model from 4K to 64K+ context, compared to thousands of steps for Position Interpolation and full retraining for naive approaches • Combining three techniques — YaRN's effectiveness comes from the synergy of (1) NTK-aware base scaling, (2) dimension-dependent interpolation ramps, and (3) attention temperature scaling, each addressing a different aspect of context extension

Extension Method4K→16K PPL4K→64K PPLFine-Tune StepsImplementation
Direct ExtrapolationDivergesDiverges0Trivial
Position Interpolation~6.5~8.01000Simple
NTK-Aware (Static)~6.3~7.5400Moderate
NTK-Aware (Dynamic)~6.5~8.50Moderate
YaRN~6.0~7.0400Moderate
Full Retraining~5.8~6.510,000+Expensive

YaRN is the most comprehensive and effective method for extending RoPE-based model context length, combining frequency-dependent interpolation, NTK-aware base scaling, and attention temperature adjustment into a unified framework that achieves near-retrained quality at a fraction of the computational cost.

yarn (yet another rope extension)yarnyet another rope extension

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.