Understanding and Improving Knowledge Distillation for Quantization-Aware Training of Large Transformer Encoders

Minsoo Kim, Sihwa Lee, Sukjin Hong, Du-Seong Chang, Jungwook Choi

TL;DR

This paper tackles the challenge of compressing large Transformer models like BERT using Quantization-Aware Training (QAT) by improving Knowledge Distillation (KD). They introduce novel KD techniques, "attention-map loss" and "attention-output loss," which significantly boost accuracy for sub-2-bit quantized models, achieving state-of-the-art results.

What Problem Does This Paper Address?

Large Transformer models, such as BERT, are incredibly powerful for natural language processing but come with a hefty computational and memory cost. Quantization is a key technique to reduce this cost by using lower-precision numbers for model weights. However, aggressive quantization (especially below 2 bits) severely degrades model accuracy. Quantization-Aware Training (QAT) helps mitigate this by incorporating quantization errors during training. Knowledge Distillation (KD) is often used alongside QAT to transfer knowledge from a full-precision "teacher" model to a quantized "student" model. Despite its widespread use, there's a lack of understanding about which KD methods are most effective for QAT in Transformers, and existing approaches often fall short, especially for larger models. This paper aims to fill this gap by analyzing KD's role in attention recovery during QAT and proposing improved KD strategies.

Methods

The authors delve into the mechanism of KD for attention recovery in quantized Transformers. They first establish that distilling knowledge from all Transformer layers is crucial for QAT, unlike in standard model compression. They then propose two novel KD losses:

  • Attention-Map Loss: This loss uses Kullback-Leibler (KL) divergence to match the attention maps between the teacher and student models. This is a departure from previous methods that used Mean Squared Error (MSE) on attention scores, which they found insufficient. They argue that KL divergence better preserves the relative importance of tokens in the attention mechanism.
  • Attention-Output Loss: Recognizing that attention-map loss alone struggles with larger models and specific tasks, they introduce a loss that directly matches the attention output (the final representation before the feed-forward network) of the teacher and student. This loss is particularly effective in recovering disruptions caused by quantization in the self-attention propagation path.

Furthermore, they explore a unified attention-map and output loss, combining the two proposed methods with a tunable mixing parameter to adapt to task-dependent characteristics.

Datasets

The paper evaluates their methods on several standard NLP benchmarks:

  • GLUE Benchmark: A collection of diverse NLP tasks for evaluating language understanding systems. Specific tasks mentioned include RTE, CoLA, STS-B, SST-2, QNLI, MNLI, QQP, and MRPC.
  • KLUE Benchmark: A Korean language understanding evaluation benchmark, specifically KLUE-TC (Topic Classification) and KLUE-STS (Semantic Textual Similarity).
  • NSMC (NAVER Sentiment Movie Corpus): A dataset for sentiment analysis.

Key Insights and Ideas

  • All-layer distillation is key for QAT: Unlike model compression where selective layer distillation can be sufficient, QAT of Transformers benefits significantly from distilling knowledge across all layers.
  • Attention-map loss is better than attention-score loss for QAT: Matching attention maps with KL divergence is more effective than matching attention scores with MSE for recovering attention information disrupted by quantization.
  • Large Transformers need more than just attention-map matching: For larger models like BERT-Large, the attention-map loss alone is insufficient. Quantization disrupts attention propagation in a way that requires a different approach.
  • Attention-output loss is crucial for large models: Directly matching the attention output helps recover the teacher's distinctive attention patterns, especially for complex tasks and larger models.
  • Task-dependent characteristics matter: The effectiveness of different KD strategies varies based on the specific NLP task and model size, highlighting the need for adaptive or unified approaches.

Key Results

The proposed KD methods achieve state-of-the-art accuracy for Quantization-Aware Training (QAT) with aggressive sub-2-bit weight quantization.

  • BERT-Base: The attention-map loss significantly improves accuracy across various tasks, while the attention-output loss is less effective.
  • BERT-Large: The attention-map loss offers marginal improvements, but the attention-output loss significantly boosts accuracy, particularly for "Case-1" tasks (e.g., RTE, CoLA).
  • Unified Loss: The combined attention-map and output loss generally improves QAT accuracy, with optimal mixing parameters found to be task-dependent.
  • Quantitative improvements: Tables in the paper show significant accuracy gains compared to baseline QAT methods, with the best results often surpassing full-precision models on certain metrics or tasks (e.g., MRPC). For instance, on BERT-Large, the "Output" loss achieves 82.72% average accuracy on GLUE, compared to 81.84% for the baseline.

Limitations and Future Work

  • Theoretical Analysis: The authors acknowledge that while their empirical findings are strong, a more theoretical analysis of how quantization impacts KD and vice-versa would be beneficial.
  • Automatic Balancing of Losses: They suggest exploring automatic methods for balancing the proposed KD losses (attention-map and attention-output) rather than relying on manual tuning of mixing parameters. This could lead to more robust and generalizable solutions.

Summary updated

BibTeX
@inproceedings{kim2022understanding,
  author = {Minsoo Kim and Sihwa Lee and Sukjin Hong and Du-Seong Chang and Jungwook Choi},
  title = {{Understanding and Improving Knowledge Distillation for Quantization-Aware Training of Large Transformer Encoders}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  url = {https://openreview.net/forum?id=3T2eE2VbRp},
}
Figure