Order the pipeline that stretches an 8k pretrained model to 128k context
- 1Pick the target context length and derive the new RoPE base theta or frequency scaling factor
- 2Gate the release on long context evals such as needle in a haystack and RULER, not just short context perplexity
- 3Continue pretraining on a mixture rich in genuinely long sequences at the new length
- 4Apply the rescaled rotary frequencies to the pretrained checkpoint
- 5Run long context instruction tuning so chat behavior survives at extended lengths
Pick the target length, derive new RoPE frequencies, apply them, continue pretraining on long sequences, redo long-context instruction tuning, then gate on long-context evals before shipping.
Imagine teaching a child to read full novels when they have only ever read picture books. You cannot just hand them a 500 page book and hope. First, you change the way the page numbers are written so the child can still tell page 387 apart from page 388 in a long book; the existing numbering scheme would just blur them together. Then you give the child many real long books to practice on, not the same picture book stretched out. Next you let them practice answering questions about long stories so their conversation skills survive. Only after all that do you test: can they actually find a specific detail buried in chapter 14? If yes, ship.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Extending a pretrained model from 8k context to 128k or 1M is one of the highest leverage moves an LLM team can make, and one of the easiest to get wrong. The pipeline has five stages: pick the target and rescale positions, apply the rescaling to the checkpoint, continue pretraining on long-data mixtures, redo instruction tuning at the new length, and gate the release on long-context evaluations.
The order is not interchangeable. Each stage provides a precondition the next stage assumes. Skip continued pretraining and the model never learns to use the extended range, no matter how good the positional surgery was. Skip long-context evals and you ship a model that retrieves from short windows and hallucinates everywhere else.
This deep dive walks through each stage with the reasoning, the failure modes, and the actual recipes shipped by Llama 3, DeepSeek-V3, and similar 2026 production models.
Stage 1 and 2: pick the target and rescale RoPE
RoPE encodes position by rotation. Each pair of dimensions in Q and K gets rotated by an angle that depends on position and a per-dimension frequency. The frequencies are derived from a base theta, typically 10000 in the original RoPE paper.
At the pretraining length, the model sees rotation angles between Q and K that span a known range. Extend the sequence to 128k with the same base theta and the rotation angles at long distances are completely outside that range. The attention dot product depends on cos(theta_m - theta_n), which aliases or saturates at long m and n the model never saw. Quality on long-range retrieval collapses.
Rescaling fixes the geometry. Three common approaches: linear position interpolation (PI) compresses positions before applying RoPE; NTK-aware scaling raises the base theta so high frequencies remain intact; YaRN combines NTK with per-dimension correction terms. Llama 3 chose base theta 500k at pretraining time so 128k is reachable without further rescaling; Llama 3.1 extends Llama 3 models further with similar staging.
Apply to the checkpoint. With the new frequencies in place, every layer's attention now produces in-distribution rotation angles even at 100k tokens. This step is mechanical, but if you skip the rescaling or apply it wrong, the next stage runs at wrong geometry and the compute is mostly wasted.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- Llama 3.1 extended 8B and 70B models from 8k to 128k using rescaled RoPE plus continued pretraining on long data, then redone instruction tuning, gated on RULER scores
- DeepSeek-V3 ships at 128k context via YaRN-style RoPE scaling and a long-context continued pretraining phase, validated on long-context benchmarks before release
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you split the continued pretraining budget between long-only and mixed data?
A pure long-only mixture degrades short-context quality. Most recipes use 70-90% mixed and 10-30% deliberately long, with the long fraction front-loaded to teach the new range and then taper toward mixed to preserve base abilities.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Rescaling RoPE theta and shipping, skipping the long-context continued pretraining that actually teaches the model to use the extended range.
60 second bullets to scan on the way to the call.
Why RoPE base theta or scaling must change before continued pretraining
Why continued pretraining on long data is non-optional
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.