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:- 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.
- 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.
- The student runs the same forward pass to get its own probabilities at each position.
- The loss compares the two models’ probabilities at each position, and averages over every response token in the batch. See The loss function.
- 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 and response in a batch , the loss compares the teacher’s next-token distribution with the student’s at every position of the response, and averages over all response tokens in the batch: is the divergence that the Beta setting selects: where , and , summed over every token 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.
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.
- 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.
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 selectOn-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:- Run the job with the default settings, and evaluate the model.
- 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.
- 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.
- If the student’s responses lose variety, or keep getting longer during training, lower beta toward forward KL divergence.
- 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.