↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Loading the recording…

What RLHF is

Supervised fine-tuning can only imitate answers someone wrote. Yet people find it easier to say which of two answers is better than to write the best one. Reinforcement learning from human feedback (RLHF) uses such comparisons in two steps. First a reward model learns to give a higher score to the answer people preferred. Then the language model, now called the policy, generates answers, the reward model scores them, and reinforcement learning makes high-scoring answers more likely, while a penalty keeps the policy close to the model it started from.

This page shows both halves on small models: OpenAssistant's DeBERTa-v3-large reward model (435 M parameters) scores answers from SmolLM2-135M-Instruct to one question from UltraFeedback, "What kind of meat do cattle eat?". The question has a trap: cattle eat no meat. The policy is then updated with TRL 0.19.1's PPO, ported line by line, for 3 rounds of 8 answers and 4 epochs each, 12 updates in all.

The reward model

A reward model reads a question and an answer and returns one number. It is trained on pairs, an answer people preferred and one they did not, with the Bradley–Terry model of paired comparison: the probability that wins is , and the loss is

Only differences of scores matter, so the scale is arbitrary. The reward model scores answers shows its input, [CLS] question [SEP] answer [SEP] in DeBERTa's own tokens, and its output, a logit. For calibration the page scores UltraFeedback's own two answers to this question. GPT-4 rated the chosen one, which says cattle are herbivores and eat no meat, 10. It rated the rejected one, which lists what cattle are fed, 6. The reward model gives them −0.198 and 2.014: it prefers the answer GPT-4 rejected. A reward model is a learned guess at human preference, and the policy will optimise whatever it rewards, its mistakes included.

The objective and the per-token rewards

RLHF maximises the reward while penalising the policy's divergence from the reference model , the starting checkpoint:

Without the penalty the policy would drift towards whatever text fools the reward model. PPO treats each generated token as one action. The table in From one score to per-token advantages shows how the single score becomes a reward per token: every token pays , with , and the reward model's score is added at the end. Every sampled answer here ran to the 64-token limit, so the score lands on the last token. In round 1 the policy is still the reference, so all the KL penalties are 0.

Values and advantages

To tell a good token from a lucky one, PPO learns a value model that predicts the reward still to come from each position. The reward model uses a different tokenizer, so the value model here is a SmolLM2 trunk with a new scalar head. Generalised advantage estimation (GAE) then measures how much better than predicted each step went:

With and , the end-of-answer score is carried back with weight per token. The advantages of all 8 answers are then whitened together (shifted and scaled to mean 0 and variance 1). In round 1 the value head is new, so its values are noise. Over the 12 updates the value loss falls from 1.674 to 1.155.

The clipped update

PPO reuses each batch of answers for several gradient steps. To keep these steps from moving the policy too far from the one that sampled the answers, it clips the probability ratio :

With , once a token's ratio has moved past in the direction its advantage pushes, it stops contributing gradient. The value model gets its own clipped squared error, weighted by 0.1, and one AdamW optimiser at a learning rate of updates both models. The clipped update shows the ratios and losses at each update. In the first epoch on a batch every ratio is 1; by the last update 18.2 % of the batch's tokens are clipped, as Share of tokens clipped shows.

What twelve updates changed

What 12 updates changed re-scores round 1's eight answers with the policy after every update. The change in each answer's log-probability follows its reward-model score, with a correlation of 0.88. The best-scored answer became 2.16 nats more likely and the worst 22.43 nats less likely.

The Fresh answers each round table samples new answers each round. Their mean score goes −2.190, −2.512, −2.693 and, after training, −2.223. Eight samples are too few to see a shift this small. Meanwhile the policy's KL from the reference, summed over each answer, grows from 0 to 0.456, 2.366 and 5.132 nats. Real RLHF runs use thousands of prompts and many more updates, and they watch that KL closely.

Where RLHF came from

Christiano et al. (2017) trained agents to play Atari games and move simulated robots from human comparisons of short clips, with feedback on less than 1 % of the agent's interactions. Ziegler et al. (2019) brought the method to language models: a reward model from human comparisons, then PPO with a KL penalty to the original model. InstructGPT (Ouyang et al., 2022) made SFT, reward model and PPO the recipe for chat models; its 1.3 B model's outputs were preferred to the 175 B GPT-3's. PPO's many moving parts led to simpler methods. DPO (the DPO tab) removes the reward model and the sampling. GRPO (the GRPO tab) drops the value model and, with answers that can be checked, the reward model too.

Papers

  1. Deep reinforcement learning from human preferences Paul Christiano et al. · NeurIPS 2017 Introduces learning a reward model from human comparisons and optimising a policy against it with RL.
  2. Fine-Tuning Language Models from Human Preferences Daniel M. Ziegler et al. · arXiv 2019 RLHF for language models: a reward model from human comparisons, then PPO with a KL penalty to the starting model.
  3. Training language models to follow instructions with human feedback Long Ouyang et al. · NeurIPS 2022 InstructGPT: SFT, a reward model trained with the pairwise loss, then PPO, the recipe this page follows.
  4. Proximal Policy Optimization Algorithms John Schulman et al. · arXiv 2017 PPO: several gradient steps per batch with the clipped probability ratio.
  5. High-Dimensional Continuous Control Using Generalized Advantage Estimation John Schulman et al. · ICLR 2016 GAE: advantages as exponentially weighted sums of temporal-difference errors, with the γ and λ the page uses.
  6. DeBERTaV3: Improving DeBERTa using ELECTRA-Style Pre-Training with Gradient-Disentangled Embedding Sharing Pengcheng He, Jianfeng Gao, Weizhu Chen · ICLR 2023 The encoder behind the reward model this page records.
  7. The N+ Implementation Details of RLHF with PPO: A Case Study on TL;DR Summarization Shengyi Huang et al. · arXiv 2024 Reproduces OpenAI’s RLHF pipeline and documents the many implementation details, such as advantage whitening, that TRL’s PPO trainer shares.

See also