A model can write its own practice questions and grade its own answers, but only if the questions sit at the edge of what it can solve. Choose the questions below and watch the skill curve.
Learn how one reinforcement learning step really runs, what to watch while it trains, and how self-play lets a model make its own curriculum.
Press a question source, then drag the rounds. See which source keeps teaching and which one stalls. Then we build, piece by piece, the training step underneath, the loss, the dashboards, the code, and three self-play papers.
You need a feel for what a probability is and a little Python. We teach the reinforcement learning, the batch sizes and the self-play from zero.
Based on the Week 9 session of MIT MAS.S62 How to AI an AI for (Almost) Anything (Fall 2026, MIT Multisensory Intelligence group): Lecture 6, RL and Self-Distillation in Practice, by Ao Qu, with a guest part on self-distillation by Idan Shenfeld. The slides are posted on the course schedule page. Every idea is re-taught here in our own words and devices.
A toy model, not a paper result. Skill runs from 0 to 1. A question succeeds with a chance that rises as skill passes the question’s difficulty. The solver learns most when that chance is near one half, the idea behind R-Zero’s reward (Chapter 8). Self-proposed questions sit just above the current skill.
Chapter 0
See the three things every training run needs, and watch self-play remove the humans from each one
You ask a language model to add 17 and 25. It answers 52. You want it to do better tomorrow. What must you hand to the training code so the model improves?
Three things. First, a question to practise on. Second, an answer key, so someone knows the right result is 42. Third, a score: a number that says how good the model’s reply was. Think of a student with a worksheet. The worksheet is the question, the back page is the answer key, and the red pen is the score.
For years, humans supplied all three. People wrote the questions, wrote the solutions, and graded the replies. This session asks a bold question: how many of the three can the model supply for itself?
Picture a basketball player at the free-throw line. She shoots, sees whether the ball goes in, and adjusts. She does not need a coach to rewrite her arm. She needs a way to see the result of each try.
That is reinforcement learning (RL): the model tries something, gets a score, and shifts toward the tries that scored well. The model being trained is called the policy, because it decides what to write. The score is the reward. For a language model, one “try” is one whole reply.
Rewards come in two kinds. A person or a second model can judge the reply. Or a program can check it: run the code, compare the final number. A reward a program can check is verifiable. Verifiable rewards are cheap and hard to argue with, so most reasoning models today train on them.
The lecture is by Ao Qu, and the slide on today’s tutorial lists five parts: what the RL loop looks like, how RL differs from on-policy distillation, what to watch during training, a quickstart for the open-source trainer verl, and then “from verl to reef”: infrastructure for agents that improve themselves. A guest part by Idan Shenfeld on self-distillation sits at the front of the deck. The syllabus line adds self-play, with three readings. We weave all of it into one path.
One short note on logistics: the session is Week 9 (4 November) of the Fall 2026 course, the slides are on the course schedule page, and the readings are the three papers on self-play that we teach in Chapters 8 and 9.
The device below is the idea of the whole session in four rows. Choose a way to train. Each of the three pieces lights up in the colour of whoever supplies it.
Blue is a human, pink is a program, orange is the model itself. Press each method and count the blue boxes.
Drawn from the sources: supervised fine-tuning learns from human-written questions and solutions; RL with verifiable rewards keeps human questions and known answers but lets a program score; Absolute Zero proposes its own tasks and uses a code executor (Chapter 8); R-Zero proposes its own questions and takes the Solver’s majority vote as the answer key (Chapter 8).
Notice that the row for the supervised method has three blue boxes, and the self-play rows have none. The cost of training moves from human hours to compute hours. That trade is the reason this session exists.
It also raises a danger. If the model writes the question and the key, who stops it from teaching itself nonsense? The answer is the verifier, and the whole second half of the session is about keeping it honest.
Why prefer a program as the scorer? A person gets tired and a judge model has moods. A program gives the same score for the same reply every time, and it costs almost nothing per reply. The price is reach: a program can check “is the answer 42”, but not “is this essay kind”. So the first half of this session assumes a checkable task, and the second half asks how far a model can go when it also writes the tasks.
Chapter 1
Follow one batch of questions through rollout, reward, advantage, update and weight sync, and learn the words every RL trainer uses
Imagine a teacher who gives a class one question, five students answer, and the teacher marks them. Three students are right. The teacher says “do more of what the right ones did, and less of what the wrong ones did”. That is one training step of RL for a language model. The class is five replies from the same model.
The slide draws the step as a loop of five numbered stages. We take them in order, with the smallest example that still shows every part.
Stage 1, rollout. A rollout means letting the current model write replies. The trainer takes a batch of prompts from the dataset and asks the model for n replies to each prompt. Our example: one prompt, “What is 17 + 25?”, and n = 5. The model writes 42, 42, 41, 42 and 52.
The model writing these replies is not the trainer. A fast inference engine does the writing. The slide names vLLM and SGLang. Both are programs built to generate text quickly.
Stage 2, reward. Each reply gets one score. The slide lists three kinds of scorer: a verifier, unit tests, or a judge model. Ours is a verifier that compares the number with 42. Rewards: 1, 1, 0, 1, 0. That is one number per reply, not one per word.
Stage 3, advantage. A reward of 1 sounds good, but good compared with what? The advantage answers that: how much better or worse than expected was this reply? The simplest expectation is the average reward of the group. Here it is (1+1+0+1+0) / 5 = 0.6. So the advantage is the reward minus 0.6: +0.4, +0.4, −0.6, +0.4, −0.6. The slide writes this as At = r − baseline. The word baseline means the expected score we compare against.
The slide says advantage is computed “for every token”. In this recipe every token of one reply carries the same number. A reply of 80 tokens has 80 advantages, all +0.4.
Stage 4, update. The trainer changes the model’s weights so tokens with positive advantage become more likely and tokens with negative advantage become less likely. The slide names FSDP and Megatron, two systems that split a big model across many GPUs for training.
Stage 5, weight sync. The inference engine still holds the old weights. After the update, the trainer copies the new weights to it. Only then can the next rollout use the improved model.
Step through all five on the toy batch.
Press Next stage. Watch the five replies pick up a reward, then an advantage, then a push up or down.
A toy batch: one prompt, five replies, a checker that compares with 42. The group average is the baseline, as in GRPO (Chapter 4). The numbers are illustrative.
The slide asks this question itself. The answer has two halves. Writing text fast needs a KV cache, a memory of what the model already read, which the inference engine manages well. Training needs gradients (the directions to move each weight) and optimizer state (extra numbers per weight, such as momentum), which take several times the memory of the weights themselves. One program tuned for both would do both badly.
So there are two copies, and copying the weights after every update is the price. This is the weight sync of stage 5. If you forget it, the engine keeps sampling from a stale model and the run learns nothing new.
Concept plus realization: here is the data at each stage, with shapes. B is the number of prompts, n the replies per prompt, T the number of tokens in the longest reply.
The next slide is a glossary that maps each term to a name in the verl code. Learn these once and every RL paper reads easily.
| Term | Symbol | Plain meaning | Name in verl |
|---|---|---|---|
| Policy, actor | πθ | The model being trained | actor |
| Rollout | none | Sampling replies with the current model | rollout |
| State | st | The prompt plus the tokens written so far | none |
| Reward | r | The score of one reply | token_level_scores |
| Advantage | At | Better or worse than expected, per token | advantages |
| Old policy | πold | The weights that wrote this batch | old_log_probs |
| Reference policy | πref | The frozen starting model | ref_log_prob |
| Critic, value model | V(st) | A model that predicts the reward from a state (PPO only) | critic, values |
| Step | none | One rollout plus one update | global_steps |
| Epoch | none | One pass over the prompt dataset | total_epochs |
Two of these deserve a word. The old policy and the policy are the same model at the start of a step, but they drift apart as you update, which matters in Chapter 2. The reference policy never changes. It is a bookmark of where you started, and Chapter 5 shows how a penalty keeps you near it.
Chapter 2
Split one rollout into updates and GPU-sized pieces, and find out which part of the data is still on-policy
A teacher marks 5,120 exam papers. She cannot read them all at once, and she does not want to wait until the pile is done before she changes her lesson plan. So she marks in stacks of 1,280, adjusts the plan after each stack, and hands each assistant a few papers at a time. RL training does the same with replies. Three nested sizes control it, and they cause more confusion than any other setting.
Start with the training batch. The config calls it train_batch_size and the slide sets it to B = 1,024 prompts. Each prompt gets n = 5 replies (rollout.n). So one rollout holds B × n = 1,024 × 5 = 5,120 responses.
Next, the mini-batch: the data used for one weight update. The slide sets M = 256 prompts (ppo_mini_batch_size). That is M × n = 1,280 responses. The batch holds B ÷ M = 1,024 ÷ 256 = 4 mini-batches, so one rollout produces 4 optimizer steps.
Then the work is spread over G = 8 GPUs in data parallel: every GPU holds a full copy of the model and handles a slice of the data. Each GPU gets 1,280 ÷ 8 = 160 responses.
Last, the micro-batch. A GPU cannot run 160 long replies through the model at once; the memory would overflow. So it runs m = 4 at a time (ppo_micro_batch_size_per_gpu). That makes 160 ÷ 4 = 40 micro-batches per GPU. It adds up the gradients from all 40 before the update. This trick is gradient accumulation. The micro-batch changes nothing about the maths. It only makes the data fit in memory.
The defaults are the slide’s numbers. Change one and watch the counts below. Green is on-policy. Yellow is older data.
The slide’s run is B = 1,024, n = 5, M = 256, G = 8, m = 4. Other choices are yours to try; the device clamps M to at most B and does not check that the sizes divide evenly, and it says so when they do not.
The slide asks a sharp question. On-policy means: trained on samples written by the current weights. Mini-batch 1 or mini-batch 2, which one is on-policy?
Only mini-batch 1. All 5,120 replies came from the same weights, call them πold. After the first update the weights change. When the trainer moves on to mini-batch 2, the model is no longer the one that wrote it. So from mini-batch 2 on, πθ ≠ πold.
Is that a problem? A little. The data is slightly out of date, like practising with last week’s feedback. Chapter 5 shows the repair: a ratio between the new and old probability, plus a clip, keeps each step small so older data stays safe to use. The reward is that you get four updates for the price of one rollout, and rollouts are the expensive part.
Change one number and the whole table moves. Set M = 512 instead of 256. Now B ÷ M = 2 updates per rollout, each of 512 × 5 = 2,560 responses, 320 per GPU, and 80 micro-batches of 4. You get half as many updates from the same rollout, but each update sees twice the data, and only one update is behind the rollout instead of three. The drag-and-see device above does this arithmetic for you.
Data parallel deserves one more sentence, because it explains the per-GPU number. Each GPU holds a full copy of the weights. It computes gradients on its own 160 replies. The GPUs then average their gradients, so every copy takes the same step and stays identical. Eight GPUs do eight times the work in the same time, but only if each has a similar load, which is why the trainer balances the batch (Chapter 7).
The symptom: the run stops with an out of memory error in the update stage, or the first update is fine and later ones crash on long replies. The measurement: watch peak GPU memory, and note that long reasoning replies cost more than short ones. The fix: lower the micro-batch m. Gradient accumulation then uses more passes of smaller size, and the update stays identical. Never fix it by lowering M. That changes how many updates one rollout buys and so changes how off-policy the run is.
The opposite error is subtler. Set M equal to B and you get a single update per rollout. Every sample is on-policy, and learning from each rollout is simple, but you waste rollouts. Set M tiny and the last updates train on data that is many steps old. Most runs choose a small number of mini-batches, such as the 4 in the slide.
Chapter 3
Replace one verdict per reply with a score on every token, using a bigger model or the model itself with a hint
A teaching assistant grades homework with an agent. The agent writes: “Correct answer: 220. Your solution is correct.” The assistant replies: “Too brief. Tell the student why each step is right.” Think about what that message contains. It says the reply was not good. It also says how to fix it. A plain RL score throws the second part away.
This chapter is about keeping it. It covers the guest part of the deck (slides 1 and 2, with Idan Shenfeld’s work on self-distillation) and the slide on on-policy distillation.
In Chapter 1, a reply got one reward, and every token inherited the same advantage. Suppose the judge gives the brief reply r = −1. Every token, the good ones and the bad ones, is pushed down by the same amount. The slide puts it plainly: a score on every turn, but one number.
Distillation means training a model to match another model’s behaviour. The model we train is the student, and the one it copies is the teacher. Old-style distillation has the teacher write the text, and the student imitates it. On-policy distillation (OPD) flips this. The student writes the reply. The teacher then reads it and says, for each token, how much it agrees. The student learns from its own mistakes, not from text it would never have written.
To compare two models on one token we use log-probabilities. A model gives each possible next token a probability. Its logarithm is a negative number: closer to zero means more likely. The difference of two log-probabilities says how much more one model likes the token.
The slide gives the advantage of token yt as log πteacher(yt) − log πθ(yt). If the teacher finds the token more likely than the student does, the number is positive and the student moves toward it. If the teacher finds it less likely, the number is negative.
Worked example. The student ends its reply with a full stop and gives that token probability 0.50, so log = −0.69. The teacher, who wants the reply to continue, gives the full stop 0.08, so log = −2.53. The advantage is −2.53 − (−0.69) = −1.84. The student learns not to stop there. Another token in the same reply may get +0.1. So each token gets its own number.
Where does the teacher come from? The slide gives two answers in a table. In OPD the teacher is another, bigger model, and it knows more because of its size and training. In self-distillation the teacher is the model itself, with an extra piece of text c in its prompt. The slide says c can be a demonstration, a solution, or feedback. Without c, the teacher equals the student and the signal is zero.
This is the clever part. In the grading example, a judge reads the brief reply and the assistant’s complaint, and turns them into a hint h, for example “explain each step”. The model then reads the same prompt plus the hint. With the hint in view, it knows more, so it makes a better teacher for its own earlier reply. The slide writes the advantage as At = log πθ(yt | h) − log πθ(yt).
The slide credits this line of work to several papers, among them GKD (Agarwal et al., 2024) for on-policy distillation, SDFT (Shenfeld et al., 2026) and SDPO (Hübotter et al., 2026) for self-distillation. The guest slide adds the motive. Shenfeld’s earlier paper RL’s Razor (ICLR 2026) found that on-policy RL forgets less than supervised fine-tuning, because it stays closer to the original model. Self-distillation turns that into a method that needs no reward: a demonstration in the prompt makes the model its own teacher. The slide also notes that Cursor used self-distillation to train Composer 2.5.
The lecture combines both scorers. In the OpenClaw-RL example (Wang et al., 2026), the loss is the RL part plus the self-distillation part, on the same responses, in one update. Try the three pieces on the brief reply.
Each row is one token of “Correct answer: 220. Your solution is correct.” Bars to the right push the token up. Bars to the left push it down. Press each scorer.
Illustrative numbers. The RL score is r = −1 on every token (OpenClaw-RL slide). The self-distillation values stand in for log π(token | hint “explain each step”) minus log π(token): the two full stops that end the reply too early get the largest negative values. A real run computes them with the model.
Look at the rows. RL says “everything was bad”. Self-distillation says “stopping here was the problem”. Add them and you keep both: the sign of the verdict and the place to fix. The slide puts it in two lines: the first term gives a score on every turn but only one number, and the second says which tokens to change, but only when the reply has a correction.
Symptom: the self-distilled advantages are all near zero and training does nothing. Measurement: print the mean absolute value of log π(y | h) − log π(y). Cause: the hint added no information, so teacher and student agree. Fix: write a hint that carries something new, such as the correct solution or the feedback text. This is the slide’s warning: without c, the teacher is the student and there is no signal.
A second failure comes from a weak teacher. With OPD, a teacher that is wrong teaches the student to be confidently wrong. Check the teacher on the same prompts first.
For the longer story of how a teacher’s probabilities are used as training signal, see our on-policy distillation lesson and knowledge distillation. The slide also points to the Thinking Machines blog post on on-policy distillation.
Chapter 4
Compare PPO, GRPO, on-policy distillation and self-distillation by one question: where does the advantage come from?
Four methods, one step of the loop, and a single difference between them. After the model writes its replies, something must say how good each token was. The slide on RL against distillation is a table with four rows. Read it as four answers to two questions: who scores a response, and what number does token yt get?
The slide defines two helper quantities. Let st be the state: the prompt plus the tokens written so far. V(st) is the reward the model expects to earn from this point on. Q(st, yt) is the reward it expects after it picks token yt. If picking this token makes the outlook better than average, Q is bigger than V. Their difference, Q − V, is the advantage in its original form: how much did this one choice help?
PPO (proximal policy optimization, Schulman et al., 2017) scores a reply with the reward r(x, y) and sets the advantage to Q − V. To know V, it trains a second network, the critic (the slide says “V = a learned critic”). The critic reads each partial reply and predicts the final reward. That gives a different advantage on every token, which is a sharp signal. The price: a second large model in memory, and a critic that can be wrong.
GRPO (group relative policy optimization, from DeepSeekMath, Shao et al., 2024) drops the critic. It samples a group of n replies to the same prompt, which Chapter 1 already did, and uses the group itself as the baseline. The advantage is (r − mean) / std over the n responses. The slide says it plainly: the mean replaces V.
Worked example with n = 8 replies and 3 correct ones. The rewards are 1, 1, 1, 0, 0, 0, 0, 0.
Rare successes earn bigger bonuses. If only 1 of 8 is correct, that one reply gets about +2.6. That seems fair: finding the one good reply is worth more than finding the fourth. Every token in a reply shares its reply’s number.
Eight replies to one prompt. Drag how many are correct and choose whether to divide by the spread. Try 0 and 8.
Exact arithmetic on a 0 or 1 reward with n = 8. The standard deviation here is the population one, as in the worked example; a real trainer adds a tiny constant so a zero spread does not divide by zero.
One more name appears on the slide: GAE, generalized advantage estimation (Schulman et al., ICLR 2016). It is a way to build the PPO advantage from the critic by blending short-range and long-range estimates, so the advantage is neither too noisy nor too biased. You do not need the formula to use PPO in verl. Know only that PPO’s per-token advantages come from the critic, and GRPO’s come from the group.
The per-token difference has a cost. In GRPO a long reply with one wrong step in the middle is wrong as a whole, so all 300 of its tokens get the same negative number, including the 299 good ones. The critic in PPO can in principle blame the one bad step. In practice, most reasoning runs accept the coarse signal because it needs no second model and works well when the checker is strict.
Drag the slider to 0 or to 8. Every bar flattens to zero. If all eight replies are right, or all eight wrong, nothing is above or below average, so the advantage is 0 and the update does nothing. This is a real failure. The symptom: reward flat from the start and no learning, which the slide on what to watch calls “flat from the start: no signal”. The measurement: count the share of prompts whose group has all-equal rewards. The fix: pick prompts the model solves sometimes, not never and not always. DAPO (Yu et al., 2025), cited in later slides, filters out such prompts. Our GRPO and DAPO lesson teaches it in full.
This also previews self-play. A model that writes its own questions can aim them at the 3-in-8 zone. Chapter 8 does exactly that.
The bottom half of the table is Chapter 3 in two lines. On-policy distillation: a bigger model πT scores, and the advantage is log πT(yt) − log πθ(yt), “a different value on every token”. Self-distillation: the same model plus c scores, and the advantage is log πθ(yt | c) − log πθ(yt). The only difference between teacher and student is c in the teacher’s prompt.
| Method | Who scores | Advantage of token yt |
|---|---|---|
| PPO | reward r(x, y) | Q − V, with V from a learned critic |
| GRPO | reward r(x, y) | (r − mean) / std over the group; the mean replaces V |
| On-policy distillation | another, bigger model | log πT(yt) − log πθ(yt), different on every token |
| Self-distillation | the same model plus c | log πθ(yt | c) − log πθ(yt) |
When should you pick which? RL needs a reward and nothing else, so it fits any task a program can check. Distillation needs a teacher or a hint, but it gives a signal on every token, so it learns from far fewer replies. The lecture’s own example mixes the two.
Chapter 5
Read the policy-gradient term with its clip, the KL anchor, and the entropy bonus, and know which ones real runs switch off
A hiker walks down a mountain in fog. A good rule: take steps, but never one so big that you leave the path you can see. RL training has the same problem. The advantage tells the model which way to move. The loss decides how far.
The slide shows the full loss as three boxes added together. The first box pushes the model by the advantage. The second holds it near where it began. The third stops it from becoming too sure of itself. We take them left to right.
The first box is −min( ρtAt, clip(ρt, 1−ε, 1+ε) At ). Start with ρt = πθ ÷ πold. This ratio says how much the token’s probability changed since the batch was written. A ratio of 1 means no change. 1.25 means the token is now 25% more likely.
The advantage At sets the direction. If At > 0, the update pushes the token up. If At < 0, it pushes the token down. The clip sets the limit. It cuts the ratio to the range from 1 − ε to 1 + ε, for example 0.8 to 1.2 when ε = 0.2. Once a token has moved that far, the gradient on it drops to zero. The slide gives the job in four words: the clip keeps each step small. This is why Chapter 2’s older mini-batches stay safe to train on.
Worked example. A token had probability 0.20 when written and has 0.25 now, so ρ = 1.25. Its reply earned A = +0.4.
The curve is what the update tries to raise. Where it is flat, the gradient is zero. Drag the ratio, flip the advantage, and change the clip range.
Exact formula, with the sign flipped so higher is better: objective = min(ρA, clip(ρ, 1−ε, 1+ε)A). The advantages are the ones from Chapter 1’s toy batch. ε = 0.2 is a common default, not the slide’s number.
Flip to the negative advantage and notice the mirror image. A token in a bad reply is pushed down until its ratio falls to 0.8, then the push stops. But if the ratio somehow rises to 1.3 on a bad token, the unclipped term is the smaller one and the gradient still pushes it back down. The clip never hides a mistake. It only caps the reward for progress.
The second box is + β · KL( πθ ‖ πref ). KL divergence measures how far one probability distribution has moved from another. Here it compares the model with the frozen reference model from Chapter 1. A large KL means the model has wandered. The penalty pulls it back. The knob β sets how hard.
Worked example for one token. The reference gives three candidate words 0.6, 0.2, 0.2. The trained model gives 0.8, 0.1, 0.1. KL = 0.8 ln(0.8/0.6) + 0.1 ln(0.1/0.2) + 0.1 ln(0.1/0.2) = 0.230 − 0.069 − 0.069 = 0.092. Small, but it sums over every token of every reply.
The slide gives a practical rule. For reasoning RL, this term is usually off. For RLHF, where a reward model can be cheated, it is on. A learned reward model has holes, so you need the anchor. A program that checks the final answer has fewer holes, so you can let the model roam.
A note on signs, since the slide writes the loss with minus signs. Training minimises a loss. The policy term has a leading minus so that a higher objective means a lower loss. The KL term has a plus, because more drift should raise the loss. The entropy term has a minus, because more randomness should lower it.
The third box is − α · H(πθ). Entropy H measures how random the next-token choice is. Take a next-token distribution of 0.7, 0.2, 0.1. Its entropy is −(0.7 ln 0.7 + 0.2 ln 0.2 + 0.1 ln 0.1) = 0.80. Now let the model grow sure: 0.98, 0.01, 0.01. Entropy falls to 0.11. The slide says near 0 means the model has stopped exploring.
A model that explores finds new good replies. A model with entropy near 0 writes the same reply every time, and then all replies in a group score the same, which is the empty-signal case from Chapter 4. The bonus rewards randomness to prevent this. The slide notes the bonus is usually off, but you should always watch the curve. That curve is the subject of the next chapter.
Put the three together for one token, with illustrative weights. The policy term is −0.48 from the worked clip example. Take β = 0.01 and the KL of 0.092: the KL term adds 0.0009. Take α = 0.001 and entropy 0.80: the entropy term adds −0.0008. The policy term dominates. That is why most settings of β and α are tiny, and why the reasoning-RL default is to switch them off.
Chapter 6
Read a reasoning RL run like a doctor reads vital signs, and learn what each broken curve says about the fault
A run takes eight GPUs and many hours. At hour three, the reward curve looks fine. At hour five it is still fine, but the model has become worse at the real test. Nobody told you. Only the other curves did. This chapter is about reading them.
The slide shows an example run: reasoning RL on math, with the verl public baseline (Qwen2.5-Math-7B, a GRPO variant, tested on AIME 2024, from the DAPO reproduction by Yu et al., 2025). It has six small plots. Each has a “normal” look and a “red flag”. We take them one at a time.
Reward. The mean reward of the batch. Normal: a slow start, then a steady climb. Red flag: flat from the start. That means no signal. It is the empty-group case of Chapter 4, or a broken reward function that returns 0 for every reply.
Validation accuracy. The score on held-out questions, which the run never trains on. Normal: it rises along with the reward. Red flag: reward goes up and validation goes down. The model has learned to please the training reward without getting better. That is reward hacking or overfitting. This curve is your only honest witness, so keep it.
Entropy. From Chapter 5: how random the next token is. Normal: it stays well above zero. Red flag: it falls toward zero. That is collapse. The model writes the same few replies and stops exploring.
Response length. The mean number of tokens per reply. Normal: it changes as the reasoning changes. Red flag: stuck at the maximum length. Replies are being cut off before they finish, so the model gets no reward for answers it did not get to write.
KL per update. How far one update moved the model. Normal: small and steady; the slide shows about 1e-4 for this run. Red flag: spikes. One update moved too far.
Gradient norm. The overall size of the update direction. Normal: high at first, then it settles. Red flag: spikes, or the value stops being a number at all, which ends the run. It signals instability.
The device draws all six for a healthy run, and then breaks one at a time. The curves are made up, but their shapes follow the slide’s descriptions.
Choose a fault. The broken curve turns red. Find it, then read the diagnosis below.
Illustrative shapes drawn from the slide’s descriptions, not data from the run. Each plot is rescaled to its own range. The first diagnosis of each fault is the slide’s; the suggested fixes are common practice, not the slide’s.
A short worked reading shows how the curves work together. Imagine a log with three checkpoints (illustrative numbers). At step 100: reward 0.20, validation 0.21, entropy 0.42. At step 300: reward 0.55, validation 0.49, entropy 0.35. At step 500: reward 0.78, validation 0.41, entropy 0.18. Reward more than tripled, which looks like a triumph. But validation peaked near step 300 and fell, and entropy has halved. Two flags at once point to the same story: the model narrowed onto a habit that the training checker likes. The step to restore is the checkpoint near step 300.
Two habits make this possible. Save checkpoints often enough to go back, and run the validation set every few steps, not only at the end. Validation costs rollouts, but a long run without it is a run you cannot trust.
Each flag has a first fix. Treat them as a checklist, not a law.
Faults often come in pairs. A KL spike usually comes just before a gradient spike, and a collapse of entropy usually comes before a flat reward. So when you see one flag, look at its neighbours.
Chapter 7
Match every line of the trainer to one of the five stages, then write the three files that start a real run
You have the picture of a step. Now meet it as code. verl is an open-source library for RL training of language models. Its design comes from the HybridFlow paper (Sheng et al., EuroSys 2025). The lecture shows the heart of its trainer in a dozen lines, then the three things you must supply to run it.
The slide is a simplified copy of PPOTrainer.step() in sync mode, the default. Read the numbers in the margin: they are our five stages.
python# one training step, simplified from the slide self._add_batch_to_generate() # 1 rollout: n replies per prompt batch = self.replay_buffer.sample(batch_size=B) # 2 reward: scored as each reply finishes self.checkpoint_manager.sleep_replicas() # free GPU memory for training batch = self._balance_batch(batch) # give every GPU a similar number of tokens batch = self._compute_old_log_prob(batch) # log-probs from the weights that wrote the batch if self.use_reference_policy: batch = self._compute_ref_log_prob(batch) # log-probs from the frozen reference if self.use_critic: batch = self._compute_values(batch) # V(s_t), PPO only batch = self._compute_advantage(batch) # 3 advantage: the algorithm (GRPO, PPO, ...) batch = self._update_actor(batch) # 4 update: one step per mini-batch self.checkpoint_manager.update_weights(self.global_steps) # 5 weight sync to the rollout engine
Three lines are not in our five stages, and each one fixes a real problem.
Sleeping the replicas. The inference engines hold weights and a KV cache on the same GPUs that will train. Before the update they sleep: they release that memory so the trainer has room. After the update, update_weights wakes them with the new weights.
Balancing the batch. A GPU’s time is set by the number of tokens it processes. Suppose four replies have 100, 900, 100 and 900 tokens, and two GPUs share them. A split into (100, 100) and (900, 900) gives loads of 200 and 1,800 tokens. The step waits for the slow GPU: 1,800 units. A split into (100, 900) and (100, 900) gives 1,000 each, so the step takes 1,000. Balancing is 1.8 times faster here, with the same maths.
Three log-probabilities. The old log-prob, the reference log-prob and the values (for PPO only) are all computed before the update, with the weights as they are now. They feed the ratio in Chapter 5, the KL term, and the critic.
The comment on the slide says sync mode, the default. In sync mode the rollout and the update take turns: all engines write, then all train, then all sync. The alternative is to overlap them, so that engines keep writing while the trainer updates. That keeps GPUs busier, but the replies are then written by weights a little behind the trainer, which is the on-policy problem of Chapter 2 on a larger scale. Sync mode is simpler to reason about, which is why it is the default.
The slide boils a run down to five parts. Three are things you write.
1. Tasks as a table, one row per prompt. A parquet file, a compact table format. Each row has a data source, a chat-style prompt, and a reward spec with the right answer. For GSM8K, grade-school maths word problems, a row is: data_source “openai/gsm8k”, prompt a list with one user message holding the question, and reward_model with style “rule” and ground_truth “72”.
2. A reward function. A short Python function. It receives the data source, the model’s reply, the right answer, and extras, and returns a number.
pythondef compute_score(data_source, solution_str, ground_truth, extra_info=None, **kw): answer = extract_answer(solution_str) # your parser: pull the final answer out of the reply return float(answer == ground_truth) # 1.0 if it matches, else 0.0
Trace one reply through it. The model writes “17 + 25 = 42, so the answer is 42.” Suppose extract_answer returns the last number in the text: it finds 42, compares it with the ground truth “42”, and the function returns 1.0. Now the model writes “The answer is 42.” with a full stop. If the parser keeps the stop, it reads “42.”, which does not equal “42”, and a correct reply scores 0. A silent bug like this punishes the right behaviour. It shows up in Chapter 6 as a reward that will not rise.
This is the whole verifier. A bug here is a bug in your training data. If extract_answer takes the last number it sees, a reply “42 or 41” scores 0 for the 42 it also wrote. If it takes the first number, the hedge “42 or 41” scores 1. Test it on odd replies before launch.
3. The launch command. Settings are overrides on a config. Use the device to see what each flag of the slide’s command controls.
The command is the slide’s GRPO run on GSM8K. Press a flag to see the stage it touches and the number it sets.
Flags are from the slide’s command (python3 -m verl.trainer.main_ppo). The explanations are ours, in plain words; check the verl docs for the full list.
The last two parts need no code. 4. Watch the curves, as in Chapter 6. 5. Export: training saves FSDP shards, which are pieces of the model split across GPUs. The tool verl.model_merger merge joins them into a normal Hugging Face model, which vLLM then serves.
Chapter 8
Split one model into a question-writer and a question-solver, and reward the writer for questions at the edge of the solver’s ability
A chess player who has beaten everyone in her club needs a stronger opponent. She cannot find one, so she plays against a copy of herself. Each game is hard because the copy is exactly as good as she is. When she improves, so does her opponent. This is self-play: a learner makes its own curriculum by playing against itself.
For reasoning models the same idea reads: one role invents a question, and a second role tries to answer it. The syllabus line for this session is “self-play approaches”, and its three readings all build on it. Everything before this chapter is machinery. Here it earns its keep. The solver’s update is exactly the GRPO step of Chapters 1 to 5.
The proposer (R-Zero calls it the Challenger) writes questions. The solver answers them. The proposer is rewarded for questions that teach the solver something. The solver is rewarded for correct answers. Both are language models, and both train with RL.
The hard part is the proposer’s reward. If it is rewarded for hard questions, it writes impossible ones. If it is rewarded for solvable ones, it writes trivial ones. Chapter 4 already showed why neither helps: a group of replies that are all wrong, or all right, has zero advantage. The useful zone is in between.
The hero of this page is that argument in one picture. Questions at the edge of ability give the biggest gain. Fixed easy questions slow down and fixed hard ones stall.
The first reading, Absolute Zero: Reinforced Self-play Reasoning with Zero Data (Zhao et al., 2025, arXiv 2505.03335), uses a single model in both roles. It proposes small Python programs and tasks about them, and a Python interpreter checks everything: the task is valid, the answer is right. The proposer’s reward is rpropose = 1 − r̄solve, and it is 0 when the solver always fails or always succeeds. The paper uses n = 8 trial runs per task. With zero external training examples, the coder model reaches an overall average of 50.4 against 40.2 for its own base model. Our full lesson, Self-Play RL I: Absolute Zero, derives all of it, including the three task types and the learnability reward.
The second reading, R-Zero: Self-Evolving Reasoning LLM from Zero Data (Huang et al., 2025, arXiv 2508.05004), has no lesson of its own, so we teach it here. It starts from one base model and makes two copies with different jobs: a Challenger and a Solver. They are trained separately and take turns.
The uncertainty reward is the clever part. For a question x, let p̂ be the share of the 10 answers that match the majority label. The Challenger’s reward is r = 1 − 2 |p̂ − 1/2|. It peaks at 1 when the Solver agrees with itself half of the time, and falls to 0 when the Solver is always sure or always split. Worked cases with m = 10:
Two extra penalties keep the Challenger honest. A repetition penalty groups questions that look alike, using BLEU similarity (a score for how many words two texts share), and charges each question in proportion to its cluster’s size, so the Challenger cannot write one question a hundred times. A format check rejects any output that is not wrapped in the expected question tags.
Why 50%? Chapter 4 gave the reason. A group of replies with half right has the largest spread, so the largest advantages. R-Zero’s appendix cites work that says learning is most efficient on tasks at the frontier of a learner’s ability. Compare the two reward shapes below. Absolute Zero peaks near the hardest solvable tasks, and R-Zero peaks in the middle.
Pick a method, then drag how many of the solver’s tries succeed. Watch the writer’s reward and whether the question is kept.
Both reward formulas are the papers’: R-Zero r = 1 − 2|p̂ − 1/2| with m = 10 and a keep range of 3 to 7 answers matching the majority; Absolute Zero r = 1 − r̄ with n = 8, and 0 at r̄ = 0 or 1. Absolute Zero has no keep filter of this kind; its zero reward plays that role.
On the Qwen3-4B-Base model, the paper reports +6.49 points on math reasoning benchmarks and +7.54 on general-domain reasoning benchmarks. The Challenger writes only maths questions, so the second number says the skill transfers. The paper also ran an ablation: one model sharing its parameters between both roles did worse than two separate models.
Now the failure, which the paper states openly. Majority vote is a weak judge. The paper measures that the pseudo-labels start with 79.0% accuracy and fall to 63.0% by the third iteration. As the questions get harder, the Solver’s majority is wrong more often, so the Solver trains on more wrong keys. The symptom: gains slow and then reverse. The measurement: check a sample of pseudo-labels against a real key. The fix is a stronger judge, and that is the next chapter.
Chapter 9
See how one leaky judge can poison every later round, and how a formal verifier closes the leak
A student writes her own practice test and her own answer key. If one key answer is wrong, she studies the wrong fact until it sticks. The next test builds on it, and the mistake spreads. This is the weakness that Chapter 8 ended on: R-Zero’s pseudo-label accuracy fell from 79.0% to 63.0% in three rounds.
The third reading, Propose, Solve, Verify: Self-Play Through Formal Verification (Wilf, Aggarwal, Parno, Fried, Morency, Liang and Welleck, 2025, arXiv 2512.18160), attacks exactly this. It has no lesson of its own yet, so we teach it here.
For code, the usual judge is a set of unit tests: small checks such as “sorting [3, 1, 2] must give [1, 2, 3]”. They are cheap, but they cover only a few cases. A program can pass every test and still be wrong. Here is one that sorts nothing and passes the test above:
pythondef sort(xs): return [1, 2, 3] # passes the test sort([3, 1, 2]) == [1, 2, 3], and is wrong everywhere else
In RL, the solver is rewarded for passing. A solver under pressure finds such shortcuts, a form of reward hacking from Chapter 6. The paper says this is why self-play for code stays an open problem: tests are brittle, and errors propagate across iterations.
Formal verification proves that a program meets its specification (spec) for every possible input, not for a few. A spec has two parts. A precondition says what inputs are allowed. A postcondition, written as an ensures clause, says what must hold for the output. For sorting, the postcondition says the output is in order and holds the same items as the input. The constant function above fails it on the input [5, 4].
The paper uses Verus, a tool that verifies Rust programs. The program comes with a proof, and Verus checks the proof. If Verus accepts, the program is guaranteed to satisfy the spec. The paper calls this a sound reward signal: a wrong program can never get through. The check can still be incomplete: it may reject a correct program whose proof it cannot follow.
The proposer no longer writes questions with answers. It writes specs. The loop, run for T rounds, is:
Training only on the accepted outputs is called rejection fine-tuning (RFT), and the idea is also known as expert iteration: keep the good attempts, learn from them, try again. There is no advantage and no ratio. The paper explains the choice. Because Verus is sound but incomplete, an advantage-weighted method such as GRPO could punish correct solutions that the verifier failed to confirm. RFT never punishes. It only imitates what was proven.
The proposer matters too. A proposer told to write “hard” specs does shift the pass rate. In the paper, easy-targeted specs have a mean solver pass rate of 0.55, medium 0.45, and hard 0.36. The spread within each group is large, so the control is partial. Still, removing the difficulty labels cost an average of 5.6% across all metrics. The proposer is a difficulty dial, in the spirit of R-Zero’s uncertainty reward.
The device models the loop with one number you control: how often the judge accepts a wrong program (the false-accept rate). At 0%, the judge is sound, like Verus. Above 0%, wrong programs enter the training set. Each round, the solver’s true solve rate rises with the good examples and falls with the bad ones.
The dashed line is a sound judge. The solid line is yours. The red line is the share of wrong programs in each round’s training set. Drag the false-accept rate.
A toy, not a result from the paper. Start: the solver gets 25% of problems right. Training set: right programs always pass the judge, wrong ones pass at your rate. Each round, solve rate q becomes q + 0.12(1 − q)(1 − c) − 0.15 q c, where c is the share of wrong programs in the training set.
At 0%, skill climbs to about 0.73 in eight rounds. At 30% it reaches about 0.49. At 60% it barely moves, to about 0.32. At 90% it ends at about 0.23, below where it began. The solver is learning to satisfy the judge, not to solve the problem. The measurement that exposes this in real runs is the same as in Chapter 6: audit a sample of accepted outputs with an independent, trusted judge.
The paper trains PSV-Verus, starting from the same translated seed corpus as an earlier system, AlphaVerus. Its abstract reports up to 9.6 times higher pass@1 (the share of problems solved on the first try) than inference-only and expert-iteration baselines, three benchmarks, and gains that grow with the number of generated questions and with the number of rounds. In its test-time training setting, the MBPP benchmark pass@1 is 36.78 for PSV-Verus against 3.83 for plain rejection fine-tuning, which is where the 9.6 comes from. Ablations name two essential ingredients: formal verification, and difficulty-aware proposals.
The limit is plain. Formal specs and proofs exist for only some tasks. Where they exist, the judge cannot be fooled. Where they do not, you are back to tests, votes and models, and to the leaky judge in the device.
Chapter 10
Compare a trainer that finishes before it ships with a server that keeps learning from its own traffic
A restaurant tests a new menu for a month in a back kitchen. Then it opens, and the menu never changes. Another restaurant opens on day one and adjusts every dish from what diners send back. The first has cleaner tests. The second sees the real customers. Both are sensible, and the choice shapes the whole system.
The last two slides of the lecture draw this contrast for model training, and introduce reef, an open-source project by Ao Qu and colleagues (Human-Agent-Society) for continual, self-improving agents. We keep to what the slides show.
This is verl’s world, and it is everything in Chapters 1 to 7. Start with a fixed set of prompts and labels. The trainer loops over “rollout, reward, update” for N steps. It writes a checkpoint, which is a saved copy of the weights. You export it and deploy it separately, and then users arrive. The slide sums it up in seven words: a trainer over a dataset you prepared.
Strengths: you control the data, you can re-run the experiment, and the curves of Chapter 6 tell you when it works. Weakness: the world after deploy is not the dataset. If users ask for something new, the model does not know. It stays the same until someone starts another run.
reef turns the picture around. The slide describes it as an inference server that learns from its own traffic. Live traffic comes in from users and agents, as requests, replies and feedback. Inside reef sits a loop of three boxes: Serve, Train, Evaluate. The loop closes with an arrow labelled “new version, no restart”. So the server answers requests, trains on what it learned from them, tests the new version, and swaps it in while it keeps running.
The final slide gives the project’s name for the idea: “Your Inference Server is Secretly a Learner”, open-sourced as reef for continual self-improving agents. Its figure lists what can change as the system learns: weights, prompts, memory, skills, tools and orchestration. Learning is wider than weight updates. An agent can improve by rewriting a prompt or saving a note, with no gradient at all. Our self-improving harnesses lesson explores that side.
Seen from this lecture, the pieces fit together.
This is also the self-play idea in a different costume. In Chapter 8 the model wrote its own questions. Here the users write them, and the model keeps the loop of propose, solve and verify running on real work.
The solid line is the quality users see. Drag the day when users start asking for something new, and see who recovers.
A toy, not a benchmark of either system. Both start at quality 0.50. The offline run deploys at day 10 (0.70) and again at day 30 (0.75, now trained on the new traffic). The live server gains 8% of its remaining gap to 0.80 every day. A traffic change drops each by 0.25.
Learning from live traffic is harder to get right, and a few things need care. The symptom is a server that gets worse over time. The measurement is a fixed set of test questions run before every swap. These are the common causes.
The gate needs care, because small differences are easy to fake. Say the live version scores 0.70 on a test set of 200 questions and the new version scores 0.71. The typical error of a score near 0.70 on 200 questions is the square root of 0.70 × 0.30 ÷ 200, which is about 0.032. The one-point gain is smaller than the noise, so it is not evidence. A good gate asks for a clear margin or a larger test set before it swaps the version in.
So the two designs are not rivals. A team can train a strong base with verl, then let a reef-style loop adapt it with a gate. The choice depends on how fast your world changes and how much a bad update costs.
Chapter 11
Review the loop, keep the numbers, run the checklist, and read the core as code
You can now rebuild this session from memory: how one RL step runs, how the data is split, where an advantage comes from, what the loss does, which curves to watch, how verl runs it, and how a model can make its own questions without fooling itself.
An RL step has five stages: rollout, reward, advantage, update and weight sync. A rollout is cut into mini-batches for updates and micro-batches for memory, and only the first mini-batch is on-policy. The advantage can come from a critic (PPO), the group mean (GRPO), a bigger teacher (on-policy distillation), or the model with a hint (self-distillation). The loss clips each step, may anchor to a reference with KL, and may reward entropy. Six curves tell you if a run is healthy. Self-play splits a model into a question-writer and a solver and rewards questions at the edge of the solver’s ability. Its danger is a leaky judge, and a sound verifier closes the leak.
| What | Number | Why it matters |
|---|---|---|
| The slide’s batch | 1,024 × 5 = 5,120 responses; 4 mini-batches of 1,280; 160 per GPU on 8 GPUs; 40 micro-batches of 4 | Only mini-batch 1 is on-policy |
| Group advantage, 3 of 8 right | +1.29 right, −0.77 wrong | Rare wins pay more; all-equal groups pay 0 |
| Clip example (ε = 0.2) | ρ = 1.25, A = +0.4: objective 0.48, gradient 0 | A clipped token stops moving |
| KL and entropy examples | KL 0.092; entropy 0.80, then 0.11 after collapse | Anchor, and a sign of lost exploration |
| Example run | Qwen2.5-Math-7B, a GRPO variant, AIME 2024; KL per update about 1e-4 | What a healthy run looks like |
| Absolute Zero | overall average 50.4 against 40.2 for its coder base; n = 8 trials per task | Zero external examples |
| R-Zero | +6.49 math, +7.54 general (Qwen3-4B-Base); keep 3 to 7 of 10 agreeing answers | A 50% question teaches most |
| R-Zero pseudo-labels | 79.0% accuracy falling to 63.0% by iteration 3 | Majority vote leaks |
| Propose, Solve, Verify | up to 9.6× pass@1; MBPP 36.78 against 3.83; no difficulty labels costs 5.6% | A sound verifier and a difficulty dial |
Tick what you could explain to a friend, without looking back.
The checklist is ours, built from the chapters of this lesson. Nothing is stored.
Two short sketches. The first is one RL step. The second is one self-play round in the R-Zero shape. The helpers (engine, verify, grpo_update) stand for your inference engine, your judge and your trainer.
pythondef rl_step(policy, engine, prompts, verify, n=5): replies = engine.generate(prompts, n) # 1 rollout: B x n replies r = [[verify(p, y) for y in ys] for p, ys in replies] # 2 reward: one number per reply adv = [] for rs in r: # 3 advantage: group mean and spread (GRPO) mean = sum(rs) / len(rs) std = (sum((x - mean) ** 2 for x in rs) / len(rs)) ** .5 adv.append([(x - mean) / (std + 1e-6) for x in rs]) # all equal: every advantage is 0 policy.grpo_update(replies, adv) # 4 update: clipped ratio, mini-batches engine.load_weights(policy) # 5 weight sync def self_play_round(challenger, solver, m=10): qs = challenger.write_questions(1000) data = [] for q in qs: ans = [solver.answer(q) for _ in range(m)] label, k = most_common(ans) # pseudo-label by majority vote if 3 <= k <= 7: # keep the edge-of-ability questions data.append((q, label)) challenger.reward(q, 1 - 2 * abs(k / m - .5)) # uncertainty reward solver.train_grpo(data) # swap in a sound verifier here where you can
This session is the practice that follows the course’s model-evolution theory. Everything here is a way to turn a score into a better model: through a human, a program, a teacher, a hint, or the model’s own questions. Next, the interesting questions move to the judge. What counts as a good verifier, and how far can a model improve with only its own work?
This lesson follows Lecture 6, RL and Self-Distillation in Practice, by Ao Qu, with a guest part on self-distillation by Idan Shenfeld, in MIT MAS.S62 How to AI an AI for (Almost) Anything, Fall 2026, from the MIT Multisensory Intelligence group. The slides and syllabus are on the course schedule page. The readings are Absolute Zero, R-Zero and Propose, Solve, Verify. The tools are verl and reef. All words, devices and numbers here are our own re-teaching; the toy numbers say so where they appear.
Now press Present or Teach and explain one training step out loud from memory, then explain why a self-play loop with a leaky judge goes wrong. Then go back to the instrument at the top, choose self-proposed questions, and say why they keep teaching while the fixed sets do not.