A Metamorphic Testing Perspective on Knowledge Distillation for Language Models of Code: Does the Student Deeply Mimic the Teacher?
作者: Md. Abdul Awal, Mrigank Rochan, Chanchal K. Roy
分类: cs.SE, cs.LG
发布日期: 2025-11-07
备注: The paper is currently under review at a peer-reviewed journal
💡 一句话要点
提出MetaCompress,用于评估代码语言模型知识蒸馏的保真度。
🎯 匹配领域: 支柱二:RL算法与架构 (RL & Architecture) 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 知识蒸馏 代码语言模型 变质测试 模型压缩 行为保真度
📋 核心要点
- 现有基于准确率的评估无法充分衡量学生模型对教师模型的行为模仿程度,忽略了深层次的行为差异。
- MetaCompress通过变质测试,系统性地比较教师和学生模型在行为保持变换下的输出,评估行为保真度。
- 实验表明,MetaCompress能有效识别学生模型中高达62%的行为差异,揭示了传统评估的局限性。
📝 摘要(中文)
基于Transformer的代码语言模型在各种软件分析任务中表现出色,但由于计算成本高、推理速度慢和环境影响大,实际部署受到限制。知识蒸馏作为一种压缩大型代码语言模型(教师模型)到小型模型(学生模型)的方法,同时保持性能,受到了越来越多的关注。然而,学生模型在多大程度上深入模仿教师模型的预测行为和内部表示仍然很大程度上未被探索,因为当前基于准确性的评估仅提供了模型质量的表面视图,并且常常未能捕捉到教师模型和学生模型之间行为保真度方面更深层次的差异。为了解决这个问题,我们通过实验证明,学生模型通常未能深入模仿教师模型,导致在对抗性攻击下性能下降高达285%,而传统的基于准确性的评估无法捕捉到这一点。因此,我们提出了MetaCompress,一个变质测试框架,通过比较教师模型和学生模型在一组保持行为的变质关系下的输出来系统地评估行为保真度。我们使用三种不同的知识蒸馏技术(Compressor、AVATAR和MORPH)获得的流行代码语言模型的压缩版本,在两个广泛研究的任务上评估MetaCompress。结果表明,MetaCompress识别出学生模型中高达62%的行为差异,强调了知识蒸馏管道中行为保真度评估的必要性,并将MetaCompress确立为测试通过知识蒸馏获得的压缩代码语言模型的实用框架。
🔬 方法详解
问题定义:论文旨在解决知识蒸馏在代码语言模型压缩过程中,学生模型是否能真正模仿教师模型的行为这一问题。现有基于准确率的评估方法无法充分捕捉学生模型与教师模型在行为上的细微差异,尤其是在面对对抗性攻击时,学生模型的脆弱性可能被低估。
核心思路:论文的核心思路是利用变质测试(Metamorphic Testing)来评估学生模型对教师模型的行为模仿程度。变质测试通过定义一系列行为保持的变质关系(Metamorphic Relations),并比较模型在原始输入和变换后的输入上的输出,从而检测模型是否存在不一致的行为。如果学生模型能够很好地模仿教师模型,那么它们在相同的变质关系下应该表现出相似的行为。
技术框架:MetaCompress框架包含以下主要步骤:1) 选择或设计适用于代码语言模型的变质关系;2) 对原始输入进行变质变换,生成新的测试用例;3) 分别使用教师模型和学生模型对原始输入和变换后的输入进行预测;4) 比较教师模型和学生模型在变质关系下的输出,如果输出不一致,则认为学生模型未能很好地模仿教师模型。框架的核心在于变质关系的定义,需要确保这些关系能够有效地揭示模型行为上的差异。
关键创新:MetaCompress的关键创新在于将变质测试应用于评估代码语言模型知识蒸馏的保真度。与传统的基于准确率的评估方法相比,MetaCompress能够更深入地挖掘学生模型与教师模型在行为上的差异,尤其是在面对对抗性攻击等复杂场景下。这种方法提供了一种更全面的模型质量评估方式。
关键设计:论文中,变质关系的设计是关键。具体的设计细节取决于所评估的代码语言模型的任务类型。例如,对于代码补全任务,可以设计诸如变量重命名、注释添加等变质关系。此外,还需要定义一个合适的指标来衡量教师模型和学生模型在变质关系下的输出差异。例如,可以使用编辑距离或语义相似度等指标。
🖼️ 关键图片
📊 实验亮点
实验结果表明,MetaCompress能够识别出学生模型中高达62%的行为差异,这些差异无法通过传统的基于准确率的评估方法发现。此外,实验还发现,在对抗性攻击下,学生模型的性能下降幅度比教师模型高出285%,进一步验证了MetaCompress在评估模型鲁棒性方面的有效性。
🎯 应用场景
MetaCompress可应用于代码语言模型的知识蒸馏流程中,作为一种有效的模型质量评估工具。它可以帮助研究人员和开发人员选择更合适的知识蒸馏方法,并优化学生模型的训练过程,从而提高压缩模型的可靠性和鲁棒性。此外,该方法也可推广到其他类型的语言模型和知识蒸馏场景。
📄 摘要(原文)
Transformer-based language models of code have achieved state-of-the-art performance across a wide range of software analytics tasks, but their practical deployment remains limited due to high computational costs, slow inference speeds, and significant environmental impact. To address these challenges, recent research has increasingly explored knowledge distillation as a method for compressing a large language model of code (the teacher) into a smaller model (the student) while maintaining performance. However, the degree to which a student model deeply mimics the predictive behavior and internal representations of its teacher remains largely unexplored, as current accuracy-based evaluation provides only a surface-level view of model quality and often fails to capture more profound discrepancies in behavioral fidelity between the teacher and student models. To address this gap, we empirically show that the student model often fails to deeply mimic the teacher model, resulting in up to 285% greater performance drop under adversarial attacks, which is not captured by traditional accuracy-based evaluation. Therefore, we propose MetaCompress, a metamorphic testing framework that systematically evaluates behavioral fidelity by comparing the outputs of teacher and student models under a set of behavior-preserving metamorphic relations. We evaluate MetaCompress on two widely studied tasks, using compressed versions of popular language models of code, obtained via three different knowledge distillation techniques: Compressor, AVATAR, and MORPH. The results show that MetaCompress identifies up to 62% behavioral discrepancies in student models, underscoring the need for behavioral fidelity evaluation within the knowledge distillation pipeline and establishing MetaCompress as a practical framework for testing compressed language models of code derived through knowledge distillation.