Abstract
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.
Introduction
Vision Transformers (ViTs) have revolutionized computer vision, but their massive parameter counts (e.g., 632M for ViT-H) make them memory-hungry and computationally expensive. While quantization—reducing the precision of weights and activations—is a standard solution, jumping straight to ultra-low bit-widths like ternary weights (2 bits) usually results in a massive drop in accuracy.
The authors identify two main hurdles:
- Optimization Gap: The "loss landscape" of a ternary model is jagged and full of local minima compared to the smooth landscape of a real-valued model, making it incredibly hard to train.
- The "Dead Weight" Problem: In standard ternary training, many weights become "stuck" with near-zero gradients, preventing the model from learning meaningful representations.
Methodology
TerViT tackles these issues through three primary innovations:
Progressive Training (PT)
Instead of quantizing a 32-bit model directly to ternary, the authors use an 8-bit model as an intermediate "proxy." They first fine-tune the model at 8-bit precision to stabilize the weights before moving to ternary. This "warms up" the optimization process and leads to a much smoother loss surface.
Channel-wise Ternarization
Standard methods often apply a single quantization threshold to an entire layer. However, the authors observed that weight distributions vary significantly across different channels in ViTs. TerViT partitions matrices into channels, giving each its own unique scale factor and ternarization interval.
Selective Bit-Widths
Through Hessian matrix analysis, the authors found that the first layer (patch embedding) and the last layer (classification head) are extremely sensitive to precision loss. TerViT keeps these specific layers at 8-bit while ternarizing the rest of the backbone to maximize the compression-to-accuracy trade-off.
Experimental Results
The models were evaluated on the ImageNet (ILSVRC12) classification dataset. The authors tested their methods across several popular architectures, including DeiT (Tiny, Small, and Base) and Swin Transformer (Tiny and Small).
Key results include:
- Swin-S: Compressed the model size by 15.25x (from 199.8MB down to 13.1MB) while maintaining 79.5% Top-1 accuracy (only a 3.7% drop from the 32-bit baseline).
- DeiT-B: Achieved 76.1% accuracy with a 15.25x compression ratio, outperforming the standard Ternary Weight Network (TWN) baseline by 3.2%.
- Efficiency: Activations were successfully quantized to 8-bit with negligible impact on performance, further reducing the computational footprint (FLOPs) for inference.
Discussion
The paper provides visualizations of the loss landscapes showing that ternary models without progressive training are "cluttered" and non-convex, while TerViT’s approach creates a landscape much closer to a convex function. By analyzing "Channel-wise Absolute Mean" (CAM), the authors proved that their progressive training prevents weights from becoming "inert," ensuring that the ternary weights actually change and learn during backpropagation.
While TerViT significantly narrows the gap, there is still a 3-6% accuracy drop compared to full-precision models. Moving from ternary (2-bit) to binary (1-bit) remains a major challenge for ViTs due to their complex global attention mechanisms. Additionally, the progressive training scheme requires multiple stages of fine-tuning, increasing total training time.
Conclusion
TerViT introduces a robust framework for quantizing Vision Transformers into ternary weights, achieving up to a 15x reduction in model size. By employing a progressive training scheme and channel-wise quantization, the authors bridge the performance gap between full-precision and ultra-low-bit models, making powerful ViTs viable for resource-constrained edge devices.
Summary updated