Midtraining Bridges Pretraining and Posttraining Distributions

Emmy Liu, Graham Neubig, Chenyan Xiong · OpenReview

Abstract

Recently, many language models have been pretrained with a "midtraining" phase, in which higher quality, often instruction-formatted data, is mixed in at the end of pretraining. Despite the popularity of this practice, there is little scientific understanding of this phase of model training or why it is effective. In this work, we conduct the first systematic investigation of midtraining through controlled experiments with language models pretrained from scratch and fine-tuned on supervised finetuning datasets in different domains. We find that when compared after supervised fine-tuning, the effectiveness of midtraining is highest in the math and code domains, where midtraining can best reduce the syntactic gap between pretraining and posttraining data. In these cases, midtraining consistently outperforms continued pretraining in both in-domain validation loss as well as pretraining data forgetting after posttraining. We conduct ablations on the starting time of the midtraining phase and mixture weights of the midtraining data, using code midtraining as a case study, and find that timing has a greater impact than mixture weights, with earlier introduction of specialized data, yielding greater benefits in-domain as well as preserving general language modeling better. These findings establish midtraining as a domain adaptation technique that compared to continued pretraining yields better performance through reduced forgetting.

Introduction: The Challenge of Distributional Shifts

The standard recipe for training Large Language Models (LLMs) involves massive-scale pretraining on diverse web data, followed by Supervised Fine-Tuning (SFT) on small, high-quality datasets for specific tasks. However, jumping directly from a general distribution to a highly specialized one (like Python code or advanced calculus) often creates "gradient conflict." The model's weights are pushed in directions that clash with its foundational knowledge, leading to poor adaptation or the "catastrophic forgetting" of general reasoning abilities.

Midtraining—an intermediate phase where specialized data is mixed with general pretraining data—acts as a "distributional bridge." It smooths the optimization path between broad pretraining and narrow fine-tuning, providing a superior initialization for post-training.

Methodology: Distributional Bridging

The authors propose that midtraining functions by shifting the model's initialization point ($\theta_{mid}$) closer to the target distribution ($\theta_{target}$), thereby reducing the optimization "effort" required during SFT. This is visualized as navigating an optimization landscape to avoid high-conflict regions.

Figure 1: Schematic representation of midtraining as a distributional bridge, smoothing the path from pretraining to the target distribution.

To quantify this effect, the study introduces Proximity Advantage (PA), a model-agnostic metric that measures how much closer a midtraining mixture brings the model to the target SFT distribution compared to standard pretraining data. Additionally, Centered Kernel Alignment (CKA) was used to analyze internal representations, revealing that midtrained models undergo significantly smaller shifts in their final layers during SFT.

Key Insights: The Plasticity Window

A critical finding is the existence of a "Plasticity Window." Timing is often more influential than the specific mixture weights of the data. Early in training, the model is more malleable, allowing it to benefit from aggressive mixture weights (up to 80%). If specialized data is introduced too late, the model becomes "rigid," and high mixture weights can actually degrade performance.

Figure 3: SFT validation loss as a function of midtraining start time and mixture weights, illustrating the importance of timing over volume.

Furthermore, midtraining benefits are highly domain-specific. Code-focused midtraining significantly aids code tasks but provides negligible benefits for math tasks, and vice versa. This suggests that midtraining is a targeted domain adaptation technique rather than a general performance booster.

Results: Performance and Forgetting Mitigation

Empirical results across the Pythia model family (70M to 1B parameters) demonstrate that midtraining consistently outperforms naive continued pretraining:

  • Performance Gains: On Python-specific tasks (Pycode), midtraining reduced SFT validation loss significantly (e.g., from 2.174 to 1.888).
  • Forgetting Mitigation: Midtrained models retained general knowledge much better than those subjected to 100% specialized continued pretraining. For instance, math midtraining maintained a C4 pretraining loss of 3.018, whereas continued pretraining on math data alone saw this loss spike to 6.376.
  • Predictive Power: The Proximity Advantage metric showed a strong correlation ($r = 0.869$ for the 70M model) with downstream performance, offering a low-cost way to evaluate midtraining mixtures.

Discussion and Limitations

While this work provides a systematic framework for understanding midtraining, several questions remain. The study focused on models up to 1B parameters; it is unclear if the "plasticity window" behaves differently at the scale of frontier models (70B+). Additionally, real-world pipelines often involve multi-stage midtraining with evolving mixtures, which warrants further investigation. Future research could also explore the impact of midtraining on alignment phases like RLHF or DPO.

Summary updated

BibTeX
@inproceedings{liu2026midtraining,
  author = {Emmy Liu and Graham Neubig and Chenyan Xiong},
  title = {{Midtraining Bridges Pretraining and Posttraining Distributions}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=5PfEQzE9bf},
}
Figure