RLHF against DPO#
| Factor | RLHF (PPO) | DPO |
|---|
| Models to train | 3: SFT, reward, policy | 1: policy only |
|---|
| Training loops | 3: SFT, RM, PPO | 2: SFT, DPO |
|---|
| Hyperparameters | lr, KL coeff, clip ratio, RM lr, epochs | lr, beta, epochs |
|---|
| Reward model | Separate training | Implicit in model probabilities |
|---|
| Algorithm | PPO, complex and unstable | Supervised learning, stable |
|---|
| Models in memory | 3-4 during PPO | 2: current and reference |
|---|
| Compute | Three loops | About one-third of RLHF |
|---|
| Data | Online loop with new ratings | Fixed preference dataset |
|---|
Use X when#
- DPO: 5,000-20,000 pairs, limited compute, or many dataset experiments.
- RLHF: large scale, multi-objective rewards, or an iterative online rating loop.
- SimPO: length bias is evident. It also drops the reference model.
- KTO: you only have unpaired good or bad labels.
- ORPO: you want one stage from the base model, with no SFT checkpoint.
- BPO: DPO logs show degraded chosen log-probs.
- IPO: preference strengths vary widely and DPO saturates.
RLHF pipeline#
One DPO epoch (capstone)#
DPO loss and reference freeze#
diff_w = logp_w_pol - logp_w_refchosen log-ratio
diff_l = logp_l_pol - logp_l_refrejected log-ratio
margin = diff_w - diff_limplicit reward gap over beta
z = beta * margin
loss = -F.logsigmoid(z)stable -log sigmoid
policy.load_state_dict(reference.state_dict())start from equal weights
for p in reference.parameters():
p.requires_grad = Falsereference never moves
target = 1.0 / (2.0 * beta) if beta > 0 else 0.0
loss = (margin - target) ** 2IPO variant
Reward model and KL reward (toy)#
p = sigmoid(r_pos - r_neg)Bradley-Terry P(chosen wins)
grad_scale = 1 - p
w[t] += lr * grad_scale * cchosen tokens up, rejected down
kl_term = kl(probs_new, probs_ref)
reward = rm_score - beta * kl_termKL-penalized reward
advs = [(r - mean_r) / sd_r for r in rewards]normalized advantages
ratio = math.exp(logp - log_pi_old)
clipped = (adv > 0 and ratio > 1 + eps) or (adv < 0 and ratio < 1 - eps)