Zenaique

Compute the KL shaped reward this PPO rollout optimizes

Predict output·Medium·4.0 · 0·~2 min·Asked atNeo4jPhonepe
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 dollars for chores. 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 dollars. The wandering fee is not a punishment for working hard. It is a guardrail that keeps the kid close enough to home that they 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 optimizes against. It also 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.

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.4−0.05⋅8.0=2.4−0.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.

Many PPO implementations apply the penalty token by token: rshaped(s,a)=rϕ(s,a)−β⋅log⁡πθ(a∣s)πref(a∣s)r_{\text{shaped}}(s, a) = r_{\phi}(s, a) - \beta \cdot \log \frac{\pi_\theta(a|s)}{\pi_{\text{ref}}(a|s)}, with the reward model's score added only at the last token. Here rϕr_\phi is the learned reward model's score, πθ\pi_\theta is the current policy, and πref\pi_{\text{ref}} is the SFT anchor. Summed over the response, the per token log-ratios give the sequence log-ratio, and its expected value under the policy is the sequence-level KL. If the log-ratios of this rollout sum to 8.0 nats, the total penalty is again 0.05 · 8.0 = 0.4, and the shaped return is 2.0.

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.

  • InstructGPT's PPO runs used this KL-shaped reward, with a per-token KL penalty from the SFT model and a coefficient of 0.02
  • DeepSeekMath's GRPO adds a per-token KL term against the reference policy directly to the loss instead of the reward. DeepSeek-R1-Zero used a coefficient of 0.001
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