Fully Quantized Transformer for Machine Translation

Gabriele Prato, Ella Charlaix, Mehdi RezagholizadehEMNLP 2020

Introduction

Neural Machine Translation (NMT) models, particularly the Transformer architecture, have set the state-of-the-art across numerous benchmarks. However, these models are characterized by massive parameter counts and high computational demands, making deployment on resource-constrained edge devices or mobile platforms challenging.

While quantization—reducing numerical precision from 32-bit floats to 8-bit integers—is a common strategy for model compression, fully quantizing the Transformer has historically been difficult. Previous methods often left computationally intensive operations in full precision or suffered significant degradation in translation quality (BLEU scores). This paper introduces FullyQT, a quantization-aware training strategy that successfully compresses the entire Transformer architecture to 8-bit precision without sacrificing performance.

Methods: The FullyQT Approach

FullyQT employs a uniform quantization-aware training scheme designed to handle the specific sensitivities of the Transformer. Key components of the method include:

  • Comprehensive Quantization: Unlike partial quantization methods, FullyQT targets almost all operations that offer inference speedups, including matrix multiplication inputs, weights, and division operations in Softmax and LayerNorm. Biases and simple additions remain in full precision as they offer negligible speedups but high accuracy risk.
  • Bucketing for Precision: To mitigate precision loss in large tensors, FullyQT uses "bucketing." Tensors are partitioned into subsets (e.g., along the output dimension), with each subset assigned its own quantization scaling factor.
  • Zero-Value Anchoring: For ReLU outputs and Softmax numerators, the minimum value ($x_{min}$) is anchored to 0 to ensure exact mapping of zero values. Padding tokens are excluded from the quantization process entirely.
  • Adaptive Node Pruning: Following training, a pruning method removes "dead" nodes in feed-forward networks. By tracking the running maximum activation ($x_{max}$) of ReLU layers, the system identifies and prunes nodes that consistently output near-zero values.

Key Results and Performance

The authors evaluated FullyQT across several WMT benchmarks, including English-to-French (EN-FR) and English-to-German (EN-DE).

Performance of FullyQT across different bit-precisions and model sizes.

As shown in the results above, 8-bit quantization achieves a ~3.91x reduction in model size while maintaining or even improving upon the 32-bit baseline. Notably, a "Default Approach" to 8-bit quantization fails completely (e.g., 0.21 BLEU on EN-DE), whereas FullyQT remains robust.

Beyond 8-bit, the study explored extreme low-bit regimes. 6-bit quantization maintained baseline performance (e.g., 26.98 BLEU on EN-DE) with a 5.18x compression ratio. However, pushing the precision to 4-bit resulted in a severe performance collapse.

Comparison of FullyQT with existing quantization methods in literature.

When compared to other literature, the 8-bit FullyQT base model achieved 27.60 BLEU on WMT14 EN-DE, outperforming the 27.3 BLEU of the original full-precision Transformer and other recent quantization efforts.

Key Insights

  • Quantization as Regularization: In a majority of experiments (21 out of 35), the 8-bit quantized models outperformed their 32-bit counterparts. This suggests that the restricted numerical precision acts as a form of regularization, helping the model generalize better.
  • The Necessity of Bucketing: Ablation studies highlighted that bucketing is critical, particularly for LayerNorm. Without it, the high variance across batches makes a single scaling factor insufficient, leading to model failure.
  • Structural Sparsity: Analysis of node activations revealed that the encoder's feed-forward layers naturally contain many "dead" nodes, whereas the decoder utilizes its capacity more fully. Adaptive pruning safely removed ~13% of nodes in the base encoder and ~26% in the big encoder without impacting BLEU scores.

Conclusion and Future Directions

FullyQT demonstrates that full 8-bit quantization of Transformers is not only possible but can lead to performance gains. While the training process currently incurs a ~2x overhead due to tracking estimates, the resulting models are significantly more efficient for deployment. Future work includes extending this scheme to other architectures like BERT and GPT, and exploring specialized hardware support for 6-bit operations to fully realize theoretical compression gains.

Summary updated

BibTeX
@inproceedings{prato2020fully,
  author = {Gabriele Prato and Ella Charlaix and Mehdi Rezagholizadeh},
  title = {{Fully Quantized Transformer for Machine Translation}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2020},
  doi = {10.18653/v1/2020.findings-emnlp.1},
}
Figure