On-Policy Distillation: A Deep Dive into the Algorithm and a Practical Guide

    This article explains On-Policy (Self) Distillation (OPD), an approach to post-training that combines on-policy sampling with dense token-level supervision from a stronger teacher model. It covers why post-training needs a more efficient route, how on-policy learning and distillation work together, a minimal training loop, and key design choices including sampling temperature, KL direction, teacher-student temperature alignment, and regularization weighting. The article also compares OPD with traditional large-mix reinforcement learning, then provides a practical checklist, common pitfalls, and troubleshooting order for teams adopting this staged, verifiable, and rollback-friendly workflow.

    1. The Starting Point: Why Post-Training Needs a More Efficient Route

    In the pipeline for building large model capabilities, post-training is responsible for turning the general abilities obtained from pre-training into a usable, controllable, and aligned behavioral policy. The conventional approach tends to mix a large number of tasks together and use a one-shot, large-scale reinforcement learning run to push out a combined policy. The problem with this route is not effectiveness but engineering economics: high sampling cost, fragile reward design, high variance during training, and a tight coupling between compute budget and iteration cycles. So a natural question arises: is there a way for a model to learn on the distribution it is currently generating, while avoiding the high variance and heavy sampling overhead inherent to reinforcement learning?

    On-Policy (Self) Distillation (referred to below as OPD) is the answer to that question. Its engineering philosophy is the opposite of the traditional “one-shot large-mix RL” approach: instead of trying to blend all capabilities in a single run, it breaks post-training into multiple short, verifiable, and rollback-friendly stages. In each stage, the student model receives token-by-token guidance from a stronger teacher signal on the trajectories it currently generates.

    It is worth noting that this direction did not appear with just one generation of models. As early as October 2025, a research organization introduced the idea to a general audience in a popular-science format; later, the technical documentation of an open-source model series reported a comparison showing that roughly one-tenth of the compute could align with an RL baseline; after that, the technical reports of several mainstream industry models included OPD as a key stage of post-training. The real turning point was the most recent flagship model generation, which elevated OPD from “a technique that replaces RL” to “a post-training main course that mainstream players are willing to bet on.”

    2. Core Definition: Why On-Policy and Distillation Must Both Hold

    To understand OPD, first break it into two orthogonal dimensions.

    The first dimension is on-policy, meaning the training samples come from the distribution generated by the model’s current policy, rather than a fixed offline dataset written by someone else. This directly determines that it naturally avoids the distribution drift problem of offline distillation: the student does not become stronger only on “sentences the teacher likes to say,” but is corrected on the states it will actually reach.

    The second dimension is distillation, meaning the supervision signal is not a 0/1 scalar reward but the dense distributional information provided by the teacher model (usually the next-token probability distribution at each position). Dense signals carry far more information than sparse rewards, leading to faster convergence and lower variance.

    Only when both hold at the same time do we get the complete definition of OPD: on its own generated trajectories, using the teacher’s dense distribution for token-by-token supervision. This also explains how it differs from two other common routes:

    • Compared with offline distillation: offline distillation is off-policy; the student sees samples under the teacher’s distribution, and once its own distribution shifts, the supervision becomes mismatched.
    • Compared with pure reinforcement learning: RL has only sparse scalar rewards and requires a large amount of sampling and advantage estimation, with high variance and heavy tuning.
    • Compared with supervised fine-tuning: SFT only learns the “correct answer” and not “how to correct after an error,” whereas OPD covers exactly the error states the student itself will produce.

    3. Method Framework: A Minimal Viable OPD Training Loop

    The following is illustrative pseudocode to help understand the loop structure of OPD. It is deliberately kept generic and is not bound to any specific framework or interface.

    1. # Illustrative: single-step loop of On-Policy (Self) Distillation
    2. for step in range(total_steps):
    3. # 1) Student samples according to the current policy to get on-policy trajectories
    4. prompts = sample_prompts(batch_size)
    5. rollouts = student.generate(prompts, temperature=T_sample)
    6. # 2) Teacher scores the same batch of prompts + student trajectories to get token-level distributions
    7. with no_grad():
    8. teacher_logits = teacher.forward(rollouts.input_ids)
    9. teacher_logprobs = log_softmax(teacher_logits / T_teacher)
    10. # 3) Student forward pass to get its own distribution
    11. student_logits = student.forward(rollouts.input_ids)
    12. student_logprobs = log_softmax(student_logits / T_student)
    13. # 4) Token-level reverse KL (student moves toward the teacher)
    14. # mask out the prompt and padding parts
    15. loss = masked_reverse_kl(student_logprobs, teacher_logprobs, mask)
    16. # 5) Optional: add a small amount of RL or SFT regularization to prevent capability forgetting
    17. loss = loss + lambda_rl * rl_term + lambda_sft * sft_term
    18. loss.backward(); optimizer.step()

    There are four key engineering points in this loop, each expanded below: sampling temperature, KL direction, teacher/student temperature alignment, and the weighting of regularization terms.

    4. Breaking Down the Key Design Points

    4.1 Sampling Strategy: Making On-Policy Truly “On”

    The effectiveness of OPD depends heavily on whether the rollouts truly come from the current policy. Two common pitfalls in practice: first, reusing old rollouts to save compute, which turns the samples into near-off-policy; second, using too low a sampling temperature, so trajectories become overly deterministic, the student never sees its own error states, and the supervision value drops. A reasonable approach is to keep a moderate sampling temperature and resample at every training step; if necessary, use a compromise of “partial reuse plus importance correction,” but monitor distribution-shift metrics.

    4.2 KL Direction: Why Reverse KL Is Usually Used

    The distillation loss can be forward KL (teacher covers student) or reverse KL (student covers teacher). OPD mainstream practice uses reverse KL, because it penalizes “the student assigning probability where the teacher thinks it should not appear.” Its mode-seeking property lets the student converge faster to the teacher’s high-probability behavior and makes training more stable. Forward KL instead tends to spread the student’s probability across all of the teacher’s possible modes, easily producing a vague policy early on that “learns a bit of everything but masters nothing.”

    4.3 Temperature Alignment: An Easily Overlooked Stability Switch

    Using different softmax temperatures for the teacher and student systematically changes the target distribution. If the teacher temperature is high, its distribution is smoothed, the signal the student learns becomes “softer,” convergence is slower but more stable; if it is low, the signal is sharp, convergence is faster but prone to oscillation. A common practice is to fix the teacher temperature first, then do a small-range search over the student temperature, and monitor whether the KL curve decreases monotonically.

    4.4 Regularization Weighting: Preventing “Only Imitation, Losing Original Abilities”

    Pure OPD may make the student overfit to the teacher, causing general-capability regression. A common approach is to add a small-weight RL term or SFT term in the loss as an anchor, or to apply a “capability scope restriction” on the teacher (only letting the teacher guide within the capability domains the student already has). There is no universal weighting value; it needs to be dynamically adjusted per stage goal, with an independent evaluation set monitoring regression.

    5. Engineering Philosophy Compared with Traditional “Large-Mix RL”

    Putting OPD and one-shot large-scale RL in one table, the differences concentrate on four points:

    • Iteration granularity: RL is a large cycle, one-shot push; OPD is small cycles, multi-stage, rollback-friendly.
    • Signal density: RL is a sparse scalar; OPD is a dense token-level distribution.
    • Compute efficiency: public technical documentation generally reports that OPD can align with an RL baseline using about one-tenth of the compute.
    • Stability and observability: OPD has a dense loss curve at every step, so problems are located faster; RL relies on reward curves and manual interpretation.

    In engineering terms, this means OPD is better suited to a team rhythm of “fast trial and error, splitting by capability dimension, and staged acceptance,” while RL is better suited to specific tasks that “need strong exploration and precisely modelable rewards.”

    6. Practical Implementation Checklist

    1. Data side: prepare a prompt set covering the student’s real error distribution, and refresh it regularly to avoid staleness.
    2. Teacher side: choose a teacher in the same domain as the target task and slightly stronger than the student, avoiding “over-teaching.”
    3. Training side: first run a small number of steps to verify that KL decreases monotonically, then scale up the batch and steps.
    4. Evaluation side: build an independent regression set and monitor whether general capabilities regress.
    5. Engineering side: use a container platform to host sampling and training tasks, use a logging service and monitoring alerts to track KL, entropy, and regression metrics, and use object storage to archive each stage’s checkpoint for rollback.

    7. Common Misconceptions and Troubleshooting

    • Misconception 1: treating OPD as offline distillation and reusing a fixed dataset, which degrades it to off-policy and sharply drops effectiveness.
    • Misconception 2: only looking at the final reward and not the token-level KL, missing early divergence signals.
    • Misconception 3: the teacher’s capability far exceeds the student’s and the domain does not match, so the student fails to learn and is instead led astray.
    • Misconception 4: ignoring regularization terms, so general capabilities quietly regress in the later stage of training.
    • Suggested troubleshooting order: first check whether the rollout is on-policy, then check the temperature and KL direction, and finally check the regularization weighting and teacher selection.

    8. Conclusion

    The value of OPD is not “replacing RL” but transforming post-training from a “one-shot gamble” into a “decomposable, verifiable, and rollback-friendly engineering pipeline.” As the industry shifts from “piling up compute to push out one combined policy” to “staged convergence by capability dimension,” OPD offers a default option with denser signals, lower variance, and faster iteration. For developers, the real barrier is not the formulas but the continuous tuning of engineering details such as sampling, temperature, KL direction, and regularization weighting.