Chapter 6 · Reward Modeling and RLHF¶
6.1 What is the overall RLHF pipeline? ★★¶
One-sentence answer
RLHF, as exemplified by InstructGPT, has three stages: first, SFT on human demonstrations yields an initial policy that answers instructions; second, human rankings of several responses train a reward model that turns human preference into a scalar score for any response; finally, PPO makes the policy maximize the reward model's score, while a KL penalty keeps it close to the SFT model.
I will address three aspects: the inputs and outputs of each stage, why the pipeline is split this way, and what it achieves and costs.
(1) The three stages produce, in turn, an initial policy, a reward model and the final policy.
- SFT: the input is prompts with demonstrations written by labelers; the pretrained model is fine-tuned with the standard next-token loss, producing the SFT model \(\pi^{\text{SFT}}\). It teaches the model the dialogue format and basic instruction following, and it is the starting point for the next two stages (see Chapter 5).
- Reward model training: for each prompt, the SFT model generates several responses, which labelers rank from best to worst; these rankings train a reward model \(r_\phi\) that takes "prompt + response" and outputs a scalar representing how much humans prefer it (training is covered in 6.2).
- RL: the input is prompts only, with no labels. The policy generates responses to the prompts, the reward model scores them, and PPO updates the policy; a KL penalty relative to the SFT model keeps the policy from drifting too far in pursuit of reward (see 6.3 and 6.4). The output is the final policy \(\pi^{\text{RL}}\).
(2) The reward model is trained before RL because humans find "judging" much easier than "demonstrating", and RL needs a function that can score responses at any time.
SFT can only imitate the responses labelers write, so the model's ceiling is bounded by the labelers' writing ability, and it only ever sees "good demonstrations" without learning what is bad. By contrast, asking people which of two responses is better is cheaper and more consistent, and it provides useful signal even on responses beyond the labelers' own writing ability. However, human comparisons cover only a limited set of samples, whereas during RL the policy keeps generating new responses, each of which needs a score. Therefore the preferences must first be "distilled" into a reward model, which then stands in for humans during RL. This also explains why the RL stage needs only prompts: the policy generates the responses itself, and the reward model judges them.
(3) The effect was striking, but it also introduced an "alignment tax".
InstructGPT's human evaluation (Ouyang et al. 2022) showed that the 1.3B InstructGPT was preferred to the 175B GPT-3, while also being more truthful and less toxic. This shows that for "being a good assistant", the bottleneck is often not the model's capability but whether the model has been aligned with the behavior people want. However, after RLHF the model regressed on some public NLP benchmarks, the so-called alignment tax; to address this, the authors mixed a language-modeling loss on pretraining data into the RL objective, calling the result PPO-ptx.
In summary: the core idea of RLHF is to first learn human preferences as a reward model, and then optimize that reward with RL under a KL constraint; the later DPO and RLVR both simplify this pipeline by removing parts of it (see Chapter 7 and Chapter 8).
Going deeper: history, InstructGPT's data scale, and PPO-ptx
(1) RLHF did not begin with language models.
Today's form of RLHF traces mainly to Christiano et al. (2017): people chose the better of two short video clips of an agent's behavior (simulated robot locomotion, Atari games), these comparisons trained a reward function, and RL then optimized it. Ziegler et al. (2019) and Stiennon et al. (2020) applied it to language models; on summarization, the RLHF model beat much larger supervised fine-tuned models. InstructGPT extended it to general instruction following and established the three-stage recipe later carried over to ChatGPT.
(2) None of InstructGPT's three stages used much data.
| Stage | Data | Scale | Output |
|---|---|---|---|
| SFT | Prompts + labeler demonstrations | About 13k prompts | SFT model |
| Reward model | Prompts + \(K\) responses from the SFT model (\(K\) from 4 to 9) + human rankings | About 33k prompts | 6B reward model |
| RL (PPO) | Prompts only, no labels | About 31k prompts | Final policy |
The prompts came mainly from real user requests on the OpenAI API, with some written by labelers.
(3) PPO-ptx adds a pretraining loss to the RL objective to mitigate the alignment tax.
This follows the notation of the InstructGPT paper: \(\pi_\phi^{\text{RL}}\) is the RL policy with parameters \(\phi\), \(\pi^{\text{SFT}}\) is the SFT model, and \(r_\theta\) is the reward model with parameters \(\theta\) (the rest of this chapter uses \(\theta\) for the policy and \(\phi\) for the reward model). \(D_{\pi_\phi^{\text{RL}}}\) denotes the distribution obtained by drawing \(x\) from the prompt set and then generating \(y\) with the current policy. The first term is "reward minus a KL penalty", with \(\beta\) controlling the penalty strength; the second term is the log-likelihood on the pretraining distribution \(D_{\text{pretrain}}\), weighted by \(\gamma\); with \(\gamma=0\) it is plain PPO. Adding the second term amounts to continuing a small amount of pretraining during RL, so that the model does not forget its original abilities.
Follow-up questions
Follow-up 1: Why could the 1.3B InstructGPT beat the 175B GPT-3?
Because the human evaluation measured "whether the response follows the user's intent", which is exactly what GPT-3 lacked and RLHF supplied. GPT-3 had only been pretrained; its objective was to continue internet text, not to answer questions, so it often missed the point, fabricated content or ignored instructions. RLHF did not add much knowledge to the model; rather, it steered existing capabilities toward the behavior people want. Therefore a much smaller but well-aligned model could beat a large unaligned one at "being an assistant".
Follow-up 2: SFT already makes the model follow instructions, so why is an RL stage needed?
Because SFT can only imitate demonstrations, whereas RL can use comparison signals and learn on the model's own responses.
- Negative signal: SFT only tells the model what a good response is, whereas preference comparisons also tell it what a worse response is.
- Learning on its own samples: in RL the samples are generated by the policy itself, so the model receives feedback on the mistakes it actually makes; SFT always trains on text written by others.
- A ceiling not bounded by demonstrations: judging is easier than demonstrating, so the ceiling of RL is not limited by the labelers' writing ability.
Follow-up 3: How does the pretraining loss in PPO-ptx differ from the KL penalty?
Both serve to prevent forgetting, but they act on different distributions. The KL penalty acts on the policy's own responses, keeping it close to the SFT model, but it does not directly guarantee that the abilities underlying benchmarks such as reading comprehension or translation are preserved; the pretraining loss acts on the pretraining corpus and directly maintains language-modeling ability. InstructGPT reported that adding the pretraining loss substantially reduced these benchmark regressions without materially hurting labeler preference scores.
Common mistakes
- Do not say the RL stage needs labeled data: The RL stage needs only prompts; the policy generates the responses and the reward model scores them.
- Do not say the reward model is trained alongside RL: In InstructGPT the reward model is fully trained before RL and kept frozen during it; only iterative RLHF retrains it on new data between rounds of RL.
- Do not say the KL penalty is relative to the pretrained model: The KL penalty is usually computed relative to the SFT model, i.e. the reference model.
6.2 How is a reward model trained, and what is the Bradley–Terry model? ★★¶
One-sentence answer
A reward model is usually a language model whose output layer is replaced by a scalar head, trained on human preference pairs. Training rests on the Bradley–Terry model, which assumes that the probability of "response A beats response B" equals the sigmoid of the difference in their rewards; maximum likelihood on the preference data then gives a logistic loss that pushes the chosen response's score above the rejected one's.
I will address three aspects: why the data uses pairwise comparisons, the Bradley–Terry model and the loss, and the reward model's architecture together with the properties this loss implies.
(1) Preference data is usually collected as pairwise comparisons rather than absolute scores.
People find it hard to give well-calibrated absolute scores: the same response might receive a 7 from one labeler and a 5 from another, and one person's standard drifts over time. By contrast, a relative judgment such as "which is better, A or B" is much more stable, and labelers agree with each other more. Therefore a preference example is usually a triple \((x, y_w, y_l)\): \(x\) is the prompt, \(y_w\) is the preferred response (chosen), and \(y_l\) is the dispreferred response (rejected). RL, however, needs a function that can score any response, so the question becomes how to learn a scalar reward from comparisons.
(2) The Bradley–Terry model links comparison probabilities to reward differences, and maximum likelihood gives the reward model loss.
The Bradley–Terry (BT) model was first used to rank sports teams and chess players (the Elo rating is closely related). It assumes that each player has a latent "strength", and the probability that one wins depends only on the difference between their strengths. In RLHF, the players are different responses to the same prompt, and the strength is the reward \(r(x,y)\):
Here \(\sigma(z)=1/(1+e^{-z})\) is the sigmoid function, and the second equality comes from dividing numerator and denominator by \(\exp(r(x,y_w))\). A difference of 0 gives probability 0.5, and the larger the difference, the more certain it is that \(y_w\) is better. Next, the reward is represented by a neural network \(r_\phi\) with parameters \(\phi\), and maximum likelihood on the preference dataset \(\mathcal{D}\), after taking the negative log, gives:
It is essentially binary logistic regression, except that what is being classified is "the difference of two rewards": the chosen score must exceed the rejected score.
(3) The reward model is a language model with a scalar head, and its output has only relative meaning.
Architecturally, the reward model is usually initialized from the SFT model, and the LM head that maps to the whole vocabulary is replaced by a linear layer that outputs a scalar; it takes "prompt + response" and reads the reward from the hidden state of the last token (usually EOS), because under causal attention only the last position has seen the entire sequence. It is initialized from the SFT model because judging a response requires knowledge comparable to the policy's; otherwise the reward model may fail to distinguish a correct answer from a confident-sounding fabrication. Moreover, because the loss depends only on reward differences, adding the same constant to every response's reward (or indeed any function \(c(x)\) that depends only on the prompt) leaves the loss unchanged. Therefore the absolute value of the reward is meaningless, scores cannot be compared directly across prompts, and the reward usually has to be normalized before RL.
In summary: reward model training is logistic regression on "chosen beats rejected" under the Bradley–Terry assumption; what it learns is a preference scorer that is reliable only in a relative sense.
Going deeper: the gradient, ranking data, margins and the accuracy ceiling
(1) The loss automatically concentrates its effort on wrongly ranked pairs.
Let \(\Delta=r_\phi(x,y_w)-r_\phi(x,y_l)\). Then
If a pair is already ranked correctly by a wide margin, \(\sigma(\Delta)\to 1\) and the gradient is near 0; if it is ranked wrongly (\(\Delta<0\)), the gradient's magnitude exceeds 0.5 and approaches 1 the more wrongly it is ranked.
(2) \(K\) ranked responses split into \(\binom{K}{2}\) pairs, but they must be computed within one batch element.
InstructGPT had labelers rank \(K\) responses at once; one ranking splits into \(\binom{K}{2}\) comparison pairs, and the loss averages over them:
All pairs from the same prompt are computed together as one batch element. This has two benefits: each response needs only one forward pass to take part in every pair that contains it; and if the pairs were shuffled into independent samples, each response would be used in \(K-1\) updates within one epoch, which the authors found made the reward model overfit within a single epoch.
(3) Llama 2 adds a margin tied to preference strength to the loss.
\(y_c\) and \(y_r\) are the chosen and rejected responses, and \(m(\text{rating})\) is a discrete margin determined by the preference strength the labeler gave (e.g. "significantly better", "slightly better"): the clearer the preference, the larger the required score gap. Llama 2 reported that this improved reward model accuracy, especially on pairs with a clear difference (Touvron et al. 2023). Llama 2 also trained separate helpfulness and safety reward models to handle the conflict between helpfulness and safety.
(4) The accuracy ceiling is set by inter-labeler agreement.
| Metric (InstructGPT, Ouyang et al. 2022) | Value |
|---|---|
| Agreement among training labelers | About 73% |
| Agreement among held-out labelers | About 77% |
| 6B reward model accuracy on training labelers' preferences | About 72% |
| 6B reward model accuracy on held-out labelers' preferences | About 70% |
Since roughly one comparison in four is disputed even between people, reward model accuracy can hardly go much beyond this level. Moreover, reward models overfit easily and are usually trained for only one epoch.
Follow-up questions
Follow-up 1: Why is the absolute value of the reward meaningless, and what does that imply for RL?
Because the loss only constrains the score gap between two responses to the same prompt, the reward is determined only in a relative sense. Adding a prompt-only function \(c(x)\) to every response leaves the BT probability and the loss unchanged, so a reward model output of 3.2 means nothing by itself. In RL, an overall shift in reward becomes entangled with the scale of the KL penalty and affects optimization, so the reward is usually normalized first. For example, InstructGPT added a bias so that labeler demonstrations have a mean reward of 0. Notably, this "shift invariance" is exactly why the partition function cancels in the DPO derivation (see Chapter 7).
Follow-up 2: What are the limitations of the Bradley–Terry model?
It assumes preference can be fully described by one scalar and is transitive. Real human preferences, however, are multi-dimensional, with helpfulness, accuracy, brevity and safety in conflict; different people prefer different things, and preferences are sometimes not even transitive (A beats B and B beats C, yet C beats A). A single scalar reward can only compress all this into one number that holds on average. Moreover, if a pair's preference always holds in the data, minimizing the loss keeps widening the gap and makes the reward model overconfident, which is one reason early stopping is needed.
Follow-up 3: Why initialize the reward model from the SFT model, and should it be larger or smaller than the policy?
Initializing from the SFT model gives the reward model knowledge comparable to the policy's; in terms of size, larger is harder for the policy to exploit. If the policy knows a fact the reward model does not, the reward model may prefer a confident-sounding wrong answer. Gao et al. (2022) found that the larger the proxy reward model, the later over-optimization sets in (see 6.7). A large reward model has costs too, however: InstructGPT used a 6B rather than a 175B reward model, partly to save compute and partly because 175B reward model training was unstable, making it unsuitable for initializing the value model.
Follow-up 4: Does a more accurate reward model always yield a better policy?
Not necessarily. Held-out accuracy measures how well the reward model ranks the SFT model's responses, whereas RL cares about whether it is reliable on the ever-changing responses the policy actually generates, especially whether it gets exploited in the high-score region. Therefore, beyond accuracy and benchmarks such as RewardBench (Lambert et al. 2024), a reward model must ultimately be judged by the policy it trains. (Besides scalar reward models there are generative reward models, which write a critique before scoring, and process reward models, which score each step of a reasoning trace; see Chapter 8.)
Common mistakes
- Do not describe the BT loss as regression on the reward itself: It constrains only the gap between the chosen and rejected responses; it is a logistic loss on the difference.
- Do not compare reward scores across prompts: The reward has relative meaning only within a single prompt.
- Do not train the reward model for many epochs: It overfits easily and is usually trained for only one epoch.
- Do not ignore label noise: Inter-labeler agreement of about 73% sets the ceiling on reward model accuracy.
6.3 What is the RLHF objective, and what does the KL term do? ★★¶
One-sentence answer
The RLHF objective maximizes the reward model's expected score on the policy's own responses, minus \(\beta\) times the KL divergence between the current policy and a frozen reference model (usually the SFT model). The KL term keeps the policy in the region where the reward model can still be trusted, which prevents reward hacking while preserving the original abilities and output diversity.
I will address three aspects: the objective itself, what the KL term does, and the choice of the coefficient \(\beta\) and of the KL direction.
(1) The objective is "raise the reward as much as possible without drifting too far from the reference model".
The first term is the expected reward: take a prompt \(x\) from the prompt set \(\mathcal{D}\), let the current policy \(\pi_\theta\) generate a response \(y\), and score it with the reward model \(r_\phi\). The second term is the KL penalty: \(\pi_{\text{ref}}\) is the frozen reference model, usually the SFT model; the KL divergence measures how far the current policy is from it; and \(\beta>0\) is the penalty coefficient. Since a response's probability is the product of per-token conditional probabilities, the sequence-level KL splits into a sum of per-token log-probability ratios, so the KL penalty can be applied at every token; this is exactly where the per-token reward in PPO implementations comes from (see "Going deeper" for this question).
(2) The KL term serves three purposes.
- Preventing reward hacking: the reward model is reliable only near the distribution it was trained on (the SFT model's responses). Without a constraint, the optimizer pushes the policy toward regions where the reward model is wrong and gives inflated scores, which amounts to an adversarial attack on the reward model. The KL term keeps the policy within the range where the reward model can still be trusted, acting as a "trust region".
- Preserving the original abilities and fluency: the reference model has gone through pretraining and SFT, so it is fluent and knowledgeable; the farther the policy moves from it, the more easily it loses these abilities.
- Preserving diversity and preventing mode collapse: if only the reward is maximized, the optimum puts all probability on the single highest-reward response. Since the KL can be written as \(\mathbb{D}_{\text{KL}}[\pi_\theta\|\pi_{\text{ref}}]=-\mathcal{H}(\pi_\theta)-\mathbb{E}_{\pi_\theta}[\log\pi_{\text{ref}}]\), where \(\mathcal{H}\) is the policy's entropy, penalizing the KL amounts to rewarding entropy and keeps the distribution somewhat spread out.
(3) \(\beta\) sets where the trade-off lies, and the reverse KL confines the policy to the reference model's support.
With \(\beta\) too large, the policy barely moves and RLHF learns nothing; with \(\beta\) too small, the reward rises quickly but the policy soon starts exploiting the reward model's loopholes. In practice the KL is therefore often treated as an "optimization budget" and monitored throughout training. RLHF uses the reverse KL \(\mathbb{D}_{\text{KL}}[\pi_\theta\|\pi_{\text{ref}}]\), with the expectation computed on the policy's own samples. It is mode-seeking: if the policy puts probability where the reference model considers almost impossible, \(\log(\pi_\theta/\pi_{\text{ref}})\) is huge and the penalty is heavy; conversely, if the policy drops some of the reference model's modes, the penalty is small. Therefore the policy can become more concentrated, but it will not wander to places the reference model would never generate. In addition, the reverse KL needs only the policy's own samples, and RL samples from the policy anyway, so it comes essentially for free.
In summary: the RLHF objective is KL-regularized reward maximization, and the KL term essentially puts a trust region around an imperfect reward model.
Going deeper: the per-token decomposition, the closed-form optimum, and setting \(\beta\)
(1) The sequence-level KL splits into per-token terms and combines with the reward into a per-token reward.
Here \(T\) is the response length, \(y_t\) is the \(t\)-th token, and \(y_{<t}\) is all tokens before it. InstructGPT-style implementations accordingly define a per-token reward:
\(\mathbf{1}[t=T]\) is the indicator function, equal to 1 only at the last token. In other words, every token receives a KL penalty, while the reward model's score is added only at the last token. Summing all \(r_t\) gives exactly the per-sample "reward minus \(\beta\) times the sum of log-probability ratios". So the reward consists of a sparse signal that appears only at the end, plus per-token KL shaping; this is precisely why PPO needs a value model for credit assignment (see 6.5). (The per-token log-probability ratio folded into the reward is the simplest unbiased estimator of the KL and can be negative at a single token; GRPO instead puts the KL into the loss as a separate term and uses a different estimator; see Chapter 8.)
(2) The KL-regularized objective has a closed-form optimum.
\(Z(x)\) is the partition function that normalizes \(\pi^*\). The optimal policy is the reference model reweighted by the exponentiated reward: the smaller \(\beta\), the more it favors high-reward responses; as \(\beta\to\infty\) it falls back to the reference model. However, \(Z(x)\) requires a sum over all possible responses and cannot be computed, so RLHF can only approximate \(\pi^*\) with RL. This result is exactly DPO's starting point; the full derivation is in Chapter 7.
(3) Setting \(\beta\): adaptive control and the "KL budget".
Early work (Ziegler et al. 2019) used an adaptive controller to adjust \(\beta\) dynamically so that the actual KL stays near a target value. Gao et al. (2022) found that in their experiments the KL penalty did not improve the curve of "true quality versus KL distance" itself; its effect was closer to early stopping, halting training at a smaller KL (the authors caution that this conclusion may be sensitive to hyperparameters).
Follow-up questions
Follow-up 1: What happens if the KL constraint is removed?
The reward model's score keeps rising, but true quality first rises and then falls, ending in reward hacking and degeneration. The policy is pushed into the reward model's loopholes: responses become verbose, sycophantic and templated, the KL grows rapidly, and in extreme cases the policy generates text that the reward model scores highly but people cannot make sense of; meanwhile output diversity drops and original abilities are damaged.
Follow-up 2: Why does RLHF use the reverse KL rather than the forward KL?
Because the reverse KL needs only samples from the policy and is mode-seeking. The forward KL \(\mathbb{D}_{\text{KL}}[\pi_{\text{ref}}\|\pi_\theta]\) must be computed on samples from the reference model, which does not fit the sampling loop of RL; moreover, it is mode-covering and forces the policy to cover all of the reference model's modes, which conflicts with the goal of concentrating the policy on good responses. The reverse KL instead lets the policy contract onto a subset of the reference model's high-quality modes while forbidding it from leaving the reference model's support.
Follow-up 3: What happens if \(\beta\) is too large or too small?
With \(\beta\) too large the policy barely moves; with \(\beta\) too small the policy quickly exploits the reward model. The former means RLHF learns no preferences; the latter means the reward is inflated while true quality falls. In practice one monitors the KL, the reward and human or strong-model evaluations during training, and adjusts \(\beta\) or decides when to stop accordingly.
Common mistakes
- Do not say the KL penalty is relative to the previous step's policy: The KL in the RLHF objective is computed relative to the frozen reference model (the SFT model); the constraint relative to the previous round's policy \(\pi_{\theta_{\text{old}}}\) comes from PPO's clipping (see 6.4).
- Do not say the KL term is only for training stability: Its primary role is to prevent the policy from exploiting the reward model's loopholes.
- Do not mix up the properties of the reverse and forward KL: The reverse KL \(\mathbb{D}_{\text{KL}}[\pi_\theta\|\pi_{\text{ref}}]\) is mode-seeking; the forward KL is mode-covering.
6.4 How does PPO work? ★★★¶
One-sentence answer
PPO is a policy gradient method: it weights each token's log-probability gradient by the advantage (how much better an action is than the average in that state), raising the probability of good actions and lowering that of bad ones. To reuse each expensive batch of rollouts several times, it corrects for the difference between the new and old policies with an importance ratio and clips that ratio to \([1-\epsilon,1+\epsilon]\), forming a cheap trust region; the advantage is estimated by a separately trained value network together with GAE.
I will address four aspects: the basic form of the policy gradient, why the importance ratio is needed, how clipping limits the size of updates, and where the advantage and the value network come from.
(1) The policy gradient is essentially SFT weighted by the advantage.
First, cast text generation as a Markov decision process: the state \(s_t=(x,y_{<t})\) is the prompt plus what has been generated so far, the action \(a_t=y_t\) is the next token, the policy \(\pi_\theta(a_t\mid s_t)\) is simply the language model's next-token distribution, and the transition is deterministic (append the new token). We want to maximize the expected return \(J(\theta)\), and the policy gradient is:
Here \(\tau\) is a trajectory generated by the policy (i.e. one complete response), and \(\hat{A}_t\) is the advantage estimate at step \(t\). \(\nabla_\theta\log\pi_\theta(a_t\mid s_t)\) is exactly the SFT gradient direction that raises this token's probability, except that it is now multiplied by the weight \(\hat{A}_t\): if the action was better than expected (\(\hat{A}_t>0\)), its probability is raised; if worse, it is lowered; and the better it was, the bigger the adjustment. The advantage is used instead of the raw return because subtracting a baseline that depends only on the state introduces no bias yet greatly reduces variance.
(2) The importance ratio lets one batch of rollouts serve several gradient updates.
For LLMs, the rollout (autoregressive generation) is the most expensive step, so we want each batch of data to serve several epochs and minibatches of updates rather than being discarded after one update. After the first update, however, the policy has already changed, and the data in hand comes from the old policy \(\pi_{\theta_{\text{old}}}\). Importance sampling corrects for this: reweight each sample by the ratio
and the gradient of the objective \(\mathbb{E}_{a_t\sim\pi_{\theta_{\text{old}}}}[\rho_t(\theta)\hat{A}_t]\) at \(\theta=\theta_{\text{old}}\) equals the policy gradient exactly.
(3) Clipping together with the min forms a cheap trust region.
When the new policy is far from the old one, the importance weights have large variance, and \(\hat{A}_t\), having been estimated under the old policy, is stale; if the optimizer is allowed to follow this objective freely, it can easily take too large a step and wreck the policy, and in RL, once the policy gets worse, the data it collects gets worse too, which is hard to recover from. TRPO limits each step with a KL constraint but requires second-order optimization; PPO (Schulman et al. 2017) instead uses a much simpler clipped objective:
\(\epsilon\) is usually 0.2. For a good action (\(\hat{A}_t>0\)), once \(\rho_t\) exceeds \(1+\epsilon\), the min selects the clipped constant term, the gradient becomes 0, and its probability is no longer pushed up; likewise for a bad action, once \(\rho_t\) falls below \(1-\epsilon\), it is no longer pushed down. The min makes the objective a pessimistic lower bound on the unclipped objective: clipping only removes the incentive to "go too far in the favorable direction", and never prevents "correcting a move in the wrong direction".
(4) The advantage is estimated by a separately trained value network.
The advantage is defined as \(A(s_t,a_t)=Q(s_t,a_t)-V(s_t)\), how much better this action is than the average in this state, where \(Q\) is the expected return of taking this action and then following the policy, and \(V\) is the expected return of following the policy; therefore \(V(s_t)\) must be estimated. PPO trains an additional value network (critic) \(V_\psi\) for this purpose: in RLHF it has the same architecture as the reward model but outputs a scalar at every token position, predicting "how much return will eventually be obtained from the current prefix", and it is trained with a regression loss. With \(V_\psi\), GAE then combines per-token TD errors into the advantage (see 6.5). Since in RLHF the real reward appears only at the end of the response, whether an earlier token was good or bad is judged almost entirely by the value network, so the quality of the critic is crucial to PPO.
In summary: PPO = policy gradient (advantage-weighted log-likelihood) + importance ratio (reusing data) + clipping (limiting each update) + value network (estimating the advantage).
Going deeper: deriving the policy gradient, a case analysis of clipping, and the full loss
(1) Deriving the policy gradient: the log-derivative trick, plus the fact that subtracting a baseline adds no bias.
\(R(\tau)\) is the return of the whole trajectory, and \(p_\theta(\tau)\) is the trajectory's probability. The first step uses \(\nabla_\theta p_\theta=p_\theta\nabla_\theta\log p_\theta\), so we only need to sample from the policy rather than differentiate through sampling; the second step holds because the transitions in \(p_\theta(\tau)\) are deterministic and independent of \(\theta\), leaving only the sum of the policy's per-step log-probabilities. Using \(R(\tau)\), or the return \(G_t\) from step \(t\) onward, directly as the weight gives REINFORCE, which is unbiased but has very high variance: the randomness of the whole response enters every token's weight, and if all rewards are positive, every action's probability goes up, just by different amounts. Subtracting a state-only baseline \(b(s_t)\) introduces no bias, because
Taking \(b(s_t)=V(s_t)\) turns the weight into the advantage.
(2) A case analysis of the clipped objective.
| Sign of the advantage | Ratio region | Term selected by the min | Gradient |
|---|---|---|---|
| \(\hat{A}_t>0\) | \(\rho_t\le 1+\epsilon\) | \(\rho_t\hat{A}_t\) | Pushes \(\rho_t\) up |
| \(\hat{A}_t>0\) | \(\rho_t>1+\epsilon\) | \((1+\epsilon)\hat{A}_t\) (constant) | Zero: stop increasing |
| \(\hat{A}_t<0\) | \(\rho_t\ge 1-\epsilon\) | \(\rho_t\hat{A}_t\) | Pushes \(\rho_t\) down |
| \(\hat{A}_t<0\) | \(\rho_t<1-\epsilon\) | \((1-\epsilon)\hat{A}_t\) (constant) | Zero: stop decreasing |
If \(\hat{A}_t>0\) but \(\rho_t\) has instead fallen below \(1-\epsilon\) (the good action's probability was accidentally lowered), the unclipped term \(\rho_t\hat{A}_t\) is smaller, the min selects it, and the gradient is still there to pull the probability back. This is what the min does.
(3) The full loss contains a policy term, a value term and an optional entropy term.
\(c_1\) and \(c_2\) are weighting coefficients; \(\hat{R}_t=\hat{A}_t+V_{\psi_{\text{old}}}(s_t)\) is the return target obtained by adding the advantage to the old value; \(\mathcal{H}\) is the policy's entropy. In RLHF the entropy term is often dropped, because the KL penalty already plays a similar role. Common implementation details also include standardizing (whitening) the advantages within the batch and clipping the value update as well.
Follow-up questions
Follow-up 1: Is PPO's clipping a hard constraint?
No. A clipped token merely stops contributing gradient, but parameters are shared, so updates from other tokens can still push its ratio outside \([1-\epsilon,1+\epsilon]\). In practice, therefore, one also monitors the fraction of tokens where clipping is active (clipfrac) and the KL between the old and new policies, and if necessary reduces the number of epochs per batch or ends the current round of updates early.
Follow-up 2: How does PPO relate to TRPO?
Both aim to limit the size of each policy update, but they implement it differently. TRPO (Schulman et al. 2015a) maximizes a surrogate objective subject to a threshold on the KL between the old and new policies, which requires second-order methods such as conjugate gradient; it is complex to implement and hard to integrate with large-model training frameworks. PPO approximates the same effect with first-order optimization plus clipping; it is simple and scales easily, which is why it became the default choice for RLHF.
Follow-up 3: What happens if you skip clipping and simply run several epochs on the same batch?
The policy overfits the advantages given by that batch, and the updates become too large. The importance ratio can grow without bound, so the optimizer keeps raising the probability of a few high-advantage tokens, even though those advantages were estimated under the old policy and are no longer accurate. The usual result is policy collapse and degenerate generations. Updating only once per batch (strictly on-policy) avoids this problem but wastes expensive rollouts.
Follow-up 4: How does \(\pi_{\theta_{\text{old}}}\) in PPO differ from \(\pi_{\text{ref}}\) in the RLHF objective?
\(\pi_{\theta_{\text{old}}}\) is the policy at the time of the current rollout and is updated every round; \(\pi_{\text{ref}}\) is the frozen SFT model and never changes during training. The former limits how far each step goes, via clipping, which is a stabilization measure at the optimization level; the latter limits how far the policy goes in total, via the KL penalty, which is a regularizer at the level of the objective. They play different roles and must not be confused.
Common mistakes
- Do not say the importance ratio is computed relative to the reference model: The denominator of \(\rho_t\) is the old policy \(\pi_{\theta_{\text{old}}}\) used for the rollout, not the SFT model.
- Do not say clipping blocks all large changes: Clipping only removes the incentive to keep pushing in the favorable direction; for updates in the wrong direction, the min still keeps the gradient.
- Do not equate the advantage with the reward: The advantage is a difference relative to a baseline and can be negative; an action can have a negative advantage even when the reward is positive.
- Do not call PPO an off-policy algorithm: It performs only a few updates on each round's rollout data and uses the importance ratio to correct for slight policy differences, so it remains essentially an on-policy method.
6.5 What is GAE, and how does λ trade off bias and variance? ★★¶
One-sentence answer
GAE (generalized advantage estimation) is an exponentially weighted average of advantage estimates over different numbers of steps, equivalent to summing the per-step TD errors \(\delta_t\) discounted by \((\gamma\lambda)^l\). With \(\lambda=0\) it looks one step ahead and has the lowest variance, but is biased if the value is inaccurate; with \(\lambda=1\) it equals the Monte Carlo return minus a baseline, which is unbiased but has the highest variance; intermediate values of \(\lambda\) trade off between the two.
I will address three aspects: what the TD error is, how GAE combines multi-step estimates, and how \(\lambda\) controls bias and variance.
(1) The TD error is the most short-sighted, one-step estimate of the advantage.
Here \(r_t\) is the reward received at step \(t\), \(\gamma\) is the discount factor, and \(V\) is the state value given by the value network. \(\delta_t\) means: the reward just received plus the value of the new state, minus what was expected of the current state, i.e. "how much better this step went than expected". It uses only one real reward and relies entirely on \(V\)'s predictions for the rest.
(2) GAE is an exponentially weighted average of all \(n\)-step estimates, which simplifies to a discounted sum of TD errors.
Looking more steps ahead gives a family of \(n\)-step estimates: the 1-step estimate is \(\delta_t\); the 2-step estimate is \(r_t+\gamma r_{t+1}+\gamma^2V(s_{t+2})-V(s_t)=\delta_t+\gamma\delta_{t+1}\); and looking all the way to the end gives the Monte Carlo return minus \(V(s_t)\). GAE (Schulman et al. 2015b) takes an exponentially weighted average of these estimates with weights \((1-\lambda)\lambda^{n-1}\), which simplifies to:
Here \(T\) is the response length, and the value after the response ends is taken to be 0. In practice it is computed in one backward pass from the end of the sequence, using the recursion on the right.
(3) \(\lambda\) sets the balance between "trust real rewards nearby" and "trust value predictions far away".
- \(\lambda=0\): \(\hat{A}_t=\delta_t\) uses only one real reward, so variance is very low; but if \(V\) is inaccurate (as it often is early in training), the estimate is biased.
- \(\lambda=1\): \(\hat{A}_t=\sum_l\gamma^l r_{t+l}-V(s_t)\), the Monte Carlo return minus a baseline. Here \(V\) serves only as a baseline and introduces no bias; but the estimate accumulates the randomness of every later token, so variance is high.
- \(0<\lambda<1\): a trade-off between the two; the larger \(\lambda\), the closer to the Monte Carlo estimate, with smaller bias and larger variance.
RLHF for LLMs commonly uses \(\gamma=1\) and \(\lambda=0.95\). \(\gamma=1\) is chosen because responses have finite length, and the final reward should not be discounted merely because a response is long.
In summary: GAE uses a single parameter \(\lambda\) to interpolate continuously between a low-variance estimate that relies on the critic and an unbiased estimate that relies on sampling.
Going deeper: deriving the weights, and credit assignment in RLHF
(1) Why the exponentially weighted average simplifies to \(\sum(\gamma\lambda)^l\delta_{t+l}\).
The \(n\)-step estimate can be written as \(\hat{A}_t^{(n)}=\sum_{l=0}^{n-1}\gamma^l\delta_{t+l}\) (the intermediate \(V\) terms of adjacent TD errors cancel). So \(\delta_{t+l}\) appears in every estimate with \(n>l\), and its total weight in the weighted average is
This gives the GAE expression.
(2) In RLHF, the farther a token is from the end, the more it depends on the value network.
Under the per-token reward from 6.3, the reward model's score appears only at the last token, and earlier tokens receive only the KL penalty. So for an early token, its advantage comes mainly from how \(V\) changes around it: if \(V\) rises noticeably after a token, that token made things better and receives a positive advantage. This is how PPO solves credit assignment, and why the critic is hard to learn yet indispensable.
(3) Initializing and training the value network.
InstructGPT initialized the value network from the reward model, because the reward model can already judge text quality and already outputs a scalar, which is much closer to the target than a random initialization; if the critic gave random values at first, the advantages would be pure noise and early policy updates would be led astray. The value network regresses onto the target \(\hat{R}_t=\hat{A}_t+V_{\psi_{\text{old}}}(s_t)\) (see 6.4).
Follow-up questions
Follow-up 1: Why is \(\lambda=1\) unbiased while \(\lambda=0\) is biased?
Because with \(\lambda=1\), \(V\) appears only as a baseline, whereas with \(\lambda=0\), \(V\) replaces the real future return. Subtracting a state-only baseline does not change the expected gradient; but when \(V(s_{t+1})\) stands in for the future return, any error in \(V\) enters the advantage directly and causes bias.
Follow-up 2: Why does GRPO not need GAE?
Because GRPO treats the whole response as one action and uses the average score of several responses to the same prompt as the baseline, so all tokens share the same advantage. It therefore needs no value network and hence no GAE; the price is losing token-level credit assignment. See Chapter 8.
Follow-up 3: Why is \(\gamma=1\) common in RLHF?
Because a response is a finite-length episode, so no discount is needed to keep the return bounded, and discounting would unreasonably shrink the final reward as it propagates back to earlier tokens. With \(\gamma<1\), tokens near the start of a long response would receive a weaker signal, which conflicts with the setting in which the whole response is judged as a unit.
Common mistakes
- Do not conflate \(\lambda\) with \(\gamma\): According to the analysis in the GAE paper, \(\gamma<1\) introduces bias regardless of whether the value is accurate, effectively changing the objective; \(\lambda<1\) introduces bias only when the value is inaccurate, and it affects only how the advantage is estimated.
- Do not say the value network is unnecessary when \(\lambda=1\): \(V\) is still used as a baseline to reduce variance.
- Do not get the direction of \(\lambda\) backwards: The larger \(\lambda\), the closer to the Monte Carlo estimate, with smaller bias and larger variance.
6.6 How many models does PPO training need, and what makes it hard to engineer? ★★¶
One-sentence answer
PPO-based RLHF needs four models: the policy (actor) and the value model (critic), which are trained, plus the frozen reference model and reward model. The engineering is hard in three ways: the resource and systems overhead from memory and rollouts, the difficulty of learning a good critic, and the many coupled hyperparameters and implementation details.
I will address three aspects: the role of each of the four models, the flow of one training round, and the main engineering difficulties.
(1) Of the four models, two are trained and two are frozen.
- Policy (actor) \(\pi_\theta\): initialized from the SFT model; it generates responses and is the model being optimized.
- Reference model \(\pi_{\text{ref}}\): the frozen SFT model; it provides per-token log-probabilities for the KL penalty.
- Reward model \(r_\phi\): trained in the second stage and then frozen; it gives each complete response a scalar score.
- Value model (critic) \(V_\psi\): usually initialized from the reward model and trained; it estimates a value at every token position for computing GAE.
(2) One training round proceeds through rollout, scoring, advantage computation and several update passes.
First, a batch of prompts is drawn from the prompt set and the current policy generates responses; this step is autoregressive and usually the slowest. Next, the reward model scores each complete response, the reference model and the current policy each compute per-token log-probabilities to obtain the KL, and the value model computes a value at every position. These are then assembled into per-token rewards, GAE computes the advantages and return targets, and the advantages are standardized within the batch. Finally, 1 to 4 epochs of minibatch updates are run on this batch: the policy with the clipped loss and the value model with the regression loss. After the updates, set \(\theta_{\text{old}}\leftarrow\theta\) and start the next round.
(3) The engineering difficulties fall into three categories.
- Heavy resource and systems overhead: the two full-size models being trained both carry gradients and optimizer states, and the two frozen models must also stay in memory, so memory is roughly more than twice that of SFT at the same scale. Moreover, every step requires a rollout first, and autoregressive generation often takes most of the training time; to speed it up, generation is usually handed to a dedicated inference engine with weights synced each round, which makes the systems engineering quite complex.
- The critic is hard to learn: the value model must learn to predict the value of every prefix from "a single score that appears only when the response ends", which is a difficult regression problem in itself. Early in training the critic is inaccurate, so the advantages it produces are biased and in turn mislead the policy updates; many implementations therefore warm up the critic separately first.
- Many hyperparameters and sensitivity to implementation details: the KL coefficient \(\beta\), the clip range \(\epsilon\), the learning rates of the policy and the critic, GAE's \(\lambda\), batch sizes and the number of epochs per batch are all coupled; details such as how rewards and advantages are normalized, how responses without an EOS are handled and how padding is handled also decide whether training succeeds. Get them wrong and you see KL blow-ups, reward collapse, or outputs degenerating into repetitive text.
In summary: the difficulty of PPO-based RLHF lies in maintaining four models at once, sampling inside the training loop, and learning a good critic; these pain points directly gave rise to GRPO, which removes the critic, and DPO, which removes the reward model and sampling during training.
Going deeper: memory estimates, implementation details and simplification routes
(1) A rough memory estimate: at 7B, more than twice that of SFT.
Assuming about 16 bytes per parameter for mixed-precision Adam training and 2 bytes per parameter for frozen bf16 weights (see Chapter 3), if all four models are 7B:
| Model | Trained? | Memory (excluding activations and KV cache) |
|---|---|---|
| Policy | Yes | About 112 GB |
| Value model | Yes | About 112 GB |
| Reference model | No | About 14 GB |
| Reward model | No | About 14 GB |
| Total | About 250 GB |
SFT at the same scale needs about 112 GB, so PPO needs a bit more than twice as much, plus the KV cache required for rollouts. Real frameworks (such as OpenRLHF and veRL) hand rollouts to an inference engine like vLLM and sync weights between training and generation.
(2) Implementation details make or break it.
To reproduce OpenAI's early summarization RLHF results, Huang et al. (2024) catalogued more than twenty implementation details that affect the outcome, such as how rewards and advantages are normalized, how the value model is initialized, how responses without an EOS are handled, which KL estimator is used and how padding is handled. Systematic experiments by Zheng et al. (2023) also found that how policy updates are constrained is key to stable PPO training.
(3) Three simplification routes each remove a different part of PPO.
| Method | What it removes | Models still needed | Cost |
|---|---|---|---|
| DPO | Reward model, critic, sampling during training | Policy, reference model | Becomes offline learning and loses the ability to explore on its own samples (see Chapter 7) |
| RLOO, GRPO | Critic (the scores of several responses to the same prompt serve as the baseline) | Policy, reference model, reward model or rule-based verifier | Several responses must be sampled per prompt; token-level credit assignment is lost (see Chapter 8) |
| Verifiable rewards | The learned reward model | Depends on the RL algorithm used | Applies only to tasks whose answers can be verified automatically |
Ahmadian et al. (2024) also pointed out that for RLHF on LLMs, much of PPO's complexity is unnecessary: REINFORCE-style methods with a good baseline (such as RLOO) can do as well or better.
Follow-up questions
Follow-up 1: Why is the value model initialized from the reward model?
Because the reward model already knows how to judge text quality and already outputs a scalar, which is much closer to the value target than a random initialization. If the critic gave random values at first, the advantages would be pure noise and early policy updates would be led astray. Some implementations instead initialize the critic from the SFT model and warm it up separately before the main training.
Follow-up 2: What failure patterns are common in PPO training, and how do you debug them?
Watch several curves at once and read samples by hand regularly. Common patterns include: the KL rising fast while the reward shoots up (usually exploiting the reward model), sudden reward collapse, responses getting longer or degenerating into repetitive text, and a value loss that does not converge. When debugging, watch the reward, the KL, response length, policy entropy, the value loss and clipfrac together. Common fixes are increasing \(\beta\) or lowering the learning rate, warming up the critic, standardizing rewards and advantages, and checking how EOS and padding are handled.
Follow-up 3: Why is the rollout the slowest step of training?
Because generation is sequential token by token, whereas the forward and backward passes in training can process the whole sequence in parallel. Generation is bound by memory bandwidth, so GPU utilization is low and longer responses take longer; moreover, responses in the same batch differ in length, so short ones must wait for long ones to finish. RLHF frameworks therefore usually use a dedicated inference engine for generation and sync weights with the training engine (for inference optimization, see the Inference, Evaluation and Deployment direction).
Common mistakes
- Do not say PPO-based RLHF trains only one model: Both the policy and the value model are trained, and each needs gradients and optimizer states.
- Do not say the reward model keeps updating during PPO: In the standard pipeline it is frozen; only iterative RLHF retrains it between rounds.
- Do not judge success from the reward curve alone: A rising reward may itself be a sign of reward hacking, so it must be judged together with the KL, response length and human evaluation.
6.7 What is reward hacking, and how can it be mitigated? ★★¶
One-sentence answer
Reward hacking is when the policy exploits loopholes in the reward model to obtain high scores while true quality stagnates or falls; at its core this is Goodhart's law: the reward model is only an imperfect proxy for human preference, and RL is precisely good at finding where it is wrong. Mitigation means limiting optimization strength (KL constraints and early stopping), making the reward more robust (better reward models, ensembles, iterative updates), and switching to verifiable rewards where possible.
I will address three aspects: why it happens, what its typical symptoms are, and how to mitigate it.
(1) Reward hacking arises from combining a strong optimizer with an imperfect proxy.
Goodhart's law states: "When a measure becomes a target, it ceases to be a good measure." The reward model is a proxy for human preference learned from finite data, so it inevitably has errors, especially on responses it has not seen. RL is a strong optimizer whose whole job is to find the responses with the highest reward model score, and the places where the reward model is wrong are exactly where scores are "inflated". Therefore, the harder one optimizes, the more the policy is drawn into the reward model's loopholes; at the same time, as RL proceeds, the policy's responses drift further from the reward model's training distribution, which amplifies these errors further. The result is that the reward model's score keeps rising while true quality first rises and then falls.
(2) Typical symptoms center on length, style and sycophancy.
- Verbosity and formatting overload: responses get longer and longer, piling up lists, headers and bold text. Singhal et al. (2023) found that a large share of the reward gains in RLHF came from responses getting longer.
- Sycophancy: agreeing with the user's views and abandoning a correct answer as soon as the user pushes back. Sharma et al. (2023) found that sycophancy is widespread in RLHF models, and that humans and preference models do sometimes prefer sycophantic responses, which shows that the problem partly lies in the preference data itself.
- Templated wording and reduced diversity: stock phrases become more common, and Kirk et al. (2023) found that RLHF models' outputs are noticeably less diverse than those of SFT models.
- Observable training signals: the KL to the reference model rises rapidly, and the reward model's score begins to diverge from human evaluation or a stronger "gold" evaluation.
(3) Mitigations work in three directions: "optimize less", "optimize a better reward" and "use a different reward".
- KL constraints and early stopping: treat the KL as an optimization budget, monitor true quality with held-out human evaluation or a stronger judge model, and stop before it starts to fall.
- More robust rewards: use larger reward models and more, and more diverse, preference data; train several reward models and use their mean, their minimum, or "the mean minus the uncertainty" as the reward (Coste et al. 2023), because the policy can hardly fool all of them at once, and large disagreement between them signals exactly where the reward is unreliable; or average the weights of several reward models fine-tuned from the same initialization (WARM, Ramé et al. 2024), which costs the inference of a single model.
- Iterative RLHF: collect new preference data on the current policy's outputs, retrain the reward model, and continue RL, so that loopholes the policy found get patched in the next round (as Llama 2 did).
- Targeted fixes and verifiable rewards: add a length penalty or train the reward model on length-balanced data; for math, code and similar tasks, switch to verifiable rewards such as answer matching or unit tests, which sidestep the loopholes of a learned reward model altogether (though rule-based rewards can be gamed too; see Chapter 8).
In summary: reward hacking is the inevitable result of using a strong optimizer on an imperfect proxy; it cannot be eliminated, only controlled by limiting optimization strength, improving the proxy and monitoring continuously.
Going deeper: scaling laws for over-optimization (Gao et al. 2022)
(1) Experimental design: a large reward model plays the "human".
Gao et al. (2022) used a very large "gold" reward model in place of humans to provide labels, trained smaller proxy reward models on those labels, optimized the policy against a proxy reward model, and tracked true quality with the gold reward model. The x-axis is the square root of the KL between the current and initial policies, which measures how far optimization has gone.
(2) The gold score first rises and then falls with optimization, following fixed functional forms.
\(R\) is the improvement in gold score over the initial policy; \(d\) is the optimization distance, \(\pi\) is the optimized policy and \(\pi_{\text{init}}\) is the initial policy; \(\alpha\) and \(\beta\) are fitted coefficients (this \(\beta\) is unrelated to the KL coefficient); BoN means best-of-\(n\) sampling, i.e. generating \(n\) responses and picking the one with the highest proxy score; RL means optimizing with PPO. Both rise roughly linearly at small \(d\) and are then pulled down by the negative term.
(3) Three conclusions worth remembering.
| Factor | Effect |
|---|---|
| Size of the proxy reward model | The larger it is, the later over-optimization sets in and the higher the reachable gold score |
| Amount of reward model training data | More is better |
| KL penalty | Did not improve the curve of gold score versus KL; its effect is closer to early stopping |
Follow-up questions
Follow-up 1: During training, how can you tell that the policy is exploiting the reward model?
Look for divergence between signals. The typical signature is that while the reward keeps rising, the KL grows fast and responses get noticeably longer, but scores from held-out human evaluation or a stronger judge model stall or even fall. In addition, regularly reading samples by hand is indispensable, since many hacking patterns (such as stock phrases and sycophancy) are invisible in the curves.
Follow-up 2: Why do reward model ensembles help against reward hacking?
Because different reward models make different errors, and disagreement itself is a signal of uncertainty. It is much harder for the policy to fool several models at once; and with a conservative aggregation (the minimum, or the mean minus the variance), the score the policy receives is pushed down in regions where the models disagree, i.e. where the reward is unreliable, so the policy is no longer drawn there.
Follow-up 3: Can verifiable rewards not be hacked?
They can, just in different forms. For example, in code tasks the policy may special-case the test cases, and in math tasks it may exploit loopholes in the answer parser. Verifiable rewards therefore also need rigorous verifiers and manual spot checks (see Chapter 8).
Common mistakes
- Do not say a better reward model solves reward hacking: Every learned proxy has errors, and a sufficiently strong optimizer will find them; a better reward model only delays the onset.
- Do not treat a rising reward as evidence of success: Independent evaluation is needed to confirm whether true quality has improved.
- Do not say the KL penalty eliminates over-optimization: In the experiments of Gao et al. (2022), its effect was closer to early stopping.
6.8 What are RLAIF and Constitutional AI? ★¶
One-sentence answer
RLAIF (RL from AI feedback) uses AI rather than humans to provide preference labels. Constitutional AI is Anthropic's representative method: a list of principles written in natural language (the "constitution") guides the model in critiquing and revising its own responses, and AI then gives harmlessness preferences according to these principles, so that a harmless assistant can be trained with almost no human harmlessness labels.
I will address three aspects: why use AI feedback, the two stages of Constitutional AI, and the effectiveness and limitations of RLAIF.
(1) AI feedback addresses the cost, slowness and inconsistency of human labeling.
Human preference labeling is expensive and slow, labelers disagree with each other, and labeling harmful content can harm the labelers. Meanwhile, strong LLMs are already decent judges, so they can be used to generate preference labels, which makes both the scale of the data and the consistency of the standards easier to ensure.
(2) Constitutional AI has a supervised stage and an RL stage.
- Supervised stage (SL-CAI): red-team prompts designed to elicit harmful responses are given to a model trained only for helpfulness, which often responds harmfully; a principle is then sampled from the constitution, and the model critiques its own response according to that principle and revises it, possibly over several rounds; finally, SFT is performed on the revised responses.
- RL stage (RL-CAI, i.e. RLAIF): the SL-CAI model generates two responses to a prompt, and a feedback model judges which is better according to some principle; these AI-labeled harmlessness preferences, combined with human-labeled helpfulness preferences, train a preference model, which is then used for RL.
The result was a model more harmless than an RLHF model trained with human harmlessness labels, and less evasive: faced with a sensitive request, it explains why it objects rather than simply refusing (Bai et al. 2022b).
(3) RLAIF can approach RLHF in effectiveness, but the judge model has its own biases.
Lee et al. (2023) compared the two on summarization and dialogue tasks and found that models trained on preferences labeled by an off-the-shelf LLM were on par with RLHF in human evaluation. The advantages of RLAIF are that it is cheap, scalable and consistent, and that values are written as explicit, editable principles, which is more transparent. However, the judge model has position bias, length bias and self-preference; its judging ability has a ceiling, so it cannot help on hard problems it cannot judge itself; and the policy will still exploit the judge's loopholes.
In summary: RLAIF replaces human labeling with scalable AI judgment, and Constitutional AI further constrains that judgment with explicit principles.
Going deeper: how the feedback model gives preferences, and d-RLAIF
(1) The feedback model gives soft labels in multiple-choice form.
In RL-CAI, the feedback model sees the prompt, the two responses and a principle, and answers which is better as a multiple-choice question; the normalized probabilities of the two options serve as soft labels rather than hard 0/1 labels. The feedback model can also be asked to write a chain of thought before judging.
(2) d-RLAIF does not even train a reward model.
Lee et al. (2023) also proposed d-RLAIF (direct RLAIF): during RL, the score given by the LLM is used directly as the reward, skipping the step of first distilling a reward model.
(3) Common biases of LLM judges.
| Bias | Manifestation |
|---|---|
| Position bias | Favors the response shown first or last |
| Length bias | Favors longer, more detailed responses |
| Self-preference | Favors responses in its own style |
Common mitigations include judging twice with the order of the two responses swapped, instructing the judge to ignore length, and using a judge from a different source than the policy. (For LLM-as-judge as an evaluation method, see the Inference, Evaluation and Deployment direction.)
Follow-up questions
Follow-up 1: How does RLAIF differ from Self-Rewarding?
RLAIF usually uses a fixed external model as the judge, whereas Self-Rewarding has the model being trained score its own outputs and improve iteratively. In the latter, judging ability improves along with training, but self-reinforcing biases are also more likely (see the Self-Improving & RSI direction).
Follow-up 2: Does Constitutional AI need no human labels at all?
No. What it removes is human harmlessness labels; helpfulness preferences still come from human labeling, and the principles in the constitution are themselves written by people.
Common mistakes
- Do not say RLAIF lets a model surpass its judge: On problems the judge itself cannot judge, it provides no useful signal.
- Do not describe Constitutional AI as merely an RL method: It has two stages, "SFT after critique and revision" and "AI preferences plus RL".