Why Can You Lay Off Heads? Investigating How BERT Heads Transfer

Ting-Rui Chiang, Yun-Nung ChenarXiv 2021

TL;DR

This paper investigates how much of a BERT model's "brain" (specifically, its attention heads) can be removed while retaining performance, aiming to guide the creation of smaller, more efficient models through distillation. They find that RoBERTa is surprisingly robust to head pruning, suggesting significant redundancy, and that head importance for pre-training and downstream tasks are not strongly correlated, hinting at interesting transfer learning dynamics.

What Problem Does This Paper Address?

Large language models like BERT are incredibly powerful but also computationally expensive, making them difficult to deploy on resource-constrained devices or for real-time applications. Model distillation is a popular technique to create smaller, faster models by training a "student" model to mimic a larger "teacher" model. However, a key goal is to create task-agnostic distilled models – models that can be fine-tuned on new tasks without extensive retraining. This paper probes the fundamental question of how much of a pre-trained BERT model can be "laid off" (pruned) without sacrificing performance, and how the importance of different model components (attention heads) changes between pre-training and downstream tasks. Understanding this is crucial for developing effective distillation strategies that yield truly efficient and adaptable models.

Methods

The core of this research involves analyzing the "prunability" of Transformer heads in pre-trained models like RoBERTa and ALBERT. They leverage an existing method for estimating head importance, which involves calculating the gradient of the loss with respect to the head's output.

  • Head Importance Estimation: They adapt the head importance estimation technique proposed by Michel et al. (2019). For RoBERTa, this involves calculating the gradient of the loss with respect to the output of each specific head in each layer. For ALBERT, due to its parameter sharing across layers, the importance is aggregated across all layers for each head.
  • Normalization Strategies: They experiment with different normalization methods (L1 norm, L2 norm, and no normalization) for the importance scores, aiming to find the most effective one for pruning.
  • Pruning: Based on the estimated importance scores, they iteratively prune heads, starting from the least important ones, and observe the impact on model performance.
  • Behavioral Comparison: They also compare the attention weights and intermediate layer outputs of pre-trained and fine-tuned models to understand how knowledge is transferred and how feature representations evolve.

Datasets

The experiments were conducted on four GLUE benchmark tasks:

  • CoLA (Corpus of Linguistic Acceptability)
  • SST-2 (Stanford Sentiment Treebank)
  • QQP (Quora Question Pairs)
  • MNLI (Multi-Genre Natural Language Inference)

For pre-training analysis, they used a subset of the WikiDump.

Key Insights and Ideas

  • RoBERTa's Surprising Redundancy: RoBERTa models exhibit remarkable resilience to head pruning. They can retain over 90% of their performance even when more than 50% of their attention heads are removed, suggesting significant redundancy in the model's architecture.
  • ALBERT's Lower Prunability: In contrast, ALBERT models show a more rapid performance drop when heads are pruned, especially on tasks like CoLA and MNLI. This is attributed to ALBERT having fewer heads (12) compared to RoBERTa-Large (384).
  • L1 Norm for Better Importance: Normalizing head importance scores using the L1 norm appears to be more effective for pruning, leading to better performance retention compared to L2 norm or no normalization.
  • Weak Correlation Between Pre-train and Downstream Head Importance: A key finding is the surprisingly weak correlation (≤ 0.10) between the importance of heads for the pre-training task and their importance for downstream tasks. This suggests that heads crucial for pre-training might not be the same ones that are critical for specific downstream applications, complicating the goal of a truly task-agnostic distilled model.
  • Feature Matching as a Viable Distillation Strategy: Comparing the outputs of intermediate layers in pre-trained and fine-tuned models suggests that feature matching is a promising direction for BERT distillation.

Key Results

  • RoBERTa-Large can be slimmed down by at least 50% by pruning heads while maintaining over 75% of its original performance on downstream tasks.
  • The paper provides a guideline for distillation: retaining approximately 75% relative performance on the pre-train task is a good indicator for successful downstream task performance.
  • JS divergence analysis shows that lower-level features required for pre-training are generally coherent with those needed for downstream tasks.
  • Freezing the lower layers of RoBERTa and fine-tuning the upper layers still yields competitive performance on downstream tasks, supporting the idea that lower layers capture generalizable features.

Limitations and Future Work

  • Task-Agnostic Goal Remains Challenging: While significant pruning is possible, the weak correlation between pre-train and downstream head importance highlights the difficulty in creating a perfectly task-agnostic model through simple head pruning alone.
  • Future Work: The authors suggest further investigation into the roles heads play during fine-tuning, especially given the weak correlation observed. They also propose that feature matching is a promising avenue for future distillation research. The paper's findings provide guidance for future research in BERT family model distillation, particularly in understanding head redundancy and transferability.

Summary updated

Abstract

The huge size of the widely used BERT family models has led to recent efforts about model distillation. The main goal of distillation is to create a task-agnostic pre-trained model that can be fine-tuned on downstream tasks without fine-tuning its full-sized version. Despite the progress of distillation, to what degree and for what reason a task-agnostic model can be created from distillation has not been well studied. Also, the mechanisms behind transfer learning of those BERT models are not well investigated either. Therefore, this work focuses on analyzing the acceptable deduction when distillation for guiding the future distillation procedure. Specifically, we first inspect the prunability of the Transformer heads in RoBERTa and ALBERT using their head importance estimation proposed by Michel et al. (2019), and then check the coherence of the important heads between the pre-trained task and downstream tasks. Hence, the acceptable deduction of performance on the pre-trained task when distilling a model can be derived from the results, and we further compare the behavior of the pruned model before and after fine-tuning. Our studies provide guidance for future directions about BERT family model distillation.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
CoLA · GLUERoBERTa with five lower layers frozenRelative performance0.91fine-tuned · backbone=RoBERTa · frozen-layers=5
Source quote
L157: As a result, the partly frozen model achieves relative performance 0.91 on CoLA, and more than 0.98 on the reset three tasks.
BibTeX
@misc{chiang2021why,
  author = {Ting-Rui Chiang and Yun-Nung Chen},
  title = {{Why Can You Lay Off Heads? Investigating How BERT Heads Transfer}},
  year = {2021},
  eprint = {2106.07137},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2106.07137},
}
Figure