Two Things RL Beginners Get Confused About
and the one fact that clears up both
Contents
Over the past few months I have had a lot of technical discussions with colleagues who are ramping up on RL for LLM post-training. Most of them come from a supervised-learning background, and two comments from those conversations stuck with me, because each one is correct about the math on the page and still leads to the wrong picture of what RL does. Since they are probably common among people new to RL, I am writing them down here.
Comment 1: “RL is just weighted SFT.” This came from a colleague who had just worked through a policy-gradient derivation. The SFT loss and the REINFORCE loss, as you would write them in code, look like this:
His reading: “The only difference is the \(R(y_i)\) in front. You sample from the model, pretend the samples are labels, and weight each one by its reward. It’s SFT with a multiplier.” He was right about the math, and that is exactly what makes the comment hard to answer.
Comment 2: “The loss function means nothing.” This came from a colleague reading OpenAI’s Spinning Up, where the same \(\mathcal{L}_{\mathrm{RL}}\) is introduced together with a warning box1 that says, among other things:
“Even though we describe this as a loss function, it is not a loss function in the typical sense from supervised learning. […] It doesn’t measure performance. […] After that first step of gradient descent, there is no more connection to performance. This means that minimizing this ‘loss’ function, for a given batch of data, has no guarantee whatsoever of improving expected return. You can send this loss to \(-\infty\) and policy performance could crater; in fact, it usually will. […] The loss function means nothing.”
She found this confusing rather than clarifying, and I think her questions were the right ones:
- If the loss means nothing, why do we minimize it?
- If it has the right gradient, what exactly goes wrong after the first step?
- And how far is too far?
Side by side, the two comments contradict each other: the first says \(\mathcal{L}_{\mathrm{RL}}\) is just SFT with a weight, so surely it behaves like a loss; the second says it is not a loss at all. They turn out to be two sides of the same fact.
This post works through them in a world small enough that everything can be computed by hand. Part 1 takes Comment 1 and asks what RL actually optimizes. Part 2 takes Comment 2 and asks what the number your training loop prints actually measures. Part 3 names the one fact behind both.
A world with three answers
There is one prompt, and the model can answer it in only three ways:
| answer | what it is | reward \(R\) | base model \(\pi_\base\) | SFT demos \(p\) |
|---|---|---|---|---|
| A | the best answer | \(1.0\) | \(0.1\) | \(0.5\) |
| B | an acceptable answer | \(0.6\) | \(0.6\) | \(0.5\) |
| C | a wrong answer | \(0.0\) | \(0.3\) | \(0\) |
A policy is a distribution \(\pi=(\pi_A,\pi_B,\pi_C)\) over the three answers. It is produced by a softmax over three logits \(\theta=(\theta_A,\theta_B,\theta_C)\), and the logits are the parameters we train:
\[\pi_k=\frac{e^{\theta_k}}{e^{\theta_A}+e^{\theta_B}+e^{\theta_C}},\qquad k\in\{A,B,C\}.\]The base model is \(\pi_\base=(0.1,\,0.6,\,0.3)\): it usually says B, sometimes C, and rarely produces the best answer. This is the realistic case: if the base model already gave the best answer most of the time, there would be little left to train.
SFT is given demonstrations, say \(p=(0.5,0.5,0)\), and maximizes their log-likelihood. RL is given the reward table and maximizes the expected reward of the model’s own answers:
Keep an eye on what sits under each expectation: in SFT a fixed \(p\), in RL the very \(\pi\) we are training. Everything in this post follows from that one difference.
Part 1: Comment 1, “RL is just weighted SFT”
Comment 1 is a statement about one gradient step on one sample, and at that level it is right. The question is what happens when you average over a batch, because that is what training actually does. This part answers it in four steps:
- Step 1 checks the comment on a single sample. The two gradients are the same vector up to a scalar.
- Step 2 averages over a batch. The two averages run over different distributions, and that turns the same per-sample gradient into two different update rules, equation (1).
- Step 3 reads the two rules: what each one pushes on, and where each one comes to rest.
- Step 4 runs both rules from the base model and watches the path, which is where RL’s character shows.
Steps 1 and 2 are the math; Steps 3 and 4 are what the math means.
Step 1: per sample, the comment is right
Take one sampled answer \(y\) and differentiate its term in each loss:
Same vector, scaled by \(R(y)\). The RL update pushes up the log-probability of the sampled answer exactly as SFT pushes up the log-probability of a label, only harder or softer depending on the reward. At the level of a single sample, Comment 1 is simply correct.
Step 2: a loss is an average, and the averages run over different things
But nobody trains on one sample. The loss is an average over a batch, in the limit an expectation, so the gradient that actually moves the parameters is
In SFT the samples come from the dataset \(p\), which does not care what \(\theta\) is. In RL they come from \(\pi_\theta\) itself, so how often each answer appears in the average depends on the model being trained. Per sample this difference is invisible; in expectation it decides everything.
Recall that \(\pi\) is a softmax over the logits \(\theta=(\theta_A,\theta_B,\theta_C)\). Differentiating the softmax gives \(\partial\log\pi_i/\partial\theta_k=\delta_{ik}-\pi_k\), where \(\delta_{ik}\) is \(1\) if \(i=k\) and \(0\) otherwise. In words: raising logit \(k\) raises its own probability and lowers everyone else’s, in proportion to their current size. Now average this over \(y\sim p\) for SFT and over \(y\sim\pi\) for RL:
with \(\bar R=\sum_i\pi_iR_i\) the current expected reward. Writing \(\dot\theta_k\) for the rate at which logit \(k\) moves under gradient ascent with a small step, the two update rules are
Where does the \(\pi_k\) in the RL rule come from? Not from the per-sample update. When answer \(k\) is the one sampled, its own logit moves by \(R_k(1-\pi_k)\): for the same reward, a rare answer gets a bigger push per sample, not a smaller one. The \(\pi_k\) comes from the averaging. Answer \(k\) shows up in the batch a fraction \(\pi_k\) of the time, so its push is counted \(\pi_k\) of the time, and once you average, the push on logit \(k\) is \(\pi_k(R_k-\bar R)\): the per-sample boost for rare answers is gone, and what is left is frequency times advantage. The \(\pi_k\) is how often the model already produces answer \(k\). In SFT the same place is taken by \(p_k\), which is fixed by the dataset.
There is a compact way to say where both the \(\pi_k\) and the \(-\bar R\) come from. Write \(\mathbf 1[a=k]\) for the indicator that the sampled answer is \(k\). Then the RL rule is a covariance under the model’s own sampling,
\[\dot\theta_k=\operatorname{Cov}_{a\sim\pi}\big(\mathbf 1[a=k],\,R(a)\big)=\pi_kR_k-\pi_k\bar R,\]so the logit of answer \(k\) moves by how much “the answer was \(k\)” covaries with “the reward was high.” That covariance is zero when \(k\) is never sampled and zero when \(k\)’s reward equals the average, which are the two ways the rule can stop. And a covariance ignores constant shifts: replacing \(R\) by \(R-b\) for any baseline \(b\) leaves the expected update unchanged, which is why \(\bar R\) showed up on its own and why Part 2 can use an advantage in place of the reward.
Step 3: reading the two rules
The SFT rule says: move each logit toward its target, with a force equal to the gap between where the probability is and where it should be. An answer the model never produces but the demonstrations contain gets a full-size push. SFT can put mass where there is none.
The RL rule says: move each logit in proportion to two things, how much better than average the answer is (\(R_k-\bar R\)) and how likely the model already is to produce it (\(\pi_k\)). A rare answer barely moves, no matter how good it is; a common answer moves fast. RL can only redistribute mass among answers it already produces. It is a rich-get-richer rule.
Where does each rule come to rest? A rule stops when every \(\dot\theta_k\) is zero.
- SFT stops when \(\pi=p\). The model has matched the demonstrations: A half the time and B half the time, even though A is strictly better.
- RL stops when \(\pi_k(R_k-\bar R)=0\) for every \(k\): no probability, or reward equal to the average. As long as A does not hold all the mass, the average is below A’s reward of \(1.0\), so A is above average and still rising. The only resting point is all probability on A. Step 4 shows what this looks like in time. (If several answers tie for best, the rule rests on any mix of them.)
SFT ends by matching a distribution; RL ends by committing to the best answer.
Step 4: the path, not just the endpoint
Step 3 said where each rule ends. The path to the endpoint matters just as much, because the RL rule makes the path depend on where the model starts. Figure 1 runs both rules from the base model \((0.1,0.6,0.3)\) with a small step size and plots the three probabilities over time.
- Left, SFT: settles at the demos, A and B half each. Nothing surprising.
- Middle, RL with the graded reward: this is the panel to look at. RL does not head straight for A. It first drives C out and piles the mass onto B, the acceptable answer it was already producing; A barely moves because \(\pi_A\) is small. Only after C is gone does A start to grow, slowly, at a rate set by its own small probability. The rare good answer is exactly the one RL is slow to find.
- Right, RL with a binary reward, where A and B are both fully correct: RL does not spread over the two good answers. It concentrates on B, the one it already preferred, and A shrinks to 3%. While C is pushed out, the two good answers grow in proportion to their current size, and B started six times larger.
Why does A win at all, when B had a six-to-one head start and, at the start, the bigger push (\(0.084\) against \(0.054\), from the rule)? Step 3 gave the static reason: A is the best answer, so it is above average at every moment, and its push never reverses. The middle panel shows the same thing in time, and the key is that the bar keeps rising. Each answer is compared with the model’s current average reward \(\bar R\), and \(\bar R\) goes up as C is driven out: it starts at \(0.46\), and once C is gone it is a mix of A’s \(1.0\) and B’s \(0.6\), above \(0.6\) whenever A has any mass at all. Around time 10 the average passes \(0.6\), B’s own reward. From then on B is below average, its push turns negative, and its probability starts to fall; that is the peak of the orange curve. As B’s mass is pushed out there is nowhere for it to go but A. Hold on to this; Part 2 is about what happens when the bar stops moving.
Part 2: Comment 2, “The loss function means nothing”
Part 1 was about the objective: what RL climbs and where it ends up. Part 2 is about the loss: the number your training loop computes from one batch, and what it has to do with that objective. We stay in the three-answer world, with the same base model as the starting point. The three subsections answer the three questions from the introduction, in order.
What the loss is, and is not
Here is the REINFORCE loss as written in code. Samples \(a_i\) are drawn from the current policy \(\pi_\old\), and each gets an advantage \(A_i=R(a_i)-\bar R_\old\): its reward minus the old policy’s average (no relation to answer A). Advantages average to zero under \(\pi_\old\). Subtracting the average leaves the expected gradient unchanged (a covariance ignores constant shifts, as in Step 2), but it makes each sample’s push less noisy. Then:
logp = log_prob(model, a_i) # log pi_theta(a_i)
loss = -(A_i.detach() * logp).mean() # gradient flows through logp only
As a function of \(\theta\) with the batch frozen, this loss is \(-\tilde g(\theta)\), where
\[\tilde g(\theta)=\E_{a\sim\pi_\old}\big[A(a)\log\pi_\theta(a)\big].\]Two facts about this function are all you need, and together they are what the warning box in Comment 2 is saying:
- Its gradient at \(\theta=\theta_\old\) is \(\E_{a\sim\pi_\old}[A(a)\nabla\log\pi_\old(a)]=\nabla J_{\mathrm{RL}}(\theta_\old)\), the true policy gradient. That is the reason the loss is written this way.
- That is the only thing it does. The value of \(\tilde g\) is not the expected reward, nor an estimate of it. It is linear in \(\log\pi_\theta\) and so unbounded: push \(\log\pi_\theta(a)\to-\infty\) for any sample with negative advantage and the “loss” improves forever, while the true return is bounded by the largest reward.
So the answer to “why minimize something that means nothing” is that we don’t. We take its gradient at one point, where the gradient is right, and we never look at its value. That is what a surrogate is. In SFT the loss and the objective are the same function. In RL they only share a slope, and only at one point.
What goes wrong after the first step
Suppose you ignore this and treat \(\tilde g\) as a loss anyway: collect one batch and keep taking gradient steps on it, as you would in SFT. Concretely, in the three-answer world: draw the batch from the base model, so \(\pi_\old=\pi_\base=(0.1,0.6,0.3)\), with advantages \(A=R-\bar R_\old=(0.54,\,0.14,\,-0.46)\). To rule out sampling noise as the explanation, let the batch be infinitely large, so that everything below is an exact expectation. Figure 2 compares three ways of using the batch:
- keep stepping on it;
- keep stepping on it, but with PPO-style clipping (explained in the next subsection);
- draw a fresh batch after every step, which is the RL rule of Part 1.
Run 1 is what the warning box describes. Its loss goes down at a constant rate, step after step. Its true return rises for twenty steps, to \(0.63\), then slides to \(0.61\) and stays: the model has converged onto B, the acceptable answer, and will never leave. The reason takes one line to see. The gradient of the frozen-batch loss with respect to the logits is
\[\frac{\partial\tilde g}{\partial\theta_k}=\sum_i\pi_{\old,i}A_i(\delta_{ik}-\pi_k)=\pi_{\old,k}A_k-\pi_k\underbrace{\textstyle\sum_i\pi_{\old,i}A_i}_{=0}=\pi_{\old,k}A_k ,\]a constant vector that does not depend on \(\theta\) at all. Gradient steps on a fixed batch walk in a fixed direction forever, and the direction favors whichever answer had the largest \(\pi_{\old,k}A_k\) when the batch was drawn: \(0.6\times0.14=0.084\) for B, against \(0.1\times0.54=0.054\) for A. B wins because it was common then, and nothing in the batch can ever say otherwise.
Compare with the true rule from Part 1, \(\pi_k(R_k-\bar R)\): the same expression, but with \(\pi\) and \(\bar R\) updated as the policy moves. The rising bar is what sank B in Step 4. Here the bar is frozen at the old average \(0.46\), so B counts as above average, by \(0.14\), forever, however much mass it has already taken. Run 3 is the true rule, and A wins as in Step 4. Run 2 sits in between: it moves a little and then freezes, because once every answer’s probability has moved more than 20% in the direction its advantage points, every sample is clipped and the gradient is zero. That is the clip doing its job: it refuses to go further on a stale batch, and the freeze is the cue to draw a new one.
This is where Comment 1 and Comment 2 meet: the factor \(\pi_k\) that makes RL sharpen in Part 1 is the same factor that, left frozen, makes the loss lie in Part 2.
How far is too far: the TRPO bound
The warning box says that after the first step there is “no more connection to performance.” That is too strong, and my colleague was right to be confused by it. There is a connection. It weakens with distance from the policy that drew the batch, and the rate at which it weakens is known. This subsection builds up to that result in four moves: a better surrogate, the bound, the improvement guarantee it gives, and what TRPO, PPO and REINFORCE each do with it. Then a concrete example.
A better surrogate. There is a second surrogate, built from the same batch, that does better than \(\tilde g\). Instead of \(\log\pi_\theta(a)\) it uses the ratio \(\pi_\theta(a)/\pi_\old(a)\):
\[g(\theta)=J(\theta_\old)+\E_{a\sim\pi_\old}\Big[A(a)\,\frac{\pi_\theta(a)}{\pi_\old(a)}\Big].\](\(J\) is \(J_{\mathrm{RL}}\); I drop the subscript from here on.) The ratio says how much more or less likely the new policy is to produce the old sample. This is importance sampling, and \(g\) is the objective that PPO (Proximal Policy Optimization) and TRPO (Trust Region Policy Optimization) actually optimize. It is also the function \(\tilde g\) was approximating: near \(\theta_\old\) the ratio is close to \(1\), and for \(x\) near \(1\), \(x\approx1+\log x\). Make that replacement, use the fact that advantages average to zero, and \(g\) turns into \(\tilde g\) plus a constant. So \(\tilde g\) is \(g\) to first order around \(\theta_\old\): the same slope there, but \(\tilde g\) keeps rising in a straight line where \(g\) bends. REINFORCE, seen this way, is one gradient step on \(g\), taken at the one point where the two agree.
What \(g\) still cannot fix is two things.2 With a finite batch, the few samples whose ratio has grown large take over the average, and the estimate gets noisy. And as soon as an episode has more than one decision, the states the policy visits change as the policy changes, while \(g\) is computed only on the states the old policy visited. The bound below covers both.
The bound. Kakade and Langford (2002) and Schulman et al. (2015) proved that for every \(\theta\),
\[J(\theta)\;\ge\;g(\theta)\;-\;C\cdot\dist(\pi_\old,\pi_\theta),\]where \(\dist\) is a KL-type distance between what the two policies do and \(C\) is a constant that grows with the size of the advantages and the horizon.3 Read the right-hand side as a floor under the true return. At \(\theta_\old\) the distance is zero and the floor touches \(J\): \(g(\theta_\old)=J(\theta_\old)\). Away from \(\theta_\old\) the surrogate may overestimate \(J\), but by no more than \(C\) times the distance moved, and subtracting that worst case is what makes the right-hand side a floor.
The improvement guarantee. Subtract \(J(\theta_\old)=g(\theta_\old)\) from both sides. For any new \(\theta_1\), however you got there,
\[J(\theta_1)-J(\theta_\old)\;\ge\;\underbrace{\big[g(\theta_1)-g(\theta_\old)\big]}_{\text{gain in the surrogate}}\;-\;\underbrace{C\cdot\dist(\pi_\old,\pi_{\theta_1})}_{\text{price of leaving }\theta_\old}.\]Both terms on the right can be computed from the batch you already have. The true return is guaranteed to improve whenever the gain beats the price. This is the bridge from the loss you can see to the return you cannot.
What the algorithms do with it. Everything now turns on the distance term. The gain is whatever the optimizer squeezes out of \(g\); the price grows with how far you move from \(\pi_\old\). Each policy-gradient algorithm is a way of keeping the price in check:
- TRPO maximizes \(g\) subject to \(\dist(\pi_\old,\pi_\theta)\le\delta\). The price is capped explicitly, at \(C\delta\). The cost is a constrained optimization step on every batch.
- PPO clips the ratio \(\pi_\theta(a)/\pi_\old(a)\) to \([1-\epsilon,\,1+\epsilon]\) inside \(g\). Once a sample’s ratio has left that window, moving it further earns nothing, so the optimizer has no incentive to go far. It is a cheap stand-in for the same cap, and it is what most LLM post-training uses. Note that the ratio is always to the policy that generated the batch, held fixed across all the minibatch epochs on that batch, never to the previous iterate: the bound’s distance is measured from \(\pi_\old\).
- REINFORCE takes a single gradient step of size \(\eta\) on \(g\) (the gradient of \(\tilde g\) is the same at \(\theta_\old\)) and checks nothing. For it the bound reduces to a statement about \(\eta\):
- Small \(\eta\): the gain in \(g\) grows linearly with \(\eta\) (to first order it is \(\eta\,\|\nabla g\|^2\)), while the distance grows quadratically, as the KL between two nearby policies does. The right-hand side is positive: the step is guaranteed to improve.
- Large \(\eta\): \(g\) is bounded, so its gain flattens out, and on a complicated surface a big step can overshoot into negative gain; meanwhile the price keeps growing. The guarantee is gone.
A concrete example. To see the bound at work we need the smallest problem where \(g\) can be wrong even with infinite data: two decisions per episode, so that which states you visit depends on the policy.
At \(s_0\) the policy goes left (L) or right (R); then, at \(s_L\) or \(s_R\), it picks up (u) or down (d), which pays the reward. The old policy is 50/50 at \(s_0\) and at \(s_L\), and picks u at \(s_R\) only 35% of the time, so its return is
\[J(\theta_\old)=\underbrace{0.5}_{\text{go L}}\,(0.5\times0.52+0.5\times0.48)+\underbrace{0.5}_{\text{go R}}\,(0.35\times1.00+0.65\times0)=0.425 .\]The policy gradient at \(\theta_\old\) points in two directions at once: pick u more often at \(s_R\), whose advantage there is \(+0.65\), the biggest number in the problem; and go left more often at \(s_0\), because by the old policy’s numbers the left branch is worth \(0.50\) and the right only \(0.35\). Figure 3 moves along that gradient direction with step size \(t\) and plots four quantities against \(t\): the REINFORCE loss \(\tilde g\), the surrogate \(g\), the true return \(J\), and the floor \(g-C\cdot\dist\).
What goes wrong is visible in the gap between the blue and black curves. \(g\) is an average over the old batch, in which half the episodes went right. So it counts the improvement at \(s_R\), picking u more often, at full weight, as if \(s_R\) were still visited half the time. But the same step also sends the policy left more often, so the new policy visits \(s_R\) less and less, and the improvement it banked there is worth less and less. The true return peaks at \(t\approx3\), where the policy still goes right 28% of the time; beyond that the lost visits to \(s_R\) outweigh the better choice made there, and \(J\) falls while \(g\) keeps rising toward \(0.82\), still paying for u at a state the policy hardly visits.
Now the green curve, the floor \(g-C\cdot\dist\). It is not a good estimate of \(J\); it sits far below it almost everywhere. What it gives you is a guarantee. Its maximizer, \(t\approx0.6\), is a step certified to improve, and it does: \(J=0.495\), up from \(0.425\). The best true step is about five times larger, at \(t\approx3\), and nothing in the old batch can tell you so: the bound is sufficient, not necessary.
Part 3: The one fact behind both
In supervised learning the dataset is fixed and the model moves toward it. In RL the model generates the dataset, scores it, and moves; then the dataset is thrown away and a new one is generated for the next step. Comment 1 and Comment 2 are this loop seen from two sides. (Spinning Up’s warning box actually says this first, “the data distribution depends on the parameters”; I left it out of the quote above because it is the punchline.)
Part 1 is what the loop does to the objective and Part 2 is what it does to the loss; the trust region is the price of leaving the snapshot, and resampling is how you take a new one. Side by side:
| SFT | RL | |
|---|---|---|
| Data come from | a fixed dataset | the current policy |
| Objective | concave; optimum \(=p\) | linear; optimum \(=\) a corner |
| Gradient on a logit | \(p_k-\pi_k\) (gap to target) | \(\pi_k(R_k-\bar R)\) (frequency \(\times\) advantage) |
| Batch loss estimates | the objective, at every \(\theta\) | the objective’s gradient, at one \(\theta\) |
| Epochs on one batch | fine; that is the goal | optimizes a stale snapshot |
| Read the loss curve? | yes | no; read the return |
| The model learns | to cover what the data do | to commit to what it already does well |
A few practical habits follow from this:
- Watch the return, not the loss.
- Don’t run epochs on a rollout batch unless something (clipping) caps how far you move from the policy that produced it.
- Expect the learning rate to be more delicate than in SFT, because for a plain policy-gradient step it is the trust region.
- Expect entropy to fall and rare good behaviors to emerge slowly. That is the dynamics, not a bug, and it is why entropy bonuses, asymmetric clipping and sampling temperature are standard knobs.
- Whenever you see “KL” in an RL paper, ask which one. The KL to a reference model in the objective is about the destination; the KL to the rollout policy in the trust region is about the step.
Further reading
Achiam’s Spinning Up: Intro to Policy Optimization (2018) is where the warning box comes from. Karpathy’s Pong from Pixels (2016), Lilian Weng’s Policy Gradient Algorithms (2018) and Rui Shu’s An Homage to REINFORCE (2024) are three views of the policy gradient. Schulman et al.’s TRPO (2015) and PPO (2017) papers contain the bound and its cheap approximation. Tajwar et al. (2024) ablate on-policy sampling and negative weights separately and find that each alone sharpens.
- https://spinningup.openai.com/en/latest/spinningup/rl_intro3.html, in the “You Should Know” box under “Implementing the Simplest Policy Gradient.” ↩
- In the three-answer world \(g\) needs no help. With one decision per episode, \(\sum_k\pi_{\old,k}A_k\,\pi_{\theta,k}/\pi_{\old,k}=\sum_k\pi_{\theta,k}A_k=J(\theta)-J(\theta_\old)\), so \(g(\theta)=J(\theta)\) exactly, for every \(\theta\), and stepping again and again on the old batch with \(g\) instead of \(\tilde g\) would find A, just as resampling does. ↩
- Schulman et al. use \(C=4\epsilon\gamma/(1-\gamma)^2\) with \(\epsilon=\max|A|\) and the largest KL over states. Figure 3 plots the tighter version of Achiam et al. (2017), whose constant depends on the advantages the new policy picks up; with Schulman’s constant the bound is so loose here that its best step would be \(t=0\). ↩