On-Policy Context Distillation for Language Models

Tianzhu Ye, Li Dong, Xun Wu, Shaohan Huang, Furu WeiarXiv 2026

TL;DR

Large language models can adapt dynamically using long contexts or optimized system prompts, but processing these prompts at runtime introduces significant computational overhead and latency. This paper introduces On-Policy Context Distillation (OPCD), a method that permanently bakes transient contextual knowledge directly into a model's weights. By training the model on its own generated outputs while aligning it to a context-aware teacher via reverse KL divergence, OPCD boosts task accuracy, prevents hallucinations, and mitigates the catastrophic forgetting typical of standard distillation methods.

What Problem Does This Paper Address?

In-context learning (ICL) allows large language models (LLMs) to alter their behavior on the fly based on instructions, few-shot examples, or retrieved documents. However, this knowledge is transient—once the context window resets, the model forgets everything, requiring costly re-computation of long prompts during subsequent sessions.

"Context distillation" attempts to solve this by training a context-free "student" model to mimic a context-conditioned "teacher." However, traditional methods rely on off-policy training with forward KL divergence on a fixed dataset. This introduces two major flaws:

  1. Exposure Bias: The student is trained on teacher-generated text but struggles when generating its own sequences autoregressively at inference time.
  2. Mode-Covering Behavior: Forward KL forces the student to try and cover the teacher's entire probability distribution. When the student lacks the capacity to match a complex teacher, this results in blurred distributions and hallucinations.

Methods

The authors propose On-Policy Context Distillation (OPCD) to bridge the gap between on-policy distillation and context internalization. Instead of mimicking a static dataset, the student model generates its own response trajectories without the context. The teacher model then evaluates these exact student-generated trajectories with the context prepended.

Figure 1: Overview of on-policy context distillation (OPCD). Given a context and an input prompt, the student model generates a response without the context. It is then trained to minimize the reverse KL divergence to the teacher model that conditions on the context. The student internalizes the contextual information with on-policy learning.

The core algorithmic shift is minimizing the reverse Kullback-Leibler (KL) divergence at the token level. Reverse KL encourages mode-seeking behavior: the student focuses purely on high-probability tokens according to the teacher, effectively suppressing unlikely tokens and minimizing hallucinations. To keep computation tractable, the analytic KL is approximated by summing over only the top-$k$ tokens predicted by the student model.

OPCD supports two main configurations:

  • Teacher-Student Distillation: A larger or more capable frozen model acts as the context-aware teacher, helping a smaller student internalize both the context and superior capabilities.
  • Self-Distillation: The student and teacher share the same weights and are updated simultaneously, where the teacher simply sees the context and the student does not.

Datasets

The authors evaluate OPCD across two primary applications:

  1. Experiential Knowledge Distillation (extracting transferable insights from historical solution traces without ground-truth labels):
  2. DAPO-Math-17K: Approximately 14K English math problems with verifiable numerical answers.
  3. TextArena (Frozen Lake & Sokoban): Text-based game environments requiring multi-turn spatial reasoning and navigation.
  4. System Prompt Distillation (internalizing optimized system prompts to eliminate deployment overhead):
  5. MetaSPO: Optimized system prompts for specialized domains.
  6. MedMCQA: A large-scale medical question-answering dataset (500 test samples used).
  7. Safety Datasets: A combination of Tweet Eval, Hatecheck, and Ethos to evaluate safety classification and reasoning (500 test samples used).

For out-of-distribution (OOD) evaluation, the authors use IF-Eval (Instruction Following Evaluation) to measure whether distilled models retain general capabilities or suffer from catastrophic forgetting.

Key Insights and Ideas

  • On-Policy Alignment is Crucial for Cross-Size Distillation: Simply pasting a large model's extracted insights into a smaller model's context window can actually degrade performance. Smaller models often lack the capacity to process complex experiential data properly at runtime. OPCD bypasses this by directly baking that knowledge into the smaller model's weights via on-policy alignment.
  • Reverse KL Acts as a Hallucination Filter: By forcing the student to focus on the teacher's high-confidence modes rather than averaging across the entire token distribution, the student learns to correct its own mistakes without picking up the noisy tail of the distribution.
  • Teacher-Student Beats Self-Distillation in Stability: While self-distillation sounds elegant, using a continuously updating model as its own teacher introduces high variance and training instability. A frozen or periodically updated teacher provides a much steadier learning signal.

Key Results

  • Higher Accuracy: Across math and text games, OPCD consistently beat both the base models and traditional off-policy context distillation. For instance, on Sokoban, OPCD achieved 53.9% accuracy compared to 51.6% for standard context distillation.
  • Mitigating Forgetting: Standard context distillation often causes models to forget general capabilities when fine-tuning on specific prompts. OPCD effectively mitigates this, maintaining high OOD performance on IF-Eval and medical tasks even when distilled on safety prompts.
Figure 3: Comparison of OPCD and off-policy context distillation on in-distribution (safety) and out-of-distribution (medical) tasks when distilling from safety system prompt. Left: accuracy on the safety test dataset. Right: accuracy on the medical test dataset. OPCD achieves superior in- distribution performance while mitigating forgetting on OOD tasks.
  • Effective Scaling: As student parameters scale from 1.7B to 8B, OPCD consistently improves test accuracy using knowledge distilled from an 8B teacher.
Scaling behavior of OPCD across model sizes

Limitations and Future Work

  • Self-Distillation Instability: The authors note that self-distillation can diverge due to high variance during reinforcement learning style updates, suggesting that techniques like Exponential Moving Averages (EMA) of student parameters are needed to stabilize it.
  • Scope of Evaluation: The method was primarily tested on math, text games, and specific classification prompts. Future work is required to scale OPCD to broader, open-ended conversational domains.
  • Continual Accumulation: The paper opens up exciting avenues for how models might continually accumulate and periodically consolidate experiential knowledge over long deployment lifetimes, though the exact scheduling and selection strategies remain an open question.

Summary updated

BibTeX
@misc{ye2026policy,
  author = {Tianzhu Ye and Li Dong and Xun Wu and Shaohan Huang and Furu Wei},
  title = {{On-Policy Context Distillation for Language Models}},
  year = {2026},
  eprint = {2602.12275},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.12275},
}
Figure