TL;DR
Traditional large language model (LLM) training delays safety, factuality, and reasoning until the post-training alignment phase, leaving core pretraining unguided. This paper introduces Self-Improving Pretraining and Thinking Mid-training, techniques that leverage strong, existing post-trained models to rewrite pretraining data and act as reinforcement learning judges early in the training pipeline. This paradigm shift yields massive improvements in downstream safety, factuality, and complex reasoning compared to standard next-token prediction baselines.
What Problem Does This Paper Address?
The classical paradigm for training LLMs splits the process into two strict stages: massive pretraining on raw text (next-token prediction) followed by post-training (Supervised Fine-Tuning and Reinforcement Learning) to enforce safety, factuality, and reasoning.
The authors argue that this separation introduces a fundamental limitation. Pretraining data is notoriously messy, often containing toxic, biased, or inaccurate text. Simply filtering out bad data reduces corpus size and prevents the model from learning how to handle unsafe prompts at inference time. More importantly, because the patterns acquired during pretraining dictate a model's ultimate capabilities, waiting until post-training to inject desirable behaviors means trying to correct deeply embedded flaws. This paper aims to integrate safety, quality, and reasoning directly into the pretraining and mid-training stages.
Methods
The authors propose two interconnected frameworks to move alignment upstream:
1. Self-Improving Pretraining
Instead of predicting the very next token, pretraining is reframed as a sequence learning task: prefix-conditioned suffix generation. The training pipeline utilizes a strong, frozen, post-trained model in two roles:
- Suffix Rewriter: When the streaming pretraining data contains an unsafe or low-quality suffix, the rewriter modifies it into a high-quality, safe continuation while preserving the original prefix context.
- Suffix Judge: The judge evaluates and scores candidate completions.
During online training, the policy model generates $N$ rollouts. The judge evaluates these rollouts alongside the original suffix and the rewritten suffix. The policy is then optimized via online Reinforcement Learning—specifically Direct Preference Optimization (DPO) or Reward-Filtered Negative Log-Likelihood (RF-NLL)—based on the judge's rewards.
2. Thinking Mid-training
To inject reasoning capabilities before final post-training, the authors introduce a three-step intermediate training phase:
- Thinking Augmentation: A teacher model enriches raw pretraining text chunks by interleaving intermediate "thoughts" (reasoning traces) at semantically appropriate positions.
- SFT Mid-training: The student model undergoes supervised fine-tuning on this augmented corpus to learn the mechanics of when and what to think.
- RL Mid-training: The model is optimized using reinforcement learning with an LLM judge. The judge rewards thoughts that successfully help the model predict subsequent text, ensuring the thoughts are functionally useful rather than merely imitative.
Datasets
- Pretraining & Quality/Safety Evaluation: SlimPajama (SP) and RedPajama (RP).
- Reasoning & Mid-training Sources: DCLM and FineMath corpora.
- Post-training Alignment: DAPO-Math-14k.
- Downstream Benchmarks:
- Standard Evals: BoolQ, PIQA, SIQA, HellaSwag, ARC, OpenBookQA, MMLU.
- Safety: RealToxicityPrompts, ToxiGen, XStest.
- Factuality: FActScore, HaluEval, TruthfulQA.
- Math/Reasoning: GSM8K, MATH-500, AMC23, OlympiadBench, GPQA-Diamond.
Key Insights and Ideas
- Steering vs. Filtering: Rather than purging unsafe text from the training data, the framework keeps unsafe prefixes but pairs them with safe, rewritten suffixes. This explicitly teaches the model how to steer away from toxic or hallucinatory contexts.
- The Suffix-to-Rollout Shift: Early in training, model rollouts are low quality, so the RL process relies heavily on the original and rewritten suffixes for supervision. As the policy model improves, the judge naturally begins selecting and rewarding the model's own high-quality rollouts, creating a dynamic self-improving loop.
- Reasoning as a Native Foundation: Interleaving thinking tokens during mid-training fundamentally alters how a model processes information. It acts as a "cold-start" that makes subsequent post-training RL significantly more sample-efficient and effective.
Key Results
- Continual Pretraining Gains: When optimizing a Llama2 1.4B base model, Self-Improving Pretraining achieved a 36.2% relative improvement in factuality, an 18.5% relative improvement in safety, and up to an 86.3% win rate improvement in overall generation quality over standard baselines.
- From-Scratch Pretraining: Training from scratch in an unsafe environment (RedPajama) boosted downstream safety evaluation scores from 85.2 (baseline) to 97.5, while drastically outperforming next-token baselines in generation quality.
- Reasoning Supercharge: For Llama-3-8B, the full Thinking Mid-training pipeline achieved an average accuracy of 0.38 across challenging reasoning benchmarks (including MATH-500 and GPQA), compared to just 0.12 for direct RL post-training on the base model—a 3.2× improvement.
Limitations and Future Work
- Computational Overhead: Generating multiple online rollouts and running large judge/rewriter models (like GPT-OSS-120B) during the pretraining loop adds massive computational expense compared to cheap next-token prediction.
- Pairwise Scaling Bottleneck: Scoring rollouts scales quadratically ($O(K^2)$) with the number of rollouts. The authors attempted to use a single "pivot" generation to speed this up to $O(K)$, but found it degraded final performance, leaving fast judgment an open problem.
- Unified Reward Functions: Currently, safety, quality, and factuality are optimized via separate prompts and combined rewards. Developing a single, generic judge prompt that can holistically evaluate all dimensions simultaneously remains an objective for future work.
Summary updated