Alignment & Post-Training
A base language model trained purely on next-token cross-entropy loss () is a statistical distribution simulator, not an aligned assistant. Given a prompt like “How do I fix a memory leak in C?”, a pre-trained base model is just as likely to continue with five more unanswered forum questions as it is to output a solution.
Post-training and alignment reshape the base distribution into a controllable policy through three distinct mathematical stages:
- Supervised Fine-Tuning (SFT): Behavioral cloning on curated
(prompt, response)demonstrations to establish formatting and instruction following, producing the reference anchor . - Preference Optimization (RLHF / DPO): Shifting probability mass away from plausible-sounding errors () and toward preferred completions () under a KL-divergence trust region.
- Reinforcement Learning with Verifiable Rewards (RLVR / GRPO): Training directly against deterministic math/code verifiers to induce multi-step chain-of-thought self-correction.
From Bradley-Terry Rewards to Closed-Form DPO
1. The Bradley-Terry Preference Model
Given a prompt and two candidate completions where human or verifier evaluation prefers , the Bradley-Terry model defines the probability of this pairwise preference via a latent scalar reward function :
2. The KL-Regularized RLHF Objective
In classical Reinforcement Learning from Human Feedback (Ouyang et al. 2022), we train a policy to maximize expected reward while penalizing reverse KL-divergence from the frozen reference policy :
3. Direct Preference Optimization (DPO) Derivation
Instead of optimizing this objective with unstable online Proximal Policy Optimization (PPO), Rafailov et al. (2023) observed that the KL-constrained maximization has an exact analytical solution :
where is the partition function. Solving for the reward algebraically yields:
When we substitute this expression into the Bradley-Terry preference formula , the intractable partition function cancels out identically, giving the closed-form DPO loss:
| Symbol / Objective | Mathematical Space | Geometric & Optimization Role |
|---|---|---|
| Active Policy & Reference Anchor: Autoregressive distribution of the aligned model anchored against the frozen Supervised Fine-Tuned (SFT) policy . | ||
| Bradley-Terry Preference Model: Maps the scalar reward difference between winning response and losing response through the logistic sigmoid . | ||
| Reverse KL-Divergence Penalty: Regularizer weighted by to prevent policy collapse and reward over-optimization. | ||
| Implicit Reward | Closed-Form Implicit Reward (Rafailov et al. 2023): Expresses the ground-truth reward function directly in terms of the optimal policy log-ratio, eliminating the separate reward model and PPO critic. | |
| Group Relative Advantage (GRPO, DeepSeek-R1): Computes token advantages from a group of sampled completions per prompt, cutting value-network VRAM by 50%. |
Post-Training Architecture Topology: 4-Model RLHF (PPO) vs. 2-Model DPO
Numerical Walkthrough: DPO Margin & Gradient Weighting
To see how DPO updates token probabilities without a reward model, consider a single preference pair with KL temperature :
Sequence Log-Probabilities under and :
- Winning response : ,
- Losing response : ,
Log-Ratio Rewards ():
Implicit Preference Margin & Loss:
- Margin
- Preference probability:
- DPO Loss:
Per-Example Gradient Weight: Taking the gradient with respect to :
Notice that the factor automatically scales the gradient in proportion to how strongly the current policy misranks the pair.
Interactive Reward Hacking & Goodhart Simulator
In online RL, the reward model is only an imperfect statistical proxy for true human preference . Gao et al. (2023) established that as policy drift grows, true utility follows an inverted-U curve:
Use the simulator below to observe how pushing past the optimal frontier causes the policy to game length and sycophancy biases:
KL-Regularized Alignment & Goodhart Reward Hacking Simulator
Adjust the KL-divergence penalty and policy drift to observe how over-optimizing an imperfect proxy reward causes true human utility to collapse.
Group Relative Policy Optimization (GRPO)
For mathematical and code reasoning (DeepSeek-R1), maintaining a separate Value Critic of the same size as the policy doubles GPU memory consumption. Group Relative Policy Optimization (GRPO) (Shao et al. 2024) eliminates the critic entirely by sampling a group of outputs from for each prompt and computing the baseline directly from the group’s reward statistics:
When paired with deterministic rule-based verifiers ( for exact math answer or passing unit tests), GRPO avoids neural reward model hacking while enabling emergent self-verification and backtracking.
Comparing Post-Training Algorithms
| Algorithm | Models in VRAM | Rollout Mode | Advantage / Margin Mechanism | Primary Failure Mode |
|---|---|---|---|---|
| RLHF (PPO) | 4 () | Online sampling | Generalized Advantage Estimation (GAE) via | Critic instability & high VRAM footprint |
| DPO | 2 () | Offline pairs | Closed-form log-ratio margin | Likelihood displacement on out-of-distribution tokens |
| SimPO | 1 ( only) | Offline pairs | Length-normalized average log-prob $\frac{\beta}{ | y |
| GRPO | 2 () | Online group () | Group z-score normalization | Zero gradient when all samples fail () |