Zenaique

Compute the KL shaped reward this PPO rollout actually optimizes

Predict output·Medium·4.0 · 0·~2 min·Asked atEyNeo4jPhonepe
Attempt it
A PPO rollout earns reward model score 2.4. Its sequence level KL divergence from the frozen reference policy is 8.0 nats, and the KL coefficient beta is 0.05. Using shaped_reward = rm_score - beta * KL, compute the reward the policy gradient actually sees.
TL;DR

Shaped reward equals 2.0. The KL penalty taxes 0.4 from the 2.4 RM score, leaving 2.0 for the policy gradient. The tax is what stops the policy from drifting into reward-model exploits.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine a kid earning $2.40 for chores, but if they wander too far from the house while doing them, the parent charges a small wandering fee. The kid wandered 8 blocks and the fee is 5 cents per block, so 40 cents gets deducted. The kid takes home $2.00. The wandering fee is not a punishment for working hard; it is a guardrail that keeps the kid close enough to home that they actually finish chores instead of getting lost.

Key concepts

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

The shaped reward is the single most important quantity in PPO-style RLHF. It is what the policy actually optimizes against, and it is what determines whether the trained policy will reward-hack the underlying reward model or stay productively close to the SFT reference.

For this rollout, the arithmetic is direct: RM score 2.4, KL drift 8 nats, beta 0.05. The shaped reward is 2.0. The KL term taxed 0.4 worth of reward out of the raw score, which the policy gradient never sees.

This deep dive walks through why the formula has this shape, what the KL term is structurally protecting against, and how production teams choose beta and implement the KL penalty in practice.

The formula and the arithmetic

The standard PPO-RLHF shaped reward is:

shaped_reward=rRM(x,y)βKL(π(x)πref(x))\text{shaped\_reward} = r_{\text{RM}}(x, y) - \beta \cdot \text{KL}(\pi(\cdot \mid x) \,\Vert\, \pi_{\text{ref}}(\cdot \mid x))

For this rollout, r_RM = 2.4, beta = 0.05, KL = 8.0 nats. Plugging in:

shaped_reward=2.40.058.0=2.40.4=2.0\text{shaped\_reward} = 2.4 - 0.05 \cdot 8.0 = 2.4 - 0.4 = 2.0

The policy gradient is computed against the shaped reward, not the raw RM score. In a value-baseline PPO setup, the advantage is shaped_reward - V(x), where V is the critic; in GRPO it would be the group-normalized version of the shaped reward.

The 0.4 tax is what 8 nats of drift costs at beta=0.05. If beta were 0.01, the same drift would cost only 0.08; at beta=0.3, it would cost 2.4 — completely cancelling the RM gain. The choice of beta directly controls how much drift the policy is willing to pay for.

Make the formula explicit. The PPO reward signal used at training time is rshaped(s,a)=rϕ(s,a)βlogπθ(as)πref(as)r_{\text{shaped}}(s, a) = r_{\phi}(s, a) - \beta \cdot \log \frac{\pi_\theta(a|s)}{\pi_{\text{ref}}(a|s)}. Here rϕr_\phi is the learned reward model's score, πθ\pi_\theta is the current policy, πref\pi_{\text{ref}} is the SFT anchor, and the second term is an unbiased per-token estimator of the KL between policy and reference. For a rollout with rϕ=2.4r_\phi = 2.4 and a token-averaged log-ratio of $0.6atat\beta = 0.1, the shaped reward is \2.4 - 0.06 = 2.34$. Small per-step, large in aggregate over thousands of tokens.

Why the KL term exists structurally
Implementation choices in production
Why beta selection matters and how to do it right
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • OpenAI InstructGPT and ChatGPT-era PPO runs use this exact KL-shaped reward as the gradient signal
  • DeepSeek-R1's GRPO recipe applies a per-token KL penalty against the reference policy for the same trust-region reason
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QHow would an adaptive KL controller change the calculation here?
A

Discuss target-KL controllers that adjust beta online: at KL=8 with target=6, beta would rise; at KL=8 with target=12, beta would fall.

1 more follow-up an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Forgetting to subtract the KL term, or assuming the KL penalty does not apply when the reward is already positive.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • The shaped-reward formula r_RM - beta * KL

  • Why the KL term is a trust-region penalty

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
What is RLHF, and why is it used after pretraining?
MCQ·Easy