Skip to content
E
Educatum

How do the phases of Pretraining, SFT, and Alignment shape LLM, and how does DPO simplify this pipeline?

Curated by Educatum AI teamLast updated:
AlignmentPretrainingSFT
Direct Answer

Modern LLM training follows three stages: Pretraining learns world knowledge and language modeling via next-token prediction, Supervised Fine-Tuning (SFT) teaches instruction-following formats from curated demonstrations, and Alignment optimizes human preferences for helpfulness and harmlessness. Traditional RLHF trains a separate reward model and optimizes the policy with PPO. Direct Preference Optimization (DPO) reparameterizes the optimal RLHF policy to eliminate both the explicit reward model and online RL sampling, optimizing preferences directly with a binary cross-entropy objective.

The development of a modern Large Language Model operates through a three-stage pipeline, transitioning a raw statistical engine into a steerable assistant. The foundational stage, Pretraining, uses self-supervised next-token prediction over internet-scale corpora. This computationally massive phase encodes grammar, world knowledge, and reasoning capabilities into the weights, but yields a base model that simply continues text distributions rather than following instructions.

To mold this base model into an assistant, practitioners apply Supervised Fine-Tuning (SFT). Using high-quality, human-curated instruction-response pairs (e.g., Ouyang et al., 2022, arXiv:2203.02155), SFT aligns the model’s output to a conversational persona and specific formatting constraints. The final stage, Alignment, tunes the model to maximize helpfulness and harmlessness, traditionally requiring Reinforcement Learning from Human Feedback (RLHF). Direct Preference Optimization (DPO) simplifies this final phase by mathematically bypassing the reinforcement learning step entirely (Rafailov et al., 2023, arXiv:2305.18290).

  • Reward Reparameterization: DPO demonstrates that the reward function can be implicitly defined by the language model’s own policy (πθ\pi_\theta) relative to a frozen reference model (πref\pi_{\text{ref}}).
  • Contrastive Classification: Instead of generating text and scoring it dynamically, DPO uses a binary cross-entropy objective over static datasets of “chosen” and “rejected” responses.
  • Hardware Efficiency: By removing the standalone Reward Model and Value Network required by traditional RLHF, DPO reduces the VRAM footprint and computational overhead significantly.

⚠️ Limitations & Caveats

  • SFT is strictly bounded by the quality and diversity of the demonstration data; it relies on behavioral cloning and struggles to teach the model what not to do.
  • DPO is highly sensitive to the distribution of its preference data. If the chosen and rejected pairs lack meaningful variance, the model’s policy can quickly overfit or collapse.

🧪 Core Insights & Mathematical Foundations

[SFT Loss]: LSFT=−E(x,y)∼D ⁣[log⁡πθ(y∣x)][Bradley-Terry Preference]: P(yw≻yl∣x)=σ ⁣(r(x,yw)−r(x,yl))=exp⁡(r(x,yw))exp⁡(r(x,yw))+exp⁡(r(x,yl))[RLHF Objective]: max⁡πθEx∼D, y∼πθ(⋅∣x) ⁣[r(x,y)]−β Ex∼D ⁣[DKL ⁣(πθ(y∣x) ∥ πref(y∣x))][Optimal Policy Mapping]: π∗(y∣x)=1Z(x)πref(y∣x)exp⁡ ⁣(1βr(x,y))  ⟹  r(x,y)=βlog⁡π∗(y∣x)πref(y∣x)+βlog⁡Z(x)[DPO Loss Function]: LDPO(πθ;πref)=−E(x,yw,yl)∼D[log⁡σ(βlog⁡πθ(yw∣x)πref(yw∣x)−βlog⁡πθ(yl∣x)πref(yl∣x))]\begin{aligned} & \text{[SFT Loss]: } \mathcal{L}_{\text{SFT}} = -\mathbb{E}_{(x,y) \sim \mathcal{D}}\!\left[\log \pi_\theta(y \mid x)\right] \\ & \text{[Bradley-Terry Preference]: } P(y_w \succ y_l \mid x) = \sigma\!\left(r(x, y_w) - r(x, y_l)\right) = \frac{\exp(r(x, y_w))}{\exp(r(x, y_w)) + \exp(r(x, y_l))} \\ & \text{[RLHF Objective]: } \max_{\pi_\theta} \mathbb{E}_{x \sim \mathcal{D},\, y \sim \pi_\theta(\cdot \mid x)}\!\left[r(x,y)\right] - \beta\,\mathbb{E}_{x \sim \mathcal{D}}\!\left[D_{\mathrm{KL}}\!\left(\pi_\theta(y \mid x) \,\Vert\, \pi_{\text{ref}}(y \mid x)\right)\right] \\ & \text{[Optimal Policy Mapping]: } \pi^*(y \mid x) = \frac{1}{Z(x)} \pi_{\text{ref}}(y \mid x) \exp\!\left(\frac{1}{\beta} r(x,y)\right) \implies r(x,y) = \beta \log \frac{\pi^*(y \mid x)}{\pi_{\text{ref}}(y \mid x)} + \beta \log Z(x) \\ & \text{[DPO Loss Function]: } \mathcal{L}_{\text{DPO}}(\pi_\theta; \pi_{\text{ref}}) = -\mathbb{E}_{(x, y_w, y_l) \sim \mathcal{D}} \left[ \log \sigma \left( \beta \log \frac{\pi_\theta(y_w \mid x)}{\pi_{\text{ref}}(y_w \mid x)} - \beta \log \frac{\pi_\theta(y_l \mid x)}{\pi_{\text{ref}}(y_l \mid x)} \right) \right] \end{aligned}

Follow-up 1: Explain the mathematical intuition behind DPO’s elimination of the Reward Model.

In standard RLHF, practitioners train a separate Reward Model to output a scalar score based on the Bradley-Terry preference framework. The policy model is then optimized using algorithms like Proximal Policy Optimization (PPO) to maximize this reward, constrained by a KL-divergence penalty to prevent it from deviating too far from the reference model. This requires constantly sampling new outputs from the policy during training and passing them through the reward network.

DPO’s mathematical insight is recognizing that the closed-form optimal solution to this specific RL objective can be algebraically inverted. By manipulating the equations, the unknown reward function is expressed entirely in terms of the log-ratio between the active policy probabilities (πθ\pi_\theta) and the frozen reference model (πref\pi_{\text{ref}}), scaled by the KL penalty parameter β\beta, plus an intractable partition term βlog⁡Z(x)\beta \log Z(x).

By substituting this reparameterized reward back into the Bradley-Terry preference difference r(x,yw)−r(x,yl)r(x, y_w) - r(x, y_l), the intractable partition function Z(x)Z(x) mathematically cancels out, replacing the explicit Reward Model with the implicit reward r^θ(x,y)=βlog⁡πθ(y∣x)πref(y∣x)\hat{r}_\theta(x,y) = \beta \log \frac{\pi_\theta(y \mid x)}{\pi_{\text{ref}}(y \mid x)}. The alignment objective is thereby transformed into a maximum likelihood estimation problem where the model simply increases the relative log-probability of the chosen response and decreases that of the rejected response.

⚠️ Limitations & Caveats

  • DPO heavily relies on the assumption that the Bradley-Terry model perfectly captures human preferences, which is a known approximation. It struggles to model non-transitive human preferences (e.g., A > B, B > C, but C > A).
  • Because DPO calculates loss over static log-probabilities rather than generating text dynamically, it lacks the ability to explore the state space and correct out-of-distribution errors.

Follow-up 2: How do standard RLHF (PPO) and DPO compare in terms of computational overhead and stability?

Traditional RLHF using PPO requires loading four distinct neural networks into memory simultaneously: the active Policy Model, the frozen Reference Model, the Reward Model, and the Value Network (Critic). This massive VRAM requirement forces heavy reliance on tensor parallelism and multi-node orchestration. Furthermore, PPO generates text dynamically during the training loop, which drastically increases the time-per-step and introduces high variance.

DPO reduces this architectural footprint by requiring only two models to be loaded: the active Policy Model and the frozen Reference Model. It operates strictly on offline data, meaning no online rollout generation occurs during the training loop. This allows DPO to utilize standard gradient descent over batches, making it highly stable and accessible to smaller engineering teams, though often at the cost of peak alignment performance on complex reasoning tasks.

Dimension Standard RLHF (PPO) Direct Preference Optimization (DPO)
Computational Cost High (~4 models in VRAM, active text generation) Moderate (~2 models in VRAM, no generation step)
Data Requirements Preference data for Reward Model, plus diverse, unlabelled prompts Large, static dataset of explicitly paired chosen/rejected responses
Known Failure Modes Reward hacking, mode collapse, extreme hyperparameter sensitivity Overfitting to static dataset, weaker out-of-distribution generalization

⚠️ Limitations & Caveats

  • Empirical evidence from recent alignment research suggests that while DPO is easier to train, PPO often yields superior performance on coding, mathematics, and complex reasoning tasks.
  • PPO’s active generation allows the model to receive granular feedback on its own specific, evolving distribution of errors, whereas DPO is entirely blind to any mistakes not explicitly present in its static training corpus.
View all →

Try keywords like RoPE, FlashAttention, DPO, or Blind 75.