Self-Distilled Quantization: Achieving High Compression Rates in Transformer-Based Language Models

James O'Neill, Sourav DuttaACL 2023

Introduction

As Transformer-based language models continue to grow in scale, deploying them on resource-constrained edge devices becomes increasingly challenging. Quantization—the process of reducing weight precision from 32-bit floating point (FP32) to lower-bit integers (e.g., INT8)—is a standard technique to mitigate memory and latency overheads. However, standard quantization often suffers from "accumulative quantization error," where small precision losses in early layers are amplified throughout the network, significantly degrading performance, particularly in multilingual contexts.

To address this, we present Self-Distilled Quantization (SDQ), a novel framework designed to maintain model accuracy at high compression rates. SDQ leverages internal architectural patterns to guide the quantization process, ensuring that the compressed "student" model retains the critical representational characteristics of its full-precision "teacher" counterpart.

Methodology: Self-Distilled Quantization

The core of SDQ is a specialized distillation objective that targets intermediate representations rather than just final outputs. While traditional Knowledge Distillation (KD) focuses on matching logit distributions, SDQ enforces consistency in the self-attention mechanisms.

The SDQ architecture compares a full-precision teacher (left) with a quantized student (right), using an attention-based loss function to align their internal states.

The training objective is a hybrid loss function comprising three components:

  1. Task-Specific Loss: Standard cross-entropy loss based on ground-truth labels.
  2. Logit Distillation: KL divergence to minimize the difference between the student's and teacher's final probability distributions.
  3. Attention-Based Distillation: A Mean Squared Error (MSE) term that penalizes deviations in the student’s self-attention outputs relative to the teacher’s.

By integrating SDQ with existing Quantization-Aware Training (QAT) frameworks like Iterative Product Quantization (iPQ) and Quant-Noise, the model learns to compensate for quantization noise during the fine-tuning phase.

Experimental Setup

The effectiveness of SDQ was evaluated using the XGLUE benchmark, a comprehensive suite for cross-lingual natural language understanding. Tasks included Natural Language Inference (XNLI), News Classification (NC), Named Entity Recognition (NER), Part-of-Speech Tagging (POS), and Paraphrase Adversaries (PAWS-X). A key focus was zero-shot cross-lingual transfer, where models trained on English data were tested on diverse languages such as Arabic, Swahili, and Urdu.

Analysis and Key Insights

Empirical analysis of quantization error across different Transformer components revealed that error is not uniformly distributed.

Analysis of quantization error across different layer types reveals significant variance, justifying the need for targeted distillation of specific components like attention outputs.

Key findings include:

  • The Error Hotspot: The output of self-attention blocks was identified as a primary site for error accumulation. Targeting these specific outputs for distillation proved more effective than general parameter-matching.
  • The Jitter Effect: Quantization introduces a "jitter" or noise into the weight distributions. SDQ acts as a regularizer, stabilizing these distributions and smoothing the noise.
  • Teacher Selection: Optimal performance is achieved when the teacher and student share the same architecture (e.g., InfoXLM to InfoXLM), facilitating more precise alignment of intermediate features.

Results

SDQ demonstrates near-lossless compression for 8-bit quantization. On the XGLUE benchmark, INT8 models achieved an average score of 77.1, remarkably close to the FP32 baseline of 78.1, while providing a 4x reduction in model size. Notably, SDQ consistently outperformed standard logit-only distillation, with the addition of attention-based loss yielding an improvement of nearly 2.0 points in average score. In cross-lingual tasks like XNLI, the quantized InfoXLM model maintained 73.8% accuracy (vs. 74.6% for FP32), confirming the robustness of the method for multilingual applications.

Conclusion and Future Work

Self-Distilled Quantization provides a robust pathway for deploying high-performance Transformers on edge hardware. While highly effective at 8-bit precision, the method faces challenges at ultra-low bit-widths (2-bit or 4-bit), where the "capacity floor" of the architecture is reached. Future research will explore adaptive bit-width allocation across layers to further push the limits of compression without sacrificing the model's linguistic capabilities.

Summary updated

BibTeX
@inproceedings{oneill2023self,
  author = {James O'Neill and Sourav Dutta},
  title = {{Self-Distilled Quantization: Achieving High Compression Rates in Transformer-Based Language Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-short.114},
}
Figure