AI Infra
0%
Part I · Chapter 11

Mid-Training: Annealing, Domain Bridges, and Context Extension

AuthorChangkun Ou
Reading time~11 min

The first broad pre-training pass gives a model a general distribution of language, code, facts, styles, and latent procedures. It does not automatically give the post-training pipeline the right starting point. A model can be competent on web text and still be awkward for math traces, code edits, instruction-formatted examples, long documents, or specialist corpora. If post-training is forced to make that jump alone, it must change behavior and repair a distribution gap at the same time.

mid-training names the phase that separates those jobs. It is still pretraining-like: the model usually keeps the same architecture, updates all parameters, and often continues optimizing next-token prediction, the objective of predicting each next token from the ones before it, rather than a preference or reward objective. What changes is the data distribution, the schedule, or the context length. The aim is not to make the model polite, safe, or agentic, but to move its capability distribution closer to the data that later post-training will draw on.

The boundary is operational

The clean definition is not "training that happens in the middle." It is a phase in a sequence. Write a training run as

S={(Di,Li,ni)}i=0N,S = \{(D_i, \mathcal{L}_i, n_i)\}_{i=0}^{N},

where DiD_i is the data distribution, Li\mathcal{L}_i the loss, and nin_i the number of steps. The initial phase i=0i=0 is broad pre-training. The final phase i=Ni=N is post-training or fine-tuning. The intermediate phases 0<i<N0<i<N are mid-training when they still look like pretraining in scale and objective but change the distribution, schedule, or usable context window (Liu et al. 2025).

This makes three boundaries sharp enough to engineer:

  • Versus ordinary pre-training. Broad pre-training chooses a general corpus and spends the majority of the token budget on it. Mid-training changes the mixture after the model already has general features.
  • Versus continued pretraining. Continued pretraining can switch almost entirely to the target domain. Mid-training usually keeps a general-data component in the mixture, which reduces forgetting while still moving the model toward code, math, instructions, or long documents (Liu et al. 2025; Gururangan et al. 2020).
  • Versus post-training. Post-training changes the behavioral interface: supervised fine-tuning (SFT) on demonstrations, direct preference optimization (DPO) from chosen-versus-rejected preferences, reinforcement learning with verifiable rewards (RLVR) from automatically checkable rewards, safety hierarchy, or tool use. Mid-training tries to make the base model a better substrate before those objectives touch it.

Figure 11.1 draws the placement. The important arrow is not "more training." It is "distribution moved before behavior is optimized."

midtraining A Broad pre-training web, books, code, multilingual mix B Mid-training quality anneal, domain bridge, context extension A->B same base objective C Post-training SFT, preference, verifiable rewards, safety tuning B->C closer substrate D Served model evaluated behavior, latency and policy C->D behavioral interface
Figure 11.1. Mid-training sits between broad pre-training and post-training. It still uses pretraining-like updates, but changes the data mixture, schedule, or context window so post-training starts from a closer distribution.

The bridge view

The most useful model of mid-training is a distributional bridge. Suppose D0D_0 is the broad pretraining distribution, where DsD_s denotes a specialist slice: code, math derivations, instruction-formatted problems, high-quality web, or long documents. A simple mixture schedule is

Dt=(1αt)D0+αtDs,0αt1.D_t = (1 - \alpha_t)D_0 + \alpha_t D_s,\qquad 0 \leq \alpha_t \leq 1.

In words, if αt=0\alpha_t=0, nothing has changed. If αt=1\alpha_t=1, the run has become pure continued pretraining on the specialist domain. The middle is the bridge. It keeps enough broad data to preserve general language modeling while making the next post-training distribution less foreign. Controlled experiments in 2025 found this especially helpful for math and code, and found timing more important than the exact mixture weight in the studied code setting (Liu et al. 2025).

Figure 11.2. A toy bridge schedule. Introducing a specialist slice earlier and keeping it mixed with broad data improves target fit while preserving more general retention than an abrupt full switch. The curves are illustrative, not measured.

This is why a late high-quality slice is not merely a better corpus. It is a timing decision. A clean math or code distribution can be powerful when the model still has enough steps and learning rate left to internalize it. Arrive too late and the slice mostly polishes surface statistics; switch to it too abruptly and it can erase broad capability. There is also the case where the timing is fine but the aim is not: a slice introduced without a downstream target just optimizes the wrong gap.

Three recipes in the wild

Quality annealing gives the final part of pretraining a denser, cleaner signal. OLMo 2 reports a specialized Dolmino Mix 1124 introduced during the annealing phase of pretraining, improving downstream capability while keeping the training data, code, logs, and checkpoints open (OLMo Team 2025). MiniCPM makes the scheduling problem explicit through warmup-stable-decay (WSD): a long stable learning-rate plateau can keep a shared main branch alive, then branch into decay phases for different stopping points or domain-adaptation experiments (Hu et al. 2024). This turns "the end of pretraining" from a single terminal event into a place where recipes can be composed.

Domain mid-training moves the model toward a specialist language before post-training gives it assistant behavior. Qwen2.5-Coder is reported as a code-specific model built on Qwen2.5 and further trained on more than 5.5T tokens with cleaned code, synthetic data, and balanced mixing while retaining general and math ability (Hui et al. 2024). DeepSeekMath starts from a coder base and continues training on 120B math-related tokens mixed with natural language and code before the later SFT and reinforcement-learning stages (Shao et al. 2024). The stack implication is direct: the base model should meet post-training halfway, especially when the target format is far from ordinary web text.

Long-context mid-training changes the length distribution and positional regime. rotary position embedding (RoPE) scaling methods such as Position Interpolation and YaRN make extension cheaper by avoiding raw extrapolation beyond the trained positional range (Chen et al. 2023; Peng et al. 2023). But long context is not only a positional method. Qwen2.5-1M reports long-context pre-training, long-data synthesis, progressive pre-training, and multi-stage SFT to reach 1M-token contexts without giving up short-context performance (Yang et al. 2025). That belongs here because the model is being taught a new sequence-length distribution before serving has to schedule the resulting KV-cache pressure.

What gets tuned

Mid-training has fewer objectives than post-training, but the knobs are dangerous because each one changes what the later model can become.

  • Mixture. The data plane from Chapter 6 decides the candidate sources; mid-training decides when and how much of each source enters the stream. Proxy methods such as DoReMi make mixture selection measurable, but the final choice still depends on the target post-training distribution (Xie et al. 2023).
  • Timing. The same specialist slice can be weak when introduced late and destructive when introduced as a hard switch. The bridge experiments put timing above exact mixture weight for the code setting they studied (Liu et al. 2025).
  • Learning-rate schedule. Cosine decay (the learning rate following a cosine curve down to near zero), WSD, and branch-and-decay recipes decide whether the model can still move. A late high-quality phase with too little learning rate is mainly evaluation dressing; too much learning rate can reopen broad loss.
  • Format. Instruction-formatted data can appear before SFT, but it is still next-token data unless the objective changes. This gives the model syntax and discourse forms without yet optimizing preference, helpfulness, or refusal behavior.
  • Context length. Long-document mixtures, RoPE scaling, sequence packing, and attention kernels must be aligned with Chapter 10 and Chapter 31, because a longer context learned during training becomes a memory and scheduling cost at inference time.
What's contested

The term "mid-training" is newer than the practice. Model reports often describe late curriculum training, annealing data, domain continuation, or context extension without using one common name. The useful distinction is therefore functional rather than terminological. If the phase still uses a pretraining-like objective, updates the whole model, and exists to move the base distribution before post-training, it belongs in this layer. If it changes assistant behavior through demonstrations, preferences, rewards, or policies, it belongs to Part III.

Constraint arrow

Post-training cannot reliably add capabilities that the base model never made available. It can elicit, rank, suppress, and format behavior, but its data and reward budgets are small compared with pretraining-scale token budgets. This is why Chapter 21 and Chapter 30 repeatedly point back to base capability. Mid-training is the last large-token chance to reshape that base before alignment and evaluation start measuring behavior.

Failure modes

Mid-training fails quietly. The loss may improve on the new mixture while the model forgets broad language, loses multilingual coverage, or overfits to a format that later post-training will amplify. Specialist code data can move a model toward compiler-friendly syntax at the expense of prose. With math traces, the symbolic style transfers but reliable calculation does not always come with it. Long-context extension is its own trap: a model that passes retrieval probes can still use the middle of its context poorly. And a high-quality web slice can launder benchmark contamination if the decontamination contract from Chapter 6 is not re-run after the slice is assembled.

The engineering failure is to treat mid-training as a cheap epilogue. It touches the optimizer state, learning-rate schedule, data manifest, tokenizer assumptions, position encodings, evaluation decontamination, and checkpoint lineage. It also creates new model variants that need names, model cards, and downstream compatibility tests. If the run cannot answer which distribution changed, when it changed, how much broad data remained, and which evaluations protected against forgetting, the phase is not reproducible.

Where it lands in the stack

Part I now ends with a boundary rather than a cliff. Chapter 5 fixes the budget, Chapter 6 defines the sources, Chapter 7 settles the vocabulary, Chapter 8 and Chapter 9 shape the model body, and Chapter 10 makes the run possible. Mid-training decides whether that run stops as a broad base model or bends toward the capability distribution that Part III will adapt.

That distinction keeps the book's later layers clean. When Chapter 17 adapts behavior, it relies on a code assistant already understanding code syntax, without being the place that taught it. Chapter 21 trains with checkable rewards, yet none of those rewards conjure the mathematical substrate they exploit. Serving long prompts in Chapter 35 inherits one fact it cannot change: whether the model was trained to use long evidence at all. And the buy-tune-continue decision in Chapter 84 turns on this boundary, because it is what tells you whether a problem is really a post-training task or a mid-training one.

Further reading

  • Liu et al., “Midtraining Bridges Pretraining and Posttraining Distributions” (controlled bridge experiments for code, math, instruction, QA, and high-quality web mixtures), 2025. arXiv:2510.14865
    Defines mid-training as intermediate pretraining-like phases and finds that mixed specialist data can bridge pretraining and post-training distributions, especially for code and math, while reducing forgetting versus pure continued pretraining.
  • Gururangan et al., “Don't Stop Pretraining: Adapt Language Models to Domains and Tasks” (domain-adaptive and task-adaptive pretraining before the modern mid-training term), 2020. arXiv:2004.10964
    Shows that additional pretraining on domain and task corpora improves downstream performance across biomedical, computer science, news, and review tasks.
  • OLMo Team, “2 OLMo 2 Furious” (late-stage curriculum training with specialized Dolmino Mix 1124), 2025. arXiv:2501.00656
    OLMo 2 is a fully open family of dense autoregressive language models whose recipe includes late-stage specialized data during the annealing phase and releases data, code, logs, and checkpoints.
  • Hu et al., “MiniCPM: Unveiling the Potential of Small Language Models with Scalable Training Strategies” (WSD schedule for continuous training and branchable decay), 2024. arXiv:2404.06395
    Introduces MiniCPM and a warmup-stable-decay schedule that keeps a stable training plateau available for continuous training and domain adaptation.
  • Hui et al., “Qwen2.5-Coder Technical Report” (specialist code continuation built on Qwen2.5), 2024. arXiv:2409.12186
    Reports Qwen2.5-Coder, a code-specialized family further trained on more than 5.5T tokens with cleaned code, scalable synthetic data, and balanced mixing while retaining general and math skills.
  • Shao et al., “DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models” (math continuation plus later GRPO), 2024. arXiv:2402.03300
    Continues pretraining a coder base on 120B math-related tokens mixed with natural language and code, then adds SFT and GRPO to build a strong open math model.
  • Chen et al., “Extending Context Window of Large Language Models via Positional Interpolation” (RoPE context extension via interpolation rather than extrapolation), 2023. arXiv:2306.15595
    Extends RoPE-based LLM context windows by linearly down-scaling position indices, avoiding unstable extrapolation and preserving original-window quality after limited fine-tuning.
  • Peng et al., “YaRN: Efficient Context Window Extension of Large Language Models” (efficient RoPE context extension), 2023. arXiv:2309.00071
    YaRN extends RoPE-based LLaMA context windows using far fewer tokens and training steps than previous approaches, demonstrating extrapolation beyond the fine-tuning length.
  • Yang et al., “Qwen2.5-1M Technical Report” (progressive long-context pretraining to one million tokens), 2025. arXiv:2501.15383
    Reports Qwen2.5-1M, using long-data synthesis, progressive long-context pretraining, and multi-stage SFT to reach 1M-token contexts while preserving short-context performance.

Comments

Log in to comment