HomoDistil: Homotopic Task-Agnostic Distillation of Pre-trained Transformers

Chen Liang, Haoming Jiang, Zheng Li, Xianfeng Tang, Bin Yin, Tuo Zhao

Introduction

The rapid advancement of Transformer-based models like BERT and RoBERTa has revolutionized natural language processing. However, their massive parameter counts pose significant challenges for deployment in resource-constrained environments. While Knowledge Distillation (KD) is the standard technique for compressing these models into smaller "students," task-agnostic distillation—compressing a model before it is fine-tuned for specific tasks—remains a difficult frontier.

The primary obstacle in this process is the "capacity gap." When a small student model attempts to mimic a large teacher model across broad, open-domain datasets, the discrepancy in their representational power often leads to poor convergence. HomoDistil addresses this by introducing a homotopic approach: instead of training a small student from scratch, the method iteratively prunes the teacher model into a student, maintaining a close "distance" between the two throughout the entire shrinking process.

The Homotopic Framework

In mathematics, a homotopy represents a continuous transformation between two functions. HomoDistil applies this principle to model architecture, bridging the gap between a high-capacity teacher and a low-capacity student through a sequence of intermediate models.

1. Initialization and Iterative Pruning

Unlike traditional KD, which starts with a randomly initialized student, HomoDistil begins with the full-sized teacher model as the starting point. At this initial stage, the prediction discrepancy is zero. The model is then gradually compressed using an iterative pruning schedule.

The pruning process utilizes a sensitivity score based on the first-order Taylor expansion of the loss function. This metric identifies neurons whose removal has the least impact on the model's performance, proving more effective than simple weight-magnitude pruning. By removing neurons incrementally, the model undergoes a smooth transition from a large architecture to a compact one.

2. Simultaneous Distillation

As the model shrinks, it undergoes continuous distillation. The training objective is a multi-faceted loss function that includes:

  • Masked Language Modeling (MLM): The standard pre-training objective to maintain linguistic knowledge.
  • Distillation Losses: KL divergence on output distributions, and Mean Squared Error (MSE) on hidden states, embeddings, and attention scores.

By enforcing local sparsity on individual weight matrices rather than global pruning, the resulting models remain compatible with standard hardware accelerators and deep learning libraries.

Experimental Results

The authors evaluated the resulting HomoBERT models on the GLUE benchmark and SQuAD (v1.1 and v2.0) after pre-training on English Wikipedia and the Toronto BookCorpus.

Performance on GLUE

HomoBERT demonstrated significant improvements over established baselines like DistilBERT and TinyBERT:

  • HomoBERT-base (65M parameters): Outperformed MiniLMv2 (66M) on the GLUE average score.
  • HomoBERT-tiny (14.1M parameters): Achieved a 3.3-point lead over TinyBERT (14.5M) and even surpassed BERT-small (28.6M), a model with twice the parameters.

Performance on SQuAD

In extractive question-answering tasks, the homotopic approach proved particularly effective at preserving complex reasoning. HomoBERT-xsmall (15.6M) outperformed MiniLM (17.3M) by 3.8 points on SQuAD v2.0, suggesting that the gradual pruning process better retains the nuanced knowledge required for QA than standard distillation methods.

Discussion and Limitations

The success of HomoDistil highlights the importance of the "Effective Distillation Region." By keeping the student close to the teacher's representational space, the student can effectively inherit the teacher's knowledge without being overwhelmed by the capacity gap.

However, the study notes a distinction between pruning "width" (hidden dimensions) and "height" (number of layers). While width pruning is highly effective in a homotopic framework, removing entire layers causes a sudden "jump" in prediction discrepancy that is difficult for the model to bridge. Additionally, while the final student models are highly efficient, the distillation process itself is computationally intensive, as it requires training starting from the full teacher model.

Conclusion

HomoDistil provides a robust framework for task-agnostic distillation by reframing model compression as a continuous transformation. By maintaining a minimal prediction discrepancy during the shrinking process, HomoBERT models achieve state-of-the-art performance at various scales, offering a powerful solution for deploying high-performance Transformers on edge devices.

Summary updated

BibTeX
@inproceedings{liang2023homodistil,
  author = {Chen Liang and Haoming Jiang and Zheng Li and Xianfeng Tang and Bin Yin and Tuo Zhao},
  title = {{HomoDistil: Homotopic Task-Agnostic Distillation of Pre-trained Transformers}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=D7srTrGhAs},
}
Figure