Skip to content

On-Policy Distillation of Language Models: Learning from Self-Generated Mistakes (GKD)

optionalcorefundamentalpaperrubric 12/122023 · ICLR 2024 · ~40 min

Rishabh Agarwal, Nino Vieillard, Yongchao Zhou, … Olivier Bachem

Read first: REINFORCE and the Policy-Gradient Theorem (Williams 1992; Sutton et al. 1999)

Status

TL;DR. Classic distillation trains the student on fixed sequences (ground truth or teacher outputs). At inference, though, the student continues its own prefixes, so the errors it never practised compound. GKD trains the student on its own samples, uses the teacher’s full next-token distribution on every prefix as the label, and lets you pick both the data mix λ and the divergence (forward KL, reverse KL or generalized JSD). It also plugs straight into RL fine-tuning.

Why it matters now. This is the technical root of “on-policy distillation”, the recipe behind Qwen3’s small models and the Thinking Machines blog. It is also the root of the 2026 self-distillation wave (OPSD, SDFT). For an IR person it is the principled version of “distil the big cross-encoder or LLM reranker into a small one”: train on the student’s own outputs, not just the teacher’s.

Distillation as imitation learning. Treat the student pSθp_S^\theta as a policy and the teacher pTp_T as an expert you can query at any state. A “state” is a prefix y<ny_{\lt n}. The token-level discrepancy on a sequence is the average divergence over its positions (Eq. 2):

D(pT∥pSθ)(y∣x)=1Ly∑n=1LyD(pT(⋅∣y<n,x) ∥ pSθ(⋅∣y<n,x)).\mathcal{D}(p_T\|p_S^\theta)(y\mid x) = \frac{1}{L_y}\sum_{n=1}^{L_y}\mathcal{D}\big(p_T(\cdot\mid y_{\lt n},x)\,\big\|\,p_S^\theta(\cdot\mid y_{\lt n},x)\big).

Which sequences? Supervised KD averages this over a fixed dataset of (x,y)(x,y) pairs. On-policy KD averages it over y∼pS(⋅∣x)y \sim p_S(\cdot\mid x), the student’s own samples (temperature 1 during training), without backpropagating through the sampling. GKD mixes the two:

LGKD(θ)=(1−λ) E(x,y)∼(X,Y)[D(pT∥pSθ)(y∣x)]+λ Ex∼XEy∼pS(⋅∣x)[D(pT∥pSθ)(y∣x)].L_\text{GKD}(\theta) = (1-\lambda)\,\mathbb{E}_{(x,y)\sim(X,Y)}\big[\mathcal{D}(p_T\|p_S^\theta)(y\mid x)\big] + \lambda\,\mathbb{E}_{x\sim X}\mathbb{E}_{y\sim p_S(\cdot\mid x)}\big[\mathcal{D}(p_T\|p_S^\theta)(y\mid x)\big].

Supervised KD is λ=0\lambda=0 with forward KL. On-policy KD is λ=1\lambda=1 with forward KL.

Which divergence? Forward KL KL(pT∥pS)\mathrm{KL}(p_T\|p_S) is maximum-likelihood-like and mass-covering: the student must put mass everywhere the teacher does, and a small student then spreads mass onto tokens the teacher considers unlikely. Reverse KL KL(pS∥pT)\mathrm{KL}(p_S\|p_T) is mode-seeking: the student concentrates on what the teacher likes most, which gives higher quality and less diversity. This mass-between-modes intuition concerns a capacity-limited student; with an unrestricted student, both KL directions are minimized by matching the teacher. The generalized JSD interpolates between them:

DJSD(β)(P∥Q)=β KL(P ∥ βP+(1−β)Q)+(1−β) KL(Q ∥ βP+(1−β)Q).\mathcal{D}_{\mathrm{JSD}(\beta)}(P\|Q) = \beta\,\mathrm{KL}\big(P\,\|\,\beta P+(1-\beta)Q\big) + (1-\beta)\,\mathrm{KL}\big(Q\,\|\,\beta P+(1-\beta)Q\big).

Its gradients behave like forward KL as β→0\beta\to 0 and like reverse KL as β→1\beta\to 1.

Forward versus reverse KL with a capacity-limited student Three panels, each showing the same two-mode teacher distribution as a shaded area. Left: a single-bump student fitted with forward KL from teacher to student is wide and centred between the two modes, putting mass where the teacher has little. Middle: a single-bump student fitted with reverse KL from student to teacher sits on one teacher mode and ignores the other. Right: a student flexible enough to represent the teacher matches it exactly, which minimises both KL directions, so the mass-covering versus mode-seeking difference only appears when the student cannot match the teacher. Forward KL, capacity-limited KL(p_T ‖ p_S), one-bump student mass-covering: the fit puts mass between modes Reverse KL, capacity-limited KL(p_S ‖ p_T), one-bump student mode-seeking: the fit locks onto one mode Either KL, unrestricted student can represent p_T both KLs minimised at p_S = p_T: no difference teacher p_T (two modes) student p_S after fitting
Original sketch. With a one-bump student and a two-mode teacher, forward KL spreads the fit between the modes and reverse KL locks onto one. A student that can represent the teacher matches it exactly under either divergence.

Plus RL. Because on-policy GKD needs only student samples, it composes with RLHF/RLAIF (Eq. 5):

Ex[(1−α) Ey∼pSθ[r(y)]−α Ey∼pS[D(pT∥pSθ)(y∣x)]].\mathbb{E}_x\Big[(1-\alpha)\,\mathbb{E}_{y\sim p_S^\theta}[r(y)] - \alpha\,\mathbb{E}_{y\sim p_S}\big[\mathcal{D}(p_T\|p_S^\theta)(y\mid x)\big]\Big].

When combining with RL, the authors recommend reverse KL or JSD(0.9), which match the reverse-KL regulariser RLHF already uses.

Generalized Knowledge Distillation: a design space of data source and divergence, and one on-policy update Left: a grid whose horizontal axis is lambda, the fraction of student-generated training sequences, from 0 (fixed dataset) to 1 (fully on-policy), and whose vertical axis is the divergence, from forward KL at the bottom through generalized JSD to reverse KL at the top. Supervised KD sits at lambda 0 with forward KL, ImitKD at lambda 0.5 with forward KL, on-policy KD at lambda 1 with forward KL, and on-policy GKD with JSD 0.9 or reverse KL near the top right. The top is mode-seeking and less diverse; the bottom is mass-covering and may hallucinate. Right: one GKD update. Pick a sequence from the student with probability lambda or from fixed data, let the teacher score every prefix over the full vocabulary, average the token-level divergence, and update the student without backpropagating through sampling. Combining with RL gives the objective (1 minus alpha) times expected reward minus alpha times expected divergence. GKD design space: data source × divergence reverse KL JSD(β) forward KL mode-seeking: sharper, less diverse mass-covering: may hallucinate supervised KD ImitKD (mixed) on-policy KD on-policy GKD, JSD(0.9) or reverse KL (recommended with RL) λ = 0 0.5 λ = 1 λ = fraction of student-generated sequences 0: fixed dataset · 1: fully on-policy One GKD update 1 · y from the student (w.p. λ) or from fixed data (w.p. 1 − λ) 2 · teacher scores every prefix p_T(· | y<n, x), full vocabulary 3 · loss = mean over positions n of D(p_T ‖ p_S)(· | y<n, x) 4 · update p_S only; no backprop through sampling Plus RL (Eq. 5) (1 − α)·E[r] − α·E[D] α = 1: pure distillation α = 0: pure RL on the reward
Original sketch. GKD is a two-knob family: λ chooses whose sequences you train on, and the divergence chooses mass-covering versus mode-seeking. Each update scores every prefix of the chosen sequence with the teacher's full distribution.

Setup: T5 students (small 77M, base 250M, large 800M) distilled from a supervised-fine-tuned T5-XL (~3B) teacher, on XSum (summarisation), WMT en→de (translation) and GSM8K (arithmetic reasoning). All methods start from the same SFT student.

  • Headline (Fig. 1). Averaged over student sizes, the improvement over the initial student from on-policy GKD is 2.1× (summarisation), 1.7× (translation) and 1.9× (arithmetic) the improvement from baseline KD methods.
  • Data efficiency (Fig. 3). On XSum, on-policy GKD on a 5% subsample, without ground-truth summaries, beats supervised KD and ImitKD trained on the full dataset.
  • Divergence vs temperature (Fig. 4). Under temperature sampling, mode-seeking divergences (JSD(0.5), JSD(0.9), reverse KL) give better quality but less diversity (higher Self-BLEU). With greedy decoding the choice matters much less.
  • GSM8K (Fig. 8). Performance typically improves once more than 25% of the data is student-generated, and purely student-generated CoTs work best.
  • Task-agnostic (Fig. 10). Distilling FLAN T5-XL into T5-large with on-policy GKD (reverse KL best) gives +2% on held-out BBH and +1% on MMLU (absolute).
  • RLAIF (Fig. 5). On XSum with a factual-consistency reward, α trades distillation quality (ROUGE-2) against factual consistency.
  • Shared vocabulary implied. Token-level divergences compare the teacher’s and student’s distributions over the same MM-token vocabulary (all the paper’s models are T5). Arbitrary teacher–student pairs with different tokenizers need extra machinery that the paper does not address.
  • Small, short-output regime. The evidence comes from T5 models up to ~3B with short outputs. Long reasoning traces push student prefixes further from the teacher’s support, where teacher feedback may degrade.
  • Divergence is a hyperparameter. There is no rule for choosing it beyond “it depends on the task and temperature”.
  • The teacher only grades, never searches. If the student never visits a good region, the teacher’s per-token feedback on bad prefixes may not get it there. This is the gap that privileged teachers and Pedagogical RL target.
  • Map of the family: On-policy distillation: a map compares OPD variants and when to use OPD, RLVR or SFT.
  • Before: REINFORCE / policy gradients, imitation learning (DAgger), Hinton-style KD. DAgger queries the expert on states visited by the learner; KD transfers a teacher’s output distribution rather than only hard labels.
  • After: On-Policy Distillation (Thinking Machines) scales the reverse-KL, λ = 1 version to reasoning models. OPSD and SDFT make the teacher the same model conditioned on privileged context.
  • Concurrent: MiniLLM optimises sequence-level reverse KL with policy gradient. Multi-teacher: MOPD merges several RL specialists by on-policy distillation.
  • RL link: the RL + GKD objective is RLHF with the reference model replaced by a teacher. See PPO and InstructGPT.
  • Contrast: LUFFY takes the other route. It uses teacher trajectories (off-policy) inside GRPO rather than teacher logits 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

    A teacher's next-token distribution over three tokens is p_T = (A 0.49, B 0.49, C 0.02). A weak student can choose Q1 = (0.96, 0.02, 0.02) or Q2 = (0.34, 0.33, 0.33). Compute the forward KL(p_T‖Q) and reverse KL(Q‖p_T) for both, say which student each divergence prefers, and connect the result to the paper's quality vs diversity findings.

    What a strong answer covers
    • Forward: KL(p_T‖Q1) ≈ 1.24 and KL(p_T‖Q2) ≈ 0.32, so forward KL prefers the spread-out Q2. It is mass-covering: missing B (0.02 vs 0.49) is very costly.
    • Reverse: KL(Q1‖p_T) ≈ 0.58 and KL(Q2‖p_T) ≈ 0.67, so reverse KL prefers Q1. It is mode-seeking: putting 0.33 on C, which the teacher gives only 0.02, is very costly.
    • Q2 samples C a third of the time, a token the teacher thinks is nearly impossible. This is the low-quality or hallucination failure the paper attributes to forward KL with a low-capacity student under temperature sampling.
    • Q1 has less entropy, matching the observed drop in diversity (higher Self-BLEU) as the divergence moves from forward toward reverse KL via JSD(β).
  2. Mechanism

    Why does training on the student's own samples (λ = 1) reduce the train–inference mismatch that supervised KD on a fixed dataset suffers from? Explain in terms of which prefixes y_1..y_(n−1) the student sees during training versus at inference, and what the teacher's token-level distribution provides on a prefix that already contains a student mistake.

    What a strong answer covers
    • Supervised KD conditions on ground-truth or teacher prefixes. At inference the student conditions on its own prefixes, which drift after its first error, so errors compound (exposure bias, as in imitation learning).
    • On-policy KD samples prefixes from the student, so training states match inference states. This is the DAgger idea of an interactive expert labelling the learner's own states.
    • On an erroneous prefix the teacher still gives a full next-token distribution that says how to continue or recover from there. Fixed data never contains that recovery signal.
    • There is no gradient through the sampling step: the samples are treated as data. This keeps training stable and cheap, and the student's samples improve as it trains.
  3. What if…

    On GSM8K the paper varies the fraction λ of student-generated data and finds performance typically improves once λ exceeds 25%, with purely student-generated chain-of-thought best. Predict what happens at λ = 0, 0.25 and 1 for a weak student, and what would change if the student had not been supervised-fine-tuned first.

    What a strong answer covers
    • λ = 0 is supervised KD: the student imitates on reference CoT prefixes and never practises recovering from its own reasoning errors.
    • Low λ adds a few on-policy samples whose teacher feedback is diluted. Gains appear only once on-policy prefixes make up a substantial share of the data (above about 25% here).
    • λ = 1 gives the most on-distribution feedback. The paper's Fig. 8 shows only-student-generated CoTs beating the mixtures.
    • Without SFT, student samples could be so poor that teacher feedback on them is uninformative or off-support. The paper explicitly assumes a student of adequate quality, like the SFT stage before RLHF.
  4. Connect

    Show that on-policy GKD with reverse KL is a special case of RL: write the per-token reward that makes the policy-gradient objective equal to −KL(p_S‖p_T) on student samples, and relate it to the paper's RL + GKD objective (1 − α)·E[r] − α·E[D] and to the KL-to-reference penalty in RLHF.

    What a strong answer covers
    • Reverse KL on student samples is E over y ~ p_S of the sum over n of (log p_S − log p_T). Maximising its negative is RL with per-token reward r_n = log p_T(y_n | y_1..y_(n−1), x) − log p_S(y_n | y_1..y_(n−1), x).
    • Unlike RLHF's single end-of-sequence reward, this reward is dense: every token gets graded.
    • Eq. 5 mixes a task reward with this distillation term. α = 1 is pure distillation, α = 0 pure RL. With the teacher equal to the initial policy, the D term is exactly RLHF's KL-to-reference regulariser.
    • This is why the authors recommend reverse KL or JSD(0.9) when bolting GKD onto an existing RLHF pipeline. It is also the basis of the Thinking Machines on-policy distillation recipe.
  5. Design

    You must distil a 70B LLM reranker that writes a short rationale and then a relevance label into a 1B student for production search, with a fixed GPU budget and an unlabelled query–passage log. Choose λ, the divergence and the training temperature for GKD, state any compatibility constraint between the two models, and say how you would validate the choice.

    What a strong answer covers
    • Token-level GKD needs the teacher's full next-token distribution on the student's prefixes, so the two models must share a tokenizer and vocabulary, or you need a cross-tokenizer approximation.
    • The unlabelled log favours λ near 1: student sampling is cheap, and the teacher only scores (one forward pass), never generates.
    • Divergence: if the deployed student decodes greedily, the paper finds the divergence matters little. If you sample (for example for diversity), prefer mode-seeking JSD(0.9) or reverse KL. Label-calibration needs may favour forward KL, which preserves the label distribution.
    • Validate the student on ranking metrics (nDCG@10 on held-out judged queries) and calibration of the label probabilities, not just token-level KL. Check diversity only if it matters downstream.
  6. Critique

    GKD's evidence comes from T5 students (77M–800M) and a roughly 3B T5-XL teacher on summarisation, translation and GSM8K, and the best divergence varies by task and temperature. What are the main threats to concluding that "on-policy + mode-seeking" transfers to modern long-chain reasoning distillation, and what experiment would test it?

    What a strong answer covers
    • Scale and length gap: the outputs are short. Long reasoning traces make early student errors push prefixes far off the teacher's support, where its feedback may be poor (compare the teacher-recovery decay reported in the Pedagogical RL post).
    • Task-dependent divergence choice risks per-task tuning on the evaluation metric. A fixed protocol for selecting the divergence on a validation split is needed.
    • The metrics (ROUGE-2, BLEU, GSM8K accuracy) do not measure faithfulness, except in the RLAIF experiment.
    • Experiment: distil a 32B reasoning model into 1.5B–8B students on AIME-style data, comparing λ ∈ {0, 0.5, 1} × {forward KL, JSD(0.9), reverse KL} at matched FLOPs, with seeds and length-bucketed analysis.

Done with this page?

Status