On-Policy Distillation for LLM Post-Training: Principles and Engineering Practice

    On-Policy Distillation (OPD) is a post-training technique in which a student model generates its own responses and a teacher model provides token-level distributional guidance on those responses. This article explains the core formulation of OPD, how it differs from supervised fine-tuning, offline distillation, and reinforcement learning, the trade-offs between sampled-token and full-vocabulary objectives, multi-teacher training strategies, a complete engineering workflow, common stability issues, and evaluation practices for large language model post-training.

    Why Revisit Post-Training

    Pretraining gives large language models the ability to understand and generate language. Post-training determines whether a model actually excels at following instructions, reasoning, writing code, calling tools, and handling complex tasks. As model scale grows, the cost, stability, and capability-transfer efficiency of post-training become central system design concerns.

    Traditional post-training typically involves supervised fine-tuning (SFT), preference optimization, and reinforcement learning. SFT lets models learn from high-quality examples, but the model’s behavior ceiling is bounded by the training data. Reinforcement learning optimizes directly against a reward function, but suffers from difficult reward design, unstable training, inefficient exploration, and high engineering costs.

    On-Policy Distillation (OPD) can be understood as a distillation method where “the student generates first, and the teacher guides its current behavior.” It preserves the stability of distillation while introducing the on-policy data distribution characteristic of reinforcement learning, making it an important technical path that connects supervised learning, distillation, and RL.

    Here, “On-Policy” does not mean the teacher generates the data. It means the responses in the training samples are produced by the current student model. The student exposes its problems on its own policy distribution, and the teacher then provides higher-quality probability distributions or token-level guidance on those actual generations.

    Basic Definition of OPD

    Let the input prompt be (x), the student model be (S), and the teacher model be (T). The student first generates a response:

    [
    y=(y_1,y_2,\ldots,y_n)\sim \pi_S(\cdot|x)
    ]

    where (\pi_S) is the student’s current policy distribution. The teacher then computes the conditional probability at each position, given the same input and response prefix:

    [
    \piT(y_t|x,y{<t})
    ]

    The student computes its corresponding probability:

    [
    \piS(y_t|x,y{<t})
    ]

    The goal of OPD is to make the student progressively approximate the teacher’s behavior distribution on trajectories produced by its own policy. A common token-level objective is:

    [
    \mathcal{L}{\text{OPD}}
    =
    -\sum
    {t=1}^{n}
    \sum{v\in V}
    q_T(v|x,y
    {<t})
    \log pS(v|x,y{<t})
    ]

    where:

    • (V) is the vocabulary;
    • (q_T) is the teacher’s probability distribution at the current position;
    • (p_S) is the student’s probability distribution;
    • (v) is any token in the vocabulary.

    This objective is essentially cross-entropy, and can also be viewed as minimizing the KL divergence between the teacher and student distributions. Unlike ordinary SFT, which only learns the “correct answer tokens,” OPD leverages the teacher’s judgment over the entire vocabulary.

    For example, at a given position, the teacher might assign:

    • Candidate A a probability of 0.60;
    • Candidate B a probability of 0.25;
    • Candidate C a probability of 0.10;
    • All other candidates a combined probability of 0.05.

    Hard-label training usually only tells the student “choose A,” whereas OPD also conveys the teacher’s relative judgments about the other candidates. This soft information provides a finer-grained decision boundary.

    How OPD Differs from Traditional Training Methods

    1. Compared with Supervised Fine-Tuning

    SFT typically uses a fixed dataset and maximizes the probability of the reference answers:

    [
    \mathcal{L}{\text{SFT}}
    =
    -\sum_t \log p_S(y_t|x,y
    {<t})
    ]

    It only cares whether tokens in the reference sequence are correctly predicted; it does not directly express the teacher’s view of other candidate tokens.

    OPD instead uses the student’s current generations as training trajectories and has the teacher provide distributional guidance along those trajectories. This gives OPD two properties:

    1. The training data changes as the student’s capability evolves;
    2. The supervision signal comes not only from discrete labels but also from the teacher’s probability distribution.

    This makes OPD better suited for open-ended generation tasks, especially scenarios where multiple reasonable answers exist.

    2. Compared with Offline Distillation

    Traditional offline distillation first fixes a batch of data, has the teacher generate labels or soft distributions, and then trains the student repeatedly. This is simple to implement, but the data distribution may gradually drift away from the student’s actual behavior.

    If the student frequently makes a certain type of error during real inference and the offline data does not cover those errors, training cannot correct them in a targeted way. By having the student re-sample responses, OPD keeps the training distribution aligned with the current policy, continuously exposing the problems the model most needs to solve at its current stage.

    3. Compared with Reinforcement Learning

    Reinforcement learning adjusts the policy based on a reward function. The model may receive feedback such as “correct” or “incorrect,” but how each intermediate token should be adjusted is often hard to determine.

    OPD directly uses the teacher’s conditional distribution as dense supervision. The teacher effectively provides finer-grained behavioral guidance, so the optimization process does not have to rely entirely on sparse rewards.

    However, OPD is not a simple replacement for reinforcement learning. It depends on the teacher’s capability and coverage—if the teacher has biases in certain domains, the student may inherit them. In practice, systems usually combine rule-based checks, result verifiers, or a small amount of reward signal for quality control.

    Sampled-Token vs. Full-Vocabulary Objectives

    A key implementation choice in OPD is whether to distill only the tokens the student actually sampled, or the teacher’s distribution over the entire vocabulary.

    1. The Sampled-Token Approach

    The sampled-token approach only considers tokens in the student’s generated sequence. If the student generated token (y_t) at a step, the objective mainly constrains:

    [
    -\log pS(y_t|x,y{<t})
    ]

    Its advantages:

    • Lower computation and storage costs;
    • Relatively simple to implement;
    • Well suited to resource-constrained settings or rapid iteration.

    But it has clear limitations: the token the student actually sampled may itself be the wrong choice, and simply raising that token’s probability does not necessarily recover the teacher’s full decision structure.

    2. The Full-Vocabulary Approach

    The full-vocabulary approach uses the teacher’s complete distribution over the vocabulary at each position:

    [
    \mathcal{L}
    =
    -\sumt\sum{v\in V}
    qT(v|x,y{<t})\log pS(v|x,y{<t})
    ]

    The information transferred is more complete, telling the student simultaneously:

    • Which tokens should have higher probability;
    • Which tokens should have lower probability;
    • The relative differences among multiple candidates;
    • The teacher’s uncertainty in the current context.

    The cost is a significant increase in teacher inference, probability storage, communication, and training compute. For very large vocabularies or very long responses, full-vocabulary distillation can produce enormous intermediate data. In practice, you must trade off accuracy, throughput, and storage.

    Why Reverse KL Deserves Attention

    KL divergence is directional. Two common forms are:

    [
    D_{\mathrm{KL}}(P|Q)
    =
    \sum_x P(x)\log\frac{P(x)}{Q(x)}
    ]

    and:

    [
    D_{\mathrm{KL}}(Q|P)
    =
    \sum_x Q(x)\log\frac{Q(x)}{P(x)}
    ]

    In distillation, if the teacher distribution is treated as the target, one typically optimizes the teacher-to-student direction, which makes the student cover the probability mass the teacher considers important. This is closer to cross-entropy training.

    The other direction emphasizes keeping the student’s distribution from straying from its own high-probability regions, which can produce sharper, more concentrated behavior. Different directions lead to different behavioral tendencies:

    • One direction emphasizes coverage, making it easier for the student to learn the multiple reasonable options in the teacher’s distribution;
    • The other emphasizes concentration, allowing the student to converge faster to a few high-probability modes;
    • In multi-modal answers and open-ended generation tasks, the choice of direction affects diversity and stability.

    Reverse KL is therefore not a “magic switch” that alone determines outcomes. It must be co-designed with sampling strategy, temperature, teacher confidence, loss masking, and data filtering. If the teacher distribution is too sharp, the student may collapse prematurely; if it is too flat, the supervision signal lacks discriminative power.

    Multi-Teacher OPD Training

    In real tasks, different domains place different demands on the model. Mathematical reasoning emphasizes process correctness, coding tasks emphasize syntax and executability, tool calling emphasizes format constraints, and instruction following focuses on expression and task completion. A single teacher may struggle to be optimal across all domains.

    The basic multi-teacher OPD workflow is:

    1. Partition data by task type or capability dimension;
    2. Train specialized teachers for different domains;
    3. Use the current student model to generate responses for each domain;
    4. Have the matching domain teacher provide token-level probability guidance;
    5. Combine the losses from different domains with weights;
    6. Absorb multiple capabilities into a single unified student model.

    The overall loss can be expressed as:

    [
    \mathcal{L}
    =
    \sum_{k=1}^{K}
    \alpha_k
    \mathcal{L}_k
    ]

    where (K) is the number of teachers or domains, and (\alpha_k) is the weight of the (k)-th domain.

    The key difficulty in multi-teacher setups is not simply adding more teachers, but resolving capability conflicts. For example:

    • One teacher prefers detailed reasoning while another prefers concise answers;
    • Different teachers impose inconsistent format requirements;
    • Some domains have far more data than others, causing training imbalance;
    • A teacher may excel in its own domain but lack confidence on boundary samples.

    Training can therefore introduce domain sampling quotas, dynamic loss weights, teacher-confidence filtering, and down-weighting of conflicting samples. When multiple teachers cover the same input, weighting can be based on each teacher’s reliability on a validation set, rather than naively averaging probability distributions.

    A Complete OPD Engineering Workflow

    Step 1: Prepare the Teacher Models

    The teacher does not have to be a single large model; it can be multiple models optimized for different domains. During preparation, evaluate:

    • The teacher’s accuracy on target tasks;
    • Whether output formats are stable;
    • Whether there are obvious hallucinations or biases;
    • Whether the probability distribution is overly sharp;
    • Whether inference cost is acceptable.

    Step 2: Online Generation by the Student

    The student generates responses using its current parameters. Sampling should not keep only the best path; choose deterministic decoding or controlled stochastic sampling based on task characteristics.

    For reasoning-heavy tasks, keep multiple candidate trajectories; for format-strict tasks, limit invalid outputs to reduce wasted teacher computation.

    Step 3: Teacher Replay and Distribution Computation

    The teacher reads the same inputs and student-generated sequences and computes logits or probabilities at each position. Input concatenation, positional encoding, end-of-sequence markers, and loss masks must be exactly consistent, otherwise teacher-student token alignment will break.

    Step 4: Compute the Distillation Loss

    You can use full-vocabulary cross-entropy, or adopt Top-K probabilities, sampled-token, or hybrid objectives depending on resources. A common hybrid loss is:

    [
    \mathcal{L}
    =
    \lambda\mathcal{L}{\text{OPD}}
    +
    (1-\lambda)\mathcal{L}
    {\text{SFT}}
    ]

    where the SFT term preserves curated high-quality answers, and the OPD term absorbs the teacher’s behavior.

    Step 5: Quality Filtering and Parameter Updates

    Not all student generations are suitable for training. Filter based on signals such as:

    • Teacher confidence;
    • Rule-based validation results;
    • Whether the task was completed;
    • Whether the output contains illegal formats;
    • The divergence between student and teacher distributions;
    • Whether the response length is anomalous.

    Filtering before gradient updates reduces the pollution of the student model by erroneous trajectories.

    Training Stability and Common Issues

    1. Low Student Generation Quality

    If the student is weak early on, online samples may contain a large amount of invalid content. The teacher can provide guidance, but training wastes substantial compute.

    Solutions include warm-up with high-quality seed data, setting a minimum generation-quality threshold, mixing in reference answers, and gradually increasing the proportion of online data.

    2. Overly Dominant Teacher

    When the teacher distribution is too sharp, the student may quickly copy the teacher’s surface patterns, reducing output diversity. Use temperature calibration, probability truncation, or label smoothing to prevent the training objective from becoming overly concentrated.

    3. Multi-Domain Capability Imbalance

    If one domain has far more samples than others, the student will drift toward that domain. Control this with domain-balanced sampling, loss normalization, or dynamic weights, and evaluate each capability separately on independent validation sets.

    4. Excessive Student-Teacher Distribution Gap

    When the student’s trajectories are far from the teacher’s familiar data distribution, the teacher’s probabilities may be unreliable. Restrict the sampling range, introduce reference trajectories, or increase the SFT proportion early in training and gradually transition to stronger online distillation.

    How to Evaluate Whether OPD Actually Works

    Do not rely on falling training loss alone. A more complete evaluation should include:

    1. Task accuracy: check final results on math, coding, information extraction, and other tasks;
    2. Format compliance: verify the model satisfies structured output and tool-calling constraints;
    3. Generalization: test on new tasks, templates, and domains not used in training;
    4. Stability: observe result variance under different random seeds and sampling temperatures;
    5. Efficiency metrics: compare teacher calls, training steps, GPU memory usage, and total compute cost;
    6. Degradation checks: confirm the model has not become overly verbose, repetitive, mode-collapsed, or degraded in basic capabilities.

    Note in particular that the student may achieve a low distillation loss on the teacher’s distribution without gaining equivalent benefits on real tasks. Possible causes include poor teacher probability calibration, overly homogeneous training data, or a mismatch between the objective function and the final evaluation metrics.

    Implications for Post-Training System Design

    The value of OPD is not just copying one model’s capability into another; more importantly, it changes how post-training systems are organized.

    Traditional approaches often try to build a single unified large-scale reward optimization pipeline, whereas OPD allows you to first obtain clearer optimization results along different capability directions, then consolidate those capabilities into one student model. This facilitates modular training, problem isolation, and resource scheduling.

    From an engineering perspective, OPD also offers a “trade teacher inference for student training efficiency” approach. Teacher computation can be concentrated in offline or batch phases, while the student absorbs capabilities through denser, more stable distributional supervision. This is especially attractive for teams that own multiple specialized models but want to deploy a single unified model.

    Of course, OPD does not eliminate all post-training difficulties. Teacher quality, data distribution, objective conflicts, compute cost, and the evaluation system still determine the final outcome. Sound practice is usually not an absolute either-or choice among SFT, reinforcement learning, and OPD, but a combination based on the training stage:

    • Use SFT to establish a reliable behavioral foundation;
    • Use OPD to absorb fine-grained decisions from specialized teachers;
    • Use verifiers or reward signals to correct final results;
    • Use independent evaluation sets to check generalization and safety.

    Overall, On-Policy Distillation can be viewed as a unified interface for LLM post-training: the student explores its current behavior, the teacher provides finer-grained direction, and verifiers judge whether results are reliable. As multi-domain teachers, online sampling, and probability-level supervision mature, OPD is poised to become a key component of efficient, modular post-training pipelines.