TL;DR
On-policy distillation (OPD) for large language models frequently stumbles when a student model makes an early mistake, leading to confused teacher feedback and fragmented gradients. This paper introduces Trajectory-Refined Distillation (TRD), a method that prompts the teacher to correct and refine the student's entire reasoning path before distillation occurs. TRD effectively eliminates this "prefix failure," significantly boosting math and coding performance across multiple model scales with remarkable compute efficiency.
What Problem Does This Paper Address?
When fine-tuning Large Language Models (LLMs) for complex reasoning tasks like math or coding, researchers often use On-Policy Distillation (OPD). In OPD, the student model generates its own reasoning path (a rollout), and a stronger teacher model evaluates it token-by-token to provide dense feedback.
However, the authors identify a fundamental flaw in this setup called prefix failure. If the student model makes a logical or computational error early in its rollout, the frozen prefix becomes a dead end. When the teacher model evaluates this broken path, it gets caught in a dilemma: it tries to output tokens that maintain sequence consistency with the student's flawed logic while simultaneously trying to steer the trajectory back toward the correct answer. This creates a confused, bimodal teacher distribution and "fragmented gradients" that destabilize training. Existing remedies try to patch this at the token level (by clipping or reweighting high-loss tokens), but they leave the fundamentally broken reasoning path completely intact.
Methods
The authors propose Trajectory-Refined Distillation (TRD) to fix prefix failure at its source. Instead of calculating distillation losses directly on the student's raw, potentially flawed rollout ($y_o$), TRD introduces an upstream trajectory-level refinement step.
The teacher model is prompted to take the student's raw rollout and rewrite it into an improved, corrected trajectory ($y_r$). Crucially, because the teacher builds upon the student's actual attempt, the refined path stays within the student's "distribution support"—meaning it aligns with the student's natural reasoning style—while fixing the bugs.
Once the refined trajectory $y_r$ is generated, standard forward KL divergence distillation is performed on it. TRD also naturally extends to On-Policy Self-Distillation (OPSD), where the student acts as its own teacher by utilizing privileged information (like the ground-truth answer) exclusively during the refinement step.
Datasets
- Training: The models were trained on the DeepScaleR math corpus (~40K problems with solutions) and TACO (~25K algorithmic code-generation problems with reference solutions and test cases).
- Evaluation: Math performance was measured across five competition-level benchmarks: AIME24, AIME25, HMMT25, BeyondAIME, and AMOBench. Code generation was evaluated using HumanEval+, MBPP+, and LiveCodeBench v6.
Key Insights and Ideas
- Trajectory-Level Over Token-Level: Token-level interventions (like loss clipping or top-K truncation) are merely band-aids. If the underlying prefix is broken, the model cannot learn a clean, multi-step recovery path. True recovery requires a structural, trajectory-level intervention.
- Exploration Boost for Correct Paths: TRD isn't just for fixing mistakes. When the student's initial rollout is already correct, the teacher's refinement step often introduces alternative, shorter, or more elegant derivations. This expands the student's exposure to diverse, valid reasoning paths.
- Beating Rejection Sampling: While rejection sampling (Best-of-N) can filter out bad rollouts, it wastes massive compute on hard problems where the student fails every single attempt. TRD salvages these failed attempts by using the teacher's guidance to rewrite them into useful training data.
Key Results
TRD consistently achieved the highest math and code macro-averages across multiple Qwen3 model scales (1.7B, 4B, and 8B).
- AMOBench Breakthrough: Under the OPSD setup on Qwen3-8B, TRD successfully solved 9 out of 23 highly difficult AMOBench questions that the base model completely failed to solve in 16 attempts, nearly doubling the performance of the strongest dense-KL baseline.
- Compute Efficiency: Compared to a Best-of-8 rejection sampling baseline on the full training corpus, TRD achieved superior downstream accuracy while requiring 7.8× less total wall-clock compute time. This efficiency is largely because the teacher-refined trajectories are significantly shorter and faster to train on.
Limitations and Future Work
- Extra Sampling Overhead: TRD requires one additional sampling pass per problem to construct the refined trajectory ($y_r$). Although this overhead is heavily mitigated by faster training times on shorter sequences, it remains an extra step during data preparation.
- Teacher Dependency: The success of TRD relies on the teacher's capability to effectively refine a trajectory without drifting too far from the student's natural distribution. If the teacher is too weak, the refinement quality degrades. Exploring how to optimize this teacher-guided alignment with even larger or more specialized models is a promising direction for future work.
Summary updated