Boost Vision Transformer with GPU-Friendly Sparsity and Quantization

Chong Yu, Tao Chen, Zhongxue Gan, Jiayuan Fan

TL;DR

GPUSQ-ViT is a hardware-aware compression framework that combines 2:4 structured sparsity with low-precision quantization (INT8/INT4) to dramatically accelerate Vision Transformers (ViTs). By co-designing the compression scheme with NVIDIA GPU hardware characteristics, the authors achieve up to 3.4x throughput gains on server-grade GPUs and significant model size reductions with negligible accuracy loss across multiple vision tasks.

What Problem Does This Paper Address?

Vision Transformers have revolutionized computer vision, but their massive computational footprint—driven by stacked self-attention blocks—makes them difficult to deploy on edge devices or even high-end servers efficiently.

The authors identify a critical gap in existing compression research: theoretical efficiency does not equal actual deployment speed. Many pruning methods result in "unstructured" sparsity (randomly distributed zeros), which modern GPUs cannot skip efficiently. Consequently, a model might have 50% fewer FLOPs but run no faster than the original. Furthermore, standard quantization often struggles to maintain accuracy when dropping below 8-bit precision.

Methods

The authors propose a two-stage pipeline called GPUSQ-ViT that prioritizes "GPU-friendly" patterns:

  1. 2:4 Structured Pruning: Instead of random pruning, they enforce a 2:4 pattern—where exactly two out of every four contiguous elements in a weight matrix are zero. This specific pattern is natively supported by NVIDIA Ampere (and newer) Tensor Cores, providing a 2x math throughput boost. Comparison of dense vs. sparse GEMM on Tensor Cores
  2. Sparse-Distillation-Aware QAT: The pruned model is further compressed using Quantization-Aware Training (QAT) to convert weights and activations to INT8 or INT4.
  3. Mixed-Strategy Knowledge Distillation (KD): To recover accuracy, the student model mimics a teacher model's hard labels, soft logits, and intermediate feature maps. The two-stage GPUSQ-ViT workflow
Figure 1. Comparison of computing a M ×N ×K GEMM onto a Tensor Core. Dense matrix A of size M × K in left side becomes M × K
Figure 5. GPUSQ-ViT scheme with two sub-workflows. For the 2:4 structured sparse pruning workflow, the dense floating-point model MDF is compressed as the sparse floating-point model MSF . Hard label, soft logits and feature-based distillation losses are accumulated as the overall sparse pruning loss. The sparse floating-point model MSF is quantized as the sparse quantized model MSQ for the sparse- distillation-aware QAT workflow. Hard label and soft logits calibration losses are obtained in a similar manner. Each feature maps calibration result is multiplied with a weight factor to indicate this layer’s probability of having a real influence on MSQ model’s final accuracy. Three calibration losses are accumulated as the overall quantization calibration loss.

Datasets

The framework was evaluated on three major benchmarks:

  • ImageNet-1K: For image classification (using DeiT and Swin Transformer backbones).
  • COCO: For object detection and instance segmentation (using Mask R-CNN and DETR).
  • ADE20K: For semantic segmentation (using UPerNet).

Key Insights and Ideas

  • Hardware-Software Co-design is King: By targeting the 2:4 sparsity pattern supported by hardware, the authors ensure that theoretical FLOP reductions translate directly into real-world latency improvements.
  • Later Stages Matter More for KD: Using Class Activation Maps (CAM), the authors discovered that early stages of ViTs focus on local features, while later stages capture the global semantics necessary for correct classification. Therefore, they prioritize mimicking feature maps from the later stages of the model. Visualization showing how attention shifts from local to global features across stages
  • Distillation Weighting: In the QAT stage, they use the distillation loss from the pruning stage as a "weight factor." If a layer was heavily impacted by pruning, they give its quantization error less weight, assuming that layer has less influence on the final accuracy.
  • Unsupervised Flexibility: The method works even without ground-truth labels by using the dense model's predictions as the target, making it useful for data-rich but label-poor scenarios.
Visualization showing how attention shifts from local to global features across stages

Key Results

The results demonstrate that GPUSQ-ViT is a state-of-the-art compression scheme:

  • Model Size: Reduced by 6.4x to 12.7x.
  • Theoretical FLOPs: Reduced by 30.3x to 62x.
  • Actual Throughput (A100 GPU): Achieved 3.22x to 3.43x improvement for INT4 models.
  • Actual Latency (AGX Orin): Achieved 1.57x to 1.69x speedup.
  • Accuracy: The INT8 versions often show zero accuracy degradation, and in some cases (like DeiT-Base), the compressed model actually outperformed the baseline.
Figure 6. CAM visualization for Swin Transformer baseline dense models and GPUSQ-ViT compressed INT8 and INT4 models.

Limitations and Future Work

The primary limitation is hardware specificity. The current framework is tightly coupled with NVIDIA's 2:4 structured sparsity support. If future hardware architectures shift to different patterns (e.g., 1:4 or 2:16), the pruning logic would need to be redesigned. The authors suggest that future work could involve extending this framework to support a wider variety of sparse patterns as hardware evolves.

Summary updated

BibTeX
@misc{yu2023boost,
  author = {Chong Yu and Tao Chen and Zhongxue Gan and Jiayuan Fan},
  title = {{Boost Vision Transformer with GPU-Friendly Sparsity and Quantization}},
  year = {2023},
  eprint = {2305.10727},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.10727},
}
Figure