Improving task-agnostic BERT distillation with layer mapping search

Xiaoqi Jiao, Huating Chang, Yichun Yin, Lifeng Shang, Xin Jiang, Xiao Chen, Linlin Li, Fang Wang, Qun Liu

TL;DR

This paper tackles the challenge of efficiently compressing large BERT models for deployment by automatically discovering optimal layer mappings for knowledge distillation. They introduce a genetic algorithm-based search (ELM) that significantly outperforms hand-crafted heuristics, leading to state-of-the-art performance on downstream tasks.

What Problem Does This Paper Address?

Pre-trained language models like BERT are incredibly powerful but also computationally expensive, making them difficult to deploy on resource-constrained devices. Knowledge Distillation (KD) is a popular technique to compress these models by training a smaller "student" model to mimic a larger "teacher" model. While KD has been successful, a key aspect for BERT distillation is "layer-level supervision," where the student learns from intermediate layers of the teacher. However, previous methods relied on heuristic layer mappings (e.g., mapping every few layers or just the last layer), which might not be optimal. The authors identify two main problems: 1) the sub-optimality of current heuristic layer mappings and 2) the difficulty in discovering better mappings due to the massive search space and computational cost of distillation.

Methods

The core of this paper is the Evolved Layer Mapping (ELM) framework, which uses a genetic algorithm (GA) to automatically search for the best layer mapping strategy. Here's how it works:

  • Gene Encoding: Each layer mapping is represented as a "gene," essentially a binary string that defines which teacher layer(s) each student layer should learn from. The search space includes options for student layers to learn from specific teacher layers or to learn from "None" (i.e., not learn from any teacher layer).
  • Proxy Setting: To make the search computationally feasible, they employ a "proxy setting." This involves using only 10% of the training corpus for distillation during the search phase and evaluating candidate mappings on a few representative "proxy tasks." This significantly reduces the search time (by about 10x) while aiming to preserve the relative performance order of different mappings.
  • Genetic Algorithm: The GA iteratively evolves a population of layer mappings. It involves:
  • Initialization: Creating an initial random set of layer mappings.
  • Distillation & Evaluation: Performing task-agnostic BERT distillation for each gene (mapping) in the current generation to create student models. These students are then fine-tuned on proxy tasks to obtain a "fitness score."
    • Selection: Genes with higher fitness scores are more likely to be selected for the next generation.
  • Crossover & Mutation: Genetic operators like crossover (combining parts of two parent genes) and mutation (randomly flipping bits in a gene) are used to create new, potentially better, offspring genes.
  • Final Distillation: Once the GA converges on an optimal layer mapping, the task-agnostic distillation is performed on the full training corpus using this discovered mapping to produce the final compact student model.

Datasets

The paper uses the following datasets:

  • Unsupervised Corpus for Distillation: BooksCorpus and English Wikipedia.
  • Proxy Tasks for GA Evaluation: SST-2 (sentiment analysis), MNLI (natural language inference), and SQuAD v1.1 (extractive question answering).
  • Downstream Tasks for Final Evaluation: GLUE benchmark tasks, including SST-2, MNLI, SQuAD v1.1, SQuAD v2.0, MRPC, CoLA, QNLI, and QQP.
  • Chinese Tasks (Appendix): Chinese Wikipedia (for distillation) and ChineseGLUE tasks (CMNLI, CSL, CMRC 2018) for evaluation.

Key Insights and Ideas

  • Layer Mapping is Crucial: The study strongly demonstrates that the choice of layer mapping strategy has a significant impact on the performance of task-agnostic BERT distillation. Different mappings can lead to quite different results, highlighting the importance of this component.
  • Heuristics are Sub-optimal: Hand-crafted heuristics like "uniform" or "last-layer" mapping, while intuitive, are not optimal and can be outperformed by automatically discovered mappings.
  • Intermediate Layers Matter: The ELM-discovered mappings often favor distilling from intermediate layers of the teacher model, aligning with prior research suggesting these layers are more transferable. Top layers might be too task-specific to the pre-training objective.
  • Proxy Setting Effectiveness: The proxy setting (using 10% of data) is shown to be effective for guiding the GA search. While absolute performance might differ slightly from full-corpus training, the relative order of performance among different mappings remains consistent, validating its use for efficient search.
  • Generalization: The optimal layer mapping found through the search process generalizes well to various downstream tasks, even those not explicitly used in the proxy evaluation.
  • Task-Specific Boost: The learned optimal layer mapping can also be beneficial for task-specific distillation, further improving performance beyond what was achieved with task-agnostic distillation.

Key Results

  • State-of-the-Art Performance: The ELM framework consistently outperforms heuristic layer mapping strategies (Uniform, Last-Layer, Contribution-based) across multiple datasets.
  • Significant Gains: For instance, on the GLUE benchmark, the ELM-derived student models achieve state-of-the-art results for their size. For a 6-layer student, ELM achieved an average GLUE score of 79.2, outperforming baselines. For a 4-layer student, ELM achieved an average of 74.9.
  • CoLA Improvement: The ELM-derived 6-layer student achieved 54.2 mcc on CoLA, a notable gain over other approaches.
  • Efficiency: The proxy setting reduces the search time by approximately 10x, making the optimization process practical.
  • Chinese Tasks: The ELM approach also shows effectiveness on Chinese NLP tasks, outperforming baselines by at least 2.2% on average.

Limitations and Future Work

  • Computational Resources: While the proxy setting significantly reduces computational cost, the GA search still requires substantial resources. The authors mention that finding an optimal ELM for multilingual tasks would require even more computational resources.
  • Future Work: The authors suggest applying the ELM framework to more scenarios, such as searching for better distillation objectives and architectures for student models, especially under limited resource constraints. They also propose investigating optimal ELMs for multilingual tasks.

Summary updated

BibTeX
@article{jiao2021improving,
  author = {Xiaoqi Jiao and Huating Chang and Yichun Yin and Lifeng Shang and Xin Jiang and Xiao Chen and Linlin Li and Fang Wang and Qun Liu},
  title = {{Improving task-agnostic BERT distillation with layer mapping search}},
  journal = {Neurocomputing},
  year = {2021},
  doi = {10.1016/j.neucom.2021.07.050},
}
Figure