[Paper Review] TernaryBERT: Distillation-aware Ultra-low Bit BERT
TernaryBERT proposes a distillation-aware, ultra-low bit quantization method that ternarizes BERT weights to {-1, 0, +1} with mixed granularity for word embeddings and Transformer layers, using both approximation-based and loss-aware ternarization. It achieves performance comparable to full-precision BERT while reducing model size by 14.9x, outperforming existing quantization and compression methods on GLUE and SQuAD benchmarks.
Transformer-based pre-training models like BERT have achieved remarkable performance in many natural language processing tasks.However, these models are both computation and memory expensive, hindering their deployment to resource-constrained devices. In this work, we propose TernaryBERT, which ternarizes the weights in a fine-tuned BERT model. Specifically, we use both approximation-based and loss-aware ternarization methods and empirically investigate the ternarization granularity of different parts of BERT. Moreover, to reduce the accuracy degradation caused by the lower capacity of low bits, we leverage the knowledge distillation technique in the training process. Experiments on the GLUE benchmark and SQuAD show that our proposed TernaryBERT outperforms the other BERT quantization methods, and even achieves comparable performance as the full-precision model while being 14.9x smaller.
Motivation & Objective
- To address the high computational and memory cost of full-precision BERT models on resource-constrained devices.
- To reduce accuracy degradation in ultra-low bit quantization (e.g., 1-2 bits) by combining ternarization with knowledge distillation.
- To investigate optimal ternarization granularity across different components of BERT, such as word embeddings and Transformer layers.
- To develop a method that maintains high performance despite reduced model capacity due to ternary weight constraints.
Proposed method
- Ternarizes BERT weights to {-1, 0, +1} using both approximation-based and loss-aware quantization strategies.
- Applies different ternarization granularities: layer-wise for Transformer weights and head-wise for word embeddings.
- Integrates knowledge distillation from a full-precision teacher model to guide training of the ternarized student model.
- Uses distillation losses on intermediate representations and attention maps, in addition to logits, to preserve knowledge.
- Employs a hybrid training objective combining cross-entropy loss with distillation losses to improve generalization.
- Extends the method to 3-bit quantization using Loss-aware Quantization (LAQ) for ablation and comparison.
Experimental results
Research questions
- RQ1Can ternary quantization of BERT weights achieve performance close to full-precision BERT while drastically reducing model size?
- RQ2How does the choice of ternarization granularity—layer-wise vs. head-wise—affect model accuracy across different BERT components?
- RQ3To what extent does knowledge distillation mitigate accuracy degradation in ultra-low bit quantized BERT models?
- RQ4How do different distillation losses (logits, intermediate features, attention maps) contribute to performance improvement in ternarized BERT?
- RQ5How does TernaryBERT compare to state-of-the-art quantization and compression methods in terms of accuracy and model size?
Key findings
- TernaryBERT achieves 83.5% MNLI-m accuracy with a model size of only 28 MB, representing a 14.9x reduction compared to full-precision BERT.
- The model outperforms mixed-precision Q-BERT and GOBO with 2-bit weights, achieving higher accuracy than both on MNLI and SQuAD benchmarks.
- Knowledge distillation significantly improves performance: removing distillation from both Transformer layers and logits reduces MNLI-m accuracy by over 5%.
- Using distillation on intermediate representations and attention maps improves performance more than relying solely on logits.
- Data augmentation and fine-tuned BERT initialization improve performance, especially on CoLA and RTE, with gains of up to 9.7% on CoLA when both are applied.
- TernaryBERT achieves comparable performance to full-precision BERT on SQuAD v1.1 (87.4/87.4 F1) while being 14.9x smaller, demonstrating strong compression efficiency.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.