Part 11 of 15 in LLM fine-tuning techniques

Reinforcement learning from human feedback (RLHF) fine-tunes a language model in three steps: humans compare model outputs, a reward model learns to predict their choices, and reinforcement learning pushes the model toward outputs that reward model scores highly. It was developed at OpenAI and DeepMind from 2017 and was the method behind OpenAI's InstructGPT in 2022.

1.3B > 175B
InstructGPT outputs preferred to GPT-3's
Ouyang et al., 2022, Sec. 4.1
85 ± 3%
labelers preferring 175B InstructGPT over GPT-3
Ouyang et al., 2022
< 1%
of agent interactions needed human feedback
Christiano et al., 2017

What is RLHF?

RLHF is a way to fine-tune a model toward what people prefer when that preference is hard to write down as a rule. Humans compare pairs or rankings of outputs; a reward model is trained on those comparisons; and the language model is then trained with reinforcement learning to maximize the learned reward, with a penalty for drifting too far from where it started (Ouyang et al., 2022, Sec. 3.1).

The motivation in the InstructGPT paper: "Making language models bigger does not inherently make them better at following a user's intent", because the next-token objective is not the same as being helpful, honest and harmless (abstract).

How does RLHF work?

RLHF works as a three-stage pipeline: supervised fine-tuning on human demonstrations, reward-model training on human rankings, then policy optimization with PPO against the reward model under a KL penalty. This is the setup InstructGPT used, following Stiennon et al. (2020) (Ouyang et al., 2022, Sec. 3.1 and 3.5).

Diagram: three RLHF stages from InstructGPT. Step 1 supervised fine-tuning on labeler demonstrations (about 13k prompts), step 2 reward model from rankings of 4 to 9 outputs (about 33k prompts), step 3 PPO against the reward model with a KL penalty (about 31k prompts)

Step 1: supervised fine-tuning (SFT)

Labelers write the answers they want for a set of prompts, and the pretrained model (GPT-3 in InstructGPT) is fine-tuned on them with ordinary supervised learning. InstructGPT's SFT dataset had about 13k training prompts from the OpenAI API and from labelers (Sec. 3.2). The demonstrations came from a team of about 40 contractors hired through Upwork and Scale AI (Sec. 3.4).

Step 2: train a reward model on comparisons

The model generates several answers per prompt and labelers rank them. InstructGPT showed labelers 4 to 9 responses at once, which yields K-choose-2 comparisons per prompt; its reward-model set had 33k training prompts (Sec. 3.2, 3.5). The reward model is the SFT model with its final unembedding layer replaced by a scalar output, trained with:

loss(θ) = −1/(K choose 2) · E[ log σ( r_θ(x, y_w) − r_θ(x, y_l) ) ]

where y_w is the preferred completion and y_l the other one (Eq. 1). This is the Bradley-Terry model that Christiano et al. used in 2017: the probability a human prefers one output "depends exponentially on the value of the latent reward" (Christiano et al., Sec. 2.2.3).

Worked example (our arithmetic). If the reward model scores answer A at 2.0 and answer B at 0.5, it predicts P(A preferred) = σ(2.0 − 0.5) = σ(1.5) ≈ 0.82. If the labeler did prefer A, the loss for that pair is −log(0.82) ≈ 0.20; if the labeler preferred B, it is −log(0.18) ≈ 1.70, so the gradient pushes the scores apart in the right direction. With K = 9 ranked answers, one prompt gives 9 × 8 / 2 = 36 comparisons.

Step 3: optimize the policy with PPO and a KL penalty

The SFT model becomes the policy. For each prompt it writes a response, the reward model scores it, and PPO updates the policy. The reward includes a penalty for moving away from the SFT model (Stiennon et al., 2020, Sec. 3.4):

R(x, y) = r_θ(x, y) − β · log[ π_RL(y|x) / π_SFT(y|x) ]

Stiennon et al. give the KL term two jobs: it "acts as an entropy bonus" that stops the policy collapsing to a single mode, and it keeps the policy from producing outputs "too different from those that the reward model has seen during training". InstructGPT adds a third term in its PPO-ptx variant, γ · E[log π_RL(x)] over pretraining data, to reduce performance regressions on public NLP benchmarks (Ouyang et al., Eq. 2). Its PPO set had 31k training prompts, all from the API.

When was RLHF introduced, and by whom?

RLHF for deep RL was introduced in 2017 by researchers at OpenAI and DeepMind, applied to summarization in 2020 and to general instruction following with InstructGPT in 2022:

PaperAuthorsFirst on arXivVenueWhat it added
Deep Reinforcement Learning from Human PreferencesPaul F. Christiano, Jan Leike, Tom B. Brown, Miljan Martic, Shane Legg, Dario AmodeiJune 12, 2017NIPS 2017Reward learning from human comparisons of 1-2 second clips, for Atari and robot control
Learning to summarize from human feedbackNisan Stiennon, Long Ouyang, Jeff Wu, Daniel M. Ziegler, Ryan Lowe, Chelsea Voss, Alec Radford, Dario Amodei, Paul ChristianoSept. 2, 2020NeurIPS 2020RM + PPO with a KL penalty on a pretrained language model
Training language models to follow instructions with human feedbackLong Ouyang, Jeff Wu, Xu Jiang, and 17 co-authors, ending with Jan Leike and Ryan LoweMarch 4, 2022NeurIPS 2022SFT + RM + PPO(-ptx) for general instructions: InstructGPT

The NIPS 2017 and NeurIPS 2022 venues are listed in the NeurIPS proceedings and on the NeurIPS 2022 poster page; Stiennon et al. list NeurIPS 2020 on arXiv.

What results did the RLHF papers report?

Christiano et al. (2017): complex behavior from little feedback. The method solved Atari games and simulated robot tasks "without access to the reward function", with human feedback on less than 1% of the agent's interactions (abstract). With 700 labels it nearly matched RL on the true reward in MuJoCo tasks (Sec. 3.1.1). A Hopper robot learned backflips from 900 queries in under an hour of human time (Sec. 3.2). For Atari, the authors estimate 5k labels at about 5 hours of human work, about $36 at US minimum wage.

Stiennon et al. (2020): a 1.3B model beat a 10x larger supervised one. On Reddit TL;DR summaries, the 1.3B human-feedback model was preferred over reference summaries 61% of the time, against 43% for a supervised model 10 times its size (Sec. 4.1). After controlling for summary length, preference dropped by about 5%, and the 6.7B model's summaries were still preferred to the human references about 65% of the time. The released dataset has 64,832 summary comparisons.

Ouyang et al. (2022): InstructGPT. Main results (Sec. 1 and 4):

ResultNumber
1.3B InstructGPT vs 175B GPT-3, labeler preference1.3B preferred, "despite having over 100x fewer parameters"
175B InstructGPT preferred over 175B GPT-385 ± 3% of the time
175B InstructGPT preferred over few-shot 175B GPT-371 ± 4% of the time
TruthfulQAtruthful and informative answers "about twice as often as GPT-3"
Compute to train 175B PPO-ptx60 petaflop/s-days, vs 3,640 for GPT-3 pretraining
Reward model used for all PPO runsone 6B model
Labeler agreement72.6 ± 1.5% (training labelers), 77.3 ± 1.3% (held-out labelers)

How is RLHF different from RLAIF, DPO and GRPO?

RLHF uses human comparisons, a separate reward model and an online RL step. Its successors each change one of those pieces:

MethodWho labels preferencesSeparate reward model?RL step?Series page
RLHFHumansYesYes (PPO in the original papers)this page
RLAIFAn AI model, guided by written principles or promptsYes in canonical RLAIF; no in d-RLAIFYesRLAIF
DPOHumans (or AI), offline preference pairsNoNo, a classification-style lossDPO
GRPOAny reward function or modelOptionalYes, with group-relative advantages instead of a value modelGRPO
RLVRA program that checks answers (math, code)No, rule-basedYesRLVR

Which libraries support RLHF?

Hugging Face TRL covers the reward-model step and online RL, but TRL no longer includes PPO. Its v1.13.0 release notes (Sept. 10, 2026) say "PPOTrainer, PPOConfig, and modeling_value_head.py ... are gone", after PPO had first been moved to trl.experimental.ppo (TRL releases; PR #7020). In TRL v1.19.0, the current release on PyPI:

  • RewardTrainer trains a reward model with the Bradley-Terry loss on preference data (chosen / rejected, with an implicit or explicit prompt). RewardConfig has an optional center_rewards_coefficient (recommended 0.01) to keep rewards near zero.
  • RLOOTrainer is an online RL trainer that implements RLOO, a REINFORCE-style method for learning from human feedback, from Ahmadian et al., 2024, whose abstract argues that "many components of PPO are unnecessary in an RLHF context". reward_funcs accepts a trained reward model's path, and RLOOConfig.beta (default 0.05) is the KL coefficient.
  • GRPOTrainer also accepts a reward model; see GRPO.

Older TRL releases with PPO still install; the PR notes that tools such as ms-swift pin trl>=0.15,<1.0.

How do you use RLHF in code?

Step 2 and step 3 with current TRL. All names are checked against the RewardTrainer and RLOOTrainer pages for TRL v1.19.0. Step 1 is a plain SFTTrainer run.

from datasets import load_dataset
from trl import RewardConfig, RewardTrainer, RLOOConfig, RLOOTrainer

# Step 2: reward model from human preference pairs (chosen / rejected)
rm = RewardTrainer(
    model="Qwen/Qwen3-0.6B",
    args=RewardConfig(output_dir="qwen3-rm", center_rewards_coefficient=0.01),
    train_dataset=load_dataset("trl-lib/ultrafeedback_binarized", split="train"),
)
rm.train()
rm.save_model("qwen3-rm")

# Step 3: online RL against that reward model, with a KL penalty (beta)
rl = RLOOTrainer(
    model="Qwen/Qwen3-0.6B",                  # your SFT model from step 1
    reward_funcs="qwen3-rm",                  # path to the trained reward model
    args=RLOOConfig(output_dir="qwen3-rloo", beta=0.05),
    train_dataset=load_dataset("trl-lib/ultrafeedback-prompt", split="train"),
)
rl.train()

This swaps PPO for RLOO in step 3, because PPO is no longer in TRL. The InstructGPT recipe used PPO with a separate value model; RLOO uses several samples per prompt as a baseline instead (num_generations, default 2).

Common pitfalls

  • Reward over-optimization. Optimizing too hard against a reward model makes outputs worse: "eventually the reward model becomes anti-correlated with human preferences" (Stiennon et al., Sec. 4.3). The KL penalty is the standard guard.
  • Alignment tax. PPO-only InstructGPT lost performance on public NLP datasets; mixing in pretraining gradients (PPO-ptx) reduced the regressions "without compromising labeler preference scores" (Ouyang et al., Sec. 1, 4.2).
  • Reward-model overfitting from correlated pairs. Shuffling all K-choose-2 comparisons into one dataset made the RM overfit in a single pass; InstructGPT trains all comparisons from a prompt as one batch element instead (Sec. 3.5).
  • Length bias. RLHF policies wrote longer summaries, and length "could account for much of our quality improvements"; controlling for it cut preference by about 5% (Stiennon et al., Sec. 4.1).
  • Large reward models can be unstable. InstructGPT used only 6B reward models because 175B RM training "could be unstable" (Sec. 3.5).
  • Whose preferences? InstructGPT aligns to its labelers and researchers, about 40 contractors mostly in the United States or Southeast Asia, not to people in general, as the authors discuss (Sec. 5.2).

FAQ

What are the three steps of RLHF?

Supervised fine-tuning on human-written demonstrations, training a reward model on human rankings of model outputs, and reinforcement learning (PPO in InstructGPT) against that reward model with a KL penalty to the SFT model.

Why does RLHF need a reward model?

Humans can't score every output the policy produces during RL. The reward model learns to predict human comparisons and then scores millions of samples. Christiano et al. needed feedback on under 1% of agent interactions this way.

What does the KL penalty do in RLHF?

It subtracts β times the log-ratio between the RL policy and the SFT model from the reward. Stiennon et al. say it acts as an entropy bonus and keeps outputs close to what the reward model saw in training.

Is RLHF better than supervised fine-tuning?

In the papers, yes on human preference: a 1.3B RLHF summarizer beat a 10x larger supervised model (61% vs 43%), and 175B InstructGPT was preferred over few-shot GPT-3 71 ± 4% of the time.

Does TRL still have a PPOTrainer?

No. TRL removed PPOTrainer and PPOConfig in v1.13.0 (Sept. 2026). The current release, v1.19.0, offers RewardTrainer for reward models and RLOOTrainer or GRPOTrainer for the online RL step.

How much does RLHF cost compared with pretraining?

For InstructGPT, training the 175B PPO-ptx model took 60 petaflop/s-days, compared with 3,640 for GPT-3's pretraining, according to Ouyang et al. Human labeling came from about 40 contractors.

What is the difference between RLHF and DPO?

RLHF trains a separate reward model and then runs online RL. DPO skips both and optimizes the policy directly on preference pairs with a classification-style loss. See Part 13 of this series.

Sources

Series: ← Prev: Federated Tuning · All 15 techniques · Next: RLAIF →

  • #llm-fine-tuning
  • #rlhf
  • #alignment
  • #reward-model
  • #ppo