[Paper Review] TerViT: An Efficient Ternary Vision Transformer
TerViT proposes a novel ternary vision transformer (ViT) that achieves high model compression with minimal accuracy drop by introducing progressive training from 8-bit to 2-bit weights and channel-wise ternarization. It reduces Swin-S model size to 13.1MB while maintaining 79.5% Top-1 accuracy on ImageNet, outperforming prior 2-bit methods by up to 4% and closing the gap with full-precision models.
Vision transformers (ViTs) have demonstrated great potential in various visual tasks, but suffer from expensive computational and memory cost problems when deployed on resource-constrained devices. In this paper, we introduce a ternary vision transformer (TerViT) to ternarize the weights in ViTs, which are challenged by the large loss surface gap between real-valued and ternary parameters. To address the issue, we introduce a progressive training scheme by first training 8-bit transformers and then TerViT, and achieve a better optimization than conventional methods. Furthermore, we introduce channel-wise ternarization, by partitioning each matrix to different channels, each of which is with an unique distribution and ternarization interval. We apply our methods to popular DeiT and Swin backbones, and extensive results show that we can achieve competitive performance. For example, TerViT can quantize Swin-S to 13.1MB model size while achieving above 79% Top-1 accuracy on ImageNet dataset.
Motivation & Objective
- To address the high computational and memory cost of vision transformers on resource-constrained devices.
- To overcome the optimization difficulty in ternary quantization of ViTs, which suffers from a large loss surface gap between real-valued and ternary parameters.
- To improve quantization stability and performance by introducing channel-wise ternarization that accounts for varying weight distributions across channels.
- To bridge the optimization gap between real-valued and ternary ViTs using a progressive training scheme starting from 8-bit models.
- To achieve state-of-the-art performance in low-bit ViT quantization with high compression ratios and minimal accuracy drop.
Proposed method
- Introduces a progressive training scheme: first train an 8-bit ViT, then use it as a proxy to initialize and train the final ternary ViT, reducing optimization instability.
- Applies channel-wise ternarization, where each channel’s weight distribution is independently mapped to ternary values (±1, 0) using unique quantization intervals.
- Uses 8-bit activation quantization to maintain activation precision while reducing memory and FLOPs, especially for the patch embedding and classification head layers.
- Saves the first (patch embedding) and last (classification head) layers in 8-bit format due to their high sensitivity, as shown by Hessian eigenvalue analysis.
- Employs a two-stage training process: first pre-train the 8-bit model, then fine-tune the ternary model with quantization-aware training (QAT) to stabilize convergence.
- Visualizes loss landscapes to demonstrate that the ternary model has a steeper, more complex loss surface than 8-bit or real-valued models, justifying the need for progressive training.
Experimental results
Research questions
- RQ1Can ternary quantization be effectively applied to vision transformers despite the large optimization gap between real-valued and ternary parameters?
- RQ2Does progressive training from an 8-bit model improve the convergence and performance of ternary ViTs compared to direct ternary training?
- RQ3Can channel-wise ternarization improve quantization stability and performance by adapting to per-channel weight distribution variance?
- RQ4How does the proposed method compare to existing 2-bit and 8-bit quantization baselines in terms of compression ratio and accuracy on ImageNet?
- RQ5What is the impact of quantizing the first and last layers on model performance, and can 8-bit precision be used for these layers to balance accuracy and efficiency?
Key findings
- TerViT reduces the Swin-S model size to 13.1MB with 15.25× compression ratio, achieving 79.5% Top-1 accuracy on ImageNet, within 4% accuracy drop of the full-precision model.
- On DeiT-S, TerViT achieves 74.2% Top-1 accuracy with 14.70× compression, outperforming the baseline TWN method by 4.0%.
- For DeiT-B, TerViT achieves 76.1% Top-1 accuracy with 15.25× compression, surpassing the 72.9% accuracy of the TWN baseline by 3.2%.
- The method reduces the performance gap between ternary ViTs and real-valued models, with TerDeiT-B outperforming the real-valued DeiT-T by 3.9% on the same model size.
- The 8-bit quantized first and last layers cause only a 0.3% accuracy drop compared to 32-bit, validating their use to maintain performance while reducing bit-width.
- Channel-wise ternarization improves quantization stability, as evidenced by lower Channel-wise Absolute Mean (CAM) and higher Standard Deviation (SDAM) in weight distributions after training.
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.