Source-linked AI summary

DistiLLM-2: A Contrastive Approach Boosts the Distillation of LLMs

Jongwoo Ko, Tianyi Chen, Sungnyun Kim, Tianyu Ding, Luming Liang, Ilya Zharkov, Se-Young Yun

arXiv:2503.07067v2cs.CLcs.AIcs.LG

TL;DR

Few studies extend contrastive strategies to LLM distillation, leaving the fit between loss functions and teacher- versus student-generated data underexplored. DistiLLM-2 uses distinct losses for these responses and achieves state-of-the-art performance across text-generation tasks, with applications including preference alignment and vision-language models.

  • Problem

    Few works extend contrastive learning strategies to LLM knowledge distillation, despite their success in other settings.

    Source: §1 · p. 1
  • Method

    DistiLLM-2 applies distinct loss functions to teacher- and student-generated responses, alongside curated data and curriculum-based adaptive loss design.

    Source: §1 · p. 2, §3 · p. 3
  • Results

    DistiLLM-2 achieves state-of-the-art performance across instruction-following, mathematical reasoning, and code-generation tasks, and supports preference alignment and vision-language applications.

    Source: §1 · p. 2
  • Takeaways & Limitations

    Experiments show DistiLLM-2 can enhance quantized LLMs, making them highly competitive with their uncompressed counterparts.

    Source: Impact Statement · p. 10

    Directly applying DPO to knowledge distillation can cause reward hacking and degenerate sentences while excessively reducing student-response likelihood.

    Source: §3.1.1 · p. 3

Abstract

from arXiv · show

Despite the success of distillation in large language models (LLMs), most prior work applies identical loss functions to both teacher- and student-generated data. These strategies overlook the synergy between loss formulations and data types, leading to a suboptimal performance boost in student models. To address this, we propose DistiLLM-2, a contrastive approach that simultaneously increases the likelihood of teacher responses and decreases that of student responses by harnessing this synergy. Our extensive experiments show that DistiLLM-2 not only builds high-performing student models across a wide range of tasks, including instruction-following and code generation, but also supports diverse applications, such as preference alignment and vision-language extensions. These findings highlight the potential of a contrastive approach to enhance the efficacy of LLM distillation by effectively aligning teacher and student models across varied data types.

1. Introduction

DISTILLM-2 introduces a contrastive framework for LLM distillation that pairs different loss functions with teacher- and student-generated responses. It adds dataset-curation and adaptive-loss strategies, and the paper reports broad performance and application scope.

  • Because LLM inference requires extensive computation, compressing models while maintaining performance is important for practical deployment.Source: §1 · p. 1
  • Prior distillation work separately explored loss design and data curation, while often overlooking their synergy; Li et al. (2024b)’s direct DPO adaptation was prone to reward hacking.Student-generated outputs were proposed to address mismatches that can arise when training only on fixed teacher-generated outputs (Agarwal et al., 2024; Lin et al., 2020; Xu et al., 2024b).Source: §1 · p. 1
  • DISTILLM-2 builds on DistiLLM with CALD, a contrastive approach that assigns distinct loss functions to student- and teacher-generated responses to exploit loss–data synergy.The approach is motivated by analysis of forward and reverse KL and SKL during training.Source: §1 · p. 2
  • DISTILLM-2 further introduces optimized dataset-curation strategies and curriculum-based adaptive-loss mechanisms as enhancements to CALD.The paper presents these enhancements as practical guidelines for the contrastive approach.Source: §1 · p. 2
  • DISTILLM-2 achieves state-of-the-art performance for small language models across instruction-following, mathematical reasoning, and code generation, with applications in preference alignment and vision-language models.The paper also describes preference alignment with better reference models.Source: §1 · p. 2

2. Backgrounds

Prior LLM distillation work developed objectives and data-curation strategies to balance student quality and training efficiency. DistiLLM-2 builds on skew divergences and adaptive off-policy distillation with a contrastive objective and epoch-level batch collection of student-generated outputs.

2.1. Related Work

  • Prior work progressed from using student-generated outputs for distillation to on-policy divergences, policy-gradient methods, speculative decoding, and DistiLLM’s skew KL with adaptive off-policy training.DistiLLM is described as achieving state-of-the-art performance and greater efficiency.Source: §2.1 · p. 2

2.2. Preliminary: KD in LLMs and DistiLLM

  • KL is the conventional tractable KD loss, but forward and reverse KL can cause mode-averaging and mode-collapse, respectively; skew KL improved convergence speed and performance over recent baselines.The cited baselines are MiniLLM and GKD.Source: §2.2 · p. 2
  • Adaptive off-policy distillation reuses student-generated outputs through a replay buffer, balancing efficiency and efficacy while addressing costly, low-quality on-policy data.The approach was also used in subsequent LLM preference-alignment work.Source: §2.2 · p. 2
  • Batch collection of student-generated outputs before each epoch reduces sample-gathering cost with minimal impact on student performance while remaining compatible with vLLM.This preserves the adaptive off-policy approach’s core philosophy while increasing generation efficiency.Source: §2.2 · pp. 2–3

3. Method: DISTILLM-2

DISTILLM-2 combines teacher-response SKL with student-response SRKL in a contrastive loss, then curates response types and adapts its loss weights to preserve the complementary effects of both terms. The method addresses DPKD’s excessive suppression of student responses while using teacher guidance and curriculum-based updates to improve distillation.

3.1.1. MOTIVATION

  • DPKD (Li et al., 2024b) can reward hack by excessively suppressing student responses, yielding student-response NLL 91.25 rather than fitting teacher responses at NLL 20.29.The paper attributes this failure to substituting the teacher for DPO’s reference model when the teacher probability of student responses is inherently small.Source: §3.1.1 · p. 3

3.1.2. CONTRASTIVE APPROACH FOR LLM DISTILLATION

  • CALD’s SKL-on-teacher and SRKL-on-student design converges faster and performs better than using either loss alone, with higher efficacy than using KL or RKL as its backbone.The method assigns SKL to teacher responses, where teacher probability is high, and SRKL to student responses, where it is generally low.Source: Figure 1 · p. 4, §3.1.2 · p. 4

3.2. Optimal Data Curation for Contrastive Approach

  • Teacher generations are preferred for SKL, while student generations are preferred for SRKL: speculative-response performance peaks at ε = 1.0 and ε = 0.0, respectively.Even stronger LLMs’ higher-quality responses did not outperform the teacher’s for SKL; speculative responses can weaken CALD’s complementary effects, while student responses help reduce training-inference mismatch.Source: §3.2 · pp. 5–6

3.3. Curriculum-based Adaptive Learning

  • Curriculum-based α adapts to sample difficulty, while a gradually increasing SRKL coefficient β significantly improves student performance.Larger α favors stability and convergence, whereas smaller α permits more knowledge acquisition; optimal α also varies by setup and training epoch. Gradually increasing β shifts emphasis toward feedback from student responses, reducing training-inference mismatch when teacher imitation is difficult.Source: §3.3 · pp. 6–7, Table 5 · p. 7

4. Experiments

Across general instruction-following, mathematical reasoning, and code generation, DISTILLM-2 outperforms competing distillation baselines in most reported evaluations. Its advantage is strongest in general instruction-following, while the math experiments also report a Qwen2.5 student surpassing its teacher on MATH.

4.1. General Instruction-Following

  • General instruction-following training uses 50k UltraChat200k prompts with teacher- and student-generated responses, evaluated on AlpacaEval, Evol-Instruct, and UltraFeedback.Evaluation uses GPT-4o or GPT-4o-mini as LLM-as-a-Judge; teachers are Qwen2-7B, Mistral-7B, and Gemma-2-9B, paired respectively with Qwen2-1.5B, Danube2-1.8B, and Gemma-2-2B students.Source: §4.1 · p. 7
  • DISTILLM-2 performs best in most instruction-following setups, except Danube2-1.8B on Evol-Instruct, and beats second-best methods on average for all three students.The average margins are +2.34% for Qwen2-1.5B, +1.95% for Danube2-1.8B, and +4.53% for Gemma2-2B.Source: §4.1 · p. 7

4.2. Mathematical Reasoning

  • The math experiments pair Qwen2-Math-7B-Inst and Qwen2.5-Math-7B-Inst teachers with their respective 1.5B students and use MetaMathQA training data.The passage specifies 50k randomly selected MetaMathQA samples and supervised fine-tuning for one epoch on the entire dataset.Source: §4.2 · p. 7
  • DISTILLM-2 outperforms recent baselines on GSM8K and MATH in both Qwen2 and Qwen2.5 setups, and the Qwen2.5 student surpasses the Qwen2 teacher on MATH.The passage describes the Qwen2.5 student's average performance as competitive and the MATH result as a challenging milestone.Source: §4.2 · p. 7

4.3. Code Generation

  • Code-generation experiments use WizardCoder prompts, Qwen2.5-Coder-7B-Inst and DeepSeek-Coder-6.7B-Inst teachers, and their respective 1.5B and 1.3B students.Students are trained for two epochs and evaluated on HumanEval and MBPP.Source: §4.3 · pp. 7–8
  • DISTILLM-2 consistently outperforms GKD and DistiLLM on HumanEval and MBPP; GKD scores higher than DistiLLM but remains below DISTILLM-2.The reported outcome is attributed to integrating SKL or SRKL with harmonized response types.Source: Table 4 · p. 7, §4.3 · p. 8

5. Additional Ablation Study

The additional ablations show incremental gains as DistiLLM-2’s components are added, consistent baseline-leading performance across training sizes and tasks, and monotonic improvement with larger teachers.

Component Analysis

  • Adding the contrastive approach, increasing β, and using curriculum-based α updates yields incremental gains that bring DistiLLM’s performance in line with DistiLLM-2.Source: §5 · p. 8

Training Size

  • Across instruction-following, math reasoning, and code generation, DistiLLM-2 consistently outperforms GKD and DistiLLM across varying training data sizes.Source: §5 · p. 8

Capacity Gap

  • With Qwen1.5-0.5B as student, DistiLLM-2 improves monotonically and outperforms baselines as Qwen-1.5-Chat teacher size rises from 1.8B to 7B and 14B.The previous version struggled with capacity gaps, particularly with 7B and 14B teachers.Source: §5 · p. 8, Table 8 · p. 8

6. Broader Impacts

DistiLLM-2 is presented across preference alignment, vision-language distillation, quantized-model recovery, and speculative decoding as a versatile approach with applications beyond standard LLM distillation.

6.1. Additional Results for DISTILLM-2 + DPO

  • Replacing SFT with distillation before DPO improved overall preference-alignment performance: DISTILLM-2 more than doubled WR for Qwen2-1.5B and showed a similar improvement for Gemma2-2B.The study evaluated the policy LLMs after DPO fine-tuning.Source: §6.1 · pp. 8–9

6.2. Expansion to Vision-Language Models

  • On VLMs, DISTILLM-2 outperformed GKD and DistiLLM by +2.01% and +4.61% on average, respectively, using LLaVA-1.5-7B as teacher and TinyLLaVA-1.4B as student.The evaluation used 83K RLAIF-V-Dataset prompts and the OK-VQA and TextVQA benchmarks.Source: §6.2 · p. 9

6.3. Restoring the Performance of Quantized LLMs

  • DISTILLM-2 achieved the best average performance among KD baselines when restoring 4-bit quantized LLMs with LoRA, while adding only a few trainable parameters.The approach replaces regular SFT with KD and can be applied to original and compressed model pairs for efficient mobile deployment.Source: §6.3 · p. 9

6.4. Inference Speedup of Speculative Decoding

  • DISTILLM-2 draft models achieved greater speculative-decoding speedup than SFT- and DistiLLM-trained drafters for both Phi3.5-mini and Phi3-medium verifiers, indicating stronger token-level distribution alignment than other baselines, including Zhou et al. (2024b).The evaluation used Phi3.5-mini and Phi3-medium as verifiers and Llama-68m as the drafter.Source: Table 10 · p. 9, §6.4 · p. 9

7. Conclusion

DISTILLM-2 combines contrastive loss, curated data, and curriculum-based learning to improve LLM distillation. Experiments report state-of-the-art performance, improved sample efficiency, and stronger reasoning and robustness across language and vision-language models.

7. Conclusion

  • DISTILLM-2 achieves state-of-the-art performance with improved sample efficiency, reducing reliance on expensive preference-labeled data.The reported experiments span instruction following, mathematical reasoning, and code generation.Source: §7 · p. 9
  • The framework combines contrastive loss, curated data, and curriculum-based learning, differentiating teacher and student outputs to strengthen alignment and generalization.Source: §7 · p. 9
  • High-quality explanations and contrastive objectives further enhance reasoning ability and robustness in language and vision-language models.Source: §7 · p. 9

Impact Statement

The impact statement describes DistiLLM-2 as useful beyond standard LLM distillation, spanning preference alignment, multimodal models, compressed models, and speculative decoding.

High-performed reference model for RLHF

  • DistiLLM-2 can replace vanilla SFT before PPO with a reward model or DPO using chosen/rejected pairs; Table 6 tests DPO, while broader preference-method use is proposed.The authors also suggest applicability to IPO and SimPO.Source: Impact Statement · p. 10

Extension to multi-modal LLMs

Recovering the compressed LLMs

  • DistiLLM-2 substantially improves quantized LLM performance, making these models highly competitive with their uncompressed counterparts; the authors suggest broader use with compression techniques.Source: Impact Statement · p. 10

Enhancing Inference speed of LLMs

  • The authors propose exploring integration of DeepSeek-R1’s reasoning ability (Guo et al., 2025) with DistiLLM-2 to improve results for sLMs.They encourage future work on broader implications across diverse domains.Source: Impact Statement · p. 10

Supplementary Material · A. Additional Related Works

The related-work section situates LLM distillation among logit-based KD methods and contrasts it with offline preference-learning approaches, while identifying data perspective as a distinction of this work.

A. Additional Related Works

B. Derivation for Mathematical Analysis … C.2. Training Details

The appendices explain how KL and RKL variants shape student probabilities, derive the contrastive objective and its approximation, and document the datasets and training setup used in the experiments.

B.1. Mathematical Explanation on Behavior of KL and RKL

  • KL and SKL pull student probability upward where teacher probability is high, while RKL and SRKL push it downward where teacher probability is near zero.The explanation uses their f-divergence generators and is stated to apply to a more general setup than Wu et al. (2025), whose explanation is limited to unimodal Gaussians.Source: §B.1 · p. 15

B.2. Derivation for Remark 1

  • Equation 5 can be rewritten as Equation 6, which behaves similarly to the contrastive approach in DPO (Rafailov et al., 2023).The derivation uses the definitions of SKL and SRKL and linearity of expectation for independent teacher and student outputs.Source: §B.2 · p. 16

B.3. First-order Approximation for Mercator Series

  • The first-order Mercator approximation expresses S(R)KL as a closed-form function of α and teacher and student probabilities, enabling per-sample α selection.Because approximation error is a concern when either probability is much smaller than the other, the implementation allocates α by mini-batch and clips it between 0.01 and 0.1.Source: §B.3 · p. 16

C. Detailed Experimental Setup

  • DISTILLM-2 and baselines GKD and SKD are implemented using the trl framework.The appendix introduces separate dataset, training, and evaluation setup descriptions.Source: C. Detailed Experimental Setup · p. 16

C.1. Dataset Description

  • The experiments cover instruction-following, mathematical reasoning, and code generation, including UltraChat200k, MetaMathQA, GSM8K, and WizardCoder.The datasets include filtered dialogue, bootstrapped math problems, grade-school multi-step problems, and evolved code instructions.Source: §C.1 · p. 17
  • Visual-language evaluation and preference data include RLAIF-V-Dataset, OK-VQA, and TextVQA.RLAIF-V-Dataset contains multimodal preference pairs, OK-VQA requires external knowledge, and TextVQA tests reasoning over text in images.Source: §C.1 · p. 18

C.2. Training Details

  • Training uses LoRA, the largest batch size that fits on four NVIDIA A100 80GB GPUs, and an effective batch size of 128.Students are first trained on ground-truth responses with SFT and then undergo KD; experiments omit pretraining-corpus language-modeling loss.Source: §C.2 · p. 18, Table 11 · p. 18

C.3. Evaluation · D. Additional Experimental Results

The evaluation uses different sampling and comparison protocols for instruction-following versus mathematical reasoning and code generation. Instruction-following includes pairwise judge comparisons against specified baselines, with response order switched to mitigate position bias.

C.3. Evaluation

  • Instruction-following responses were sampled on one NVIDIA A100 80GB GPU at temperature 0.8, top-p 0.95, and a 512-token maximum.The LLM-as-a-Judge comparison used temperature 0.7 and a pairwise prompt shown in Figure 4.Source: §C.3 · p. 18, Figure 4 · p. 19
  • For AlpacaEval, responses were compared with released text-davinci-003 responses; Evol-Instruct and UltraFeedback used internally produced gpt-3.5-turbo responses.Source: §C.3 · p. 18
  • Instruction-following pairwise comparison results were averaged across both response orders to avoid position bias.Source: §C.3 · p. 18
  • Mathematical reasoning and code-generation responses were sampled greedily on one NVIDIA A100 80GB GPU with a 1,024-token maximum.Code generation was evaluated using the EvalPlus framework.Source: §C.3 · p. 18

D.1. Comparison on On-policy Setup · D.2. LLM distillation with Inst models

The appendix reports that batched on-policy distillation avoids severe performance degradation despite its efficiency, while DISTILLM-2 performs strongly with instruction-tuned students, including on UltraFeedback.

D.1. Comparison on On-policy Setup

  • The on-policy comparison includes ImitKD (Lin et al., 2020), MiniLLM, GKD, and adaptive on-policy DistiLLM and DISTILLM-2.It follows Ko et al. (2024)’s setup, training GPT-2 on databricks-dolly-15k.Source: §D.1 · p. 19
  • On databricks-dolly-15k test-set ROUGE-L, the “batched” on-policy setup avoids severe performance degradation despite its significant efficiency.The paper says this shares the takeaway of Ko et al. (2024)’s adaptive off-policy approach.Source: §D.1 · p. 19, Table 12 · p. 19
  • DPKD (Li et al., 2024b) performs much worse than its reported values, which the authors attribute to reward hacking.They therefore exclude DPKD from the main baselines.Source: §D.1 · p. 19
  • Except in the on-policy setup, DPO performs worse than DISTILLM-2 but better than DPKD.Source: §D.1 · p. 19

D.2. LLM distillation with Inst models

  • The instruction-tuned comparison uses Gemma-2-2B-it as student and Gemma-2-9B-SimPO as teacher, training the student for one epoch of 200 iterations.The other experimental settings match those used for the base model.Source: §D.2 · p. 19
  • Inst-model students outperform base models (+SFT), and DISTILLM-2 performs best among the student models on UltraFeedback, even exceeding its teacher.The results support the effectiveness of distillation with recent state-of-the-art models.Source: §D.2 · p. 19, Table 13 · p. 19
  • The authors attribute DISTILLM-2’s strong instruction-tuned results to the contrastive approach’s fast convergence, even with limited training iterations.Source: §D.2 · p. 19
Loading 2503.07067v2…