Lab#LL02-1: Group advantage and length cost

Lab

📘 Lab#LL02-1: Group advantage and length cost

How does a reinforcement-learning run turn “right” and “wrong” into a push on the model? And how do you teach it to be right and brief? We first think it through on paper, then compute it on toy rollouts in the browser.

This lab follows the “RL at scale” part of Brandon Amos’s talk Post-training Beam and the Beam technical report. The articles that go with it are RL at scale and Evolution of post-training. The two cells are toys: no model, no GPU, just the arithmetic. The same scripts live in labs/ll02-1/ in this wiki repo.

1 The thinking first

1.1 A score is not yet a lesson

In RL the model tries a task and a verifier says 1 (correct) or 0 (wrong). That number alone does not say which way to move. If the task is easy and every try scores 1, there is nothing to learn. If it is hopeless and every try scores 0, there is nothing to learn either. The useful information is in the difference between tries.

So GRPO-style training samples a group of attempts at the same prompt and compares each one with the group:

\[ \tilde{A}_i = r_i - \frac{1}{G}\sum_{j=1}^{G} r_j \]

The advantage \(\tilde{A}_i\) is positive for an attempt that did better than its siblings, negative for one that did worse. The update makes positive-advantage attempts more likely and negative ones less likely.

Everyday example

A class of four sits the same test. A teacher who only marks “pass” or “fail” learns nothing from a class that all passed. A teacher who compares the four papers sees which approach worked, and tells the class to do more of that.

Slide titled Preliminary: PPO and GRPO. A prompt x produces four samples y1 to y4 with rewards 0, 1, 1, 0; the advantage is each reward minus the group mean, feeding a policy update.

Group-based feedback: four samples, their rewards, and the advantage as reward minus the group mean. Image: Brandon Amos, Post-training Beam, slide 25 [1]. Original methods: PPO [3] and GRPO [4].

Before you run the cell, predict: with rewards \(0, 0, 0, 1\), what advantage does the lucky attempt get? And what happens when all four are correct?

1.2 Every token has a price

Reward only correctness and the model learns that writing more never hurts. Long reasoning is slow and expensive to serve. Beam adds two things [1][2]:

  1. An effort setting \(e\) (low, high) that fixes a budget \(B(e)\) of tokens. Run past it and the attempt is stopped with no correctness reward.
  2. A linear length cost: every token costs \(\lambda(e)\), so the reward becomes \(r(y) - \lambda(e)\,c(y)\), where \(c(y)\) is the number of tokens.

In the talk’s illustration the price is tied to the budget, \(\lambda(e) = \kappa / B(e)\). A bigger budget means cheaper tokens, and spending the whole budget always costs exactly \(\kappa\) [1].

Slide titled Token efficiency via a linear length penalty with the objective r of y minus lambda of e times c of y, the flow from effort to budget to token price, and a plot of penalty against rollout length for low and high effort.

Effort, budget and a linear token cost. Image: Brandon Amos, Post-training Beam, slide 33 [1]. Original: Beam Model Technical Report, §4.1.2 [2]; the budget-normalised price is the talk’s illustration.

Predict again: if \(\kappa\) is small, which of two correct answers wins, the short one or the long one? If \(\kappa\) is large, can a short wrong answer beat a long correct one?

2 Group advantage

The cell computes the advantage for four toy groups.

Group advantage
rl advantage grpo

Ex#LL02-1

You should see \(-0.50, +0.50, +0.50, -0.50\) for the mixed group, and \(+0.75\) for the one lucky try: a rare success is a big lesson. The all-correct and all-wrong groups give zero everywhere. That is why task curation filters out tasks the model always solves or never solves: they burn GPU time and teach nothing (see Tasks, verifiers and judges).

Try it: change a group to [1, 1, 1, 0] and see which attempt gets the big negative push.

3 Length cost and effort

Now each rollout is (correct?, tokens). The cell prints the shaped reward and its advantage within the group, for three settings.

Length cost and effort
rl length-cost

Ex#LL02-2

Read the three tables:

  • Low effort, small \(\kappa = 0.2\). Both correct answers win, and the short one wins a little more. The very long answer ran past the 2,000-token budget, so it lost its correctness reward. That is the behaviour we want.
  • Low effort, large \(\kappa = 1.5\). Now the long correct answer has a negative reward, and the short wrong answer gets a higher advantage than it. The price is so high that the model is pushed toward giving up early. This is the failure mode the talk warns about: too strong a penalty sacrifices correctness [1].
  • High effort, \(\kappa = 1.5\). The same \(\kappa\) over an 8,000-token budget makes each token four times cheaper. Every correct answer is positive again, short still beats long, and the wrong answer is clearly last.

Try it: add lines such as table("low", 0.6) with values between 0.2 and 1.5 and find where the long correct answer stops beating the short wrong one.

4 What this toy leaves out

  • No model, no gradients. A real update multiplies each advantage by the gradient of the log-probability of every token in the attempt, with PPO-style clipping and corrections for stale samples [3][4]. See RL at scale.
  • Real rewards are not only 0 or 1: judges give scores, and detected reward hacks get zero correctness reward [1].
  • Beam’s report describes a linear penalty and an effort-controlled budget; the \(\kappa / B(e)\) normalisation is the talk’s illustration, not a published coefficient schedule [1].

5 FAQ

Why subtract the mean instead of using the raw reward? Raw rewards would push up every correct attempt by the same amount, even on a task the model always solves. Subtracting the group mean keeps only the information that tells good attempts from bad ones, and it needs no separate critic model.

Some GRPO versions also divide by the standard deviation. Why not here? That is a common variant. The talk shows only the centred version, and so does this lab [1]. Dividing by the spread rescales the push but does not change its sign.

Why tie the token price to the budget? So that “high effort” really means “you may think longer”. With one fixed price, a high-effort run would be punished for using the room it was given.

Does this make reasoning harder to read? It can. A strong length cost encourages clipped, unnatural text. That is one of the trade-offs listed on RL at scale.

6 See also

7 References

Back to top