On-Policy Self-Distillation: A Deep Dive into the Post-Training Algorithm

    This article breaks down On-Policy Self-Distillation (OPD), an approach that decouples sampling from supervision in large model post-training. It explains why OPD is gaining traction, how it solves the distribution mismatch of offline distillation and the sparse rewards of reinforcement learning, and what the token-level loss looks like in code. You will also find a comparison with one-shot large-scale RL, practical guidance on teacher selection, data mixing, stability, compute allocation, evaluation, and infrastructure, plus common pitfalls to avoid.

    1. Why On-Policy Self-Distillation Is Worth Revisiting Now

    Over the past two years, the dominant narrative in large model post-training has been “pour more compute into reinforcement learning”: larger sampling runs, more iterations, and increasingly elaborate reward design. Philosophically, this is a “one-shot big mix” approach. The training objective, data distribution, and reward signal are fixed early in the pipeline, and later work is limited to local tuning within that existing framework.

    On-Policy (Self) Distillation (referred to below as OPD) takes the opposite direction. It separates “sampling” from “scoring”: the current policy generates its own trajectories, and a stronger teacher (usually a larger model from the same family or a higher-capability version from the previous stage) provides fine-grained supervision on that same distribution. The idea is not new. As early as October 2025, research organizations were bringing it to a wider audience through explainer articles. An open-source model series then published a technical report with comparative experiments concluding that OPD can match reinforcement learning with roughly one-tenth of the compute. Later, the technical documentation for several flagship models wrote OPD into a key stage of post-training. The real turning point came with the most recent wave of flagship model iterations, which elevated OPD from “a technique for replacing RL” to “a post-training main course that mainstream players are willing to bet on.”

    This article takes OPD apart from end to end: what problem it solves, what its mathematical form is, how to implement it in engineering, and which pitfalls are easy to hit.

    2. Core Mechanism: Decoupling Sampling from Supervision

    The pain point of traditional offline distillation is distribution mismatch. During training, the student model sees data drawn from the teacher’s distribution, but at inference time it follows its own distribution, and errors accumulate along the sequence (exposure bias). Reinforcement learning is naturally on-policy, but its rewards are usually sparse and sequence-level, which leads to low sample efficiency and high variance.

    The clever part of OPD is that it captures the strengths of both at once:

    • Trajectories are sampled by the current policy, keeping the training distribution consistent with the inference distribution.
    • The supervision signal is a full distribution given by the teacher at every token position, carrying far more information than a single scalar reward.

    Formally, let the student policy be $\pi\theta$, and let the teacher produce a distribution $q(\cdot\mid x,y{<t})$ given the context $x$ and the generated prefix $y_{<t}$. The per-token distillation loss can be written as:

    1. import torch
    2. import torch.nn.functional as F
    3. def opd_loss(student_logits, teacher_logits, mask, T=1.0, alpha=0.9):
    4. # student_logits: [B, L, V] computed by running the current policy on its own sampled trajectory
    5. # teacher_logits: [B, L, V] teacher scores on the same trajectory
    6. # mask: [B, L] loss is computed only on tokens generated by the model itself
    7. s = F.log_softmax(student_logits / T, dim=-1)
    8. t = F.softmax(teacher_logits / T, dim=-1)
    9. kl = F.kl_div(s, t, reduction="none").sum(-1) # reverse KL
    10. kl = (kl * mask).sum() / mask.sum().clamp(min=1)
    11. # optional: add a very small sequence-level reward term to stabilize early training
    12. return alpha * kl

    There are two key design choices here. First, the mask covers only the segment generated by the student, which avoids forcing the teacher’s distribution onto the prompt. Second, the temperature $T$ controls how “soft” or “hard” the supervision is: the larger $T$ is, the smoother the teacher distribution, and the more stable early training becomes.

    3. How the Engineering Philosophy Differs from Traditional Routes

    Dimension One-shot large-scale RL On-Policy Self-Distillation
    Training distribution Fixed early, drifts later Updated with the policy every round
    Supervision granularity Sequence-level scalar reward Token-level full distribution
    Sample efficiency Low, high variance High, dense gradients
    Compute allocation Sampling and optimization coupled Sampling, teacher scoring, and optimization separable
    Main risk Imbalanced reward design Teacher capability ceiling, distribution collapse

    The difference in engineering philosophy can be summarized like this: the former tries to design the entire training recipe in one shot, while the latter breaks post-training into a pipeline of replaceable, rollback-able stages. The sampling cluster, the teacher inference cluster, and the training cluster can scale independently. When a stage underperforms, you only roll back that stage instead of rerunning the whole pipeline.

    4. Implementation Practices

    1. Teacher selection. Prefer a higher-capability version from the same family with the same tokenizer, avoiding the alignment overhead of mismatched vocabularies. If you must use a heterogeneous teacher, you need an extra token mapping layer, which raises cost significantly.
    2. Data mix. A blend of “verifiable tasks + open-ended tasks” is recommended. Verifiable tasks provide hard constraints, while open-ended tasks preserve natural language quality. Purely verifiable data tends to produce a monotonous output style.
    3. Training stability. Early on, mix in a small amount of sequence-level reward or supervised fine-tuning loss as a “warm start,” then purify into OPD once the KL has dropped and stabilized. Also monitor the distribution entropy of both teacher and student to prevent entropy collapse.
    4. Compute allocation. A common rule of thumb is to split total compute roughly three ways across sampling, teacher scoring, and parameter updates. When sampling throughput is insufficient, expand inference-side resources first rather than blindly increasing the batch size.
    5. Evaluation. Beyond standard benchmarks, add an “on-distribution consistency” evaluation: compare the student’s and teacher’s distributions on the same batch of prompts, and track the quality decay curve for long-sequence generation.
    6. Infrastructure. The sampling and scoring stages can scale elastically on a container platform, training state can be checkpointed periodically to object storage, and the task queue can be decoupled with a message queue. Pair this with logging and monitoring/alerting to locate throughput bottlenecks.

    5. Common Pitfalls

    • Treating OPD as “cheaper reinforcement learning.” Its gains come mainly from supervision density, not merely from saving compute. If the teacher is not capable enough, the saved compute is paid back in the form of degraded quality.
    • Ignoring the mask and length normalization. Without normalization on long sequences, the loss is dominated by long answers and short-answer capability degrades.
    • Replacing all data at once. OPD is sensitive to the data distribution, so scale up in small steps and keep rollback points.

    6. Summary

    The value of OPD is that it turns post-training from a “one-shot recipe” into an “iterable pipeline”: the policy samples on its own to solve distribution consistency, and the teacher scores token by token to solve sparse supervision. Combined, the two offer clear cost-performance advantages when compute is limited. Master the loss form, the temperature and mask details, the three-way compute split, and stability monitoring, and you can put this method to real use in your own model iterations.