On-policy distillation

How two specialist teachers become one student model

A student that writes its own homework

What is distillation? tells the classic story: a large teacher writes solutions, and a smaller student learns to copy them. The student only ever sees the teacher’s work.

On-policy distillation turns that around. The student writes the attempt. The teacher then looks at every step the student actually took and says, token by token, what it would have written there. The student learns from its own mistakes, in the places it really goes, with a teacher at its shoulder.

In 2026 this became a way to merge models. This page follows the last part of Brandon Amos’s talk Post-training Beam [1] and the Beam technical report, §4.3 [2]. The wider story is on Evolution of post-training.

Everyday example

Classic distillation is studying a teacher’s worked examples. On-policy distillation is doing the exercise yourself while the teacher reads over your shoulder and corrects each line as you write it. You get feedback exactly where you go wrong.

Why train two specialists at all?

Beam trains two specialists from one shared midtrained model: an agentic teacher (code, terminal, maths, search) and an alignment teacher (conversation, safety, tool use, instruction following). Each has its own SFT and RL [1][2]. The pipeline figure is on Evolution of post-training.

Slide titled Why split into agentic and alignment? Advantages: easier iteration on a subset of tasks and data, independent recipes with their own rewards, curriculum and schedules. Disadvantages: split-braining with inconsistent conventions, missed transfer between capabilities, and consolidation cost.

The trade-offs of splitting into specialists. Image: Brandon Amos, Post-training Beam, slide 47 [1].
  • For: each team can iterate on its tasks and fix a regression without touching every other domain. Each branch has its own rewards and schedule.
  • Against: the specialists may learn inconsistent habits (“split-braining”), skills that need both at once get fewer chances to grow together, and the merge itself costs compute and evaluation [1].

Other labs make different splits: by reasoning effort, by many domains (DeepSeek uses more than forty teachers), or no split at all with one joint run [1]. That comparison is a slide on Evolution of post-training.

The merge: multi-teacher on-policy distillation

Slide titled Merging with multi-teacher on-policy distillation. Objective: argmin over theta of the expectation over tasks x and over a teacher T drawn from a Bernoulli of r of x, of the KL between the student pi theta and the teacher pi T. Diagram: task x goes to the student's inference, which produces y; probabilistic routing sends y to the agentic teacher when T equals 1 or the alignment teacher when T equals 0; the teacher's distribution returns to the student's loss.

The student generates; one teacher is chosen per rollout; the loss is the reverse KL between student and teacher. Image: Brandon Amos, Post-training Beam, slide 49 [1]. Original: Beam Model Technical Report, §4.3.1 [2]. Background: Hinton and colleagues 2015 [3], Kim and Rush 2016 [4], Agarwal and colleagues 2024 [5], Gu and colleagues 2024 [6].
  1. The student starts from the midtrained model and gets SFT on the combined specialist data. SFT alone did not recover both specialists [1].
  2. The student attempts a task.
  3. One frozen teacher is chosen for that rollout, based on the task family.
  4. At every position the student visited, the teacher gives its full next-token distribution.
  5. The trainer moves the student toward the teacher with reverse KL. There is no task reward at this stage [1][2].

Reverse KL is \(\mathrm{KL}(p_{\text{student}} \,\Vert\, p_{\text{teacher}})\): the average, under the student’s own probabilities, of how much more likely the student finds a token than the teacher does. It punishes the student for putting mass where the teacher would not. Compare it with the forward KL on What is distillation?.

Slide titled OPD shares our distributed infrastructure: the same asynchronous loop as RL, with student inference, rollout workers and sandboxes, but frozen teacher annotation replaces task grading and the trainer applies reverse KL.

On-policy distillation reuses the RL machinery: the teacher takes the grader’s place. Image: Brandon Amos, Post-training Beam, slide 50 [1]. Original: Beam Model Technical Report, §4.3.2 [2].

The neat part is engineering reuse. It is the same asynchronous loop as RL at scale: the same inference pool, sandboxes, weight sync and router replay. The grader is replaced by a teacher, and the reward update by a KL loss [1].

Which teacher? Probabilistic routing

Slide titled Probabilistic teacher routing: a table of task families and the share sent to the agentic and alignment teachers. Code, terminal, maths, science and search go 100 percent agentic; instruction following, grounded queries and long context 50-50; mixed tool use 60-40; conversation, calibration, identity and safety 100 percent alignment.

Probabilistic teacher routing by task family. Image: Brandon Amos, Post-training Beam, slide 51 [1]. Original: Beam Model Technical Report, §4.3 [2].

Coding, maths and search go to the agentic teacher. Conversation and safety go to the alignment teacher. Tasks that need both — instruction following, long context, tool workflows — flip a weighted coin per rollout: 50–50 or 60–40 [1].

Why not average the two teachers at every token? Because an average of two good answers can be a bad answer. Routing lets each teacher supervise whole attempts in its own style [1].

Everyday example

A student with a maths tutor and a writing tutor. A pure maths problem goes to the maths tutor. An essay goes to the writing tutor. A science report needs both, so this week one tutor marks it and next week the other. Nobody writes a half-maths, half-writing correction in the margin.

Every word, or a sample?

There are three ways to compute the reverse KL at a position [1]:

Method What it uses Trade-off
Sampled Only the token the student actually wrote Cheap, but a noisy estimate
Top-k The student’s k most likely tokens Cheaper than full, but not a true KL on its own
Full vocabulary Every token in the vocabulary (about 152K for Beam) Exact, but looks expensive

Slide titled To subsample or not? The reverse KL formula, then three rows: student-sampled, a single-sample log-ratio; top-k, a sum over the student's k most likely tokens with an optional tail bin; full-vocabulary, a sum over every token.

Sampled, top-k and full-vocabulary reverse KL. Image: Brandon Amos, Post-training Beam, slide 52 [1]. The sampled approach follows Kevin Lu’s Thinking Machines post on on-policy distillation.

Beam uses the full vocabulary, and it ran in about the same wall time as the sampled version [1][2]. Two tricks make it cheap:

  1. Send the small vector, not the big one. The teacher’s last hidden state has 5,120 numbers; its logits have 151,936. Send the hidden state, and let the trainer multiply it by a cached copy of the teacher’s output head. For 16K tokens that is 336 MB instead of 9.96 GB [1]. DeepSeek-V4 uses the same idea [7].
  2. Compute in chunks. A FlashAttention-style kernel computes the KL a few positions at a time and never holds the whole logit table in memory [1][2].

Slide titled Full-vocab OPD is cheap, step 1, efficient hidden-state transport. Teacher hidden states h T of size N by H go to the trainer, which multiplies by a cached frozen head to get logits z T. Estimate for Beam with H equal to 5,120: full logits 151,936 values per token, 9.96 GB payload, 1.0 s transfer; hidden states 5,120 values, 336 MB, 34 ms; about 5.5 minutes of generation.

Hidden-state transport: about 30 times less data to move than full logits. Image: Brandon Amos, Post-training Beam, slide 54 [1]. Idea: DeepSeek-V4, §5.2.2 [7]; the numbers are the talk’s illustrative estimate, not a measurement.

Did the merge work?

Slide titled Our merge result: a table of benchmarks with scores for the agentic teacher, the alignment teacher and the merged Beam student. For example SWE-Bench Pro 62.2 to 67.1, Terminal-Bench 77.7 to 80.1, DeepSWE 43.4 to 40.2, IFBench 77.3 to 79.3, AA-LCR 66.3 and 78.0 to 78.7.

The merged student against both teachers. Image: Brandon Amos, Post-training Beam, slide 57 [1]. Original: Beam Model Technical Report, Table 15, §4.3.4 [2].

Mostly yes. The student matches the agentic teacher on coding, maths and science, and matches or beats the alignment teacher on its tasks. Where both teachers supervise (AA-LCR, long-context reasoning), the student beats both. DeepSWE is the clear remaining gap (43.4 → 40.2) [1][2].

In one table

Idea In one sentence
Off-policy (classic) distillation The student learns from the teacher’s own attempts
On-policy distillation The student writes; the teacher corrects every token the student wrote
Reverse KL Punishes the student for putting probability where the teacher would not
Multi-teacher routing Pick one teacher per rollout by task family; flip a weighted coin for mixed tasks
Full-vocabulary KL Compare the whole distribution, not one sampled token
Hidden-state transport Move the 5,120-number vector; rebuild the 152K logits at the trainer

FAQ

How is this different from the distillation in Lab LL01-1? In Lab#LL01-1 the student trains on traces the teacher already wrote (off-policy, hard targets). Here the student writes, and the teacher supplies full distributions on the student’s own text.

Why on-policy? Because a student copying perfect teacher traces never sees its own mistakes. Once it drifts off the teacher’s path, it is in places it never practised. On-policy feedback is given exactly where the student goes [5][6].

Is there still a reward? Not in Beam’s merge stage. The teachers already learned from rewards; the student learns from the teachers [1].

Does the student have to be smaller? No. In Beam the student is the same size as the teachers. The goal is to combine skills, not to shrink.

See also

References

Back to top