Less is More: Task-aware Layer-wise Distillation for Language Model Compression

Chen Liang, Simiao Zuo, Qingru Zhang, Pengcheng He, Weizhu Chen, Tuo Zhao

Abstract

Layer-wise distillation is a powerful tool to compress large models (i.e. teacher models) into small ones (i.e., student models). The student distills knowledge from the teacher by mimicking the hidden representations of the teacher at every intermediate layer. However, layer-wise distillation is difficult. Since the student has a smaller model capacity than the teacher, it is often under-fitted. Furthermore, the hidden representations of the teacher contain redundant information that the student does not necessarily need for the target task's learning. To address these challenges, we propose a novel Task-aware layEr-wise Distillation (TED). TED designs task-aware filters to align the hidden representations of the student and the teacher at each layer. The filters select the knowledge that is useful for the target task from the hidden representations. As such, TED reduces the knowledge gap between the two models and helps the student to fit better on the target task. We evaluate TED in two scenarios: continual pre-training and fine-tuning. TED demonstrates significant and consistent improvements over existing distillation methods in both scenarios. Code is available at https://github.com/cliang1453/task-aware-distillation.

Introduction

Large Language Models (LLMs) are incredibly capable but prohibitively expensive to deploy in resource-constrained environments. Knowledge Distillation (KD) is the standard solution, where a small "student" model learns to mimic a large "teacher." While matching the final outputs of a teacher is common, layer-wise distillation—where the student tries to match the internal hidden representations of the teacher at every layer—usually yields better results.

However, layer-wise distillation faces two major hurdles: the Capacity Gap, where a tiny student model lacks the capacity to replicate the complex internal states of a massive teacher, and Information Redundancy, where teacher models contain general knowledge that is unnecessary for specific tasks. Forcing a student to learn this "noise" wastes its limited capacity.

Methodology: Task-Aware Layer-wise Distillation (TED)

To address these challenges, we propose TED (Task-aware layEr-wise Distillation), a two-stage training framework designed to make distillation more efficient for the student by filtering out task-irrelevant information.

The TED framework consists of two stages: (Left) Stage I trains task-aware filters to extract task-relevant knowledge. (Right) Stage II performs distillation by matching the filtered representations.
  • Stage I: Training Task-Aware Filters. For every layer in both the teacher and the student, small "filters" (neural network heads) are attached. These filters are trained to predict the target task using only the hidden representations from that specific layer. Crucially, the main model weights are frozen during this stage, identifying exactly which features in each layer are useful for the task.
  • Stage II: Task-Aware Distillation. The student is then trained to match the filtered representations of the teacher rather than the raw hidden states. By matching the outputs of these filters, the student only learns the task-relevant knowledge extracted by the teacher, effectively ignoring redundant information.

Experimental Results

The researchers evaluated TED across two primary scenarios: continual pre-training (GPT-2) and task-specific fine-tuning (DeBERTaV3).

  • NLU Performance: On the GLUE benchmark, TED achieved an average score of 87.5, outperforming standard layer-wise distillation (87.0) and basic KD (87.0).
  • Question Answering: On SQuAD v2.0, TED reached an EM/F1 score of 83.0/85.8, a notable improvement over the best baseline.
  • Robustness to Capacity Gaps: In a "stress test" distilling a DeBERTaV3-large (435M params) into an xsmall (70M params) model, standard methods actually performed worse than simple fine-tuning. TED maintained its gains, proving its effectiveness at extreme compression ratios.
  • Language Modeling: TED reduced perplexity on Open WebText from 29.7 (standard layer-wise) to 28.5.

Key Insights

The core philosophy of TED is that "Less is More": by asking the student to learn only task-relevant information, it actually learns more effectively. The task-aware filters act as a selection mechanism, pointing the student toward the specific knowledge needed for downstream tasks. This reduces the discrepancy between the two models, leading to faster convergence and lower training loss compared to standard methods.

Limitations and Future Work

While TED introduces a slight training overhead (roughly 10% during distillation), it does not affect inference speed as filters are discarded after training. Current limitations include the requirement for task-specific filters and access to the teacher's internal states. Future work may explore multi-task distillation and synthetic data generation to support black-box teacher models.

Summary updated

BibTeX
@inproceedings{liang2023less,
  author = {Chen Liang and Simiao Zuo and Qingru Zhang and Pengcheng He and Weizhu Chen and Tuo Zhao},
  title = {{Less is More: Task-aware Layer-wise Distillation for Language Model Compression}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=B6J3ygdPJh},
}
Figure