A Unified Pruning Framework for Vision Transformers

Hao Yu, Jianxin Wu · OpenReview

TL;DR

This paper introduces UP-ViTs, a unified framework for structurally pruning Vision Transformers (ViTs) and their variants. By pruning channels across all ViT components while preserving structural consistency, UP-ViTs achieves significant compression with improved or comparable accuracy on tasks like image classification and object detection, outperforming previous methods.

What Problem Does This Paper Address?

Vision Transformers (ViTs) have revolutionized computer vision, achieving state-of-the-art results across various tasks. However, their large model size, high computational demands, and substantial training data requirements make them challenging to deploy in resource-constrained environments. While model compression techniques like pruning exist, their application to ViTs, especially in a way that preserves their unique structure and generalizes to downstream tasks, has been less explored. Existing methods often focus on token pruning, which can disrupt the spatial structure and hinder performance on tasks like object detection. This paper aims to bridge this gap by proposing a unified, structural pruning approach for ViTs that addresses these limitations.

Methods

The core of UP-ViTs is a unified framework for structural channel pruning. Instead of removing entire tokens or heads, UP-ViTs prunes individual channels (dimensions) within various components of a ViT block. The key steps are:

  1. Component Identification: The authors meticulously divide each ViT block into uncorrelated structural components: shortcut connections, attention embedding filters, and feed-forward network (FFN) filters. For ViT variants like PVTv2, they also account for convolutional layers.
  2. Importance Score Calculation: For each channel within these components, an importance score is computed. This is done by evaluating the KL-divergence between the model's output logits and the teacher model's logits when a specific channel is removed (or masked to zero for attention mechanisms). A proxy dataset of 2000 images is used for this evaluation.
  3. Structured Pruning: Based on the calculated importance scores and a predefined compression ratio, redundant channels are removed. Crucially, UP-ViTs ensures that the dimensionality remains consistent across components linked by shortcut connections, preserving the overall model structure.
  4. Progressive Block Pruning: For further compression, the authors propose a method to progressively prune entire blocks. This involves calculating the importance of each block and iteratively removing the least important ones.
  5. Fine-tuning with Knowledge Distillation: After pruning, the compressed sub-model is fine-tuned. The paper advocates for soft distillation, using the original pre-trained model as a teacher, which they found to be more effective than hard distillation for ViTs.

Datasets

The paper utilizes several datasets for training and evaluation:

  • ImageNet-1k: The primary dataset for image classification benchmarking.
  • Small-scale classification datasets: CIFAR-100, CUB-200, Cars, Aircraft, Indoor67, Pets, DTD, and iNaturalist-2019 were used to evaluate the generalization capabilities of the pruned models on various classification tasks.
  • MS COCO2017 and Pascal VOC07+12: These datasets were used to evaluate the performance of the pruned models on object detection tasks.

No new benchmarks were introduced; standard datasets were used to demonstrate the effectiveness of the proposed method.

Key Insights and Ideas

  • Unified Channel Pruning: The most significant insight is the development of a unified approach to prune channels across all ViT components (attention, FFN, shortcuts, normalization, and even convolutions in variants). This contrasts with previous methods that often focused on specific parts.
  • Structural Consistency is Key: The paper emphasizes that maintaining the structural consistency of ViTs is crucial for generalization. By pruning channels rather than tokens, UP-ViTs avoids disrupting the spatial relationships and token representations, leading to better performance on downstream tasks like object detection.
  • KL-Divergence for Importance: Using KL-divergence to measure the impact of channel removal on the model's output distribution is an effective way to quantify channel importance, drawing inspiration from successful CNN pruning techniques.
  • Soft Distillation for ViTs: Contrary to some observations in CNNs, the authors found that soft distillation is a superior method for fine-tuning pruned ViTs compared to hard distillation.
  • Progressive Block Pruning: While one-time pruning of channels is effective, progressive block pruning offers a way to achieve deeper compression by iteratively removing less critical blocks, albeit with a slight accuracy trade-off in some cases.

Key Results

  • ImageNet Classification: UP-DeiT-T achieved 75.79% accuracy on ImageNet, outperforming the vanilla DeiT-T by 3.59% with the same computational cost. UP-PVTv2-B0 improved PVTv2-B0's accuracy by 4.83%.
  • Object Detection: UP-ViTs demonstrated consistent improvements on object detection tasks. For instance, UP-PVTv2-B0 as a backbone for RetinaNet on Pascal VOC07+12 achieved 82.0 mAP, surpassing the original PVTv2-B0 by 1.5 AP points.
  • Efficiency: The compressed models achieved significant speedups. For example, UP-DeiT-S achieved 3.03x acceleration on a TITAN Xp GPU compared to the original DeiT-S.
  • Generalization: The pruned models showed competitive or improved accuracy across various small-scale classification datasets, indicating good generalization.

Limitations and Future Work

  • Manual Component Identification: A current limitation is the need to manually identify the uncorrelated components within different ViT architectures. The authors suggest that automating this process would be an interesting future research direction.
  • Focus on Heavy Models: The current work primarily focuses on compressing large, pre-trained ViTs into existing lighter architectures. Future work could explore pruning ViTs to make them even more attractive for embedded systems.
  • NLP Extension: Given the transformer's origin in NLP, generalizing the pruning framework to NLP tasks is another promising avenue.
  • Exploring Other Distillation Strategies: While soft distillation was found to be effective, further exploration of other distillation techniques could yield even better results.

Summary updated

Abstract

Recently, vision transformer (ViT) and its variants have achieved promising performances in various computer vision tasks. Yet the high computational costs and training data requirements of ViTs limit their application in resource-constrained settings. Model compression is an effective method to speed up deep learning models, but the research of compressing ViTs has been less explored. Many previous works concentrate on reducing the number of tokens. However, this line of attack breaks down the spatial structure of ViTs and is hard to be generalized into downstream tasks. In this paper, we design a unified framework for structural pruning of both ViTs and its variants, namely UP-ViTs. Our method focuses on pruning all ViTs components while maintaining the consistency of the model structure. Abundant experimental results show that our method can achieve high accuracy on compressed ViTs and variants, e.g., UP-DeiT-T achieves 75.79% accuracy on ImageNet, which outperforms the vanilla DeiT-T by 3.59% with the same computational cost. UP-PVTv2-B0 improves the accuracy of PVTv2-B0 by 4.83% for ImageNet classification. Meanwhile, UP-ViTs maintains the consistency of the token representation and gains consistent improvements on object detection tasks.
BibTeX
@misc{yu2021unified,
  author = {Hao Yu and Jianxin Wu},
  title = {{A Unified Pruning Framework for Vision Transformers}},
  year = {2021},
  eprint = {2111.15127},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2111.15127},
}
Figure