DL0078 LLM Training Stages

What are the standard stages of LLM training?

Answer

A modern LLM is built in a sequence of stages that share one architecture but differ in data, objective, and scale: pretraining on a web-scale corpus with next-token prediction, an increasingly explicit mid-training phase that reweights the data mix and extends the context window, supervised fine-tuning (SFT) on curated prompt-response pairs, and preference optimization that turns human or programmatic judgments into a training signal (reward model plus PPO, DPO, or reinforcement learning with verifiable rewards). The split is not cosmetic: pretraining consumes well over 90% of the total tokens and FLOPs and is where almost all knowledge and reasoning capacity is acquired, while post-training uses a tiny fraction of the compute to select and expose behaviors the base model already has. Each stage produces a named artifact that the next stage consumes, so the usual lineage is base model → long-context base → instruct model → aligned model. Practical pipelines also interleave evaluation, safety filtering, distillation, and quantization, but those are packaging steps rather than new learning objectives.

(1) Pretraining: self-supervised next-token loss on trillions of filtered web, code, and book tokens, run once at enormous cost; this stage fixes the tokenizer, the parameter count, and the knowledge cutoff.
(2) Mid-Training: continued pretraining on a higher-quality mix with upsampled math, code, and long documents, plus context-length extension and learning-rate annealing, using roughly 1-10% of the pretraining tokens.
(3) Supervised Fine-Tuning: the same cross-entropy loss but computed only on response tokens with the prompt masked out, teaching format, instruction following, and tool-call syntax from 10^4 to 10^6 curated examples.
(4) Preference Optimization: optimizes a reward (learned from pairwise comparisons, or computed by a verifier) under a KL penalty toward the SFT reference policy, which is what shifts a model from plausible to preferred.
(5) Compute Asymmetry: post-training is cheap, so it is where iteration happens; anything that requires new knowledge or a longer context has to go back to a pretraining-style stage.

Four-stage LLM training pipeline: filtered web text feeds pretraining with a next-token loss producing a base model, a high-quality long-document mix feeds mid-training producing a long-context base, prompt-response pairs feed SFT with the prompt masked producing an instruct model, and preference pairs or verifiable tasks feed preference RL with a reward plus KL penalty, yielding a deployed assistant

Figure 1: The four canonical stages with their input data, objective, and output artifact. Only the data distribution and loss mask change between stages 1 to 3; stage 4 replaces likelihood with a reward under a KL constraint.

Mathematical Formulation:
\mathcal{L}_{\mathrm{PT}}(\theta) = -\sum_{t=1}^{T} \log p_{\theta}(x_t \mid x_{1:t-1})
\mathcal{L}_{\mathrm{SFT}}(\theta) = -\sum_{t \in \mathcal{A}} \log p_{\theta}(y_t \mid x, y_{1:t-1})
\mathcal{L}_{\mathrm{RM}}(\phi) = -\log \sigma\big(r_{\phi}(x,y_w) - r_{\phi}(x,y_l)\big)
J(\theta) = \mathbb{E}\big[r_{\phi}(x,y)\big] - \beta\,\mathrm{KL}(\pi_{\theta}\,\|\,\pi_{\mathrm{ref}})

Where:

  • x_{1:t-1} is the preceding context and x_t the target token, so pretraining averages this loss over every position of every document.
  • x is the prompt, y the response, and \mathcal{A} the set of assistant token positions; positions outside \mathcal{A} are masked, which is the only structural difference between SFT and pretraining.
  • y_w and y_l are the preferred and rejected responses for the same prompt, r_{\phi} is the reward model, and \sigma is the logistic function, giving the Bradley-Terry pairwise objective.
  • \pi_{\theta} is the policy being trained and \pi_{\mathrm{ref}} the frozen SFT checkpoint; the KL term is what keeps generations fluent instead of collapsing onto reward-model artifacts.
  • \beta > 0 sets the strength of that anchor: small \beta permits reward hacking, large \beta leaves the model barely changed from SFT.
Log-scale bar chart of training tokens per stage: pretraining 15 trillion tokens at 94.9 percent, mid-training 0.8 trillion at 5.1 percent, SFT 0.2 billion at 0.001 percent, and preference RL 4 billion at 0.03 percent

Figure 2: Illustrative token budget for a frontier-scale run. Pretraining and mid-training together see about 99.97% of all tokens, so post-training cannot add missing knowledge, only elicit and shape what is already in the weights.

Post-Training OptionReward Model + PPODPOVerifiable Rewards (GRPO)
Signal requiredPairwise human preferences, then a learned scalar rewardPairwise preferences used directly, no reward modelA programmatic checker: unit tests, math answer match, schema validity
Models held in memoryFour: policy, reference, reward, criticTwo: policy and frozen referenceTwo plus a sampler: no critic, group baseline replaces it
Online generationYes, rollouts dominate wall-clock timeNo, offline on a fixed pair datasetYes, several samples per prompt
Main failure modeReward hacking and length inflation once the reward model is over-optimizedOff-policy drift: pairs stop reflecting the current policy, likelihood of both responses can fallOnly works where correctness is checkable; gaming the checker instead of the task
Typical useBroad helpfulness and safety at frontier labs with annotation pipelinesSmall teams, quick style and tone alignment on limited GPUsMath, code, and reasoning models where long chains of thought pay off

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *