Skip to content

On-Policy Distillation (Thinking Machines)

optionalcorefrontierblogrubric 9/122025 · ~30 min

Kevin Lu and Thinking Machines Lab

Read first: On-Policy Distillation of Language Models: Learning from Self-Generated Mistakes (GKD) · Proximal Policy Optimization (PPO) · DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models

Status

TL;DR. SFT on teacher outputs gives a dense signal, but only on the teacher’s states. RL trains on the student’s states, but with one sparse grade per episode. On-policy distillation (OPD) gets both. The student samples, the teacher grades every sampled token with its log-probability, and a standard policy-gradient step uses per-token advantage log⁡pT−log⁡pS\log p_T - \log p_S. In code this is a one-line change to an RL loop.

Why it matters now. This 2025 blog turned GKD into a practical recipe for reasoning models. It replicates a result from the Qwen3 technical report (whose Table 21 shows OPD beating RL at about a tenth of the GPU hours), and it is the baseline that 2026 work (OPSD, SDFT, Pedagogical RL) builds on or argues against. The personalization section is also a clean demo of “continued pre-training breaks the chat model, and OPD repairs it”. Search teams hit exactly that problem when they adapt an LLM to a corpus.

Three ways to post-train a student, by where states come from and how densely they are graded:

MethodSamplingReward signal
SFT / off-policy distillationoff-policy (teacher’s states)dense
RLon-policy (student’s states)sparse (per episode)
On-policy distillationon-policydense (per token)

The blog’s chess analogy: SFT is watching a grandmaster play, in board positions you will never reach. RL is playing games and learning only win or loss. OPD is a coach grading each of your moves from blunder to brilliant.

The loss is per-token reverse KL on student samples:

KL(πθ ∥ πteacher)=Ext∼πθ[log⁡πθ(xt+1∣x1..t)−log⁡πteacher(xt+1∣x1..t)].\mathrm{KL}(\pi_\theta\,\|\,\pi_\text{teacher}) = \mathbb{E}_{x_t\sim\pi_\theta}\big[\log\pi_\theta(x_{t+1}\mid x_{1..t}) - \log\pi_\text{teacher}(x_{t+1}\mid x_{1..t})\big].

As RL. Set the per-token advantage to

At=−(log⁡πθ(xt+1∣x1..t)−log⁡πteacher(xt+1∣x1..t))A_t = -\big(\log\pi_\theta(x_{t+1}\mid x_{1..t}) - \log\pi_\text{teacher}(x_{t+1}\mid x_{1..t})\big)

with discount factor 0, so each token is credited only with its own grade. This is a sampled log-ratio advantage: a single sampled token’s AtA_t can be positive or negative, and only its expectation over the student’s next-token distribution at a prefix equals the negative reverse KL at that prefix. Treating the rollout prefixes as fixed, this averages per-prefix reverse-KL gradients; it drops the term that credits a token for changing later prefixes, which MiniLLM keeps. The authors call a discount above 0 “more mathematically correct” but report that it did not help in practice. The teacher needs just one forward pass over the student’s sample; it never generates.

Why reverse KL. It is mode-seeking: the student learns the teacher’s behaviour, not a blur of all behaviours. The blog calls it “unhackable” in the sense that exact KL has a known distribution-matching optimum and a low exact KL always means teacher-like behaviour, unlike a learned reward model. That does not guarantee safe optimisation with sampled, clipped or length-normalised surrogates: MiniLLM observes short or repetitive outputs and adds stabilising remedies.

On-policy distillation: on-policy sampling with a dense per-token teacher grade Left: a two by two grid. Columns are where training sequences come from, off-policy (teacher or dataset) or on-policy (the student's own samples). Rows are reward density, sparse (one grade per answer) or dense (a grade per token). Supervised fine-tuning on teacher outputs is off-policy and dense. Reinforcement learning is on-policy and sparse. On-policy distillation is on-policy and dense, combining both advantages. Right: one update. The student samples a full answer; the teacher computes its log-probability for each sampled token in a single forward pass; each token's advantage is the teacher log-probability minus the student log-probability, a sampled log-ratio that can have either sign and whose expectation over student-sampled tokens is the negative reverse KL at that prefix, with discount factor zero; then a standard policy-gradient update is applied. A toy bar chart shows one sampled token the teacher finds unlikely receiving a large negative advantage. RL conveys order one bits per episode while distillation conveys order N bits for N tokens. Data source × grading density off-policy (teacher data) on-policy (own samples) sparse per answer dense per token (not a common recipe) RL right states, 1 grade/answer SFT / off-policy KD all tokens graded, teacher's states On-policy distillation own states, all tokens graded RL: O(1) bits per episode. Distillation: O(N) bits for N tokens. Chess: SFT = watch a grandmaster; RL = win/loss; OPD = each move graded. One update (a one-line RL change) 1. Student samples y ~ π_S(· | x); keep log p_S 2. Teacher scores y 1 forward pass → log p_T(y_t) 3. Sampled log-ratio advantage A_t = log p_T − log p_S (γ = 0) 4. Policy-gradient step E[A_t] = −reverse KL at prefix Toy A_t for 4 sampled tokens: ← "blunder" teacher-unlikely token → A_t ≪ 0
Original sketch. OPD occupies the on-policy, dense-reward cell. Each step samples from the student, gets one teacher forward pass, and turns the per-token log-probability gap into a sampled log-ratio advantage, whose expectation at a prefix is the negative reverse KL.

All results are blog-reported, single runs on Tinker (no seeds or error bars).

  • Reasoning (AIME’24, Qwen3-8B-Base student). SFT on 400K prompts reaches 60%; the authors extrapolate that ~2M prompts would be needed for ~70%. From the 400K checkpoint, OPD reaches 70% in ~150 steps (~77K prompts, 4 samples each). They report 9× less compute than extrapolated SFT given the SFT data, ~18× in GPU hours, and ~30× if teacher sampling for SFT data is counted. Note: the teacher was actually Qwen3-8B, with FLOPs counted as if it were Qwen3-32B.
  • Qwen3 report, Table 21 (vendor-reported). RL reaches 67.6% AIME’24 and 61.3% GPQA-Diamond at 17,920 GPU-hours; OPD reaches 74.4% and 63.3% at 1,800 GPU-hours.
  • LoRA. At rank 32, LoRA trails full fine-tuning by 13% after SFT but only 6% after OPD.
  • Distilling an RL-trained policy. OPD recovers the teacher’s performance in 7–10× fewer gradient steps than RL with matched architecture (LoRA rank 128). The authors call this 50–100× compute efficiency overall.
  • Data reuse. Training on a single prompt for 20 steps (256 rollouts each) approximately matches teacher performance.
  • Personalization.
Model (Qwen3-8B)Internal QA (knowledge)IF-eval (chat)
base18%85%
+ midtrain on docs (100%)43%45%
+ midtrain (70% docs, 30% chat)36%79%
+ midtrain (70%) + OPD from original Qwen3-8B41%83%
  • You need a teacher. OPD learns from the teacher’s distribution; its gains depend on the teacher and student, and teacher-training cost (often RL) is excluded from these savings. The blog gives no theorem that the student cannot exceed the teacher’s task score, and GKD’s self-distillation experiment (App. A.1) reports students that do.
  • Support problem. Reverse KL is mode-seeking within the student’s support. If the student’s chance of producing the right tokens starts near zero, the teacher has nothing to grade. That is why the domain experiments mid-train first.
  • Same tokenizer (implied). Per-token log-probabilities of the student’s tokens must be computable under the teacher, so teacher and student need a shared vocabulary. All the blog’s pairs are Qwen3 models.
  • Teacher feedback on bad prefixes. If the student wanders far off the teacher’s distribution, the teacher’s grades on those prefixes may be uninformative. Pedagogical RL argues this caps how much a non-trained teacher can help on hard problems.
  • Evidence quality. These are blog results without seeds, and the headline cost comparison uses an extrapolated baseline.
  • Reproducing today (dated note). The numbers above are the original Qwen3 experiments. A June 2026 update to the blog says those teacher and student models have been retired from Tinker and the cookbook’s distillation recipes now use Qwen3.5-9B-Base (student) and Qwen3.5-9B (teacher). Running the current recipe is therefore a different setup; the historical Qwen3 numbers are not Qwen3.5 results.
  • Map of the family: On-policy distillation: a map compares OPD variants and when to use OPD, RLVR or SFT.
  • Before: GKD (this is GKD with λ = 1 and reverse KL on sampled tokens) and PPO / GRPO, the policy-gradient loop it reuses.
  • Many teachers: MOPD uses this per-token advantage to merge several RL-trained domain specialists into one student. MiniLLM is the earlier reverse-KL policy-gradient formulation with a cumulative return.
  • Teacher = self with extra context: OPSD (teacher sees the reference solution), SDFT (teacher sees a demonstration) and π-Distill (teacher sees privileged tool traces).
  • Train the teacher: RLT and Pedagogical RL make the teacher itself an RL learner optimised for the student’s benefit.
  • Opposite data source: LUFFY mixes teacher trajectories into on-policy RL instead of teacher grades on student trajectories.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    Show that a policy-gradient update with discount factor 0 and per-token advantage A_t = log p_T(y_t | x, y_1..y_(t−1)) − log p_S(y_t | x, y_1..y_(t−1)), computed on student samples y ~ p_S, follows the gradient of the per-prefix −KL(p_S ‖ p_T) when the rollout prefixes are treated as fixed. What does the full sequence-level KL gradient add that discount 0 drops? Why is the "reward" here not a fixed function of the trajectory, and in what sense is it "unhackable"?

    What a strong answer covers
    • At a fixed prefix h_t, KL(p_S‖p_T) = E over y_t ~ p_S of (log p_S − log p_T). Its gradient is E[∇log p_S(y_t) · (log p_S − log p_T)] plus E[∇log p_S(y_t)], which is zero at that fixed prefix. So the sampled log-ratio gives an unbiased gradient of the negative per-prefix reverse KL.
    • With rollout prefixes treated as fixed data, discount 0 averages these local gradients: each token is credited only with its own grade. The full sequence-KL gradient also credits each token for its effect on which future prefixes are visited, i.e. ∇log p_S(y_t) is multiplied by the sum of future log-ratios from t onward. MiniLLM keeps that future-return term; the blog itself calls a positive discount "more mathematically correct" but found it did not help in practice.
    • The reward depends on θ through log p_S. That is fine because it acts as an entropy-regularised reward: −log p_S is the student's own surprisal, which rewards not over-concentrating.
    • The blog calls it "unhackable" in a specific sense: exact reverse KL has a known optimum (p_S = p_T on the visited states), and low exact KL always means teacher-like behaviour, unlike an unconstrained learned reward model. That does not guarantee safe optimisation of sampled, clipped or length-normalised surrogates: MiniLLM observes degenerate short or repetitive outputs while reverse KL falls, and adds remedies.
  2. Mechanism

    The post says RL teaches O(1) bits per episode while distillation teaches O(N) bits for N tokens, and that on-policy distillation works with much smaller batches than RL. Explain both claims and how they lead to the reported compute savings.

    What a strong answer covers
    • An RL episode yields one scalar (e.g. correct or not), so a long trajectory carries only a few bits about which tokens were good. Credit assignment over N tokens must be inferred from many episodes.
    • Distillation gives each of the N sampled tokens its own graded signal from the teacher distribution, so information per episode scales with length.
    • More information per sample means lower gradient noise per update, so smaller batches and fewer steps suffice (about 150 steps to 70% AIME'24 from a 60% SFT checkpoint).
    • Cost per step is close to RL's: student sampling plus one teacher forward pass, with no teacher generation. The savings therefore come from needing far fewer steps and samples (7–10× fewer gradient steps when distilling an RL-trained policy).
  3. Critique

    The headline comparison says on-policy distillation reaches ~70% AIME'24 with 9–30× less compute than extrapolated SFT, and the Qwen3 report's Table 21 (vendor-reported) shows OPD beating RL at ~1/10 of the GPU hours. List the comparability caveats that a careful reviewer should raise.

    What a strong answer covers
    • The SFT-2M baseline is extrapolated from a log-linear fit, not run. The 9×/18×/30× range depends on whether teacher sampling cost and GPU efficiency are counted.
    • The teacher in the main experiment was actually Qwen3-8B, with FLOPs computed as if it were 32B. Teacher-choice effects are therefore muddled with the cost accounting.
    • OPD requires an existing strong teacher whose training cost (often RL itself) is not counted. RL needs no teacher and can exceed one.
    • Qwen3 Table 21 compares RL and OPD from the same off-policy-distilled Qwen3-8B checkpoint and reports six benchmarks. Remaining caveats: excluded teacher-development cost, training limited to math and code queries, no uncertainty estimates, and no breakdown of the GPU-hour accounting.
  4. What if…

    In the personalization experiment, Qwen3-8B is mid-trained on internal documents and loses instruction following (IF-eval 85% → 45% at a 100% document mix; 79% at a 70% mix). Then on-policy distillation from the original Qwen3-8B on unrelated Tulu3 prompts restores IF-eval to 83% while keeping knowledge at 41%. Why does OPD here not erase the new knowledge, and what control would confirm the mechanism?

    What a strong answer covers
    • Distillation is on chat prompts unrelated to the documents, so gradients mostly touch chat behaviour. Because it is on-policy, the student is pulled toward the teacher only on states it actually visits in chat.
    • The teacher is the model's own earlier version, so the target behaviour is already within the student's support, which suits a mode-seeking reverse KL.
    • Knowledge is not erased; it even rises (36% → 41% after distillation, vs 43% for the pure-document mix). That suggests chat-style distillation also helps the model surface what it learned, though this is a single run.
    • Controls: SFT on teacher outputs for the same Tulu3 prompts (off-policy) at matched compute; distillation on document-related prompts; and measuring knowledge retention as distillation steps increase.
  5. Design

    You maintain an LLM-based query rewriter for a search engine, trained with RL against a click-based reward. Every quarter you continue pre-training it on fresh documents, and its rewriting quality regresses. Design an on-policy-distillation recovery loop: who is the teacher, what prompts, what metric gates release, and what failure mode remains?

    What a strong answer covers
    • Teacher: the previous released rewriter (the pre-midtrain checkpoint), which already has the RL-trained behaviour. The student is the freshly mid-trained model, and both must share a tokenizer.
    • Prompts: sampled from the query log (the rewriter's real distribution), with no click labels needed. The student samples rewrites, the teacher scores per-token log-probs, and the update uses reverse KL.
    • Gate: offline retrieval metrics (recall@k or nDCG@10 of rewritten queries) on held-out judged queries, plus a freshness test that new-entity queries still benefit from the new knowledge.
    • Remaining risk: the teacher never saw the new entities, so on rewrites mentioning them it may assign low probability and pull the student back toward stale behaviour. Consider masking or down-weighting tokens about new entities.
  6. Connect

    Relate this recipe to GKD and to RLHF. Which GKD configuration (λ, divergence) is it, what does it add beyond GKD, and how does its per-token reward relate to the KL-to-reference penalty in RLHF?

    What a strong answer covers
    • It is GKD with λ = 1 (fully on-policy) and reverse KL, evaluated only on sampled tokens rather than the full vocabulary, so it fits an RL code path.
    • Additions: an implementation as an RL advantage (discount 0), scale-up to reasoning models and LoRA, compute accounting against SFT and RL, and uses for personalisation and continual learning.
    • In RLHF the KL to a reference model is a regulariser added to a task reward. Here the KL to a better teacher is the whole objective: the "reference" is the target, not an anchor.
    • GKD's RL + distillation mix (1 − α)E[r] − αE[D] interpolates between the two.

Done with this page?

Status