Modern LLMs advertise eye-popping context windows: 128K, 1M, 10M tokens. Almost none of them were originally pretrained at those lengths. Behind the marketing is a serious engineering effort — context extension — that takes a model trained at, say, 8K and pushes it to 128K without retraining from scratch.
Why it's hard
Positional encodings are calibrated to the range the model saw during training. A model that learned RoPE rotations across positions 0-8191 has no real signal for what position 100,000 should look like. Naively extending the position scheme produces nonsense — attention patterns become noisy at unfamiliar relative distances, and the model stops referring back to far-away tokens reliably.
What works
- Position Interpolation (Chen et al. 2023): for RoPE, interpolate the rotation frequencies so that "position 100,000" in the extended model aligns with "position 8,191" in the original. Then fine-tune briefly on long sequences.
- NTK-aware scaling (Reddit/EleutherAI): scale different RoPE frequency dimensions differently. High-frequency dims unchanged (preserves local patterns), low-frequency dims rescaled (accommodates new range).
- YaRN (Peng et al. 2023): refines NTK-aware scaling with attention temperature adjustments. Llama 3 used YaRN-style scaling to extend from 8K to 128K with relatively cheap fine-tuning.
- Sliding window + global tokens: at architecture-design time, restrict attention to a local window with a few global tokens. Mixtral and Gemma 3 use this; LLaMA 4 Scout's 10M context relies on similar tricks.