Knowledge Distillation of Black-Box Large Language Models黑盒大型语言模型的知识蒸馏
Abstract摘要
Given the exceptional performance of proprietary large language models (LLMs) like GPT-4, recent research has increasingly focused on boosting the capabilities of smaller models through knowledge distillation (KD) from these powerful yet black-box teachers. While leveraging the high-quality outputs of these teachers is advantageous, the inaccessibility of their internal states often limits effective knowledge transfer. To overcome this limitation, we introduce Proxy-KD, a novel method that uses a proxy model to facilitate the efficient transfer of knowledge from black-box LLMs to smaller models. Our experiments show that Proxy-KD not only enhances the performance of KD from black-box teacher models but also surpasses traditional white-box KD techniques. This approach presents a compelling new avenue for distilling knowledge from advanced LLMs.鉴于GPT-4等专有大型语言模型(LLM)的卓越性能,近期研究越来越关注通过知识蒸馏(KD)从这些强大但黑盒的教师中提升较小模型的能力。虽然利用这些教师的高质量输出是有利的,但无法访问其内部状态通常限制了有效的知识迁移。为克服这一限制,我们引入了Proxy-KD,一种新颖的方法,使用代理模型促进从黑盒LLM到较小模型的高效知识迁移。我们的实验表明,Proxy-KD不仅增强了从黑盒教师模型进行KD的性能,而且超越了传统的白盒KD技术。该方法为从先进LLM中蒸馏知识提供了一条令人信服的新途径。
Knowledge Distillation of Black-Box Large Language Models
Hongzhan Chen1, Runjun Chen 1, Yuqi Yi 1, Xiaojun Quan1††thanks: Corresponding author., Chenliang Li2, Ming Yan2 and Ji Zhang2 1School of Computer Science and Engineering, Sun Yat-sen University, China 2Alibaba Group, China 1chenhzh59@mail2.sysu.edu.cn, quanxj3@mail.sysu.edu.cn 2ym119608@alibaba-inc.com Hongzhan Chen1, Runjun Chen 1, Yuqi Yi 1, Xiaojun Quan1††通讯作者。, Chenliang Li2, Ming Yan2 and Ji Zhang2 1中山大学计算机科学与工程学院,中国 2阿里巴巴集团,中国 1chenhzh59@mail2.sysu.edu.cn, quanxj3@mail.sysu.edu.cn 2ym119608@alibaba-inc.com
1 Introduction1 引言
Recently, proprietary large language models (LLMs) like GPT-3.5 (OpenAI, 2022) and GPT-4 (OpenAI, 2023) have demonstrated significant superiority over open-source counterparts such as the Llama series (Touvron et al., 2023a, b; MetaAI, 2024). However, their vast number of parameters leads to high inference costs, and they are only accessible via API calls, offering limited customization and transparency. To address these challenges, recent efforts like Alpaca (Taori et al., 2023), Vicuna (Chiang et al., 2023), and Orca (Mukherjee et al., 2023) have focused on transferring the capabilities of proprietary LLMs to smaller open-source models through knowledge distillation (Chen et al., 2023; Hsieh et al., 2023; Ho et al., 2022).近年来,像GPT-3.5(OpenAI, 2022)和GPT-4(OpenAI, 2023)这样的专有大型语言模型(LLM)已表现出显著优于Llama系列(Touvron et al., 2023a, b; MetaAI, 2024)等开源模型的性能。然而,它们庞大的参数量导致推理成本高昂,且只能通过API调用访问,定制化和透明度有限。为了应对这些挑战,近来如Alpaca(Taori et al., 2023)、Vicuna(Chiang et al., 2023)和Orca(Mukherjee et al., 2023)等工作专注于通过知识蒸馏(Chen et al., 2023; Hsieh et al., 2023; Ho et al., 2022)将专有LLM的能力迁移到较小的开源模型上。

Knowledge distillation (KD) (Hinton et al., 2015) is a technique used to enhance the performance of a smaller student model by learning from a larger, more sophisticated teacher model. Depending on the level of access to the teacher model’s internals, KD methods can be categorized into two types: KD with black-box teachers and KD with white-box teachers. As illustrated in Figure 1, white-box KD allows the student model to distill more intrinsic knowledge from the teacher by mimicing the teacher model’s output distribution (Gu et al., 2023; Wen et al., 2023), hidden states (Jiao et al., 2020; Sun et al., 2019), and attention scores (Wang et al., 2021). Therefore, this method can only be applied when the teacher model’s parameters are accessible. On the other hand, black-box KD leverages the high-quality outputs from powerful proprietary LLMs to fine-tune the student model (Hsieh et al., 2023; Fu et al., 2023). Both white-box and black-box KD have their respective drawbacks. While white-box KD is hindered by the limited capacity of the teacher model, which often restricts the distillation performance of the student, black-box KD faces challenges with knowledge transfer due to the inaccessibility of the teacher model’s output distribution and internal states.知识蒸馏(KD)(Hinton et al., 2015)是一种通过学习更大、更复杂的教师模型来增强较小学生模型性能的技术。根据对教师模型内部访问程度的不同,KD方法可分为两类:黑盒教师KD和白盒教师KD。如图1所示,白盒KD通过模仿教师模型的输出分布(Gu et al., 2023; Wen et al., 2023)、隐藏状态(Jiao et al., 2020; Sun et al., 2019)和注意力分数(Wang et al., 2021),使学生模型能够从教师中蒸馏更多内在知识。因此,此方法仅当教师模型参数可访问时才适用。另一方面,黑盒KD利用强大的专有LLM的高质量输出来微调学生模型(Hsieh et al., 2023; Fu et al., 2023)。白盒和黑盒KD各有其缺点。白盒KD受限于教师模型的容量,这常常限制学生的蒸馏性能;而黑盒KD由于无法访问教师模型的输出分布和内部状态,面临知识迁移的挑战。
In this paper, we propose Proxy-based Knowledge Distillation (Proxy-KD) to better transfer knowledge from black-box teacher models. Proxy-KD introduces a proxy model, typically a white-box LLM, between the student and the black-box teacher. The proxy model first aligns with the capabilities of the black-box teacher by leveraging the teacher’s outputs. Moreover, preference optimization is performed to further refine and enhance the alignment between the proxy and teacher models.在本文中,我们提出基于代理的知识蒸馏(Proxy-KD),以更好地从黑盒教师模型中迁移知识。Proxy-KD在学生和黑盒教师之间引入一个代理模型,通常是白盒LLM。代理模型首先利用教师的输出来对齐其能力。此外,进行偏好优化以进一步细化和增强代理与教师模型之间的对齐。
During the knowledge distillation process, the proxy model generates a dense distribution that closely approximates the black-box teacher’s output distribution. This enables the student model to train effectively as if it were using the black-box teacher’s guidance. To further improve the student’s learning effect, we propose incorporating a sample-level weight into the distillation objective. This weight reflects the quality of alignment between the proxy and the teacher model for each sample, allowing the student to concentrate on learning well-aligned distributions from the proxy. Moreover, the outputs from the black-box teacher serve as pseudo-labels for the supervised fine-tuning of the student model, akin to traditional white-box knowledge distillation. Introducing the proxy model also mitigates the model capacity gap issue (Cho and Hariharan, 2019), which typically occurs when there is a notable disparity in capabilities between the teacher and the student.在知识蒸馏过程中,代理模型生成一个与黑盒教师输出分布紧密近似的密集分布。这使得学生模型能够像使用黑盒教师指导一样有效地进行训练。为了进一步提高学生的学习效果,我们提出在蒸馏目标中加入样本级权重。该权重反映了每个样本上代理与教师模型之间的对齐质量,使学生能够专注于从代理中学习对齐良好的分布。此外,黑盒教师的输出作为学生模型监督微调的伪标签,类似于传统的白盒知识蒸馏。引入代理模型还缓解了模型容量差距问题(Cho and Hariharan, 2019),该问题通常出现在教师与学生能力存在显著差异时。
To validate the effectiveness of our method, we conducted comprehensive experiments across a range of well-established benchmarks. The results show that Proxy-KD consistently outperforms both black-box and white-box KD methods. We observed that the alignment between the proxy model and the black-box teacher is crucial; a poorly aligned proxy model significantly diminishes the performance of knowledge distillation. We also found that larger and more robust proxy models are generally more desirable, as they possess stronger foundational capabilities and can align more effectively with the black-box teacher, enhancing the distillation process. Furthermore, we discovered that directly fine-tuning the proxy model with outputs from the black-box teacher is suboptimal for the alignment, requiring more effective alignment methods. These findings highlight the importance of selecting a well-aligned and capable proxy model to fully leverage the benefits of Proxy-KD.为了验证我们方法的有效性,我们在各种公认基准上进行了全面实验。结果表明,Proxy-KD始终优于黑盒和白盒KD方法。我们观察到代理模型与黑盒教师之间的对齐至关重要;对齐不佳的代理模型会显著降低知识蒸馏性能。我们还发现,更大、更稳健的代理模型通常更可取,因为它们具有更强的基础能力,能更有效地与黑盒教师对齐,从而增强蒸馏过程。此外,我们发现直接使用黑盒教师的输出微调代理模型并非最优的对齐方法,需要更有效的对齐方法。这些发现强调了选择对齐良好且能力强大的代理模型以充分利用Proxy-KD优势的重要性。
We summarize our contribution as below:我们的贡献总结如下:
-
•
To tackle the challenge of knowledge distillation for closed-source LLMs, we propose Proxy-KD, which introduces an aligned proxy between the teacher and student models. 为了应对闭源LLM的知识蒸馏挑战,我们提出了Proxy-KD,在教师和学生之间引入对齐的代理。
-
•
We propose a DPO-based alignment strategy for the proxy to align with the teacher and demonstrate that this alignment is essential for Proxy-KD to achieve effective distillation.我们提出了一种基于DPO的代理对齐策略,使代理与教师对齐,并证明了该对齐对Proxy-KD实现有效蒸馏至关重要。
-
•
We propose to include a sample-level weight in the distillation objective. This weight allows the student to concentrate on learning well-aligned distributions from the proxy.我们建议在蒸馏目标中加入样本级权重。该权重使学生能够专注于从代理学习对齐良好的分布。
2 Related Work2 相关工作
Existing knowledge distillation methods can be categorized into white-box knowledge distillation and black-box knowledge distillation.现有的知识蒸馏方法可分为白盒知识蒸馏和黑盒知识蒸馏。
2.1 White-Box Knowledge Distillation2.1 白盒知识蒸馏
Traditional knowledge distillation (KD) research predominantly employs white-box teachers and is typically classified into three main branches: feature-based, response-based, and relation-based methods. Feature-based methods seek to replicate the teacher’s intermediate representations, such as attention scores (Jiao et al., 2020), attribution maps (Wu et al., 2023), and hidden representations of tokens (Sun et al., 2019). Response-based methods train the student model by minimizing divergences like Kullback–Leibler (KL) divergence (Hinton et al., 2015; Sanh et al., 2019), reverse KL (Gu et al., 2023; Wen et al., 2023), Jensen–Shannon Divergence (JSD) (Fang et al., 2021; Yin et al., 2020), and Total Variation Distance (TVD) (Wen et al., 2023) based on the teacher’s output distribution. Relation-based methods train the student model by learning pairwise distances and triple-wise angles among token representations from the teacher (Park et al., 2021), or extracting structural relations from multi-granularity representations (Liu et al., 2022).传统的知识蒸馏(KD)研究主要采用白盒教师,通常分为三个主要分支:基于特征、基于响应和基于关系的方法。基于特征的方法试图复制教师的中间表示,如注意力分数(Jiao et al., 2020)、归因图(Wu et al., 2023)和标记的隐藏表示(Sun et al., 2019)。基于响应的方法通过基于教师输出分布最小化诸如Kullback-Leibler(KL)散度(Hinton et al., 2015; Sanh et al., 2019)、反向KL(Gu et al., 2023; Wen et al., 2023)、Jensen-Shannon散度(JSD)(Fang et al., 2021; Yin et al., 2020)和全变差距离(TVD)(Wen et al., 2023)等散度来训练学生模型。基于关系的方法通过学习教师标记表示之间的成对距离和三元角度(Park et al., 2021),或从多粒度表示中提取结构关系(Liu et al., 2022)来训练学生模型。

2.2 Black-Box Knowledge Distillation2.2 黑盒知识蒸馏
Given the remarkable performance achieved by proprietary LLMs like GPT-4 (OpenAI, 2023), Claude 3 Anthropic (2024), and Gemini (Team et al., 2023), recent studies like Alpaca (Taori et al., 2023), Vicuna (Chiang et al., 2023), and Orca (Mukherjee et al., 2023) have focused on transferring diverse capabilities from these black-box teachers into smaller open-source models. For instance, Li et al. (2024) and Liu et al. (2023) improved the mathematical capability of small models by training on tailored rationale samples generated by GPT-3.5-Turbo and GPT-4. To transfer the code generation capability, Azerbayev et al. (2023) prompted Codex (Chen et al., 2021) to create natural language-code pairs and fine-tuned a smaller model on these samples. To transfer the tool usage capability, Gou et al. (2023) utilized GPT-4 to generate interactive tool-use trajectories as training samples for the target model. Other approaches, such as Hsieh et al. (2023); Ho et al. (2022); Chen et al. (2023), utilize rationales generated by black-box teachers as training data to transfer their general reasoning capabilities.鉴于GPT-4(OpenAI, 2023)、Claude 3 Anthropic(2024)和Gemini(Team et al., 2023)等专有LLM所取得的显著性能,近期研究如Alpaca(Taori et al., 2023)、Vicuna(Chiang et al., 2023)和Orca(Mukherjee et al., 2023)专注于将这些黑盒教师的各种能力迁移到较小的开源模型中。例如,Li et al.(2024)和Liu et al.(2023)通过使用GPT-3.5-Turbo和GPT-4生成的定制推理样本训练小模型,提高了小模型的数学能力。为了迁移代码生成能力,Azerbayev et al.(2023)提示Codex(Chen et al., 2021)创建自然语言-代码对,并在这些样本上微调较小模型。为了迁移工具使用能力,Gou et al.(2023)利用GPT-4生成交互式工具使用轨迹作为目标模型的训练样本。其他方法,如Hsieh et al.(2023); Ho et al.(2022); Chen et al.(2023),利用黑盒教师生成的推理作为训练数据来迁移其一般推理能力。
White-box knowledge distillation (KD) efficiently distills knowledge by leveraging the internal states of the teacher model. However, white-box teachers typically possess a more limited capacity compared to their black-box counterparts. In contrast, black-box KD capitalizes on the superior performance of the teacher models but is restricted to fine-tuning on teacher-generated samples. This approach captures input-output patterns without accessing the deeper, intrinsic knowledge of the teacher model. To bridge these gaps, we propose Proxy-KD, a straightforward method that combines the strengths of both white-box and black-box KD while mitigating their respective limitations.白盒知识蒸馏(KD)通过利用教师模型的内部状态有效地蒸馏知识。然而,白盒教师通常比黑盒教师具有更有限的容量。相比之下,黑盒KD利用了教师模型的优越性能,但仅限于在教师生成的样本上进行微调。这种方法捕获输入-输出模式,而无法访问教师模型更深层的内在知识。为了弥补这些差距,我们提出了Proxy-KD,一种简单的方法,结合了白盒和黑盒KD的优点,同时减轻了它们各自的局限性。
2.3 Connection with Teacher Assistant2.3 与教师助手的联系
The proposed Proxy-KD method draws inspiration from TAKD (Mirzadeh et al., 2020), as both methods use an intermediate network to aid knowledge distillation, but they differ in three significant ways. Firstly, the motivation behind each approach is distinct: TAKD focuses on mitigating the capacity gap between the teacher and student in white-box settings, whereas Proxy-KD addresses the challenges posed by black-box teacher models and seeks to incorporate the benefits found in white-box scenarios. Secondly, the methodologies diverge, with Proxy-KD introducing a crucial proxy alignment phase that includes preference optimization to better align the proxy model with the black-box LLM. This step is essential for reducing discrepancies between the proxy and teacher models, thereby improving the effectiveness of the distillation process. Lastly, they operate in different domains: TAKD is applied in the field of computer vision, while Proxy-KD is specifically designed for natural language processing, targeting the distillation of proprietary large language models (LLMs).所提出的Proxy-KD方法借鉴了TAKD(Mirzadeh et al., 2020),因为两种方法都使用中间网络来辅助知识蒸馏,但它们在三个重要方面有所不同。 首先,每种方法的动机不同:TAKD专注于缓解白盒设置下教师与学生之间的容量差距,而Proxy-KD解决黑盒教师模型带来的挑战,并寻求融合白盒场景中的优势。 其次,方法论不同,Proxy-KD引入了一个关键的代理对齐阶段,包括偏好优化,以更好地将代理模型与黑盒LLM对齐。这一步骤对于减少代理和教师模型之间的差异,从而提高蒸馏过程的有效性至关重要。 最后,它们应用领域不同:TAKD应用于计算机视觉领域,而Proxy-KD专门为自然语言处理设计,针对专有大型语言模型(LLM)的蒸馏。
3 Method3 方法
In this section, we introduce Proxy-based Knowledge Distillation (Proxy-KD), a simple yet efficient approach for knowledge distillation from black-box LLMs. As illustrated in Figure 2, Proxy-KD introduces a larger white-box LLM as the proxy aiming to capture the black-box teacher’s knowledge. The process unfolds in two main stages: (1) proxy model alignment and (2) student knowledge distillation. First, the proxy model is aligned with the teacher through supervised fine-tuning and preference optimization. Once aligned, the student model learns from both the explicit outputs (hard labels) of the black-box teacher and output distributions (soft labels) provided by the aligned proxy.在本节中,我们介绍基于代理的知识蒸馏(Proxy-KD),一种简单而高效的黑盒LLM知识蒸馏方法。如图2所示,Proxy-KD引入一个较大的白盒LLM作为代理,旨在捕获黑盒教师的知识。该过程分为两个主要阶段:(1)代理模型对齐和(2)学生知识蒸馏。首先,代理模型通过监督微调和偏好优化与教师对齐。一旦对齐,学生模型同时从黑盒教师的显式输出(硬标签)和对齐代理提供的输出分布(软标签)中学习。
3.1 Problem Statement3.1 问题描述
To facilitate the transfer of knowledge from a black-box teacher LLM to a smaller, open-source student LLM , we introduce a proxy model . The training dataset consists of input-output pairs , where represents the input prompt and is the output sequence generated by the teacher model . This dataset is strategically divided into three parts: 10% () for the warm-up phase, 45% () for aligning the proxy model with the teacher, and the remaining 45% () for the knowledge distillation training of the student model.为了促进知识从黑盒教师LLM πtsubscript𝜋𝑡\pi_{t}... 向更小的开源学生LLM πssubscript𝜋𝑠\pi_{s}... 的迁移,我们引入代理模型 πpsubscript𝜋𝑝\pi_{p}...。训练数据集 𝒟𝒟\mathcal{D}... 由输入-输出对 (x,y)... 组成,其中 x... 表示输入提示,y... 是教师模型 πt... 生成的输出序列。该数据集被策略性地分为三部分:10%(𝒟w...)用于预热阶段,45%(𝒟p...)用于代理模型与教师对齐,其余45%(𝒟s...)用于学生模型的知识蒸馏训练。
The process begins with a warm-up phase where the proxy model is trained on . This phase helps develop a basic capability to generate responses to input prompts. Following this, the proxy model undergoes alignment with the teacher model using the next dataset, . This alignment is achieved through two methods: hard-label knowledge distillation (KD) and preference learning. These methods enable to approximate the behavior and outputs of the teacher model. Once aligned, acts as an intermediary, facilitating the transfer of knowledge to the student on .该过程首先进入预热阶段,代理模型πpsubscript𝜋𝑝\pi_{p}...在𝒟w...上训练。此阶段帮助πpsubscript𝜋𝑝\pi_{p}...发展生成输入提示响应的基本能力。之后,代理模型使用下一个数据集𝒟p...与教师模型πt...进行对齐。这种对齐通过两种方法实现:硬标签知识蒸馏(KD)和偏好学习。这些方法使πpsubscript𝜋𝑝\pi_{p}...能够近似教师模型的行为和输出。一旦对齐,πpsubscript𝜋𝑝\pi_{p}...作为中介,促进在𝒟s...上向学生πs...的知识迁移。
3.2 Preliminary3.2 预备知识
Hard-Label Knowledge Distillation.硬标签知识蒸馏。
In this approach, the student model is trained using the outputs generated by the teacher model by minimizing the negative log-likelihood (NLL) function:在这种方法中,学生模型通过最小化负对数似然(NLL)函数,使用教师模型生成的输出进行训练:
| (1) |
where is the probability of generating given . This approach is essentially a form of supervised fine-tuning and typically employed when the teacher is a black-box model.其中πs(y|x)是πs给定x生成y的概率。 这种方法本质上是一种监督微调,通常在教师为黑盒模型时采用。
Soft-Label Knowledge Distillation.软标签知识蒸馏。
In this approach, the student is trained to imitate the token-level probabilities of the teacher, by minimizing the Kullback-Leibler (KL) divergence:在这种方法中,学生通过最小化Kullback-Leibler(KL)散度来模仿教师的词元级概率:
| (2) |
This knowledge distillation approach is typically employed when the teacher is a white-box model. 这种知识蒸馏方法通常在教师为白盒模型时采用。
While the KL divergence objective provides richer supervision signals by using the token-level output distributions of the teacher model, it cannot be applied to black-box teachers due to the inaccessibility of these distributions. Consequently, current methods (Chiang et al., 2023; Mukherjee et al., 2023) rely on supervised fine-tuning using the outputs generated by black-box models to transfer their knowledge. Proxy-KD addresses this limitation by using a proxy model to incorporate the KL objective. The proxy mimics the black-box teacher, allowing access to its output distributions and enabling a more effective knowledge transfer.虽然KL散度目标通过使用教师模型的词元级输出分布提供了更丰富的监督信号,但由于这些分布不可访问,它无法应用于黑盒教师。因此,当前方法(Chiang et al., 2023; Mukherjee et al., 2023)依赖使用黑盒模型生成的输出进行监督微调来迁移其知识。 Proxy-KD通过使用代理模型来融合KL目标来解决这一限制。代理模仿黑盒教师,允许访问其输出分布,从而实现更有效的知识迁移。
3.3 Proxy Model Alignment3.3 代理模型对齐
The proxy model is typically a larger white-box LLM than the student model . For effective knowledge transfer, it’s crucial to first align the output distribution of the proxy model with that of the black-box teacher model . This alignment ensures that the proxy accurately captures the teacher’s behavior.代理模型πpsubscript𝜋𝑝\pi_{p}...通常是一个比学生模型πssubscript𝜋𝑠\pi_{s}...更大的白盒LLM。为了实现有效的知识迁移,首先将代理模型的输出分布与黑盒教师模型πtsubscript𝜋𝑡\pi_{t}...的输出分布对齐至关重要。这种对齐确保代理准确捕获教师的行为。
The proxy model first undergoes supervised fine-tuning on a warm-up dataset . Following this, the proxy is further trained on the dataset by minimizing the NLL loss:代理模型πpsubscript𝜋𝑝\pi_{p}...首先在预热数据集𝒟w...上进行监督微调。之后,代理进一步在𝒟p...数据集上通过最小化NLL损失进行训练:
| (3) |
To enhance the alignment of the proxy model with the teacher, we further introduce a preference learning-based alignment objective, with the hypothesis that the teacher model’s responses are of higher quality compared to those from the unaligned proxy model. The objective is to iteratively adjust the proxy model so that it increasingly favors responses similar to those of the teacher while reducing its preference for its own initial outputs. To implement this, we employ the Direct Preference Optimization (DPO) algorithm (Rafailov et al., 2024), which refines the proxy model by systematically preferring the teacher’s responses.为了增强代理模型与教师的对齐,我们进一步引入基于偏好学习的对齐目标,其假设是教师模型的响应比未对齐代理模型的响应质量更高。目标是迭代调整代理模型,使其越来越偏好与教师相似的响应,同时减少对其自身初始输出的偏好。为此,我们采用直接偏好优化(DPO)算法(Rafailov et al., 2024),通过系统性地偏好教师的响应来改进代理模型。
Specifically, for a given input , we iteratively sample a response from the teacher and from the proxy. These responses form a preference pair . To train the proxy model to prefer over , we define the following preference loss function:具体来说,对于给定输入x,我们迭代地从教师采样响应y,从代理采样响应y^。这些响应形成偏好对(x,y,y^)。为了训练代理模型偏好y而非y^,我们定义以下偏好损失函数:
| (4) | ||||
where is the proxy model from the previous training iteration. The overall preference loss over all the preference samples is defined as:其中πp(i−1)是来自前一次训练迭代的代理模型。所有偏好样本上的总体偏好损失定义为:
| (5) |
At each iteration , the proxy model is updated based on the combined objective that includes both the NLL loss and the preference loss:在每次迭代i时,代理模型基于包含NLL损失和偏好损失的组合目标进行更新:
| (6) |
This iterative process continues for a fixed number of iterations or until the proxy model converges. Through this method, the proxy model is aligned to emulate the distribution of the black-box teacher , becoming an effective intermediary for transferring knowledge to the student model.该迭代过程持续固定迭代次数k,直到代理模型收敛。 通过这种方法,代理模型πpsubscript𝜋𝑝\pi_{p}...被对齐以模拟黑盒教师πtsubscript𝜋𝑡\pi_{t}...的分布,成为向学生模型迁移知识的有效中介。
3.4 Knowledge Distillation3.4 知识蒸馏
To transfer knowledge from the black-box teacher to the student model , we define the first training objective using teacher-generated sequences and the hard-label knowledge distillation objective:为了将知识从黑盒教师迁移到学生模型πssubscript𝜋𝑠\pi_{s}...,我们使用教师生成的序列和硬标签知识蒸馏目标定义第一个训练目标:
| (7) |
Based on the proxy model aligned with the black-box teacher, which delivers accessible output distributions, we define another training objective for the student through soft-label knowledge distillation:基于与黑盒教师对齐且可访问输出分布的代理模型,我们通过软标签知识蒸馏为学生定义另一个训练目标:
| (8) |
In this process, the proxy model functions as an intermediary for the black-box teacher, facilitating the transfer of knowledge to the student model. However, as illustrated in Figure 5 in Appendix, discrepancies between the teacher’s and the proxy’s output distributions persist even after aligning the proxy model, potentially degrading the effectiveness of knowledge distillation. To address these discrepancies, we propose a weighted approach to the soft-label knowledge distillation objective. By introducing weights, we dynamically adjust the influence of each sample based on the alignment quality between the proxy and the black-box teacher. This approach ensures that the student model prioritizes samples where the proxy’s distribution closely matches the teacher’s distribution and reduces focus on samples where it does not. The weights are calculated based on the log-likelihood of the teacher’s output generated by the proxy, normalized by the mean and variance of these log-likelihoods:在此过程中,代理模型充当黑盒教师的中间媒介,促进知识向学生模型的迁移。然而,如图5(附录)所示,即使在代理模型对齐后,教师和代理的输出分布之间仍存在差异,可能降低知识蒸馏的有效性。为了解决这些差异,我们提出一种加权的软标签知识蒸馏目标。通过引入权重,我们根据代理与黑盒教师之间的对齐质量动态调整每个样本的影响。这种方法确保学生模型优先处理代理分布与教师分布紧密匹配的样本,并减少对不匹配样本的关注。权重基于代理生成的教师输出的对数似然计算,并通过这些对数似然的均值和方差进行归一化:
| (9) | ||||
where is a weight reflecting the quality of the proxy’s prediction for the sample , is the variance operation, is the standard deviation, is the sigmoid function. Based on Equation (8), we derive the sample-level weighted version of as follow:其中w(x,y)是反映代理对样本(x,y)预测质量的权重,𝕍ar(·)是方差运算,γ是标准差,σ是sigmoid函数。基于公式(8),我们推导出ℒStudent-KL的样本级加权版本如下:
| (10) | ||||
Therefore, the overall objective for student knowledge distillation can be derived as:因此,学生知识蒸馏的总体目标可推导为:
| (11) |
where is a hyperparameter utilized to adjust the strength of the weighted KL loss.其中α是一个超参数,用于调整加权KL损失的强度。
This knowledge distillation strategy effectively blends the advantages of both black-box and white-box knowledge distillation methods, employing the proxy model to bridge the gap between black-box LLMs and open-source student LLMs.这种知识蒸馏策略有效地融合了黑盒和白盒知识蒸馏方法的优点,利用代理模型弥合黑盒LLM与开源学生LLM之间的差距。
4 Experimental Setup4 实验设置
In this section, we introduce the experimental settings of models, datasets, and method baselines.本节介绍模型、数据集和方法基线的实验设置。
4.1 Models and Datasets4.1 模型与数据集
Teacher/Proxy/Student Models. In Proxy-KD, we choose GPT-4 (OpenAI, 2023) as the teacher, which is a powerful proprietary large language model. We select Llama-2-70b (Touvron et al., 2023b) and Llama-2-13b (MetaAI, 2024) as the proxy, respectively. Our student models come from two model types: Llama-1-7B (Touvron et al., 2023a) and Llama-2-7B (Touvron et al., 2023b).教师/代理/学生模型。在Proxy-KD中,我们选择GPT-4(OpenAI, 2023)作为教师,这是一个强大的专有大型语言模型。我们分别选择Llama-2-70b(Touvron et al., 2023b)和Llama-2-13b(MetaAI, 2024)作为代理。我们的学生模型来自两种模型类型:Llama-1-7B(Touvron et al., 2023a)和Llama-2-7B(Touvron et al., 2023b)。
Training Corpus. 训练语料。
We combine the OpenOrca (Lian et al., 2023) and Nectar (Zhu et al., 2023) datasets as our training corpus, containing a total of 1M output sequences generated by the block-box teacher GPT-4. The OpenOrca dataset consists of instruction-following tasks, where GPT-4 is prompted to generate responses based on diverse input instructions. Nectar is a 7-wise comparison dataset, we filter and select those responses derived from GPT-4. Following Li et al. (2024), we also incorporate synthetic data generated by GPT-4, based on existing benchmark training sets. We split the original training corpus into three parts: 10% as with 100K samples, 45% as with 450K samples, and 45% as with 450K samples.我们将OpenOrca(Lian et al., 2023)和Nectar(Zhu et al., 2023)数据集合并作为我们的训练语料,包含由黑盒教师GPT-4生成的共1M个输出序列。OpenOrca数据集由指令遵循任务组成,其中GPT-4被提示根据多样化的输入指令生成响应。Nectar是一个7路比较数据集,我们筛选并选择那些源自GPT-4的响应。 遵循Li et al.(2024),我们还加入了基于现有基准训练集由GPT-4生成的合成数据。 我们将原始训练语料𝒟分为三部分:10%作为𝒟w,包含100K样本;45%作为𝒟p,包含450K样本;45%作为𝒟s,包含450K样本。
Evaluation Benchmarks.评估基准。
Evaluation benchmarks include complex reasoning dataset BBH (Suzgun et al., 2022), knowledge-based datasets AGIEval (Zhong et al., 2023), ARC-challenge (Clark et al., 2018), and MMLU (Zeng, 2023), commonsense reasoning dataset CSQA (Talmor et al., 2019), and mathematical reasoning dataset GSM8K (Cobbe et al., 2021). All evaluated models apply a zero-shot greedy decoding strategy.评估基准包括复杂推理数据集BBH(Suzgun et al., 2022)、基于知识的数据集AGIEval(Zhong et al., 2023)、ARC-challenge(Clark et al., 2018)和MMLU(Zeng, 2023)、常识推理数据集CSQA(Talmor et al., 2019)和数学推理数据集GSM8K(Cobbe et al., 2021)。 所有评估模型均采用零样本贪心解码策略。
Method Student Teacher / Dataset AGIEval ARC BBH CSQA GSM8K MMLU Avg Black-Box Teacher GPT-4 - - 56.40 93.26 88.0 - 92.0 86.4 - White-Box KD Forward KL Llama-1-7B Llama-2-70B-Chat 25.16 62.18 37.27 74.20 37.39 45.43 46.94 Forward KL Llama-2-7B Llama-2-70B-Chat 35.16 66.87 35.68 74.40 44.12 51.42 51.27 Forward KL Llama-2-7B Llama-2-70B-Proxy 35.56 69.34 45.72 74.97 46.34 51.13 53.84 MiniLLM (Gu et al., 2023) Llama-2-7B Llama-2-70B-Chat 35.77 63.25 53.11 75.15 44.64 51.32 53.87 GKD (Agarwal et al., 2023) Llama-2-7B Llama-2-70B-Chat 34.22 62.28 52.58 75.16 42.79 50.64 52.95 Black-Box KD GPT-3 (Ho et al., 2022) GPT-3-6.7B text-davinci-002 - - - 56.76 6.75 - - FlanT5-XL (Fu et al., 2023) FlanT5-3B text-davinci-003 - - 39.0 - 22.4 - - FlanT5-XXL (Fu et al., 2023) Flant-11B text-davinci-003 - - 47.20 - 27.10 - - MCC-KD (Chen et al., 2023) FlanT5-11B ChatGPT - - - 84.93 33.99 - - MCC-KD (Chen et al., 2023) Llama-1-7B ChatGPT - - - 76.41 41.58 - - Orca-1 (Mukherjee et al., 2023) Llama-1-13B GPT-4 41.7 74.74 49.7 - 26.46 53.80 - Orca-2 (Mitra et al., 2023) Llama-2-7B GPT-4 45.10 78.41 45.93 - 47.23 53.70 - Orca-2 (Mitra et al., 2023) Llama-2-13B GPT-4 49.93 83.36 50.18 - 59.14 57.73 - WizardLM (Xu et al., 2023) Llama-2-13B ChatGPT 38.25 74.74 38.47 - 48.60 55.00 - Vicuna (Chiang et al., 2023) Llama-2-13B ShareGPT 29.3 - 23.3 - - - - Vanilla Black-Box KD Llama-1-7B GPT-4 28.01 63.17 41.98 74.43 41.83 45.21 49.11 Vanilla Black-Box KD Llama-2-7B GPT-4 34.71 66.85 46.68 74.43 49.51 49.82 53.66 TAKD (Mirzadeh et al., 2020) Llama-1-7B GPT-4 25.73 63.61 38.87 73.01 39.45 39.12 46.63 TAKD (Mirzadeh et al., 2020) Llama-2-7B GPT-4 35.05 67.18 43.0 76.04 47.54 48.09 52.82 Proxy-KD Llama-1-7B GPT-4 35.47 67.48 43.74 74.08 44.89 41.88 52.09 Proxy-KD Llama-2-7B GPT-4 36.59 71.09 53.40 75.18 53.07 51.35 56.78
方法 学生 教师/数据集 AGIEval ARC BBH CSQA GSM8K MMLU 平均 黑盒教师 GPT-4 - - 56.40 93.26 88.0 - 92.0 86.4 - 白盒知识蒸馏 前向KL ♣ Llama-1-7B Llama-2-70B-Chat 25.16 62.18 37.27 74.20 37.39 45.43 46.94 前向KL ♣ Llama-2-7B Llama-2-70B-Chat 35.16 66.87 35.68 74.40 44.12 51.42 51.27 前向KL ♣ Llama-2-7B Llama-2-70B-Proxy 35.56 69.34 45.72 74.97 46.34 51.13 53.84 MiniLLM ♣ (Gu et al., 2023) Llama-2-7B Llama-2-70B-Chat 35.77 63.25 53.11 75.15 44.64 51.32 53.87 GKD ♣ (Agarwal et al., 2023) Llama-2-7B Llama-2-70B-Chat 34.22 62.28 52.58 75.16 42.79 50.64 52.95 黑盒知识蒸馏 GPT-3 (Ho et al., 2022) GPT-3-6.7B text-davinci-002 - - - 56.76 6.75 - - FlanT5-XL (Fu et al., 2023) FlanT5-3B text-davinci-003 - - 39.0 - 22.4 - - FlanT5-XXL (Fu et al., 2023) Flant-11B text-davinci-003 - - 47.20 - 27.10 - - MCC-KD (Chen et al., 2023) FlanT5-11B ChatGPT - - - 84.93 33.99 - - MCC-KD (Chen et al., 2023) Llama-1-7B ChatGPT - - - 76.41 41.58 - - Orca-1 (Mukherjee et al., 2023) Llama-1-13B GPT-4 41.7 74.74 49.7 - 26.46 53.80 - Orca-2 (Mitra et al., 2023) Llama-2-7B GPT-4 45.10 78.41 45.93 - 47.23 53.70 - Orca-2 (Mitra et al., 2023) Llama-2-13B GPT-4 49.93 83.36 50.18 - 59.14 57.73 - WizardLM (Xu et al., 2023) Llama-2-13B ChatGPT 38.25 74.74 38.47 - 48.60 55.00 - Vicuna (Chiang et al., 2023) Llama-2-13B ShareGPT 29.3 - 23.3 - - - - 原始黑盒知识蒸馏 ♣ Llama-1-7B GPT-4 28.01 63.17 41.98 74.43 41.83 45.21 49.11 原始黑盒知识蒸馏 ♣ Llama-2-7B GPT-4 34.71 66.85 46.68 74.43 49.51 49.82 53.66 TAKD ♣ (Mirzadeh et al., 2020) Llama-1-7B GPT-4 25.73 63.61 38.87 73.01 39.45 39.12 46.63 TAKD ♣ (Mirzadeh et al., 2020) Llama-2-7B GPT-4 35.05 67.18 43.0 76.04 47.54 48.09 52.82 Proxy-KD Llama-1-7B GPT-4 35.47 67.48 43.74 74.08 44.89 41.88 52.09 Proxy-KD Llama-2-7B GPT-4 36.59 71.09 53.40 75.18 53.07 51.35 56.784.2 Training Configurations4.2 训练配置
All experiments are conducted on 8×A100 Nvidia GPUs with 80GB memory. All proxy and student models are trained for only one epoch. We use a constant learning rate of 1e-5 and the Adam optimizer, with a max sequence length of 1024. We set hyperparamter in Equation (11), and for the number of proxy alignment iterations. All models are trained using LoRA (Hu et al., 2021) with mixed-precision: frozen parameters in bfloat16 and LoRA-trained parameters in float32.所有实验均在8×A100 Nvidia GPU上运行,显存为80GB。所有代理和学生模型仅训练一个epoch。我们使用恒定的学习率1e-5和Adam优化器,最大序列长度为1024。 我们在公式(11)中设置超参数α=100,并设置k=16作为代理对齐迭代次数。 所有模型均使用LoRA(Hu et al., 2021)和混合精度训练:冻结参数为bfloat16,LoRA训练参数为float32。
4.3 Baselines4.3 基线
We compare Proxy-KD with different white-box KD and black-box KD methods.我们将Proxy-KD与不同的白盒KD和黑盒KD方法进行比较。
White-Box KD. For knowledge distillation with white-box teachers, we compare forward KL methods (Hinton et al., 2015; Agarwal et al., 2024) and reverse KL methods including MiniLLM (Gu et al., 2023) and GKD (Agarwal et al., 2023) (with the same hyperparameters set in the paper.). The chat version of Llama-2-70b is utilized as the white-box teacher. We also compare with using the aligned proxy as white-box teacher to perform distillation.白盒知识蒸馏。对于白盒教师的知识蒸馏,我们比较前向KL方法(Hinton et al., 2015; Agarwal et al., 2024)和反向KL方法,包括MiniLLM(Gu et al., 2023)和GKD(Agarwal et al., 2023)(使用论文中设置的相同超参数)。 我们使用Llama-2-70b的对话版本作为白盒教师。我们还比较了使用对齐代理作为白盒教师进行蒸馏的方法。
Black-Box KD. For knowledge distillation with black-box teachers, we compare the vanilla black-box KD methods (Mukherjee et al., 2023; Mitra et al., 2023; Xu et al., 2023), which directly fine-tunes the student on the data generated by the black-box teacher. We also compare Proxy-KD with the TAKD (Mirzadeh et al., 2020) method.黑盒知识蒸馏。对于黑盒教师的知识蒸馏,我们比较原始黑盒KD方法(Mukherjee et al., 2023; Mitra et al., 2023; Xu et al., 2023),该方法直接微调学生模型于黑盒教师生成的数据。我们还将Proxy-KD与TAKD(Mirzadeh et al., 2020)方法进行比较。
For baselines implemented by us, we start from the same student checkpoint as Proxy-KD and use the same input prompts. In white-box KD, output sequences are generated by the white-box teacher, while in black-box KD, output sequences are generated by the black-box teacher.对于我们自己实现的基线,我们从与Proxy-KD相同的学生检查点开始,并使用相同的输入提示。在白盒KD中,输出序列由白盒教师生成;在黑盒KD中,输出序列由黑盒教师生成。
Method AGIEval ARC BBH CSQA GSM8K MMLU Studnet Model Distillation 36.59 71.09 53.40 75.18 53.07 51.35 w/o 34.71 (-1.88) 66.85 (-4.24) 46.68 (-6.72) 74.43 (-0.75) 49.51 (-3.56) 49.82 (-1.53) w/o 35.05 (-1.54) 67.18 (-3.91) 43.0 (-10.40) 76.04 (+0.86) 47.54 (-5.53) 48.09 (-3.26) w/o 35.38 (-1.21) 66.11 (-4.98) 52.51 (-0.89) 75.51 (+0.33) 52.49 (-0.58) 48.79 (-2.56) w/o 33.99 (-2.60) 71.81 (+0.72) 51.50 (-1.90) 75.11 (-0.07) 52.91 (-0.16) 49.47 (-1.88) Proxy Model Alignment 49.12 87.67 66.04 82.18 78.24 68.62 w/o 48.31 (-0.81) 86.93 (-0.74) 62.16 (-3.88) 80.95 (-1.23) 79.15 (+0.91) 66.38 (-2.24)
方法 AGIEval ARC BBH CSQA GSM8K MMLU 学生模型蒸馏 ℒStudent 36.59 71.09 53.40 75.18 53.07 51.35 无πp 34.71 (-1.88) 66.85 (-4.24) 46.68 (-6.72) 74.43 (-0.75) 49.51 (-3.56) 49.82 (-1.53) 无ℒProxy 35.05 (-1.54) 67.18 (-3.91) 43.0 (-10.40) 76.04 (+0.86) 47.54 (-5.53) 48.09 (-3.26) 无ℒPref 35.38 (-1.21) 66.11 (-4.98) 52.51 (-0.89) 75.51 (+0.33) 52.49 (-0.58) 48.79 (-2.56) 无ℒWeight-KL 33.99 (-2.60) 71.81 (+0.72) 51.50 (-1.90) 75.11 (-0.07) 52.91 (-0.16) 49.47 (-1.88) 代理模型对齐 ℒProxy 49.12 87.67 66.04 82.18 78.24 68.62 无ℒPref 48.31 (-0.81) 86.93 (-0.74) 62.16 (-3.88) 80.95 (-1.23) 79.15 (+0.91) 66.38 (-2.24)5 Result and Analysis5 结果与分析
In this section, we present the main results and additional experiments of Proxy-KD.本节介绍Proxy-KD的主要结果和附加实验。
5.1 Overall Results5.1 总体结果
We show the comparison of Proxy-KD against baselines in Table 1, the proxy models in Proxy-KD are based on Llama-2-70B backbone. Overall, the performance of black-box KD methods outperforms that of white-box KD methods, demonstrating the efficacy of distilling knowledge from powerful black-box models.我们在表1中展示了Proxy-KD与基线的比较,Proxy-KD中的代理模型基于Llama-2-70B骨干。总体而言,黑盒KD方法的性能优于白盒KD方法,证明了从强大的黑盒模型中蒸馏知识的有效性。
Proxy-KD outperforms white-box KD and black-box KD methods. Notably, Proxy-KD further enhances the performance, consistently achieving higher scores across most evaluated benchmarks compared to the white-box KD methods (e.g. MiniLLM and GKD) and the black-box KD methods. Improvement is particularly pronounced in the challenging datasets like BBH and GSM8K, where Proxy-KD obtains scores of 53.40 and 53.07, respectively, outperforming even larger models trained using traditional black-box KD methods.Proxy-KD优于白盒KD和黑盒KD方法。值得注意的是,Proxy-KD进一步提升了性能,在大多数评估基准上相较于白盒KD方法(如MiniLLM和GKD)和黑盒KD方法始终取得更高分数。在BBH和GSM8K等具有挑战性的数据集上提升尤为显著,Proxy-KD分别获得53.40和53.07的分数,甚至优于使用传统黑盒KD方法训练的更大模型。
Proxy-KD outperforms TAKD consistently. TAKD performs even worse than vanilla Black-Box KD. When using Llama-1-7B as the student, vanilla Black-Box KD achieves an average of 49.11%, while TAKD only reaches 46.63%. Similarly, with Llama-2-7B as the student, vanilla Black-Box KD attains 53.66% compared to TAKD’s average of 52.82%. This decline in performance is likely due to TAKD’s failure to account for the proxy alignment process, which is essential for effective closed-source KD. Introducing an unaligned proxy not only fails to enhance performance but actually degrades the performance of the student model.Proxy-KD始终优于TAKD。TAKD的性能甚至低于原始黑盒KD。当使用Llama-1-7B作为学生时,原始黑盒KD的平均得分为49.11%,而TAKD仅达到46.63%。同样,以Llama-2-7B作为学生时,原始黑盒KD达到53.66%,而TAKD的平均为52.82%。这种性能下降可能是由于TAKD未考虑代理对齐过程,而这对于有效的闭源KD至关重要。引入未对齐的代理不仅无法提升性能,反而会降低学生模型的性能。
Proxy-KD outperforms white-box KD with an aligned proxy as the teacher. Relying solely on an aligned proxy for white-box KD offers limited knowledge to the student. This suggests that the capabilities of closed-source teachers are more beneficial than those of open-source teachers, even after alignment, underscoring the superiority of distilling from closed-source LLMs.Proxy-KD优于使用对齐代理作为教师的白盒KD。仅依赖对齐代理进行白盒KD为学生提供的知识有限。这表明闭源教师的能力即使在对齐后也比开源教师更有益,凸显了从闭源LLM蒸馏的优越性。
We also present the performance changes of student models during the distillation process in Figure 6 in Appendix. We show the accuracy curves of students on the benchmark test sets for every 40K training steps. We compare three methods: vanilla black-box KD, Proxy-KD, and white-box KD (forward KL). The results show that Proxy-KD stands out with the most significant enhancements, indicating its superior capability to efficiently transfer the comprehensive knowledge of black-box teachers to student models. The steeper and more consistent improvement curves of Proxy-KD across benchmarks such as AGIEval, ARC, and particularly in complex tasks like BBH and GSM8K, underscore its robust and effective approach in leveraging proxy models for knowledge distillation.我们还在附录图6中展示了蒸馏过程中学生模型的性能变化。我们展示了学生在每40K训练步后在基准测试集上的准确率曲线。我们比较了三种方法:原始黑盒KD、Proxy-KD和白盒KD(前向KL)。 结果表明,Proxy-KD的提升最为显著,表明其高效地将黑盒教师的综合知识迁移到学生模型的优越能力。在AGIEval、ARC以及BBH和GSM8K等复杂任务上,Proxy-KD的曲线更陡峭且更一致,凸显了其利用代理模型进行知识蒸馏的稳健有效方法。
5.2 Ablation Studies5.2 消融研究
In this section, we examine the impact of different components within Proxy-KD. Llama-2-7B and Llama-2-70B are utilized as the backbones of the student and the proxy models, respectively.本节检验Proxy-KD中不同组件的影响。学生模型和代理模型分别使用Llama-2-7B和Llama-2-70B作为骨干。
Effect of the Proxy Model. The proxy model is crucial for the effectiveness of Proxy-KD. Removing the proxy model forces the distillation process to revert to hard-label knowledge distillation, leading to significant performance drops across multiple benchmarks: a decrease of 4.24 on ARC, 6.72 on BBH, and 3.56 on GSM8K, as shown in Table 2. These declines underscore the proxy model’s essential role in capturing and transferring the distributional knowledge from the black-box teacher, which is particularly important for tasks involving complex reasoning and mathematical challenges. Without the proxy, the student model fails to benefit from the detailed distributional guidance, resulting in markedly lower performance.代理模型的效果。 代理模型πp对Proxy-KD的有效性至关重要。移除代理模型会使蒸馏过程退化为硬标签知识蒸馏,导致多个基准上的性能显著下降:ARC下降4.24,BBH下降6.72,GSM8K下降3.56,如表2所示。这些下降凸显了代理模型在捕获和迁移黑盒教师分布知识方面的关键作用,尤其对于涉及复杂推理和数学挑战的任务。没有代理,学生模型无法从详细的分布指导中受益,导致性能明显降低。
Effect of Proxy Model Alignment. The proxy model alignment, facilitated by the loss , is vital for effective knowledge transfer. Table 2 shows that when the proxy is initialized directly from the Llama-2-70B checkpoint without alignment, the performance drops notably on BBH (-10.40), GSM8K (-5.53), and MMLU (-3.26). This decline illustrates the adverse effect of an unaligned proxy, which fails to approximate the teacher’s distribution and consequently underperforms compared to models directly fine-tuned on teacher data. The slight increase on CSQA (+0.86) when skipping alignment might be attributed to the simplicity of the task, indicating potential overfitting to teacher outputs without proxy guidance. This reinforces the necessity of the alignment process to ensure the proxy effectively bridges the knowledge transfer from the black-box teacher to the student model across diverse and complex tasks.代理模型对齐的效果。 由损失ℒProxy促进的代理模型对齐对于有效的知识迁移至关重要。表2显示,当代理直接以Llama-2-70B检查点初始化而不进行对齐时,性能在BBH(-10.40)、GSM8K(-5.53)和MMLU(-3.26)上显著下降。这种下降说明未对齐代理的负面影响,它无法近似教师的分布,因此与直接在教师数据上微调的模型相比性能不佳。在CSQA(+0.86)上跳过对齐时性能略有提升,可能归因于该任务的简单性,表明没有代理指导时可能对教师输出过拟合。这强化了对齐过程的重要性,以确保代理能够有效地在多样化和复杂任务中桥接从黑盒教师到学生模型的知识迁移。
Effect of Preference Optimization. Table 2 illustrates the significant role of preference optimization in enhancing the performance of both the proxy and student models. When the proxy preference loss is removed, reducing the proxy alignment loss to , we observe notable performance drops across various benchmarks. Specifically, the alignment of the proxy model with the black-box teacher deteriorates, as evidenced by decreases in scores on benchmarks like BBH and MMLU, which subsequently impacts the student model. The overall trend confirms that preference optimization is crucial for refining the proxy model’s ability to emulate the teacher effectively.偏好优化的效果。 表2展示了偏好优化在提升代理和学生模型性能方面的重要作用。当移除代理偏好损失ℒPref,将代理对齐损失简化为ℒProxy-NLL时,我们观察到各基准上的显著性能下降。具体来说,代理模型与黑盒教师之间的对齐会恶化,BBH和MMLU等基准上的分数下降即为证据,这进而影响学生模型。总体趋势证实,偏好优化对于改进代理模型有效模拟教师的能力至关重要。
Effect of Weighted KL. When is replaced with the standard KL loss , we also observe declines in performance across most benchmarks, indicating that the effectiveness of the distillation process diminishes. The results shown in Table 2 highlight that focusing on high log-likelihood distributions from the proxy, as facilitated by the weighted KL loss, significantly enhances the quality of knowledge transfer. The overall declines underscore that this weighting mechanism significantly improves the quality of knowledge distillation, enhancing the student’s ability to learn from a well-aligned proxy.加权KL的效果。 当ℒWeight-KL被标准KL损失ℒStudent-KL替换时,我们同样观察到大多数基准上的性能下降,表明蒸馏过程的有效性降低。表2中的结果强调,通过加权KL损失关注代理的高对数似然分布,显著提高了知识迁移的质量。总体下降表明这种加权机制显著改善了知识蒸馏的质量,增强了学生从良好对齐代理中学习的能力。

5.3 Impact of Proxy Model’s Capability5.3 代理模型能力的影响
How well the proxy aligned with the teacher can directly affect the performance of the student. The final alignment effectiveness of the proxy model depends on two factors: the design of the alignment algorithm and the inherent alignment capability of the proxy backbone model itself. In this section, we investigate the impact of the latter. We hypothesize that the size of the proxy model’s parameters is crucial for its capacity to align with the black-box teacher’s capability, especially when the teacher’s parameter size is significantly larger than the proxy’s. Experiments are conducted with Llama-2-70B and Llama-2-13B as the proxy backbone models. We show the performance of these aligned proxy models. As depicted in Figure 3, the proxy model based on Llama-2-70B performs better than the one based on Llama-2-13B, the latter has fewer parameters. We also examine the impact of proxy models with different capacities on student performance. We observe that the stronger proxy based on Llama-2-70B yields better student performance than the weaker proxy based on Llama-2-13B. Furthermore, when using a proxy based on a backbone model with a larger capacity, the student demonstrates a greater potential for achieving higher performance.代理模型与教师的对齐程度会直接影响学生的表现。代理模型的最终对齐效果取决于两个因素:对齐算法的设计和代理骨干模型本身固有的对齐能力。在本节中,我们研究后者的影响。我们假设代理模型的参数量对其与黑盒教师能力对齐的能力至关重要,尤其是当教师的参数量远大于代理时。我们使用 Llama-2-70B 和 Llama-2-13B 作为代理骨干模型进行实验。我们展示了这些对齐后的代理模型的性能。如图 3 所示,基于 Llama-2-70B 的代理模型表现优于基于 Llama-2-13B 的代理模型,后者的参数更少。我们还考察了不同能力的代理模型对学生表现的影响。我们观察到,基于 Llama-2-70B 的更强代理比基于 Llama-2-13B 的较弱代理带来了更好的学生表现。此外,当使用基于更大容量骨干模型的代理时,学生展现出实现更高性能的更大潜力。
6 Conclusion6 结论
This paper aims to tackle the challenge of knowledge distillation for black-box large language models (LLMs), where we can only access the outputs generated by the teacher model. Given the inaccessibility of the internal states of these black-box models, we introduce Proxy-KD, a novel approach that leverages a proxy model to enhance the distillation process. The proxy model is first aligned with the black-box teacher, closely mimicking its behavior. Then, the student model is trained using the combined knowledge from both the black-box teacher and the proxy model. Extensive experiments and analyses across a variety of well-established benchmarks demonstrate that Proxy-KD significantly outperforms existing black-box and white-box knowledge distillation methods.本文旨在解决黑盒大型语言模型(LLM)知识蒸馏的挑战,在这种情况下我们只能访问教师模型生成的输出。由于无法访问这些黑盒模型的内部状态,我们引入了 Proxy-KD,一种利用代理模型来增强蒸馏过程的新方法。代理模型首先与黑盒教师对齐,紧密模仿其行为。然后,使用来自黑盒教师和代理模型的组合知识来训练学生模型。在各种公认基准上的大量实验和分析表明,Proxy-KD 显著优于现有的黑盒和白盒知识蒸馏方法。
Limitations局限性
The limitations of this work include the training time overhead associated with proxy model alignment, particularly when the proxy model has a large number of parameters. Additionally, the proposed preference optimization requires online sampling from the proxy model, further increasing the training time overhead. Another limitation is the type of experimental backbone models used. Due to resource constraints, this work only conducts experiments with the Llama model series, without including other model backbones such as Qwen (Bai et al., 2023) or Mistral (Jiang et al., 2023).这项工作的局限性包括与代理模型对齐相关的训练时间开销,特别是当代理模型具有大量参数时。此外,所提出的偏好优化需要从代理模型进行在线采样,进一步增加了训练时间开销。另一个局限性是所使用的实验骨干模型类型。由于资源限制,这项工作仅使用 Llama 模型系列进行实验,没有包括其他模型骨干,如 Qwen (Bai et al., 2023) 或 Mistral (Jiang et al., 2023)。
References
- Agarwal et al. (2024) Rishabh Agarwal, Nino Vieillard, Yongchao Zhou, Piotr Stanczyk, Sabela Ramos Garea, Matthieu Geist, and Olivier Bachem. 2024. On-policy distillation of language models: Learning from self-generated mistakes. In The Twelfth International Conference on Learning Representations.
- Agarwal et al. (2023) Rishabh Agarwal, Nino Vieillard, Yongchao Zhou, Piotr Stanczyk, Sabela Ramos, Matthieu Geist, and Olivier Bachem. 2023. Generalized knowledge distillation for auto-regressive language models.
- Anthropic (2024) Anthropic. 2024. Claude 3 family. Accessed: 2024-06-04.
- Azerbayev et al. (2023) Zhangir Azerbayev, Ansong Ni, Hailey Schoelkopf, and Dragomir Radev. 2023. Explicit knowledge transfer for weakly-supervised code generation.
- Bai et al. (2023) Jinze Bai, Shuai Bai, Yunfei Chu, Zeyu Cui, Kai Dang, Xiaodong Deng, Yang Fan, Wenbin Ge, Yu Han, Fei Huang, et al. 2023. Qwen technical report. arXiv preprint arXiv:2309.16609.
- Chen et al. (2023) Hongzhan Chen, Siyue Wu, Xiaojun Quan, Rui Wang, Ming Yan, and Ji Zhang. 2023. MCC-KD: Multi-CoT consistent knowledge distillation. In Findings of the Association for Computational Linguistics: EMNLP 2023, pages 6805–6820, Singapore. Association for Computational Linguistics.
- Chen et al. (2021) Mark Chen, Jerry Tworek, Heewoo Jun, Qiming Yuan, Henrique Ponde, Jared Kaplan, Harrison Edwards, Yura Burda, Nicholas Joseph, et al. 2021. Evaluating large language models trained on code. ArXiv, abs/2107.03374.
- Chiang et al. (2023) Wei-Lin Chiang, Zhuohan Li, Zi Lin, Ying Sheng, Zhanghao Wu, Hao Zhang, Lianmin Zheng, Siyuan Zhuang, Yonghao Zhuang, Joseph E. Gonzalez, Ion Stoica, and Eric P. Xing. 2023. Vicuna: An open-source chatbot impressing gpt-4 with 90%* chatgpt quality.
- Cho and Hariharan (2019) Jang Hyun Cho and Bharath Hariharan. 2019. On the efficacy of knowledge distillation. In Proceedings of the IEEE/CVF international conference on computer vision, pages 4794–4802.
- Clark et al. (2018) Peter Clark, Isaac Cowhey, Oren Etzioni, Tushar Khot, Ashish Sabharwal, Carissa Schoenick, and Oyvind Tafjord. 2018. Think you have solved question answering? try arc, the ai2 reasoning challenge. ArXiv, abs/1803.05457.
- Cobbe et al. (2021) Karl Cobbe, Vineet Kosaraju, Mohammad Bavarian, Mark Chen, Heewoo Jun, Lukasz Kaiser, Matthias Plappert, Jerry Tworek, Jacob Hilton, Reiichiro Nakano, et al. 2021. Training verifiers to solve math word problems. arXiv preprint arXiv:2110.14168.
- Fang et al. (2021) Gongfan Fang, Yifan Bao, Jie Song, Xinchao Wang, Donglin Xie, Chengchao Shen, and Mingli Song. 2021. Mosaicking to distill: Knowledge distillation from out-of-domain data. Advances in Neural Information Processing Systems, 34:11920–11932.
- Fu et al. (2023) Yao Fu, Hao Peng, Litu Ou, Ashish Sabharwal, and Tushar Khot. 2023. Specializing smaller language models towards multi-step reasoning. arXiv preprint arXiv:2301.12726.
- Gou et al. (2023) Zhibin Gou, Zhihong Shao, Yeyun Gong, Yelong Shen, Yujiu Yang, Minlie Huang, Nan Duan, and Weizhu Chen. 2023. Tora: A tool-integrated reasoning agent for mathematical problem solving. ArXiv, abs/2309.17452.
- Gu et al. (2023) Yuxian Gu, Li Dong, Furu Wei, and Minlie Huang. 2023. Minillm: Knowledge distillation of large language models. In The Twelfth International Conference on Learning Representations.
- Hinton et al. (2015) Geoffrey Hinton, Oriol Vinyals, and Jeff Dean. 2015. Distilling the knowledge in a neural network. arXiv preprint arXiv:1503.02531.
- Ho et al. (2022) Namgyu Ho, Laura Schmid, and Se-Young Yun. 2022. Large language models are reasoning teachers. arXiv preprint arXiv:2212.10071.
- Hsieh et al. (2023) Cheng-Yu Hsieh, Chun-Liang Li, Chih-kuan Yeh, Hootan Nakhost, Yasuhisa Fujii, Alex Ratner, Ranjay Krishna, Chen-Yu Lee, and Tomas Pfister. 2023. Distilling step-by-step! outperforming larger language models with less training data and smaller model sizes. In Findings of the Association for Computational Linguistics: ACL 2023, pages 8003–8017, Toronto, Canada. Association for Computational Linguistics.
- Hu et al. (2021) Edward J Hu, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, Weizhu Chen, et al. 2021. Lora: Low-rank adaptation of large language models. In International Conference on Learning Representations.
- Jiang et al. (2023) Albert Q Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, et al. 2023. Mistral 7b. arXiv preprint arXiv:2310.06825.
- Jiao et al. (2020) Xiaoqi Jiao, Yichun Yin, Lifeng Shang, Xin Jiang, Xiao Chen, Linlin Li, Fang Wang, and Qun Liu. 2020. TinyBERT: Distilling BERT for natural language understanding. In Findings of the Association for Computational Linguistics: EMNLP 2020, pages 4163–4174, Online. Association for Computational Linguistics.
- Li et al. (2024) Chen Li, Weiqi Wang, Jingcheng Hu, Yixuan Wei, Nanning Zheng, Han Hu, Zheng Zhang, and Houwen Peng. 2024. Common 7b language models already possess strong math capabilities. arXiv preprint arXiv:2403.04706.
- Lian et al. (2023) Wing Lian, Bleys Goodson, Eugene Pentland, Austin Cook, Chanvichet Vong, and "Teknium". 2023. Openorca: An open dataset of gpt augmented flan reasoning traces. https://https://huggingface.co/Open-Orca/OpenOrca.
- Liu et al. (2023) Bingbin Liu, Sébastien Bubeck, Ronen Eldan, Janardhan Kulkarni, Yuanzhi Li, Anh Nguyen, Rachel Ward, and Yi Zhang. 2023. Tinygsm: achieving >80% on gsm8k with small language models. ArXiv, abs/2312.09241.
- Liu et al. (2022) Chang Liu, Chongyang Tao, Jiazhan Feng, and Dongyan Zhao. 2022. Multi-granularity structural knowledge distillation for language model compression. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 1001–1011, Dublin, Ireland. Association for Computational Linguistics.
- MetaAI (2024) MetaAI. 2024. Introducing meta llama 3: The most capable openly available llm to date.
- Mirzadeh et al. (2020) Seyed Iman Mirzadeh, Mehrdad Farajtabar, Ang Li, Nir Levine, Akihiro Matsukawa, and Hassan Ghasemzadeh. 2020. Improved knowledge distillation via teacher assistant. Proceedings of the AAAI Conference on Artificial Intelligence, 34(04):5191–5198.
- Mitra et al. (2023) Arindam Mitra, Luciano Del Corro, Shweti Mahajan, Andres Codas, Clarisse Simoes, Sahaj Agarwal, Xuxi Chen, Anastasia Razdaibiedina, Erik Jones, Kriti Aggarwal, et al. 2023. Orca 2: Teaching small language models how to reason. arXiv preprint arXiv:2311.11045.
- Mukherjee et al. (2023) Subhabrata Mukherjee, Arindam Mitra, Ganesh Jawahar, Sahaj Agarwal, Hamid Palangi, and Ahmed Hassan Awadallah. 2023. Orca: Progressive learning from complex explanation traces of gpt-4. ArXiv, abs/2306.02707.
- OpenAI (2022) OpenAI. 2022. Introducing chatgpt. Technical report.
- OpenAI (2023) OpenAI. 2023. Gpt-4 is openai’s most advanced system, producing safer and more useful responses. Technical report.
- Park et al. (2021) Geondo Park, Gyeongman Kim, and Eunho Yang. 2021. Distilling linguistic context for language model compression. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pages 364–378, Online and Punta Cana, Dominican Republic. Association for Computational Linguistics.
- Rafailov et al. (2024) Rafael Rafailov, Archit Sharma, Eric Mitchell, Christopher D Manning, Stefano Ermon, and Chelsea Finn. 2024. Direct preference optimization: Your language model is secretly a reward model. Advances in Neural Information Processing Systems, 36.
- Sanh et al. (2019) Victor Sanh, Lysandre Debut, Julien Chaumond, and Thomas Wolf. 2019. Distilbert, a distilled version of bert: smaller, faster, cheaper and lighter. arXiv preprint arXiv:1910.01108.
- Sun et al. (2019) Siqi Sun, Yu Cheng, Zhe Gan, and Jingjing Liu. 2019. Patient knowledge distillation for BERT model compression. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP), pages 4323–4332, Hong Kong, China. Association for Computational Linguistics.
- Suzgun et al. (2022) Mirac Suzgun, Nathan Scales, Nathanael Scharli, Sebastian Gehrmann, Yi Tay, Hyung Won Chung, Aakanksha Chowdhery, Quoc V. Le, Ed Huai hsin Chi, Denny Zhou, and Jason Wei. 2022. Challenging big-bench tasks and whether chain-of-thought can solve them. In Annual Meeting of the Association for Computational Linguistics.
- Talmor et al. (2019) Alon Talmor, Jonathan Herzig, Nicholas Lourie, and Jonathan Berant. 2019. CommonsenseQA: A question answering challenge targeting commonsense knowledge. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), pages 4149–4158, Minneapolis, Minnesota. Association for Computational Linguistics.
- Taori et al. (2023) Rohan Taori, Ishaan Gulrajani, Tianyi Zhang, Yann Dubois, Xuechen Li, Carlos Guestrin, Percy Liang, and Tatsunori B. Hashimoto. 2023. Stanford alpaca: An instruction-following llama model. https://github.com/tatsu-lab/stanford_alpaca.
- Team et al. (2023) Gemini Team, Rohan Anil, Sebastian Borgeaud, Yonghui Wu, Jean-Baptiste Alayrac, Jiahui Yu, Radu Soricut, Johan Schalkwyk, Andrew M Dai, Anja Hauth, et al. 2023. Gemini: a family of highly capable multimodal models. arXiv preprint arXiv:2312.11805.
- Touvron et al. (2023a) Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, et al. 2023a. Llama: Open and efficient foundation language models. arXiv preprint arXiv:2302.13971.
- Touvron et al. (2023b) Hugo Touvron, Louis Martin, Kevin R. Stone, Peter Albert, et al. 2023b. Llama 2: Open foundation and fine-tuned chat models. ArXiv, abs/2307.09288.
- Wang et al. (2021) Wenhui Wang, Hangbo Bao, Shaohan Huang, Li Dong, and Furu Wei. 2021. MiniLMv2: Multi-head self-attention relation distillation for compressing pretrained transformers. In Findings of the Association for Computational Linguistics: ACL-IJCNLP 2021, pages 2140–2151, Online. Association for Computational Linguistics.
- Wen et al. (2023) Yuqiao Wen, Zichao Li, Wenyu Du, and Lili Mou. 2023. f-divergence minimization for sequence-level knowledge distillation. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 10817–10834, Toronto, Canada. Association for Computational Linguistics.
- Wu et al. (2023) Siyue Wu, Hongzhan Chen, Xiaojun Quan, Qifan Wang, and Rui Wang. 2023. AD-KD: Attribution-driven knowledge distillation for language model compression. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 8449–8465, Toronto, Canada. Association for Computational Linguistics.
- Xu et al. (2023) Can Xu, Qingfeng Sun, Kai Zheng, Xiubo Geng, Pu Zhao, Jiazhan Feng, Chongyang Tao, and Daxin Jiang. 2023. Wizardlm: Empowering large language models to follow complex instructions.
- Yin et al. (2020) Hongxu Yin, Pavlo Molchanov, Jose M Alvarez, Zhizhong Li, Arun Mallya, Derek Hoiem, Niraj K Jha, and Jan Kautz. 2020. Dreaming to distill: Data-free knowledge transfer via deepinversion. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 8715–8724.
- Zeng (2023) Hui Zeng. 2023. Measuring massive multitask chinese understanding. ArXiv, abs/2304.12986.
- Zhong et al. (2023) Wanjun Zhong, Ruixiang Cui, Yiduo Guo, Yaobo Liang, Shuai Lu, Yanlin Wang, Amin Saied Sanosi Saied, Weizhu Chen, and Nan Duan. 2023. Agieval: A human-centric benchmark for evaluating foundation models. ArXiv, abs/2304.06364.
- Zhu et al. (2023) Banghua Zhu, Evan Frick, Tianhao Wu, Hanlin Zhu, and Jiantao Jiao. 2023. Starling-7b: Improving llm helpfulness and harmlessness with rlaif.
Appendix A Experimental Analysis
Models #GPUs Hours/Round Llama-7B-SFT 4 1.0 Llama-7B-Distill 4 2.0 Llama-7B-GKD 8 10.0 Llama-13B-SFT 8 1.8 Llama-13B-Pref 8 9.0 Llama-70B-SFT 8 5.5 Llama-70B-Pref 8 28.0
模型 #GPU数 小时/轮 Llama-7B-SFT 4 1.0 Llama-7B-Distill 4 2.0 Llama-7B-GKD 8 10.0 Llama-13B-SFT 8 1.8 Llama-13B-Pref 8 9.0 Llama-70B-SFT 8 5.5 Llama-70B-Pref 8 28.0A.1 Analysis of Training EfficiencyA.1 训练效率分析
We show the training time overhead for different methods in Table 3. We show the training hours per round for supervised fine-tuning, knowledge distillation, and preference optimization methods across various model sizes. Each round contains 40K training samples. We note that preference optimization is the main time overhead due to online sampling from the proxy model. In Proxy-KD, we obtain the proxy model’s output distribution offline during student distillation. As Figure 4 shows, most probability mass is concentrated on a few tokens. To save memory, only the top 10 token indices and their logits are retained.我们在表 3 中展示了不同方法的训练时间开销。我们展示了各种模型规模下监督微调、知识蒸馏和偏好优化方法每轮的训练小时数。每轮包含 40K 个训练样本。我们注意到,由于需要从代理模型进行在线采样,偏好优化是主要的时间开销。 在 Proxy-KD 中,我们在学生蒸馏期间离线获取代理模型的输出分布。如图 4 所示,大部分概率质量集中在少数几个 token 上。为了节省内存,仅保留前 10 个 token 的索引及其 logits。

A.2 Output Token AgreementA.2 输出 Token 一致性
To serve as a stand-in for the teacher model’s output distribution, it’s important for the proxy model’s output to align with the teacher model’s output distribution, which is achieved through proxy model alignment. We measure the change in agreement between the top-1 token given by the proxy and the token provided by teacher in current step, before and after alignment. To visualize this alignment, at each step, consider the top-1 token given by the proxy’s output distribution and the token given by the teacher. If the top-1 token given by the proxy matches the token given by the teacher at the current step, it is considered a match; otherwise, it is considered a mismatch. As shown in Figure 5, We find that after the proxy model alignment, the matched portions show a significant upward trend, indicating a trend towards alignment.为了作为教师模型输出分布的替代,代理模型的输出与教师模型的输出分布对齐非常重要,这通过代理模型对齐来实现。我们测量了对齐前后,代理给出的 top-1 token 与教师当前步骤给出的 token 之间一致性的变化。 为了可视化这种对齐,在每个步骤中,考虑代理输出分布给出的 top-1 token 和教师给出的 token。如果代理给出的 top-1 token 与教师当前步骤给出的 token 匹配,则视为匹配;否则视为不匹配。 如图 5 所示,我们发现代理模型对齐后,匹配部分呈现显著上升趋势,表明对齐趋势。

A.3 Additional ResultsA.3 附加结果
We present the performance changes of student models during the distillation in Figure 6 and 7. The student models are based on Llama-2-7B and Llama-1-7B backbone, and the proxy models are based on Llama-2-70B backbone. We test the accuracy of students on benchmarks for every 20K training steps. We compare Proxy-KD with vanilla black-box KD method and white-box KD method (Forward KL with Llama-2-70b-chat as white-box teacher) . We observe Proxy-KD consistently outperform vanilla black-box KD and white-box KD.我们在图 6 和图 7 中展示了蒸馏过程中学生模型的性能变化。学生模型基于 Llama-2-7B 和 Llama-1-7B 骨干,代理模型基于 Llama-2-70B 骨干。我们每隔 20K 训练步骤测试学生在基准上的准确率。我们将 Proxy-KD 与普通黑盒 KD 方法以及白盒 KD 方法(以 Llama-2-70b-chat 作为白盒教师的前向 KL)进行比较。我们观察到 Proxy-KD 持续优于普通黑盒 KD 和白盒 KD。

