Dense Vision Transformer Compression with Few Samples

Hanxiao Zhang, Yifan Zhou, Guo-Hua WangCVPR 2024

TL;DR

This paper introduces DC-ViT, a novel framework for compressing large Vision Transformers (ViTs) using very limited training data (few-shot learning). Unlike previous methods that offer sparse compression options, DC-ViT achieves "dense compression," producing a wide range of model sizes with improved accuracy and lower latency, outperforming existing methods by a significant margin.

What Problem Does This Paper Address?

Deploying large Vision Transformers (ViTs) on resource-constrained devices is a major challenge due to their massive computational requirements. While model compression techniques like pruning can help, they often rely on large, labeled datasets for training. This is problematic in scenarios where data is scarce, sensitive (e.g., medical data), or expensive to label. Few-shot compression aims to address this by using only a small subset of training data. However, existing few-shot compression methods have primarily focused on Convolutional Neural Networks (CNNs) and have not been effectively adapted for ViTs. Furthermore, many existing methods result in "sparse compression," meaning they can only produce a few distinct compressed model sizes, leading to inefficient use of computational budgets. This paper tackles the problem of few-shot compression for ViTs, aiming to achieve both high performance and a dense range of compression options.

Methods

The core of the proposed method, DC-ViT, involves a novel approach to block-level pruning in ViTs. Instead of simply removing entire blocks, DC-ViT selectively removes the attention module within a block while retaining and reusing parts of the Multi-Layer Perceptron (MLP) module. This strategy allows for more fine-grained control over compression and parameter reuse.

The framework operates in three main stages:

  1. Determining Network Structure: The method first calculates the minimum number of blocks to compress and the extent to which the MLP within those blocks should be reduced to meet a target MACs (Multiply-Accumulate Operations) reduction. This is formulated to minimize the number of compressed blocks for better accuracy.
  2. Block Selection (Block-wise Trial and Synthetic Metric Set): To identify which blocks are most suitable for compression, DC-ViT employs a "block-wise trial" procedure. Candidate models are created by compressing individual blocks and then finetuned using a Mean Squared Error (MSE) loss on the limited training data for feature mimicking. Crucially, to evaluate the recoverability of these compressed blocks without relying solely on the small training set (which can lead to overfitting), the paper introduces a novel "synthetic metric set." This set is generated using the pre-trained model itself, leveraging techniques like DeepDream to create images that capture the model's learned representations. The metric loss calculated on this synthetic set is shown to correlate well with actual performance on the test set, providing a more reliable measure of block importance.
  3. Progressive Pruning and Finetuning: The compression is applied progressively, meaning blocks are pruned and finetuned sequentially. This gradual approach is found to be more effective and stable than attempting to compress many blocks at once. The finetuning process is also optimized by updating only the initial blocks up to the last compressed one, further reducing computational cost.

Datasets

  • Training: The method is designed for few-shot learning, utilizing tiny subsets of training data from ImageNet-1k. The paper emphasizes that these training sets are often unlabeled.
  • Evaluation: The primary evaluation dataset is ImageNet-1k. The paper also reports results on downstream tasks using datasets like CIFAR-10, CIFAR-100, Flowers, Oxford-IIIT Pets, CUB-200, and Indoor67.
  • Synthetic Metric Set: A novel synthetic metric set is generated using the pre-trained model itself, not relying on external datasets.

Key Insights and Ideas

  • Dense Compression for ViTs: The paper argues for the necessity of "dense compression," where a wide range of model complexities can be achieved, as opposed to "sparse compression" which offers only a few discrete options. This allows for better utilization of available computational budgets.
  • Attention Module Removal + MLP Reuse: Selectively removing the attention module (a significant latency contributor in ViTs) and reusing parts of the MLP module is an effective strategy for ViT compression. This differs from traditional CNN compression where entire filters or blocks are removed.
  • Synthetic Metric Set for Reliable Evaluation: Using a self-generated synthetic metric set is a key innovation. It effectively bridges the gap between perceived recoverability (from training loss on limited data) and actual performance, mitigating overfitting issues common in few-shot learning.
  • Progressive Pruning and Partial Finetuning: A gradual, block-by-block pruning and finetuning approach, combined with updating only the initial blocks, proves more effective and efficient for few-shot ViT compression.
  • ViT Compression is Different from CNN Compression: The paper highlights that existing few-shot CNN compression methods do not directly translate well to ViTs, necessitating specialized approaches.

Key Results

  • Accuracy Improvement: DC-ViT outperforms state-of-the-art few-shot compression methods (like PRACTISE) by a significant margin of up to 10 percentage points in top-1 accuracy on ImageNet.
  • Dense Compression: Figure 1 and Figure 2 visually demonstrate that DC-ViT produces a dense spectrum of compressed models across various MACs ranges, unlike the sparse options offered by other methods.
  • Lower Latency: The method achieves lower latency for compressed ViT models compared to baselines, even when achieving similar or higher accuracy. For example, with a 24.5% MACs reduction on ViT-Base, DC-ViT achieves 81.60% accuracy with 84.9 ms latency, compared to PRACTISE's 73.28% accuracy with 85.9 ms latency.
  • Transfer Learning: The compressed DC-ViT models retain their efficiency and achieve comparable or even better performance on downstream classification tasks compared to original ViTs and other SOTA models.

Limitations and Future Work

  • Compression Ratio Limit: A current limitation is that extremely high compression ratios (e.g., >30%) can still lead to significant accuracy drops. The authors suggest that the introduction of small MLPs in DC-ViT has the potential to partially address this in future work.
  • Focus on Recognition: The current work and most few-shot compression methods are primarily focused on image recognition tasks. The authors express interest in extending DC-ViT to more complex tasks like object detection and semantic segmentation in the future.

Summary updated

BibTeX
@inproceedings{zhang2024dense,
  author = {Hanxiao Zhang and Yifan Zhou and Guo-Hua Wang},
  title = {{Dense Vision Transformer Compression with Few Samples}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2024},
  url = {https://openreview.net/forum?id=JwMo78Zr6j},
}
Figure