Alignment & Post-Training

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:

  1. Supervised Fine-Tuning (SFT): Behavioral cloning on curated (prompt, response) demonstrations to establish formatting and instruction following, producing the reference anchor .
  2. Preference Optimization (RLHF / DPO): Shifting probability mass away from plausible-sounding errors () and toward preferred completions () under a KL-divergence trust region.
  3. 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 / ObjectiveMathematical SpaceGeometric & 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 RewardClosed-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

1. Online RLHF with PPO (4 Models in GPU HBM + Online Rollouts)Actor Policy πθTrainable (FP16)Ref Policy πrefFrozen KL AnchorReward Model rφFrozen ScorerValue Critic Vψ(GAE)Trainable Baseline2. Direct Preference Optimization — DPO (2 Models, Zero Reward/Critic Overhead)Policy πθ(yw, yl| x)Trainable Log-ProbReference πref(yw, yl| x)Precomputed Log-ProbImplicit Margin Δrθ−log σ(βΔlog(πθ/ πref))
Figure 1: Online PPO requires holding four multi-billion-parameter models in GPU memory simultaneously. By substituting the analytical solution into the Bradley-Terry loss, DPO optimizes the policy directly via binary cross-entropy over log-probability ratios.

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 :

  1. Sequence Log-Probabilities under and :

    • Winning response : ,
    • Losing response : ,
  2. Log-Ratio Rewards ():

  3. Implicit Preference Margin & Loss:

    • Margin
    • Preference probability:
    • DPO Loss:
  4. 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.

0.10
Drift DKL: 6.25 nats
KL Divergence DKL(πθ|| πref) (nats)ScoreProxy RproxyTrue Rgold
Proxy Reward Model Score +2.10
Trained classifier score (). Continues rising even when the policy exploits spurious formatting correlations.
True Human Utility +1.48 (Optimal Peak)
Actual response quality (). Collapses when drifts too far from .
DPO Implicit Gradient Weight 0.438
Policy Output Behavior: Concise, factual step-by-step derivation without sycophancy.
Sweet Spot (Aligned)
Policy Drift DKL:

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

AlgorithmModels in VRAMRollout ModeAdvantage / Margin MechanismPrimary Failure Mode
RLHF (PPO)4 ()Online samplingGeneralized Advantage Estimation (GAE) via Critic instability & high VRAM footprint
DPO2 ()Offline pairsClosed-form log-ratio margin Likelihood displacement on out-of-distribution tokens
SimPO1 ( only)Offline pairsLength-normalized average log-prob $\frac{\beta}{y
GRPO2 ()Online group ()Group z-score normalization Zero gradient when all samples fail ()

Key Papers & References