All six chapters. The lab's static comparisons are included. Use your browser's Print command for a paper copy.
Chapter 1
One rollout
An answer is the visible end of a path. Start by seeing the path.
What was the rollout?
You give a language model a small task:
A box has 3 red labels and 2 blue labels. How many labels? Reply with one digit.
It replies 5. What, exactly, was the rollout?
Not the digit alone. In this article, one rollout is one sampled trajectory: the path from the starting prompt through generated actions to a stopping condition. The completed text is the part you can read. The path explains how that text was produced.
RL introductions commonly use trajectory, episode, and rollout for this idea, although individual systems may use “rollout” for a shorter segment. Spinning Up: trajectories
A longer context, one action at a time
For a simple text-only, single-turn interaction, picture the prompt as the beginning of a line. The model selects a token, appends it, and uses that longer context for the next selection. Eventually generation stops.
Figure 001Each token becomes context
The prompt stays; the generated prefix grows. A completion is the generated sequence rendered as text. Token marks are symbolic, not actual tokenizer boundaries; this is a simple text-only mapping.
We can name the parts without guessing how a particular tokenizer would split the words:
st=(x,a1,…,at−1),at∼πbeh(⋅∣st)
Here x is the prompt, st is the prompt plus the generated prefix, and at is the next token. The policy πbeh supplies the action probabilities. Repeating these steps gives one trajectory, τ=(x,a1,…,aN), where N is the number of generated tokens.
The subscript “beh” means this policy generated the behavior; chapter 5 will make that distinction useful. This token/state mapping is a synthesis for the stated text-only case, not a model of every tool-using agent. DeepSeekMath §4.1.1
First collect, then evaluate
The rollout exists before a reward function scores it. A score can be attached afterward; an update may happen later still. Neither a correct answer nor a completed update is required to identify the trajectory.
If you independently generate six responses to the same prompt, you have six rollouts—even if every response reads 5. You do not have one rollout with six steps.
Check your understanding
You generate 5 twice and The answer is 5. once. How many rollouts? Does the duplicate count?
Reveal answer
Three. Each separate generation is a trajectory; duplicate text does not merge them.
One answer tells you what happened once. What tells you what could happen?
Chapter 2
A distribution of answers
Separate what could happen from what happened in a few samples.
Possibilities are not counts
Suppose repeated responses to our prompt include 5, The answer is 5., and 6. They are three possible answers, not three steps in one answer.
A stochastic policy assigns probabilities; a sampled group records what was actually drawn. These are different objects. A probable answer can fail to appear in a small group. A less probable answer can appear more than once. Sampling permits variety, but does not promise it. Spinning Up: stochastic policies
A deliberately small world
To see that distinction without downloading a model, our lab uses only three whole-completion choices. These choices and logits are invented teaching inputs, not measurements of an LLM.
Toy whole-completion distribution at temperature 1
Index
Completion
Logit
Probability
0
5
1.2
58.96%
1
The answer is 5.
0.4
26.49%
2
6
−0.2
14.54%
A logit here is an unnormalized score. Softmax turns the three scores into probabilities:
pi(T)=∑j=02exp(zj/T)exp(zi/T)
The probabilities sum to one before display rounding. The table's percentages sum to 99.99% only because each is rounded separately.
Figure 003Six samples. Three distinct answers.
Each line is one separately sampled whole completion, not a token-decoding tree. Equal line weights count draws, not probabilities. This is the fixed-seed toy group at T = 1, K = 6—not a measurement of an LLM.
Temperature changes the distribution
At temperature T=1, 5 has probability about 0.5896. Lowering T to 0.5 increases it to about 0.7919; raising T to 2 lowers it to about 0.4615. Those numbers follow from the formula and the fixed toy logits.
This does not say that higher temperature is generally better or worse. It says what division by T does to this particular distribution. Nor does changing a sampling setting train a model.
The lab draws an entire completion as one category. A real autoregressive language model selects tokens from changing, context-dependent distributions. The preceding trajectory picture explains that mechanism; this simplified sampler lets us inspect probabilities, sampled groups, and scores.
Check your understanding
If 5 has probability about 59%, must exactly 59% of six rollouts be 5?
Reveal answer
No. Six draws can only produce counts from zero to six. A finite sample is not the probability distribution itself.
Once we have sampled an answer, how do we decide what feedback it receives?
Chapter 3
From reward to a relative signal
A score tells you how an answer did. A baseline tells you what to compare it with.
Start with a scoring rule
5 follows both parts of our instruction: it is correct, and it is one digit. The answer is 5. is correct but misses the format. 6 is incorrect.
Our toy verifier encodes those judgments as scores:
Invented rewards for this lesson only
Completion
Reward
Reason under this rule
5
1.00
Correct and correctly formatted
The answer is 5.
0.75
Correct, wrong format
6
0.00
Incorrect
The numbers are not calibrated measures of quality, and they do not mean short answers are always preferable. Real systems may instead use a learned reward model or a task-specific rule. InstructGPT §3.1 and §3.5 · DeepSeekMath §4.1.2
A score is not yet a comparison
Take a hand-authored group with rewards [1,0.75,0,1]. This is an arithmetic example, not a seeded sample or a claim about frequencies. Its mean is
rˉ=41+0.75+0+1=0.6875
Now ask a different question: how far above or below the group average is each reward? Our teaching signal is
Aitoy=ri−rˉ
Figure 004A score is a position. A signal is a difference.
Subtract the dashed mean from each reward. Right is positive; left is negative. This is the hand-authored [1, 0.75, 0, 1] arithmetic example (mean 0.6875), not the seeded sample. Centering alone is not full GRPO.Check the arithmetic without the diagram
Hand-authored example, not a seeded sample; mean = 0.6875
Draw
Reward
Centered signal
1
1.0000
+0.3125
2
0.7500
+0.0625
3
0.0000
−0.6875
4
1.0000
+0.3125
A smaller hand-authored comparison makes the same point: [1, 0.75] has mean 0.8750, giving the 0.75 reward a centered value of −0.1250. In [0.75, 0], the mean is 0.3750 and that reward has centered value +0.3750. The reward is unchanged; its companions differ.
The results are [+0.3125,+0.0625,−0.6875,+0.3125]. The reward 0.75 gives a positive signal because it lies above 0.6875. If the other rollouts raised the mean above 0.75, that same reward would give a negative signal. The score did not change; the comparison did.
This is a centered group-relative teaching signal, not full GRPO. Published outcome-supervision GRPO additionally scales by the group's standard deviation and places the result inside a richer optimization objective. DeepSeekMath §4.1.1–§4.1.2
Three terms worth separating
Reward is feedback. Return accumulates rewards under a declared rule. Advantage compares action value with a baseline; it is not another name for reward. Spinning Up: reward, return, and advantage
Our toy assumes zero intermediate task rewards, one terminal score, and no discounting or additional shaping. Only under those assumptions does the task return reduce to that final score:
Gt=u=t∑Nru=rterminal
How this relates to standard advantage
A standard definition is Aπ(s,a)=Qπ(s,a)−Vπ(s), where Q is the action value and V is the state-value baseline. Our sampled group-mean calculation illustrates a relative comparison; it is not that general definition or a complete advantage estimator for every trainer.
A standardized estimator also needs an explicit convention when every reward is equal, because the group standard deviation is zero. This toy only mean-centers and never divides by the standard deviation.
Check your understanding
Two rollouts both receive reward 1. What are their mean-centered signals?
Reveal answer
Both are zero: their mean is 1. A high absolute score does not guarantee a positive relative signal. More generally, centered values sum to zero: ∑i(ri−rˉ)=0.
Keep one rollout's reward fixed and watch its comparison change.
Chapter 4
The rollout lab
Keep one answer fixed. Give it different companions. Watch its relative signal change.
Follow draw 3
The most useful thing to track is not the entire table. Track draw 3.
At T=1, that draw is The answer is 5. and always receives reward 0.75 from our fixed verifier. Before changing anything, predict: if we give it different companions, must its relative signal keep the same sign?
Whole-completion toy. A centered group-relative teaching signal (not full GRPO). No model is loaded and no policy update occurs.
Try 3 → 6 → 8 first
Then explore the distribution
Live comparisonFollow the ring: draw 3
Dots are rewards; the dashed line is their mean. The segment from mean to dot is the signed difference. Reward scale stays fixed at 0–1.
Group mean · Sum of centered signals
Sampling viewProbabilities are not counts
Stems show exact toy probabilities, not empirical frequencies. Counts describe this finite group. Raising K does not change the probability distribution.See every draw and probability interval
Computed toy draws; display rounded to four decimals
Draw
u
Index
Completion
Reward
Centered A
1
0.3982
0
5
1.0000
+0.2500
2
0.4663
0
5
1.0000
+0.2500
3
0.7087
1
The answer is 5.
0.7500
+0.0000
4
0.6670
1
The answer is 5.
0.7500
+0.0000
5
0.5855
0
5
1.0000
+0.2500
6
0.9719
2
6
0.0000
-0.7500
One reward, three comparisons
Keep T = 1. Draw 3 stays at reward 0.7500 while its companions move the mean.
K = 3
Rewards: 1, 1, 0.75 Mean 0.9167 Draw 3: -0.1667 negative
K = 6
Rewards: 1, 1, 0.75, 0.75, 1, 0 Mean 0.7500 Draw 3: +0.0000 zero
The reward does not change; the shared baseline does. These are derived snapshots of the seeded whole-completion toy, not training results. At K = 1, the only reward equals its mean and its centered value is zero.
Frozen inputs and the sampling rule
These are invented whole-completion categories, not token-level model outputs.
Fixed inputs · candidate indices are zero-based
Index
Completion
Logit
Reward
0
5
1.2
1
1
The answer is 5.
0.4
0.75
2
6
-0.2
0
Seed 20260903; generator LCG32-v1. Restart the same stream for every prospective setting. K takes its first K draws.
state = (1664525 * state + 1013904223) mod 2^32
u = state / 2^32
Choose the first candidate whose cumulative full-precision probability is strictly greater than u. Compute at full precision; round only displayed values. A seed alone does not make different generators equivalent.
Exact probability derivations from fixed logits (rounded)
T
p(5)
p(The answer is 5.)
p(6)
0.5
0.7919
0.1599
0.0482
1
0.5896
0.2649
0.1454
1.5
0.5051
0.2963
0.1986
2
0.4615
0.3093
0.2292
At T = 1 the rounded values sum to 0.9999; the unrounded probabilities sum to one. No weights, token likelihoods, KL terms or optimizer exist in this sandbox.
The original CPython lab capture is a measured seeded toy-process output, not measured LLM behavior. Other displayed snapshots are computed from the frozen mathematical model. Inspect the capture (local copy).
Read the code or run it yourself
The core comparison needs only a mean and a subtraction. This self-contained arithmetic example is not the sampler:
rewards = [1, 1, 0.75, 0.75, 1, 0]
mean = sum(rewards) / len(rewards)
centered = [reward - mean for reward in rewards]
# mean: 0.75
# centered: [0.25, 0.25, 0, 0, 0.25, -0.75]
Arithmetic output follows from the shown inputs. For the complete seeded sampler, use the canonical Python lab (standard library only).
Leave temperature at 1. Try group sizes K=3, K=6, and K=8. Here K counts separately drawn whole completions; it does not count tokens.
Draw 3 at temperature 1; values rounded to four decimals
Group size
Group mean
Reward
Centered signal
3
0.9167
0.7500
−0.1667
6
0.7500
0.7500
0.0000
8
0.6563
0.7500
+0.0938
These values follow from the frozen sampler and reward rule. The same 0.75 score is below one mean, equal to another, and above the third. The baseline is part of the answer whenever you discuss a relative signal.
At the default T=1, K=6, seed 20260903, the recorded local toy run drew candidate indices [0,0,1,1,0,2]. Their rewards are [1,1,0.75,0.75,1,0], their mean is 0.75, and their centered signals are [0.25,0.25,0,0,0.25,−0.75]. This is output of the disclosed seeded toy process, not samples from a language model. Recorded lab output (local copy)
Now change temperature
Predict whether increasing T from 1 to 2 makes 5 more or less probable. Then try it. Follow the chain: temperature changes probabilities; probabilities and the fixed random draws determine the new group; the reward rule determines its scores; those scores determine the mean.
Every setting starts a prospective draw from the same initial seed. Reset restores T=1, K=6, and seed 20260903. Nothing edits the verifier's reward for a recorded completion, and nothing updates model weights.
This remains a whole-completion toy and centered teaching signal—not full GRPO.
Check your understanding
Set K=1. Why is the only centered signal zero, whatever completion appears?
Reveal answer
The only reward is also the group mean: r1−rˉ=r1−r1=0.
A useful score still does not tell us which policy produced the data.
Chapter 5
Which policy made this?
Good answers can be old behavior. The response text cannot tell you its provenance.
The answer did not change its author
Suppose model version 12 generated a rollout. The trainable model has since advanced to version 14. The response still says 5, and its reward is still 1. Has it become version-14 data?
No. A useful answer can be old behavior. The text cannot tell you the policy that generated it.
Three names, three jobs
The behavior policy is the distribution that generated the recorded actions. For this example, πbeh=πv12.
The current policy is the trainable policy under consideration now. Here, πcur=πv14. In ratio-based methods such as PPO and GRPO, comparisons use the current policy's probabilities and those of the behavior or old policy that generated the actions. PPO §3 · DeepSeekMath §4.1.1
An optional reference policy supplies a different comparison—for example, a KL penalty that discourages moving too far from a reference distribution. It is not automatically the behavior policy; it is not the reward model or the group mean either. Our notation could name it πref−v1, separately identified from both versions above. InstructGPT §3.5 · DeepSeekMath equation 3
These are functional roles, not necessarily three unrelated architectures or three permanent model copies. At fresh collection, current and behavior weights may coincide. A method may omit a reference role altogether.
Figure 005The data keeps its origin
Changing current weights does not rewrite the origin of stored actions. Version labels identify snapshots, not a numerical distance or a safe age. The optional reference is not the verifier or group mean.
On-policy is about provenance
An introductory on-policy distinction asks whether the data comes from the policy used for the update, rather than an older or different behavior policy. It is not a label for whether an answer is correct. Spinning Up: kinds of RL algorithms
There is a practical qualification: original PPO can reuse a freshly collected batch for several minibatch epochs. “On-policy” therefore does not mean collecting a new rollout before every individual gradient step. It also does not grant unlimited reuse of old data. PPO abstract and Algorithm 1
Check your understanding
May the trainer use the version-12 rollout to update version 14?
Reveal answer
We cannot decide from the response or policy labels alone. We know who generated the data, but need the chosen algorithm's acceptance and correction rules. There is no universal safe age or version gap asserted here.
We can finally put collection, feedback, and learning on one timeline.
Chapter 6
Collection is not learning
Generating behavior and changing a policy are separate operations. Close the loop.
Find the step that changes weights
Imagine requesting eight answers instead of one. You now have more sampled behavior. You have not, just by generating it, changed the model's parameters.
That boundary is the reason to separate the stages of a learning loop:
Serving can exit after generation. A learning path continues to feedback, estimation, and an update. This is a representative conceptual order, not a required production schedule.
Collection produces trajectories under a recorded behavior policy. Scoring supplies feedback. An estimator constructs the quantities an algorithm needs. Optimization changes the trainable policy; later collection can then use a newer snapshot.
PPO and DeepSeekMath describe this alternation between collecting behavior and optimizing a policy. The diagram is a conceptual order, not a demand that production systems run every stage serially. PPO Algorithm 1 · DeepSeekMath Algorithm 1
The same generation can have a different job
Ordinary serving inference and rollout collection can use the same basic autoregressive generation mechanics. In serving, the immediate job is to return an answer. In an RL workflow, generated behavior and the metadata required by the method feed a learning path. This is a distinction in purpose and downstream use, not a claim that every serving and training stack is identical.
The browser lab stops well before optimization. It has no token-level likelihoods, learned reward model, critic, KL calculation, policy-ratio loss, clipping, or optimizer. Its changing plot is not a training curve.
Take the idea somewhere new
Try a different task:
A shelf has 4 green cards and 3 black cards. Return JSON with one key named n.
A new stipulated toy rule gives {"n": 7} reward 1, plain 7 reward 0.6, and {"n": 8} reward 0. A four-rollout group scores [1,0.6,0,1]. Behavior version 12 generated it; the proposed update targets version 14.
Your turn
How many rollouts are there? Calculate their mean and centered signals. Is a positive reward necessarily above the baseline? Has collection changed version 14?
Reveal the worked answer
Four rollouts. The mean is rˉ=(1+0.6+0+1)/4=0.65, giving centered signals [+0.35,−0.05,−0.65,+0.35].
Reward 0.6 is positive but below the group average. Collection alone changes no weights. And the data still belongs to behavior version 12; an algorithm contract must decide its use for version 14.
You now have the complete small model: a trajectory records what happened; reward scores it; a relative signal compares it; provenance identifies who produced it; optimization is the separate step that changes the policy.