Deep Dive into On-Policy Distillation: Algorithm and Engineering Practices
As large language models scale in parameters and inference depth, post-training paradigms are rapidly evolving. Traditional monolithic reinforcement learning faces challenges like reward design difficulties, training instability, and massive compute costs. On-Policy Distillation (OPD) has emerged as a core component in the post-training phase. This article explores the OPD algorithm, its position between supervised fine-tuning (SFT) and reinforcement learning (RL), the evolution from classic distillation methods, token sampling strategies, and critical engineering practices for optimizing compute and memory.
In recent years, with the continuous rise in the parameter scale and inference depth of large language models, the post-training paradigm is undergoing profound changes. Traditional “one-time large-scale mixed reinforcement learning” often encounters bottlenecks when fusing multi-domain capabilities, such as reward design difficulties, training instability, and huge compute overhead. Frontier industry technical reports indicate that a scheme known as On-Policy Distillation (OPD) is transitioning from a marginal algorithmic trick to a core component in the post-training phase. This article provides a comprehensive analysis of OPD from dimensions including algorithm essence, implementation paths, and engineering challenges.
1. OPD Algorithm Positioning: An Intermediate State Between SFT and RL
To understand OPD, we must first clarify its boundaries with traditional Supervised Fine-Tuning (SFT) and Reinforcement Learning (RL). SFT uses a fixed, pre-prepared high-quality dataset for cross-entropy training, where the model passively accepts the “standard answers” and lacks the ability to correct its own error distribution. RL (such as the classic GRPO algorithm) drives model exploration through reward signals. Although it can unlock model potential, it is highly prone to capability forgetting or reward hacking during multi-domain mixed training.
OPD sits between the two. During training, the student model generates responses based on its current policy distribution, and the teacher model then evaluates the probability of the same responses. The student model is updated by minimizing the difference between the two distributions. In terms of the loss function, OPD typically uses reverse KL divergence as the optimization objective:
$ L = D{KL}(p{student}(\cdot|x) || p_{teacher}(\cdot|x)) $
Compared to forward KL divergence, which pursues full coverage and makes the student model prone to hallucinations, reverse KL divergence tends to concentrate the student model on the high-probability distribution areas of the teacher model. This effectively suppresses low-quality outputs while maintaining generation diversity. Therefore, OPD combines the stability and supervised signals of SFT with the advantage of learning on the model’s own distribution found in RL.
2. Evolution and Differences Between OPD and Classic Distillation Methods
As early as 2023, the industry proposed online distillation methods like GKD and MiniLLM. Modern OPD inherits the core ideas of these methods but has undergone deep evolution in multi-domain capability fusion and training stability.
Classic methods often distill on a single task or general corpus, whereas modern OPD is applied to the complex merging of multi-expert model capabilities. Specific engineering practices usually follow two steps: First, expert models are trained independently in various domains such as mathematics, code, agents, and instruction following using SFT plus RL. Second, a multi-teacher OPD mechanism is used to distill the capabilities of these dozens of expert models back into a unified student model. This “divide and conquer” philosophy avoids multi-domain reward conflicts, allowing the student model to accurately absorb the strengths of domain experts along its own generated trajectories.
3. Token Sampling Strategies: Why Full-Vocabulary?
When implementing OPD, how to compute the distribution difference between the teacher and student models is the most core divergence point in engineering implementation. Currently, there are three main approaches: Sampled-Token, Top-k, and Full-Vocabulary.
1. Sampled-Token
This method only computes the log probability of the tokens actually generated by the student model within the teacher model.
# Sampled-Token pseudo-codesampled_tokens = student_model.generate(input_ids)student_logits = student_model.forward(input_ids, sampled_tokens)teacher_logits = teacher_model.forward(input_ids, sampled_tokens)loss = compute_reverse_kl(student_logits, teacher_logits)
Pros: Extremely low memory overhead, as it only needs to store and compute Logits at sampled positions.
Cons: The gradient estimation has a large bias because it ignores the information of a large number of other tokens in the vocabulary. It is difficult for the student model to correct its preference for unsampled low-probability tokens.
2. Top-k
To balance bias and overhead, the Top-k strategy only computes the distribution of the top k highest-probability tokens. Compared to Sampled-Token, this provides richer negative sample information, but it still loses some valuable distribution details when facing long-tail distributions.
3. Full-Vocabulary
Frontier large models tend to choose the most expensive Full-Vocabulary strategy during post-training. This means that at each generation position in the sequence, the complete probability distribution of the entire vocabulary (usually over 150,000 tokens) in both the teacher and student models must be computed, and the reverse KL divergence calculated.
Why choose the most expensive Full-Vocab?
The core reason lies in the accuracy of gradient signals and training robustness. During multi-expert capability distillation, the student model needs to precisely learn what “not to say” in specific contexts. Full-Vocab provides the most complete negative gradient feedback, forcing the student model to align with the expert distribution in the global probability space. Despite the massive compute consumption, the resulting training stability and capability fidelity make this method the go-to choice for mainstream players.
4. Engineering Trade-offs for Compute and Memory Overhead
Choosing Full-Vocabulary OPD brings the direct challenge of memory explosion. Assuming a model vocabulary size of 150,000, a sequence length of 4,000, and a batch size of 8, under Float32 precision, merely saving the Logits tensor generated by one forward pass consumes about 8 × 4000 × 150000 × 4 bytes ≈ 19GB of memory. If computing forward passes for both the teacher and student models simultaneously, one must also consider the storage of intermediate states like activations and gradients, which a single GPU simply cannot handle.
For such massive tensor computations, developers typically need to rely on high-performance GPU computing clusters and AI development platforms, such as Baidu AI Cloud. In engineering practices, developers can alleviate these bottlenecks through the following methods:
- Tensor Parallelism: Split the massive Logits matrix along the vocabulary dimension across multiple GPUs. Each GPU computes the local Softmax and KL divergence, which are then aggregated using efficient cross-GPU communication primitives (like All-Reduce).
- Mixed Precision Training: Convert intermediate states to BF16 or FP8 formats, halving or even quartering the memory footprint without sacrificing numerical stability.
- Recomputation: During the forward pass, do not save certain massive intermediate tensors; instead, recompute them during the backward pass, trading time for space.
5. Conclusion
On-Policy Distillation is no longer a simple model compression trick, but a key mainstay for reconstructing model capability systems in the post-training era. By learning on its own distribution combined with the full-vocabulary reverse KL divergence constraint, OPD provides a path that balances training stability with capability diversity. For developers, a deep understanding of OPD’s sampling strategies and memory optimization schemes not only helps grasp the evolution of large models but also provides a theoretical basis for building cost-effective AI infrastructure. As distributed compute scheduling continues to optimize, the engineering threshold for Full-Vocab OPD is expected to lower further, becoming a standard for more application scenarios.
