Policy gradient methods optimize a parameterized policy directly from sampled outcomes. In RLHF, a language model generates completions for prompts, a reward model scores them, and gradient updates make higher-scoring behavior more likely. A frozen reference policy commonly contributes a KL penalty, limiting drift while preference feedback is translated into model behavior. section 6.0 section 3.3
The central update has the form Δθ ∝ Ψt ∇θ log πθ(at|st). The log-probability gradient identifies parameters that made an action likely; Ψt scores its quality. Positive scores reinforce an action, negative scores discourage it. For language models, states and actions can be read as prompts and completions, or as token-level sequential decisions. section 6.2 section 6.3.1
Figure 6.1 Overview of the RLHF training loop. A prompt from the dataset is passed to the tuned policy, which generates a completion. The reward model scores this completion, and the frozen initial model (typically the instruction-tuned model before RL) computes log probabilities on the same text to calculate a Kullback–Leibler penalty that prevents excessive drift. The combined reward signal then drives an RL update to the policy parameters.
Follow the operational loop: sample a completion from the current policy, score it, subtract the reference-policy KL cost, then update the policy from the combined reward. section 6.0
The objective is expected trajectory reward, J(θ) = Eτ∼πθ[R(τ)]. The likelihood-ratio derivation turns its gradient into sampled policy log-probabilities weighted by return: ∇θJ(θ) = E[Σt ∇θlogπθ(at|st) R(τ)]. Environment dynamics and the initial-state distribution disappear from the parameter gradient because they do not depend on θ. Monte Carlo rollouts approximate the expectation in a batch. section 6.2.1
Raw-return updates are noisy, especially with small rollout sets, stochastic generation, or sparse rewards. A baseline reduces variance without changing the expected gradient. The common advantage signal A(s,a) = Q(s,a) − V(s) instead reinforces actions better than expected and suppresses those worse than expected. REINFORCE uses Monte Carlo returns and may use a batch or state-dependent baseline; it does not require a learned value network. section 6.2.2 section 6.2.3
Practical RLHF policy-gradient variants change how the score signal and update are stabilized:
- REINFORCE and RLOO use Monte Carlo returns; RLOO forms a leave-one-out baseline across several completions per prompt. section 6.6
- PPO uses importance ratios, clipping, and a learned value function to constrain a policy change; its per-token advantages can use GAE. section 6.6 section 6.3.5
- GRPO replaces PPO's learned value function with group-relative advantage normalization across multiple completions, and is popular for reasoning tasks. section 6.6
Advantage-weighted loss
For each sampled completion, sum token log probabilities only over completion tokens, multiply by its advantage, negate, average, and backpropagate. With positive advantage, minimizing the loss raises the completion probability; with negative advantage, it lowers it. PPO instead weights the advantage by a new-to-old probability ratio and clips that ratio to prevent overly large changes. section 6.2.1 section 6.3.1 section 6.3.5


