Understanding and Overcoming the Challenges of Efficient Transformer Quantization
arXiv:2109.12948
Abstract
Transformer-based architectures have become the de-facto standard models for a wide range of Natural Language Processing tasks. However, their memory footprint and high latency are prohibitive for efficient deployment and inference on resource-limited devices. In this work, we explore quantization for transformers. We show that transformers have unique quantization challenges -- namely, high dynamic activation ranges that are difficult to represent with a low bit fixed-point format. We establish that these activations contain structured outliers in the residual connections that encourage specific attention patterns, such as attending to the special separator token. To combat these challenges, we present three solutions based on post-training quantization and quantization-aware training, each with a different set of compromises for accuracy, model size, and ease of use. In particular, we introduce a novel quantization scheme -- per-embedding-group quantization. We demonstrate the effectiveness of our methods on the GLUE benchmark using BERT, establishing state-of-the-art results for post-training quantization. Finally, we show that transformer weights and embeddings can be quantized to ultra-low bit-widths, leading to significant memory savings with a minimum accuracy loss. Our source code is available at~\url{https://github.com/qualcomm-ai-research/transformer-quantization}.
References in corpus (20)
- Longformer: The Long-Document Transformer
- Estimating or Propagating Gradients Through Stochastic Neurons for Conditional Computation
- DoReFa-Net: Training Low Bitwidth Convolutional Neural Networks with Low Bitwidth Gradients
- Quantizing deep convolutional networks for efficient inference: A whitepaper
- Fixed Point Quantization of Deep Convolutional Networks
- Generating Long Sequences with Sparse Transformers
- Reformer: The Efficient Transformer
- HAT: Hardware-Aware Transformers for Efficient Natural Language Processing
- Fine-Tuning Pretrained Language Models: Weight Initializations, Data Orders, and Early Stopping
- Mixed Precision Quantization of ConvNets via Differentiable Neural Architecture Search
- Post-training 4-bit quantization of convolution networks for rapid-deployment
- Rethinking Attention with Performers
- Training with Quantization Noise for Extreme Model Compression
- BERT and PALs: Projected Attention Layers for Efficient Adaptation in Multi-Task Learning
- Bayesian Bits: Unifying Quantization and Pruning
- NAT: Neural Architecture Transformer for Accurate and Compact Architectures
- Efficient 8-Bit Quantization of Transformer Neural Machine Language Translation Model
- When BERT Plays the Lottery, All Tickets Are Winning
- I-BERT: Integer-only BERT Quantization
- A White Paper on Neural Network Quantization