RLHF

Layer 2 · Mechanics

RLHF

The PPO training loop step by step: rollouts, reward scoring, KL penalty, and the policy update.

8 min read70 XP

  1. Sample prompt

    from a prompt dataset

  2. Policy generates response

    current model, sampling

  3. Reward model scores it

    scalar reward r

  4. Subtract KL to reference

    penalize drift

  5. PPO update

    clip + advantage

One RLHF training iteration.

Each PPO iteration is a loop over four models: the policy (being trained), the reference (frozen copy of the SFT model, used only to measure drift), the reward model (frozen, scores full responses), and a value model (predicts expected reward, used to reduce variance in the policy gradient).

Go deeper: L3 Code