Order the three steps of a position-interpolation fine-tune that takes RoPE from 4k to 16k.
- 1Evaluate on long-context benchmarks (e.g. needle-in-a-haystack, passkey) to confirm long-range retrieval works without regressing short-context quality.
- 2Briefly fine-tune the model on long-context data so attention weights adapt to the new effective rotation frequencies.
- 3Optionally swap linear scaling for YaRN, which rescales different RoPE frequency bands non-uniformly to reduce short-context degradation.
- 4Scale the position indices fed into RoPE at attention time: pos' = pos / scale_factor, where scale_factor = target_length / training_length (here 16k / 4k = 4).
Rescale positions first (cheap, no training), then fine-tune at long context (mandatory adaptation), then evaluate, then optionally swap linear scaling for YaRN for better short-context quality.
Picture stretching a song to play in slow motion so it lasts four times longer. First you change the playback speed (cheap, instant). The instruments now sound weird because they were not designed for that tempo, so you give the band a brief practice session to adapt their playing (the fine-tune). Then you record a test concert to check it sounds good. Finally, if some instruments still sound off, you could swap the uniform slowdown for a smarter scheme that slows down only certain pitches, that is YaRN.
Detailed answer & concept explanation~8 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Order the four steps (rescale, fine-tune, evaluate, optionally YaRN), explain each step's role, justify the order dependencies, and mention YaRN as the refinement for the short-context cost of uniform scaling.
Real products, models, and research that use this idea.
- Llama 4 long-context variants use a PI-like recipe combined with YaRN for native 128k-1M context support.
- Qwen 3.5's 1M-token context was achieved via base raising plus YaRN-style per-band scaling plus continued pretraining.
- Vicuna and early Llama-2 community extensions used pure PI (Chen 2023 recipe) for 4k -> 16k and 4k -> 32k extensions.
- Mistral's 32k context support combined sliding-window attention with PI-style extension of the underlying RoPE.
- DeepSeek V4's long-context recipe combines high-base RoPE pretraining with YaRN-style refinement during extension.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhat benchmark would you use to distinguish a model with 'real' 128k context from one with '128k context that aliases past 32k'?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Fine-tuning BEFORE rescaling positions. The rescale is the cheap algebraic prerequisite; the fine-tune is what adapts the model to the rescaled spectrum.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.