Midtraining Bridges Pretraining and Posttraining Distributions
Emmy Liu, Graham Neubig, Chenyan Xiong
Overview
Recent technical reports from major AI labs over the past two years reveal a standard addition to the large language model (LLM) training pipeline: midtraining. Typically occurring during the tail end of pretraining—specifically during the learning rate annealing phase when the learning rate decreases toward zero—midtraining introduces higher-quality and more domain-specific data before a model moves on to posttraining stages like Supervised Fine-Tuning (SFT) or Reinforcement Learning (RL). Despite its widespread adoption across models of all scales, midtraining has lacked a rigorous definition in the machine learning literature.

Key moments
- 0:00 Introduction to midtraining and defining the training stage
- 2:00 Research questions and controlled experimental setup
- 4:00 Evaluation methodology and dataset similarity metrics
- 5:00 Headline results: code and math domain benefits
- 6:00 Comparing mixed midtraining versus continued pretraining
- 7:00 Talk recap and concluding takeaways
- 7:30 Audience Q&A and discussion on retention versus specialization
Midtraining Bridges Pretraining and Posttraining Distributions
Speakers: Emmy Liu; Graham Neubig; Chenyan Xiong
Conference: ICML
YouTube: https://slideslive.com/39083717
Overview
Recent technical reports from major AI labs over the past two years reveal a standard addition to the large language model (LLM) training pipeline: midtraining. Typically occurring during the tail end of pretraining—specifically during the learning rate annealing phase when the learning rate decreases toward zero—midtraining introduces higher-quality and more domain-specific data before a model moves on to posttraining stages like Supervised Fine-Tuning (SFT) or Reinforcement Learning (RL). Despite its widespread adoption across models of all scales, midtraining has lacked a rigorous definition in the machine learning literature.
This talk, presented at ICML by Emmy Liu alongside advisors Graham Neubig and Chenyan Xiong, investigates the exact mechanics of midtraining. The authors examine why midtraining improves downstream performance, addressing the central trade-off between domain specialization and the retention of general knowledge acquired during broad web pretraining. To study this systematically, the research team conducted controlled experiments by pretraining and midtraining models from scratch across multiple scales, establishing clear empirical guidelines for data composition, scheduling, and domain matching.
Background
▶ Watch: Introduction to midtraining and defining the training stage (0:00)
In the standard modern LLM training pipeline, models transition abruptly from massive, unfiltered web corpora (such as Common Crawl derivatives) directly to alignment stages like SFT and RL. However, practitioners quickly discovered that this direct jump often results in suboptimal adaptation for specialized capabilities like coding, mathematical reasoning, or long-context processing. To bridge this gap, labs began inserting an intermediate phase at the end of pretraining.
While practitioners intuitively adopted midtraining, its theoretical foundations remained unexplored. Previous work treated midtraining recipes as monolithic, unexamined mixtures of code, math, and curated web text. Furthermore, the relationship between midtraining data distributions and subsequent SFT performance was not quantified. Understanding this transition is critical in the ML systems space, as compute budgets for pretraining are immense, and inefficient allocation during the final annealing phase can waste substantial GPU hours. By defining midtraining as an intermediate training stage that intentionally shifts the data distribution toward higher-quality regimes prior to posttraining, this work provides a rigorous framework to evaluate its necessity and mechanics.
Key Findings
▶ Watch: Evaluation methodology and dataset similarity metrics (4:00)
The authors uncovered several fundamental insights regarding how midtraining interacts with downstream SFT and general data retention:
- Domain-Matched Specialization: Midtraining yields the most pronounced improvements when the chosen domain matches the subsequent SFT task. Specifically, StarCoder-based midtraining provides the largest improvements on Python code evaluation (PyCode), while math-based midtraining maximizes performance on mathematical reasoning benchmarks like GSM8K.
- Superior Initialization for Posttraining: Loss curves demonstrate that midtrained models provide a significantly better initialization for downstream SFT. Training and validation losses start at a lower baseline and follow a consistent downward trajectory compared to models that did not undergo midtraining.
- Mixed Data Outperforms Abrupt Shifts: The limiting case of midtraining—continued pretraining via a 100% switch to specialized domain data—is consistently outperformed by blended midtraining mixtures that retain general web data. Mixed distributions achieve superior in-domain loss while simultaneously mitigating catastrophic forgetting.
- Predictable Proximity Advantage: The benefit of a specific midtraining mix can be predicted using a simple unigram token-level similarity metric. Across various model scales, a clear linear relationship exists between the "proximity advantage" (how much closer a midtraining mix brings the model to the target downstream dataset) and downstream performance gains.
Technical Deep Dive
▶ Watch: Headline results: code and math domain benefits (5:00)
To study midtraining under strictly controlled conditions, the researchers avoided proprietary, pre-existing checkpoints and instead pretrained models from scratch across three distinct parameter scales: 70M, 1B, and a larger scale up to 70B. The base models were pretrained on the C4 (Colossal Clean Crawled Corpus) dataset for 128 billion tokens using identical optimizer hyperparameters and configurations.
The midtraining phase consumes the final 2% to 10% of the total pretraining compute budget. Rather than treating midtraining recipes as black boxes, the authors decomposed them into five distinct data components:
- StarCoder (code generation data)
- Math datasets
- FLAN (instruction-following data)
- KnowledgeQA (scientific and knowledge-intensive reasoning data, similar to the MiniCPM recipe)
- DCLM (DataComp-LM, a higher-quality web corpus compared to standard C4)
To evaluate the impact of these components, the models were fine-tuned on four domain-matched downstream datasets: PyCode (coding), GSM8K (math), Llama instruction benchmarks, and SciQ (science QA). Catastrophic forgetting was rigorously tracked by measuring cross-entropy loss on the general C4 validation set after SFT, serving as a continuous proxy for general knowledge retention.
Furthermore, preliminary investigations into data scheduling revealed that the timing of when specialized data is introduced during the annealing phase is critical. Introducing specialized data earlier in the budget—even with the exact same token count—yields superior results compared to late introduction, pointing to distinct plasticity windows for different data types.
Experimental Setup & Results
▶ Watch: Talk recap and concluding takeaways (7:00)
The empirical evaluation was conducted across a ladder of model sizes, primarily focusing on 1B parameter models for fine-grained loss curve analysis. All models shared the Pythia family architectural setup to ensure reproducibility.
- Baseline Comparison: Midtrained models were compared against control models that continued training on the original C4 pretraining distribution for an identical token budget.
- Specialized vs. General Yield: While code and math midtraining showed massive performance deltas on PyCode and GSM8K, FLAN-style general instruction data showed minimal differentiation from standard web data when paired with specialized SFT targets.
- Forgetting Mitigation: Counter to the classical machine learning assumption that domain specialization inevitably incurs heavy catastrophic forgetting on past domains, the experiments demonstrated that mixed midtraining preserves C4 validation loss while simultaneously dropping domain-specific loss. The authors attribute this to the vast asymmetry between massive pretraining token budgets and relatively small SFT adjustments.
Practical Implications
▶ Watch: Audience Q&A and discussion on retention versus specialization (7:30)
For infrastructure teams, model builders, and deployment engineers, these findings offer actionable guidance on constructing efficient training pipelines:
- Targeted Allocation: Allocate the final 2% to 10% of your pretraining compute specifically to data distributions that diverge significantly from broad web pretraining—namely code and math.
- Avoid Pure Continued Pretraining: Never switch 100% of your data mixture to a single specialized domain during annealing. Always blend in general web data (such as DCLM) to maintain downstream generalization and prevent catastrophic forgetting.
- Leverage Proximity Metrics: Use simple unigram token-level similarity metrics as a cheap diagnostic to predict whether a proposed midtraining mixture will successfully bridge the distribution gap toward your target SFT domain.
- Sequence Early: Introduce specialized midtraining data earlier in the learning rate decay phase rather than waiting until the absolute final steps, taking advantage of model plasticity before capacity solidifies.
Key Takeaways
- Midtraining serves as an essential bridge between broad web pretraining and specialized posttraining (SFT/RL).
- It is most effective for domains heavily divergent from web data, such as code and math.
- Mixed midtraining distributions consistently outperform pure continued pretraining, improving target domain performance while suppressing catastrophic forgetting.
- Simple unigram similarity metrics can successfully predict the transfer efficacy of midtraining data mixes.
- The timing of specialized data introduction matters significantly, suggesting distinct plasticity windows during learning rate annealing.
About the Speaker(s)
- Emmy Liu: Presenter of the paper on midtraining; has advisors Graham Neubig and Chenyan Xiong on this project, and was advised by Scott Yih from Meta on a proto-version of the project.
- Graham Neubig: Advisor on Emmy Liu's midtraining project.
- Chenyan Xiong: Advisor on Emmy Liu's midtraining project.
Reviews
→ Top-rated talks at International Conference on Machine Learning 2026
All talks from International Conference on Machine Learning 2026