Skip to main content
QUICK REVIEW

[Paper Review] MiniLMv2: Multi-Head Self-Attention Relation Distillation for Compressing Pretrained Transformers

Wenhui Wang, Hangbo Bao|arXiv (Cornell University)|Dec 31, 2020
Topic ModelingComputer Science45 references15 citations
TL;DR

This paper proposes MiniLMv2, a knowledge distillation method that uses multi-head self-attention relation distillation to compress pretrained Transformers without requiring matching attention head counts between teacher and student models. By distilling fine-grained scaled dot-product relations between query, key, and value vectors across multiple relation heads, the method achieves state-of-the-art performance on monolingual and multilingual tasks, with a 6×768 model distilled from BERT Large outperforming BERT Base while being 2× faster.

ABSTRACT

We generalize deep self-attention distillation in MiniLM (Wang et al., 2020) by only using self-attention relation distillation for task-agnostic compression of pretrained Transformers. In particular, we define multi-head self-attention relations as scaled dot-product between the pairs of query, key, and value vectors within each self-attention module. Then we employ the above relational knowledge to train the student model. Besides its simplicity and unified principle, more favorably, there is no restriction in terms of the number of student's attention heads, while most previous work has to guarantee the same head number between teacher and student. Moreover, the fine-grained self-attention relations tend to fully exploit the interaction knowledge learned by Transformer. In addition, we thoroughly examine the layer selection strategy for teacher models, rather than just relying on the last layer as in MiniLM. We conduct extensive experiments on compressing both monolingual and multilingual pretrained models. Experimental results demonstrate that our models distilled from base-size and large-size teachers (BERT, RoBERTa and XLM-R) outperform the state-of-the-art.

Motivation & Objective

  • To address the limitation in knowledge distillation where student and teacher models must have the same number of attention heads.
  • To improve model compression by leveraging fine-grained self-attention relations rather than just attention distributions.
  • To identify optimal teacher layers for distillation, especially for large models with many layers.
  • To achieve state-of-the-art performance in both monolingual and multilingual settings using task-agnostic distillation.
  • To enable flexible student model design by decoupling the number of attention heads from the teacher.

Proposed method

  • The method defines multi-head self-attention relations as scaled dot-product operations between pairs of query, key, and value vectors within each self-attention module.
  • It introduces a relation head mechanism that concatenates attention head outputs and splits them into a user-defined number of relation heads, enabling alignment across models with different head counts.
  • Knowledge distillation is performed by minimizing the L2 loss between the relation matrices of teacher and student models for Q-Q, K-K, and V-V relations.
  • The approach allows distillation from any layer of the teacher model, not just the final layer, and experiments show upper-middle layers often yield better performance for large models.
  • The method uses a unified training objective that combines masked language modeling and relation distillation, with no architectural constraints on the student model.
  • The number of relation heads is not required to be a multiple of the student or teacher head count, allowing for flexible and fine-grained knowledge transfer.

Experimental results

Research questions

  • RQ1Can self-attention relation distillation improve model compression without requiring identical attention head counts between teacher and student models?
  • RQ2Does transferring knowledge from an upper-middle layer of a large teacher model yield better performance than using the final layer?
  • RQ3How does increasing the number of relation heads affect the performance of distilled student models?
  • RQ4Can multi-head self-attention relation distillation outperform existing knowledge distillation methods on both monolingual and multilingual tasks?
  • RQ5What is the trade-off between using more self-attention relations and computational cost in distillation?

Key findings

  • The 6×768 model distilled from BERT Large outperforms BERT Base in GLUE benchmark while being 2.0× faster in inference.
  • The student model distilled from RoBERTa Large outperforms RoBERTa Base using significantly fewer training examples.
  • Using an upper-middle layer (e.g., layer 12 of 24) from large teachers like BERT Large and XLM-R Large yields better performance than using the final layer.
  • Increasing the number of relation heads improves performance, with more fine-grained knowledge transfer leading to better mimicry of the teacher’s self-attention module.
  • Transferring Q-Q, K-K, and V-V relations achieves better results than using Q-K and V-V relations, and outperforms MobileBERT on most GLUE tasks with faster inference.
  • The method is flexible and generalizable, enabling distillation from various large models (e.g., BERT, RoBERTa, XLM-R) without architectural constraints on the student.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.