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

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

Introduction

As Large Language Models (LLMs) continue to scale, deploying them on resource-constrained edge devices necessitates extreme model compression. Quantization-Aware Training (QAT) has emerged as a primary solution, reducing 32-bit floating-point weights to low-precision formats. However, pushing weights below 2 bits (ternary quantization) often leads to a significant degradation in model accuracy.

While Knowledge Distillation (KD) is frequently employed to bridge this gap, standard KD recipes designed for model pruning—where a smaller student mimics a larger teacher—often fail in the context of QAT. In QAT, the student and teacher share the same architecture but differ in precision. This paper identifies that standard Mean Squared Error (MSE) loss on attention scores is insufficient for large models like BERT-Large and proposes a refined distillation approach to recover performance lost to quantization noise.

Methodology

The authors propose a nuanced distillation framework specifically tailored for ternary QAT:

  1. All-Layer Distillation: In contrast to traditional KD that might skip layers to reduce student size, the authors find that for QAT, distilling every single layer is crucial. This provides dense supervision to guide the student through the noisy loss landscape created by extreme quantization.
  2. Attention-Map Loss (KL-Div): Instead of raw score matching via MSE, the method utilizes Kullback-Leibler Divergence (KL-Div) on softmax-normalized attention maps. This focuses on preserving the relative importance of tokens, a metric more robust to the coarse weight representations of ternary models.
  3. Attention-Output Loss: A key innovation of this work is the application of MSE loss directly to the attention mechanism's output (the vector prior to the residual connection). This helps the model maintain distinctive features that are otherwise lost during quantization.
  4. Unified Loss: A mixing strategy combines map and output losses, allowing the distillation process to adapt to the specific requirements of different downstream tasks.
The proposed distillation architecture, highlighting the Self-Attention Generation (SA-GEN) and Propagation (SA-PROP) stages where the new losses are applied.

Key Insights: The Homogenization Trap

The primary challenge identified in large quantized models is "homogenization." In models like BERT-Large, extreme quantization acts as a blur filter, causing the attention outputs for different tokens to become nearly identical. This loss of feature diversity is particularly damaging for "Case-1" tasks (e.g., RTE or CoLA) which rely on sharp, distinct attention patterns.

The proposed attention-output loss serves as a "de-blurring" agent, forcing the student to recover the teacher's diverse feature representations. Conversely, "Case-2" tasks (e.g., SST-2) exhibit more naturally homogeneous attention and benefit more from simple map matching.

Visualization of token value ranges for RTE (Case-1) and SST-2 (Case-2). The 'homogenization' effect is evident in the narrow value ranges for quantized BERT-Large on RTE.

Experimental Results

The proposed methods achieve state-of-the-art (SOTA) results for ternary weight quantization across multiple benchmarks:

  • BERT-Base: Average GLUE score improved from 81.28 to 81.87.
  • BERT-Large: Significant improvement from 81.84 to 82.72. On the challenging RTE task, accuracy increased from 65.02% to 69.50%.
  • Compression Efficiency: These performance gains were achieved while maintaining a 14.9x to 15.4x compression rate relative to FP32 models.
  • Cross-Lingual Generalization: The method proved effective on Korean models (ULM-Large), outperforming TernaryBERT baselines on KLUE and NSMC datasets.

Conclusion

This work demonstrates that successful QAT for large Transformers requires moving beyond standard KD recipes. By recognizing the structural equivalence between teacher and student and addressing the homogenization of attention outputs, it is possible to achieve extreme compression without sacrificing significant accuracy. Future work includes automating the tuning of loss mixing parameters and extending this analysis to decoder-only architectures like GPT.

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