Abstract
MKQ-BERT pushes the boundaries of Transformer compression by successfully quantizing both weights and activations to 4-bits. By introducing a novel MSE-based gradient for quantization scales and an advanced distillation strategy, the authors achieved a 15x inference speedup for individual layers and a 5.3x reduction in model size with minimal impact on accuracy.
Introduction
Large-scale language models like BERT have revolutionized NLP, but their massive parameter counts make them "heavyweight" and difficult to deploy on mobile or edge devices. While 8-bit quantization (converting 32-bit floats to 8-bit integers) has become a standard way to shrink models without losing accuracy, moving down to 4-bits usually causes performance to "fall off a cliff."
The challenge is two-fold:
- Mathematical: Standard methods for updating the "quantization scale" (the factor that maps floats to integers) often provide inaccurate gradients at low bit-widths.
- Engineering: Even if you have a 4-bit model, you need specialized hardware kernels to actually see a speedup during inference.
Methods
The authors propose MKQ-BERT, which utilizes three key innovations:
- MSE-based Gradient for Quantization Scale: Traditionally, researchers use a "Straight Through Estimator" (STE) to calculate gradients for non-differentiable quantization functions. The authors prove that STE can actually push the quantization scale in the wrong direction. They derive a new gradient based on Mean Squared Error (MSE) that more accurately minimizes the difference between the original float values and the quantized integers.
- Advanced "MINI" Distillation: Instead of the standard layer-by-layer distillation, they use a strategy that focuses on the Multi-Head Attention (MHA) and Feed-Forward Network (FFN) outputs of the last layer. This allows a deeper, more powerful teacher model to train a smaller, quantized student.
- Custom int4 Kernels: To prove the theoretical gains, the team developed efficient CUDA kernels for 4-bit matrix multiplication, enabling real-world end-to-end inference testing on NVIDIA T4 GPUs.
Key Results
The model was evaluated on the GLUE (General Language Understanding Evaluation) benchmark. MKQ-BERT outperformed the previous state-of-the-art (KDLSQ-BERT) across almost all tasks. For example, on the SST-2 task, the MKQ-BERT 4-bit version achieved 90.4% accuracy, matching the uncompressed baseline.
In terms of efficiency, a single int4 layer is 15x faster than a float32 layer and 1.25x faster than an int8 layer. The researchers found that quantizing the first 50% of layers to 4-bits and the remaining 50% to 8-bits allows the model to maintain almost the same performance as a full-precision model while still gaining massive speedups.
Conclusion
MKQ-BERT demonstrates that 4-bit quantization is a viable path for deploying large language models on resource-constrained hardware. By addressing the fundamental gradient issues of low-bit quantization and providing optimized kernels, the authors achieved significant compression and speedup. While fully 4-bit models still face accuracy challenges in the embedding layers, this work sets a new benchmark for efficient Transformer deployment.
Summary updated