Chapter 4 · Mid-training¶
4.1 What is mid-training, and why do we need it? ★★¶
One-sentence answer
Mid-training is a training stage between pretraining and post-training: near the end of pretraining, training continues on a smaller but higher-quality and more targeted dataset, usually while the learning rate is decayed. Its purpose is to build a foundation for key capabilities such as reasoning, code, math and long context before SFT and RL.
I will address three aspects: where it sits in the training pipeline, why it is a separate stage, and what it actually does.
(1) Position: mid-training sits between pretraining and post-training; its objective is the same as pretraining, but the data is curated.
- Pretraining: next-token prediction on trillions of tokens of web pages, books and code, to learn general language ability and world knowledge.
- Post-training: much smaller instruction data, preference data and verifiable tasks, used with SFT, preference optimization and RL to make the model an assistant that follows instructions and reasons.
- Mid-training: still next-token prediction, but on curated high-quality data; far less data than pretraining, yet far more than post-training.
(2) Reasons: there are three main reasons for making it a separate stage.
- High-quality data is most effective when combined with learning-rate annealing: Near the end of pretraining the learning rate gradually decreases, and the model becomes more strongly shaped by recent data. Switching to high-quality data such as math, code and textbook-style text at this stage yields a clear improvement with relatively few tokens. Rather than diluting this valuable data within a vast amount of web text, it is therefore better to reserve it for the end and use it in concentrated form. Both Llama 3 and OLMo 2 adopt this approach (see 4.2).
- Some capabilities are best trained in a dedicated stage, the most typical being long context: Attention compute grows quadratically with sequence length, so running all of pretraining at 128K would be prohibitively expensive. The usual practice is therefore to complete most of pretraining with short 4K or 8K sequences, and then use a dedicated stage, together with a RoPE scaling method, to gradually extend the context to 32K or even 128K (see 4.3 for the training recipe and the Model Architecture direction for the details of RoPE scaling).
- It lays the groundwork for post-training and thereby raises the ceiling of RL: The prevailing view is that RL mainly elicits capabilities the model already has, and can hardly teach entirely new ones from scratch. If mid-training injects large amounts of reasoning, math, code and data containing reasoning traces in advance, the ceiling that subsequent RL can reach is higher. For example, OctoThinker (Wang et al. 2025) found that a key reason Llama underperformed Qwen in RL was precisely the lack of such data; after mid-training on high-quality math data, Llama could reach the level of Qwen models of the same size after RL (see 4.4).
(3) Content: common practices fall into three categories.
- High-quality data with learning-rate annealing: switch to curated data while decaying the learning rate.
- Long-context extension: gradually increase the training sequence length while adjusting the positional encoding.
- Targeted strengthening of capabilities or domains: increase the share of reasoning, code and math data, add synthetic Q&A and reasoning data, or add corpora for a specific domain.
In summary: the essence of mid-training is to train the foundational capabilities that post-training requires into the model in advance, with the most suitable data at the most suitable time.
Comparing the three stages:
| Pretraining | Mid-training | Post-training | |
|---|---|---|---|
| Data | Massive web, books and code; quantity wins | Curated high-quality data: math, code, reasoning, long documents, synthetic Q&A | Instruction data, preference data, verifiable tasks |
| Data size | Largest (trillions of tokens) | Medium (far smaller than pretraining) | Smallest |
| Learning rate | Held or slowly decayed after warmup | Usually in the decay (annealing) phase | Very small |
| Objective | Next-token prediction | Next-token prediction | SFT loss, preference loss, RL objective |
| Problem it solves | Learn general language ability and knowledge | Strengthen key capabilities, extend context, prepare for post-training | Follow instructions, align with preferences, strengthen reasoning |
Going deeper: what labs have published
(1) The labs' approaches share curated data, a decaying learning rate, and the goal of preparing capabilities for later stages; they differ in emphasis.
| Model | Emphasis | Approach |
|---|---|---|
| Llama 3 (Dubey et al. 2024) | High-quality annealing and long context | Linearly annealed the learning rate to 0 over the final ~40M tokens of pretraining while upsampling high-quality data; a separate long-context stage extended the context from 8K to 128K in six steps |
| OLMo 2 (OLMo et al. 2024) | High-quality annealing | Explicitly calls this stage mid-training, using a purpose-built Dolmino Mix 1124 (high-quality web, educational and math content, instruction data, etc.) with the learning rate annealed linearly to 0; trains several times with different data orders and averages the resulting models (model souping) |
| Qwen3 (Yang et al. 2025) | Reasoning data | Pretraining in three stages: a general stage of ~30T tokens; a reasoning stage of ~5T tokens with a higher share of STEM, code, reasoning and synthetic data and faster learning-rate decay; and finally hundreds of billions of tokens to extend the context to 32K |
| DeepSeek-V3 (DeepSeek-AI 2024) | Long context | After pretraining, extends the context with YaRN in two steps, first from 4K to 32K and then to 128K |
(2) A practical technique: evaluate data with small-scale annealing runs first.
OLMo 2 proposed "micro-annealing": each data source is first evaluated separately through small-scale annealing runs, and the final data mix is then determined accordingly. This makes it possible to compare the value of different data without running a full mid-training each time, which substantially reduces the cost of trial and error (see 4.6).
Follow-up questions
Follow-up 1: How does mid-training differ from continued pretraining?
The two are technically identical; they differ in purpose. Both continue next-token prediction on new data. Continued pretraining usually refers to adapting an already-trained general model to a new domain or language, whereas mid-training refers to a fixed stage in the main training pipeline whose purpose is to prepare capabilities for post-training. The boundary is not strict, however, and many papers use the two terms interchangeably (see 4.5 for how domain continued pretraining avoids forgetting).
Follow-up 2: Can mid-training data include Q&A or instruction data? Does that overlap with SFT?
It can, but the two serve different purposes. Many teams include some synthetic Q&A and data containing reasoning traces so that the model becomes familiar with such content early. Mid-training, however, still uses the language-modeling loss and aims to build capability, whereas SFT specifically trains the model to respond in a conversational format and usually computes the loss only on the response.
Follow-up 3: How can one tell whether mid-training is effective?
It should be evaluated in three respects, the most important being the ceiling after post-training.
- Target capabilities of the base model: whether evaluations such as math, code and long-context retrieval improve.
- Ceiling after post-training: whether the final result is higher after the same SFT and RL.
- General capabilities: whether any regression occurs.
Common mistakes
- Do not describe mid-training as "another kind of SFT": Its goal is to strengthen foundational capabilities using a language-modeling loss, not to teach the model how to converse.
- Do not claim that long context requires pretraining on long sequences from the start: In practice, nearly everyone trains on short sequences first and extends the context later in a dedicated stage.
- Do not claim that mid-training requires a large amount of data: Its value lies in the quality and timing of the data; the amount is far smaller than in pretraining.
4.2 Why does switching to high-quality data during the learning-rate annealing phase pay off more? ★¶
One-sentence answer
Because as the learning rate falls, gradient noise weakens and the model settles out of the oscillation of the high-learning-rate phase into the low-loss region defined by the current data, so the data seen during annealing has the largest influence on the final model; at the same time, high-quality data is scarce, and concentrating it at the end keeps it from being diluted in a vast amount of web text. In practice, upsampling data such as math and code during annealing yields clear gains with relatively few tokens.
I will address three aspects: the optimization perspective, the data perspective, and the limits of this practice.
(1) Optimization perspective: the annealing phase determines where the model finally "lands".
An intuitive explanation is the "river valley" picture (Wen et al. 2024): the pretraining loss surface is like a valley with steep slopes on both sides and a gently descending river along the bottom. In the high-learning-rate phase, the parameters advance quickly along the river but oscillate strongly between the two slopes, so the loss appears to fall slowly; once the learning rate decays, the oscillation disappears, the parameters drop to the valley floor, and the loss falls rapidly. The key point is that the exact position of the valley floor is determined by the loss surface of the data used at that moment. The data in the annealing phase therefore directly determines where the model finally converges, and its influence is far larger than that of the same amount of data seen during the high-learning-rate phase, where it is drowned in noise.
(2) Data perspective: high-quality data is scarce, so using it in concentrated form is more efficient.
The total amount of high-quality data such as math, code and textbook-style text is limited. Mixed evenly into more than ten trillion tokens of pretraining data, it would make up only a tiny share, and most of it would be seen during the high-learning-rate phase. Reserving it for the annealing phase, by contrast, allows its share to be raised substantially, and it can even be repeated a few times if necessary; OLMo 2 found that repeating math data 2 to 4 times during annealing still helps (OLMo et al. 2024). In addition, a common explanation is that by this point the model already has basic language ability and knowledge, so it is better able to absorb more difficult content.
(3) Limits: the gains concentrate on the target capabilities, and general data must be kept.
First, the larger the model, the smaller the gain: Llama 3 found that annealing on high-quality math and code data clearly improved the 8B model but brought almost no gain for the 405B model (Dubey et al. 2024). Second, the upsampling phase should not be too long, and the share of high-quality data should not be too high, otherwise general language-modeling ability declines; Blakeney et al. (2024) found that an upsampling phase of 10–20% of training works best, and roughly half of OLMo 2's annealing mix is still filtered general web data. Finally, the annealing data must not contain the training or test sets of benchmarks, otherwise the improvement is merely an artifact of contamination.
In summary: the annealing phase is the stage in which the model "sets": the learning rate is low and the noise is small, so the data seen at this point has the largest influence on the final model, which is why the best data should be reserved for this stage.
Going deeper: published annealing results, and a quantitative description of the annealing gain
(1) Several labs have observed clear gains.
| Work | Setup | Result |
|---|---|---|
| Llama 3 (Dubey et al. 2024) | Annealing on high-quality math and code data | The 8B model improved by 24.0% on the GSM8k validation set and 6.4% on MATH; the 405B model barely improved |
| MiniCPM (Hu et al. 2024) | Mixing high-quality SFT-style data into the decay phase | The 2.4B model's GSM8K rose from 27.7 to 42.3 and C-Eval from 40.0 to 52.6 |
| Blakeney et al. 2024 | A 7B model trained on 1T tokens, with domain data upsampled at the end | Gains of up to 6.90, 8.26 and 6.17 percentage points on MMLU, GSM8K and HumanEval; an upsampling phase of 10–20% works best |
| OLMo 2 (OLMo et al. 2024) | A small-scale anneal on math data mixed 35 : 65 with general web data | A GSM8K-style evaluation rose from 28.5 to 63.5 |
(2) The loss reduction from annealing can be described quantitatively.
Tissue et al. (2024) proposed predicting the validation loss at any point in training from two "areas" under the learning-rate curve:
where \(s\) is the training step, \(S_1\) is the area under the learning-rate curve up to step \(s\) (the "forward area"), \(S_2\) is the learning-rate annealing area, and \(L_0\), \(A\), \(C\) and \(\alpha\) are fitted constants (here \(C\) is not compute). The term \(A\cdot S_1^{-\alpha}\) captures the cumulative progress made in the high-learning-rate phase, and the term \(C\cdot S_2\) captures the extra drop brought by annealing, which is consistent with the river-valley picture.
Follow-up questions
Follow-up 1: If high-quality data works so well, why not use only high-quality data from the start?
Because high-quality data is limited in quantity, and using it alone sacrifices diversity. If all of pretraining used only high-quality data, that data would have to be repeated many times, and beyond about 4 epochs the benefit drops quickly (Muennighoff et al. 2023); at the same time, massive web data provides broad world knowledge and long-tail content, and data that is too narrow hurts the model's general ability. The more sensible arrangement is therefore to use large, broad data in the main phase and to concentrate high-quality data in the annealing phase.
Follow-up 2: How low should the learning rate go during annealing? Does the shape of the decay matter?
It is usually decayed to 0 or close to 0, and the shape matters somewhat. Both Llama 3 and OLMo 2 decay the learning rate linearly to 0 during annealing; Hägele et al. (2024) found that a \(1-\sqrt{\cdot}\)-shaped decay outperforms linear decay; and Bergsma et al. (2025) found that linear decay to 0 outperforms cosine decay to 10% of the peak.
Follow-up 3: Is the improvement from the annealing phase genuine capability, or adaptation to the evaluation format?
Both, which is why evaluation should happen after post-training and on decontaminated data. Annealing data often includes Q&A and instruction data, which familiarize the model with the format of evaluation questions in advance; some data sources even contain benchmark questions directly. Olmo 3 found that some data sources contained entire validation or test splits, although contamination did not always inflate scores (Olmo et al. 2025). The more reliable practice is therefore to compare models after the same post-training and to decontaminate the annealing data strictly (see 4.6).
Common mistakes
- Do not say the annealing gain comes entirely from the data: Even without changing the data, learning-rate decay alone lowers the loss noticeably; high-quality data brings an additional gain on top of that.
- Do not mix benchmark training or test sets into the annealing data: Otherwise the improvement is merely an artifact of contamination.
- Do not stretch the annealing phase too long or remove general data entirely: Otherwise general ability declines.
4.3 How is long-context extension done in training? ★★¶
One-sentence answer
Complete the main pretraining phase with short 4K–8K sequences, then lengthen the sequences in one or more steps during mid-training; each lengthening step also adjusts RoPE (a larger base or a scaling method such as YaRN), and training continues for billions to hundreds of billions of tokens on a mix of "long documents that contain genuine long-range dependencies" and "a substantial share of high-quality short data". Training uses a document-level attention mask, and whether training is sufficient is judged with long-context downstream tasks rather than perplexity.
I will address three aspects: the training strategy, the data, and how to judge whether training is sufficient. The details of the RoPE scaling methods themselves are covered in the Model Architecture direction.
(1) Training strategy: short first, then long, lengthening gradually and adjusting the positional encoding at each step.
Training on long sequences from the start is both expensive and unnecessary: attention compute grows quadratically with sequence length, while the vast majority of documents are short anyway. Xiong et al. (2023) found that continued long-context training starting from a short-context model works about as well as training on long sequences from scratch, at a much lower cost. The standard practice is therefore to set up a dedicated stage at the end of pretraining: each time the sequence is lengthened, the RoPE base is increased (ABF) or a scaling method such as YaRN is applied, so that the new length falls within a range of positions the model can adapt to, and training then continues at a small learning rate. Lengthening can happen in several steps; for example, Llama 3 extended from 8K to 128K in six stages and moved to the next stage only when performance on short-context evaluations had fully recovered and the model perfectly solved needle-in-a-haystack tests at the current length (Dubey et al. 2024). In addition, when several documents are packed into one long sequence, a document-level attention mask is needed so that each token attends only to content in its own document; training on very long sequences also requires parallelism techniques such as context parallelism (see Chapter 3).
(2) Data: long data must contain genuine long-range dependencies, and it must be mixed with short data.
- Sources of long data: naturally long documents such as books, multiple files from the same code repository concatenated according to their dependencies, and long papers, as well as synthetic data that requires aggregating information across long distances. Merely concatenating unrelated short documents does not teach the model to use long-range dependencies.
- Keep the domain mix balanced: Fu et al. (2024) found that one should raise the share of long documents within each domain while keeping the original domain mix; simply upsampling books heavily (because books are the longest) distorts the domain distribution and actually works worse.
- Mix in high-quality short data: Gao et al. (2024) found that training only on long data actually hurts long-context ability, and that a mix of about 60% long data with the rest high-quality short data works best; in Olmo 3's long-context stage, long data makes up only 34% (Olmo et al. 2025). Short data keeps short-context ability from regressing and maintains overall data quality.
(3) Evaluation: use long-context downstream tasks rather than perplexity or needle-in-a-haystack.
Perplexity is dominated by tokens that depend only on local context and is insensitive to whether the model actually uses distant information: Gao et al. (2024) found that as the share of long data increased, perplexity kept improving while long-context downstream tasks actually got worse. Needle-in-a-haystack tests are already saturated for strong models and can hardly tell them apart. One should therefore use a suite of long-context evaluations covering retrieval, question answering, summarization, multi-hop reasoning and similar tasks, preferably after SFT, and also check short-context benchmarks to confirm there is no regression (evaluation methods are covered in the Inference, Evaluation and Deployment direction).
In summary: the key points of long-context extension are short first and then long, lengthening gradually, continuing training on data that mixes long and short and keeps domains balanced, and judging the result with downstream tasks rather than perplexity.
Going deeper: published long-context stages
(1) The labs' approaches differ widely, but the overall trend is toward spending more and more tokens on long context.
| Model | Length change | Training amount | Key points |
|---|---|---|---|
| Llama 3 (Dubey et al. 2024) | 8K → 128K in 6 stages | About 800B tokens | Recovery of short-context performance and needle-in-a-haystack as conditions for moving to the next stage |
| DeepSeek-V3 (DeepSeek-AI 2024) | 4K → 32K → 128K | 1,000 steps per stage | Uses YaRN; the learning rate stays at the end-of-pretraining value of \(7.3\times 10^{-6}\) |
| DeepSeek-V3.1 | Two stages, 32K and 128K | 630B tokens at 32K, 209B tokens at 128K | About 10 times and 3.3 times more than V3, respectively |
| Qwen3 (Yang et al. 2025) | 4K → 32K | Hundreds of billions of tokens | 75% of texts are 16K–32K long and 25% are 4K–16K; the RoPE base is raised from 10,000 to 1,000,000; at inference, methods such as YaRN extend it about 4 times further |
| ProLong (Gao et al. 2024) | Based on Llama-3-8B, first 64K then 512K | 40B tokens in total | About 30% code repositories, 30% books and 3% textbooks, with the rest high-quality short data; training at a length beyond the evaluation length helps |
| Olmo 3 (Olmo et al. 2025) | 8K → about 65K | 50B tokens for the 7B model, 100B tokens for the 32B model | Long data makes up 34%; intra-document attention mask; best-fit packing; synthetic long-range aggregation tasks added |
(2) Different abilities need different amounts of data.
Fu et al. (2024) found that continued training on only 0.5 to 5 billion tokens is enough for the model to retrieve information from any position within 128K; but to use long context robustly for complex tasks, the amount the labs actually invest is usually tens to hundreds of billions of tokens.
Follow-up questions
Follow-up 1: Short-context ability dropped after context extension. What do you do?
Raise the share of high-quality short data, and make short-context performance a condition for advancing stages. Common measures include keeping a substantial share of high-quality short data in the long-context mix; using a document-level attention mask so that the model does not pick up the habit of attending to distant, unrelated content; lowering the learning rate somewhat; and, as Llama 3 did, lengthening further only after short-context evaluations have fully recovered.
Follow-up 2: Does SFT after the long-context stage necessarily need long instruction data?
Not necessarily. Gao et al. (2024) found that SFT on short instruction data alone yields strong long-context performance; many teams nonetheless add synthetic long-document Q&A and summarization data to strengthen the model's ability to use long inputs in conversation (see Chapter 5).
Follow-up 3: Why lengthen gradually over several stages rather than all at once?
Gradual lengthening means the model only has to adapt to a limited change each time, and it saves compute. At each lengthening step, the RoPE adjustment and the shift in the data distribution are small, so the model adapts more easily; meanwhile, shorter stages are cheaper to compute, so most of the adaptation can be done at shorter lengths first. This is not the only option, however: DeepSeek-V3 used only two stages, and Qwen3 used only one stage and then relied on YaRN to extend further at inference.
Common mistakes
- Do not say that modifying RoPE without continued training can reliably extend the context many times over: Training-free extrapolation has limited effect, and some continued training on long text is usually needed.
- Do not upsample only books: This distorts the domain distribution; raise the share of long documents within each domain instead.
- Do not use perplexity or needle-in-a-haystack as the only criterion: Neither reflects whether the model actually uses long context.
- Do not forget the document-level attention mask: Otherwise the model learns to attend to distant, unrelated content.
4.4 Reasoning-oriented mid-training: long-CoT data, synthetic reasoning data, and laying the groundwork for RL ★★¶
One-sentence answer
RL mainly amplifies the reasoning behaviors a base model already has, so the "seeds" of reasoning should be planted during mid-training: upsample high-quality math, code and STEM corpora and add synthetic Q&A data and long-CoT reasoning traces, so that the model already exhibits reasoning behaviors such as verification and backtracking before entering RL. Work such as OctoThinker shows that this substantially raises the ceiling of subsequent RL; but the share and format of long-CoT data need to be controlled, and the result should be evaluated after RL.
I will address three aspects: why groundwork for RL is needed, what data to include, and what to watch out for.
(1) Reason: RL can only reinforce what the model can already do, so the base model sets the ceiling of RL.
RL learns from the model's own samples: if the model never samples a correct solution for some type of problem, the reward is always 0 and that type of problem is never learned (see Chapter 8). Whether the base model already has useful reasoning behaviors therefore determines how far RL can go. Gandhi et al. (2025) gave a clear example: under exactly the same RL training, Qwen-2.5-3B far outperformed Llama-3.2-3B on the Countdown arithmetic game, because Qwen naturally exhibits four behaviors (verification, backtracking, subgoal setting and backward chaining) while Llama lacks them. After priming Llama with examples containing these behaviors, it matched or even exceeded Qwen in RL; more interestingly, even when the examples' final answers were wrong, the effect was similar as long as the reasoning behaviors were right. Continued pretraining on OpenWebMath data filtered to amplify these reasoning behaviors likewise allowed Llama to match Qwen's self-improvement trajectory. This shows that shaping reasoning behaviors during mid-training is an effective way to raise the ceiling of RL.
(2) Data: there are three main types.
- High-quality math and code corpora: Data quality is crucial. OctoThinker found that the high-quality MegaMath-Web-Pro improves both the base model and its performance after RL, whereas the lower-quality FineMath-4plus brings only marginal gains (Wang et al. 2025).
- Synthetic Q&A and short-CoT data: Q&A data with step-by-step solutions familiarizes the model with the format of solving problems step by step, and adding instruction data strengthens this effect further (Wang et al. 2025).
- Long-CoT reasoning traces: These are usually distilled from reasoning models and contain behaviors such as reflection, verification and backtracking, directly providing RL with behavior patterns it can reinforce. After OctoThinker added long-CoT data in the decay phase, a 3B Llama model reached a level on par with Qwen2.5-3B after RL; Olmo 3 likewise deliberately added instruction data and thinking traces in mid-training to lay the groundwork for post-training (Olmo et al. 2025).
(3) Caveats: control the share and format of long CoT, and evaluate by the result after RL.
Although long-CoT data brings the largest gains, it can also have side effects: OctoThinker found that it makes responses verbose and destabilizes RL training, with response lengths exploding and performance dropping sharply, which had to be mitigated with instruction data, a more structured prompt template and a gradually relaxed maximum generation length. Reasoning data also needs to be mixed with general data so as not to harm general ability. More important still is how it is evaluated: the goal of reasoning-oriented mid-training is to raise the ceiling after RL, not the base model's scores, so one should run some RL after mid-training and compare; and results should be checked across several model families and on clean benchmarks, because some models are contaminated on common math benchmarks, which easily overstates the effect. A controlled study by Zhang et al. (2025) also shows that, with total compute fixed, "mid-training + RL" outperforms RL alone.
In summary: the goal of reasoning-oriented mid-training is not to push up the base model's scores directly, but to ensure that the model already has reasoning behaviors that RL can reinforce when it enters RL.
Going deeper: OctoThinker's recipe and related work from 2025–2026
(1) OctoThinker uses a two-stage "stable-then-decay" recipe.
- Stable stage: about 200B tokens at a constant learning rate, with data dominated by high-quality math web corpora (about 72.5%) mixed with general web data (10%), math text with code blocks, math Q&A and so on.
- Decay stage: about 20B tokens with the learning rate decayed by cosine to 10% of the stable-stage value, split into three branches: a long-CoT branch (adding long reasoning data such as Open R1, 30% in total), a short-CoT branch (adding OpenMathInstruct2, NuminaMath-1.5 and others) and a hybrid branch. All three branches share 55% high-quality math web data, 10% instruction data and 5% general web data.
- Stabilization in the RL stage: to counter the length explosion caused by long CoT, the maximum generation length is relaxed gradually: 2,048 tokens for the first 200 steps, 4,096 tokens for steps 200–320, and 8,192 tokens for steps 320–400.
(2) Related work from the past two years.
| Work | Approach | Main conclusion |
|---|---|---|
| Gandhi et al. 2025 | Priming with examples that contain reasoning behaviors, or continued pretraining on filtered math corpora | Whether reasoning behaviors are present matters more than whether answers are correct |
| OctoThinker (Wang et al. 2025) | Stable-then-decay mid-training | The more thorough the mid-training, the stronger the subsequent RL |
| Qwen3 (Yang et al. 2025) | A reasoning stage of about 5T tokens | Higher share of STEM, code, reasoning and synthetic data, with faster learning-rate decay |
| MiMo (LLM-Core Xiaomi 2025) | About 25T tokens in total, with the mix adjusted over three stages: math and code make up about 70% in the middle stage, and about 10% synthetic reasoning responses are added in the final stage | The 7B base model's reasoning potential exceeds that of some 32B models |
| Akter et al. 2025 | Comparing reasoning data added during pretraining with reasoning data added only during SFT | Adding reasoning data during pretraining brings an average gain of about 19%, which later SFT can hardly make up for |
| TPT (Wang et al. 2025) | Using off-the-shelf LLMs to generate thinking for documents, concatenated and trained with next-token prediction | About 3 times better data efficiency |
| Olmo 3 (Olmo et al. 2025) | 100B tokens of mid-training that deliberately include instruction data and thinking traces | With these data included, the base model improves on every evaluation |
| Zhang et al. 2025 | Controlled experiments on synthetic reasoning tasks | With compute fixed, mid-training + RL beats RL alone; RL's gains require data whose difficulty is "slightly beyond current ability" |
Follow-up questions
Follow-up 1: How does adding long-CoT data in mid-training differ from an SFT cold start?
They differ in data scale, loss and purpose. Long-CoT data in mid-training usually amounts to billions of tokens mixed with large amounts of other data and is trained with the language-modeling loss on all tokens, with the aim of making reasoning behaviors part of the model's "prior"; a cold-start SFT usually has only thousands to hundreds of thousands of samples, computes the loss only on the response, and aims to teach the model a specific output format and improve readability; for example, DeepSeek-R1 used a few thousand long-CoT samples for a cold start before RL (see Chapter 8). The two are complementary: mid-training determines whether the model has these behaviors at all, and the cold start determines the format in which it expresses them.
Follow-up 2: How do you judge whether a base model is suitable for RL?
Not by its current accuracy alone, but by its "reachability". Common practices include looking at pass@\(k\) for large \(k\) to see whether the model can occasionally solve hard problems; checking whether its outputs already contain behaviors such as verification and backtracking; and simply running a short RL pilot to observe the gain. Mao et al. (2026) proposed using RL with random rewards as a probe: on several OLMo checkpoints, they found that two checkpoints with the same 3.5% accuracy on synthetic arithmetic reached best results of 8.5% and 55% respectively after RL with correct rewards, showing that models with the same current performance can have completely different trainable ceilings.
Follow-up 3: Is reasoning data better placed in pretraining or in mid-training?
The earlier it is introduced, the more solid the foundation, but the two stages emphasize different things. Akter et al. (2025) found that adding reasoning data already during pretraining brings an average gain of about 19%, and that this foundation can hardly be made up for later by enlarging the SFT data; they also found that pretraining benefits most from diversity in reasoning patterns, whereas SFT is more sensitive to data quality. In practice, models such as Qwen3 and MiMo raise the share of reasoning-related data in the later stages of pretraining and add synthetic reasoning data.
Common mistakes
- Do not say "RL can teach reasoning from scratch, so mid-training does not matter": RL mainly amplifies behaviors the base model already has, and the base model sets the ceiling of RL.
- Do not judge reasoning-oriented mid-training only by the base model's benchmark scores: What really matters is the result after the same RL.
- Do not push the share of long-CoT data up without limit: It can make responses verbose and RL unstable.
- Do not validate conclusions on a single model family only: Some models are contaminated on common math benchmarks, so the conclusions may not generalize.
4.5 How do you avoid catastrophic forgetting in domain continued pretraining? ★★¶
One-sentence answer
The core tools are data replay and a suitable learning-rate schedule: mix a share of general pretraining data into the domain data (about 5% for a small distribution shift and about 25% for a large one), re-warm the learning rate to a moderate peak and then decay it to a very low value; in addition, limit the amount of training, start from the base model and redo post-training or merge weights afterward, and monitor both domain and general abilities throughout. Ibrahim et al. (2024) showed that learning-rate re-warming and re-decaying combined with replay comes close to retraining from scratch on all the data.
I will address three aspects: why forgetting happens, what tools are available, and how to evaluate.
(1) Cause: all abilities share one set of parameters, while the gradient comes only from the new data.
Continued pretraining means continuing next-token training on a domain corpus, starting from an existing base model. The gradient then serves only to lower the loss on the new data, and no loss term protects the old abilities, so the parameters move toward fitting the new distribution and, along the way, damage structures that matter for old abilities but are irrelevant to the new domain; this is catastrophic forgetting. The larger the difference between the old and new distributions, the higher the learning rate and the longer the training, the worse the forgetting. Continued pretraining also has a particular difficulty: by the end of base-model training, the learning rate has already decayed to a very low value, at which the model can hardly learn new knowledge, so the learning rate must be raised again, and raising it in itself increases the loss on the original data (Ibrahim et al. 2024). This is exactly the tension between "stability" and "plasticity".
(2) Tools: there are four main ones.
- Data replay: Mix a share of general pretraining data into the domain data so that the old abilities keep receiving gradient. Ibrahim et al. (2024) found that about 5% replay suffices for a small distribution shift (English to English), while a large shift (English to German) needs about 25%. For example, Code Llama continued training Llama 2 on 500B tokens, of which 85% was code, 8% was natural language related to code and 7% was general natural language, precisely to retain natural-language understanding (Rozière et al. 2023).
- A suitable learning-rate schedule: Re-warm the learning rate to a moderate peak and then decay it again. The higher the peak, the more fully the model adapts to the new domain, and the more it forgets, so the two must be balanced. If a pre-annealing checkpoint is available (for example, a WSD stable-phase checkpoint), continuing from it avoids the loss caused by raising the learning rate again.
- Limit the size of the update: Fewer training tokens and a lower learning rate both reduce forgetting, but the model also learns less new knowledge. LoRA updates only a low-rank increment, so it "learns less and forgets less" (Biderman et al. 2024); but in continued pretraining, where a large amount of new knowledge must be injected, LoRA learns markedly worse than full-parameter training, so full-parameter training is usually still used.
- Start from the base model and restore chat ability afterward: Running continued pretraining directly on a chat model washes out its instruction following and safety alignment. The more common practice is to run continued pretraining on the base model and then redo post-training, or to add the weight difference between the chat model and the base model (the chat vector) to the continually pretrained model, restoring chat ability at very low cost (Huang et al. 2023).
(3) Evaluation: measure both the domain gain and general ability, and determine the mix with small-scale experiments.
Reporting only the improvement on domain tasks is meaningless; one must also track a suite of general-ability evaluations (knowledge, code, math, instruction following and safety) and the validation loss on general data, the latter requiring no extra labels and being the cheapest forgetting signal. The replay ratio and the peak learning rate are usually determined by small-scale experiments, and they can also be predicted by fitting dedicated scaling laws: for example, the D-CPT Law uses small-scale experiments to predict general and domain performance under different mixing ratios (Que et al. 2024), and the CMR scaling law predicts the critical mixing ratio that balances general ability against domain performance (Gu et al. 2024).
In summary: the core of avoiding forgetting is keeping the old distribution present during training (replay) and limiting how far the parameters move from the original model (learning rate and amount of training), while evaluating the result as a trade-off between "domain gain and general regression".
Going deeper: the conclusions of Ibrahim et al., and the cost of each method
(1) The main conclusions of Ibrahim et al. (2024).
- Setup: at two scales, 405M and 10B, they studied a weak distribution shift (Pile to SlimPajama) and a strong one (Pile to German Common Crawl).
- Learning rate: re-warming and re-decaying are necessary to adapt fully to the new data; the higher the maximum learning rate, the more complete the adaptation and the greater the forgetting; even when training continues on the same data, raising the learning rate again makes the loss rise.
- Replay: a small amount of replay effectively mitigates forgetting while barely affecting adaptation to the new data; about 5% for the weak shift and about 25% for the strong shift.
- Conclusion: combining the two matches retraining from scratch on all the data, at a small fraction of the compute; the authors also proposed learning-rate schedules that are not tied to a fixed token budget, to reduce the forgetting caused by re-warming.
(2) What each method does and what it costs.
| Method | Effect | Cost |
|---|---|---|
| Data replay | Old abilities keep receiving gradient | Requires general data and extra compute; the ratio must be tuned |
| Re-warming and re-decaying | Lets the model learn new knowledge | The higher the peak, the more forgetting |
| Less training or a lower learning rate | Smaller parameter shift | Less new knowledge is learned |
| LoRA | Restricts the freedom of the update | Knowledge injection becomes markedly worse |
| Regularization toward the original model (e.g. a KL or L2 constraint) | Constrains the shift in outputs or parameters | The coefficient must be tuned, and adaptation is limited |
| Weight interpolation or chat vector | Restores general or chat ability cheaply | Gives up part of the domain gain |
Follow-up questions
Follow-up 1: If the original pretraining data is unavailable, how do you do replay?
Substitute public high-quality corpora with a similar distribution. The purpose of replay is to keep the model seeing the general distribution, so the original data is not required; public web, encyclopedia, code and math corpora of similar quality usually serve the purpose. Data generated by the original model can also be used as a substitute, but note that generated data is usually less diverse than real data.
Follow-up 2: If performance drops after continued pretraining, has knowledge necessarily been lost?
Not necessarily; part of it is a failure to retrieve. Zheng et al. (2025) call this spurious forgetting: the knowledge is still stored in the parameters, but the task alignment has been disrupted, and a small amount of training brings it back. When judging the degree of forgetting, it is therefore best to apply the same light post-training after continued pretraining before comparing.
Follow-up 3: How does domain continued pretraining relate to mid-training?
Technically they are the same, both continuing next-token prediction on new data; they differ in purpose and starting point. Mid-training is a fixed stage in the main training pipeline and usually continues from a checkpoint whose learning rate has not yet fully decayed; domain continued pretraining usually starts from a general model that has finished training and adapts it to a new domain or language, so it has to deal more with learning-rate re-warming and forgetting (see 4.1).
Common mistakes
- Do not use a tiny learning rate for continued pretraining to "avoid forgetting": Too low a learning rate means almost no new knowledge is learned; re-warm to a moderate peak and combine it with replay instead.
- Do not report only the improvement on domain tasks: Changes in general ability and safety must be reported as well.
- Do not run large-scale continued pretraining directly on a chat model: This washes out instruction following and safety alignment; run it on the base model and restore chat ability afterward.
4.6 How do you evaluate the data mix for mid-training (e.g. micro-annealing)? ★¶
One-sentence answer
Because a full mid-training run cannot be repeated for every decision, evaluation usually happens in two layers: first, small-scale annealing runs (micro-annealing) evaluate each data source on its own, by mixing the candidate data with an equal amount of general web data, running a short learning-rate anneal from a pretraining checkpoint, and comparing against a web-only baseline; then the candidate full mix is put through an integration test and evaluated after a quick round of post-training, to confirm that the gains carry over into post-training.
I will address three aspects: how to evaluate a single data source, how to evaluate a full mix, and which metrics to use.
(1) A single data source: evaluate it with micro-annealing.
The value of mid-training data shows up mainly during learning-rate annealing (see 4.2), so evaluation should also take place under annealing conditions. Micro-annealing works as follows: take a pretraining checkpoint, mix the candidate data with a roughly equal amount of general web data, run a short anneal of only a few billion tokens, and compare target and general abilities against a baseline annealed on web data alone (OLMo et al. 2024). The cost is low: OLMo 2 ran 19 micro-anneals totaling 130B tokens, less than three full 50B-token anneals. Llama 3 also used a similar method to assess the value of small domain datasets (Dubey et al. 2024).
(2) The full mix: run an integration test and check the result after post-training.
That each data source works on its own does not mean the mixture still works, because different sources can complement or conflict with one another. After a candidate mix is chosen, therefore, a full anneal at real scale is still needed, i.e. an integration test. Going further, since the ultimate purpose of mid-training is to lay the groundwork for post-training, one should run a quick round of SFT on the checkpoint from the integration test and evaluate it with the post-training evaluation suite; Olmo 3 calls this step checking "post-trainability" (Olmo et al. 2025). For reasoning-oriented mid-training, some RL should also be run for comparison (see 4.4).
(3) Metrics: choose metrics that discriminate at small scale, and decontaminate strictly.
- Use continuous metrics instead of accuracy: In small-scale experiments, accuracy on many tasks is near chance and very noisy. Continuous metrics such as the likelihood of the correct answer or bits-per-byte distinguish between data earlier and more reliably (Magnusson et al. 2025).
- Watch both target and general abilities: Check whether target metrics such as math and code improve, and also whether general ability regresses.
- Decontaminate strictly: Mid-training data often contains Q&A data in formats close to benchmarks, and sometimes even includes benchmark validation or test sets directly; Olmo 3 found that some public data sources contained entire test sets, so decontamination must come first for the evaluation results to be trustworthy (Olmo et al. 2025).
In summary: the principle for evaluating a mid-training mix is to run small-scale experiments under the same annealing conditions as real training, evaluate data sources one by one before validating the whole, and use the result after post-training as the final criterion.
Going deeper: the labs' annealing-based evaluation setups, and what OLMo 2 found
(1) Experimental setups.
| Setting | Llama 3 | OLMo 2 | Olmo 3 |
|---|---|---|---|
| Starting point | An 8B model trained to 50% | A pretraining checkpoint | A pretraining checkpoint |
| Data | 30% new data, 70% default mix | Candidate data and general web data, about half each | 5B tokens of candidate data plus 5B tokens of web data |
| Scale and comparison | 40B tokens, learning rate decayed linearly to 0 | Effects are usually visible in under 10B tokens | 10B tokens in total, compared with a 10B-token web-only anneal |
(2) What OLMo 2 found about math data.
| Experiment | GSM8K-style evaluation (GSM* in the paper) |
|---|---|
| Baseline | 28.5 |
| Math data : web data = 35 : 65 | 63.5 |
| Math data : web data = 10 : 90 | 61.0 |
| Math data repeated 2 times | 66.0 |
| Math data repeated 4 times | 65.0 |
| TinyGSM in its original code-style solutions | 25.0 |
| TinyGSM rewritten into natural language | 65.5 |
| Rewritten data repeated 2 times | 70.0 |
Three lessons follow: domain data needs only a small share to deliver most of the gain; when data is scarce, a few repeats still help; and the form of the data matters a great deal, since rewriting code-style solutions into natural language turned a result below the baseline into a large improvement.
Follow-up questions
Follow-up 1: Do micro-annealing conclusions extrapolate to the real training run?
Broadly yes, but they cannot be relied on completely. OLMo 2 found that the effect a single source shows in micro-annealing persists when it is mixed with other sources; DataDecide also found that ranking data at a single small scale picks the best data at the 1B scale about 80% of the time (Magnusson et al. 2025). But interactions between data sources and differences in scale can still change the conclusion, so an integration test is still needed in the end.
Follow-up 2: Besides annealing experiments, what other methods are there for setting the data mix?
Mainly fitting the relationship between mix and outcome with small models. For example, RegMix trains many small models on different mixes and uses regression to predict the outcome of unseen mixes (Liu et al. 2024); Data Mixing Laws fit a functional relationship between the mix and the loss (Ye et al. 2024); and DoReMi uses a small proxy model to learn domain weights (Xie et al. 2023). These methods are used more for the mix of the main pretraining phase; see Chapter 1.
Follow-up 3: Why anneal from a pretraining checkpoint rather than train a small model from scratch to compare data?
Because the effect of mid-training data depends on the state the model is in at that point. Mid-training happens on a model that has already learned from a large amount of general data, and the value of the data lies in what it can add to that model during annealing; a small model trained from scratch has neither the same knowledge base nor the same learning-rate phase, so its conclusions may not apply. A short anneal from a real pretraining checkpoint reproduces the conditions of actual mid-training at very low cost.
Common mistakes
- Do not compare data by accuracy alone in small-scale experiments: The noise is too large; use continuous metrics.
- Do not look only at the base model's scores: The ultimate purpose of mid-training is to improve the result after post-training.
- Do not evaluate data sources one by one and simply add up the gains: Data sources interact, so an integration test is needed.