Skip to main content
On-Policy Distillation (OPD) trains a smaller student model with guidance from a larger teacher model. The student generates responses during training, and the teacher scores each token of those responses, so the student learns to match the teacher on the kinds of text it actually produces. The result is a model close to the teacher’s quality on your task, at the size, latency, and cost of the student. You can set up an OPD training run via the web app or ask FAiE to set one up for you!

BENEFITS OF SMALLER MODELS

Well-trained smaller models can often outperform larger general-purpose models within their specific domains. They also offer practical advantages: they’re easier to deploy locally (thereby enhancing privacy and security), more cost-efficient to run, and simpler to update or retrain as new data becomes available. To train these smaller student models, two main post-training strategies are commonly used:
  • Off-policy training – The student learns from responses that it didn’t generate, such as a fixed dataset or responses sampled from the teacher. In distillation, this typically means training on the teacher’s completed responses, or on the teacher’s logits over a fixed dataset.
  • On-policy training – The student generates responses during training, and the teacher provides supervision (e.g., logits) on those samples.

WHY USE ON-POLICY DISTILLATION?

OPD combines the strengths of supervised fine-tuning (SFT) and reinforcement learning (RL). The student trains on its own responses, as in RL, and receives feedback on every token, as in SFT.

The student learns from its own mistakes

In SFT and other off-policy methods, the student learns from text that the teacher or a dataset wrote. It sees a correct prefix and learns to predict the correct next token. At inference, the student writes the prefix itself. If it gets one token wrong, every token after that is conditioned on a mistake it never saw in training, so it’s more likely to go wrong again. This train-inference mismatch gets worse as responses get longer, since there’s more room for errors to pile up. OPD removes the mismatch by training the student on its own responses, mistakes included. The teacher scores every token the student wrote, so the student learns where it went wrong and what the teacher would have written instead. The teacher also scores the tokens after a mistake, so the student learns how the teacher would continue from there. As the student improves, its responses become better training data. On summarization, translation, and arithmetic reasoning, training on student-generated responses consistently outperformed training only on a fixed dataset.

Denser feedback lets OPD match RL with less compute

RL also trains on the student’s own responses, but it assigns one reward to each response. The student learns that a response was wrong, not which token made it wrong. In OPD, the teacher scores every token, so each response carries far more training signal, and you don’t need a reward function. In the Qwen3 technical report, OPD scored higher than RL on AIME 2024 with about a tenth of the GPU hours.

HOW IT WORKS

Each training step works like this:
  1. The student generates a response to each prompt in the batch. With Lambda below 1, some batches skip this step and use the responses in your training data instead.
  2. The teacher runs a forward pass on each prompt and response, and returns its probability for every possible next token at each position of the response. The teacher doesn’t generate any text, and its weights stay fixed.
  3. The student runs the same forward pass to get its own probabilities at each position.
  4. The loss compares the two models’ probabilities at each position, and averages over every response token in the batch. See The loss function.
  5. The student’s weights update to lower the loss. The next step samples new responses from the updated student.

The loss function

For each prompt xx and response yy in a batch BB, the loss compares the teacher’s next-token distribution pTp_T with the student’s pSp_S at every position of the response, and averages over all NN response tokens in the batch: L=1N∑(x,y)∈B  ∑n=1∣y∣Dβ(pT(⋅∣x,y<n) ∥ pS(⋅∣x,y<n))\mathcal{L} = \frac{1}{N} \sum_{(x, y) \in B} \; \sum_{n=1}^{|y|} D_\beta\Big(p_T(\cdot \mid x, y_{\lt n}) \,\Big\|\, p_S(\cdot \mid x, y_{\lt n})\Big) DβD_\beta is the divergence that the Beta setting selects: Dβ(pT ∥ pS)={KL(pT ∥ pS)β=0 (forward KL)β KL(pT ∥ M)+(1−β) KL(pS ∥ M)0<β<1 (Jensen-Shannon)KL(pS ∥ pT)β=1 (reverse KL)D_\beta(p_T \,\|\, p_S) = \begin{cases} \mathrm{KL}(p_T \,\|\, p_S) & \beta = 0 \text{ (forward KL)} \\ \beta \, \mathrm{KL}(p_T \,\|\, M) + (1 - \beta) \, \mathrm{KL}(p_S \,\|\, M) & 0 \lt \beta \lt 1 \text{ (Jensen-Shannon)} \\ \mathrm{KL}(p_S \,\|\, p_T) & \beta = 1 \text{ (reverse KL)} \end{cases} where M=β pT+(1−β) pSM = \beta \, p_T + (1 - \beta) \, p_S, and KL(P ∥ Q)=∑vP(v)log⁡P(v)Q(v)\mathrm{KL}(P \,\|\, Q) = \sum_v P(v) \log \frac{P(v)}{Q(v)}, summed over every token vv in the vocabulary. KL divergence isn’t symmetric, so the order of the two models changes what the student learns:
  • Forward KL weights each token by the teacher’s probability. It penalizes the student for missing any token that the teacher considers likely, so the student learns to cover all of them (mode-covering). Training is stable, but a student too small to match the teacher can end up spreading probability onto tokens the teacher considers unlikely.
  • Reverse KL weights each token by the student’s probability. It penalizes the student only for tokens that it favors and the teacher doesn’t, so the student learns to commit to the teacher’s most likely tokens and can ignore the rest (mode-seeking). Responses are more focused, with less variety.
For example, if the teacher splits its probability between two good ways to start a solution, forward KL pushes the student to keep both, and reverse KL lets it commit to one: The token-by-token example earlier in this section shows the reverse KL case (β=1\beta = 1), estimated from the one token the student wrote at each position. The Lambda setting decides where each batch’s responses come from. With probability λ\lambda, the student generates them. Otherwise, they’re the responses in your training data, as in SFT. On average, the loss is: E[L]=(1−λ) Ldata+λ Lstudent\mathbb{E}[\mathcal{L}] = (1 - \lambda) \, \mathcal{L}_{\text{data}} + \lambda \, \mathcal{L}_{\text{student}} where Ldata\mathcal{L}_{\text{data}} is the loss on a batch of training-data responses, and Lstudent\mathcal{L}_{\text{student}} is the loss on a batch of student responses. Either way, the teacher only scores the responses and never generates any.

WHEN TO USE OPD

Use OPD when both of the following are true:
  • A larger teacher does the task well, and you need a smaller model. OPD brings the student close to the teacher’s quality at the student’s size, latency, and cost. The student rarely does better than the teacher, so if the teacher can’t do your task well, the student won’t either.
  • The teacher is an open-weight model. OPD needs the teacher’s log probabilities for every token of the student’s responses. Closed models that you call through an API don’t return log probabilities for text they didn’t write, so they can’t be the teacher.
OPD gives the biggest gains when the task needs long or multi-step responses, such as a step-by-step math solution. One wrong token early on can throw off everything after it, and that’s the error OPD trains away. Use another training method when:
  • The responses are short and you have good target responses, such as labels for classification. A short response leaves little room for errors to compound, so the problem OPD solves barely comes up. SFT can get you similar performance but with less cost. Generate responses with the teacher through synthesis, and train on them with SFT.
  • No available open weight teacher does better than your model on the task. Use RFT (coming soon) if a judge can grade the responses. OPD can’t take the student past the teacher, and RFT doesn’t need one.
OPD trains best when the student already approaches the task the way the teacher does, even if it often gets the answer wrong. The teacher scores each token by how well it follows the text before it, including the student’s own earlier tokens, not by whether the response will answer the question. For example, asked for 17 × 24, a student that adds instead of multiplying writes 17 + 24 = 41. The teacher pushes down +, because it would have written ×. But it rates 41 highly, because after 17 + 24 =, 41 is the correct next token. Only the first wrong token teaches the student to change its method, and the rest of the feedback goes to continuing a method it shouldn’t use. The student still learns, but slowly, and training can be unstable. To fix this, train in two phases: SFT on the teacher’s responses first, then OPD on the SFT model. After SFT, the student already works through the task the way the teacher does, so OPD’s corrections go to the mistakes it still makes. Another way to address this is to set Lambda below 1, which mixes in responses from your training data. If the responses in those batches are generated by the teacher, training works like SFT, with richer signal from the teacher’s probabilities as the targets. Once the student’s responses resemble the teacher’s, a higher Lambda works better to address the train-inference mismatch discussed above.

START AN OPD JOB

Follow Train a model, and select On-Policy Distillation as the training method. The form adds two fields:
  • Teacher Model: The model whose behavior the student learns. The list depends on the base model. If the form says “This teacher pairing has not been optimized by the team”, the pairing works, but results may vary.
  • Distillation Settings: Optional settings for how the student generates responses and how the teacher’s feedback is applied. Leave them blank to use the settings tuned for the base model.

DISTILLATION SETTINGS

The API also accepts temperature, the sampling temperature of the student’s responses. See Training recipe.

TUNE THE SETTINGS

No single value of beta works best for every task, and the best lambda depends on how close the student starts to the teacher, so change them only after a first run with the tuned settings:
  1. Run the job with the default settings, and evaluate the model.
  2. If the model falls short but its responses already resemble the teacher’s, raise lambda. More batches then train on the student’s own responses, which removes more of the train-inference mismatch.
  3. If the student’s responses look nothing like the teacher’s, train with SFT first, then run OPD on the SFT model. See The loss function. If the student’s responses only diverge slightly from the teacher’s, set Lambda below 1 to mix in some responses in your training data.
  4. If the student’s responses lose variety, or keep getting longer during training, lower beta toward forward KL divergence.
Otherwise, choose beta by how many good responses your task has:
  • Raise beta toward reverse KL when each prompt has one right answer, such as a math problem, or when the student writes tokens the teacher wouldn’t, such as made-up details. The student commits to the teacher’s most likely tokens.
  • Lower beta toward forward KL when many responses are good, such as in open-ended writing, and you want the student to keep that variety.
Beta matters less if you serve the model with greedy decoding (temperature 0). The student then always picks its most likely token, and the divergences differ mostly in how they spread probability over the other tokens. Change one setting at a time, and evaluate each run on the same evaluation set.

REFERENCES