Pruning Self-Attentions Into Convolutional Layers in Single Path

Haoyu He, Jianfei Cai, Jing Liu, Zizheng Pan, Jing Zhang, Dacheng Tao, Bohan Zhuang

Here is a concise, engaging summary of the paper "Pruning Self-attentions into Convolutional Layers in Single Path".

TL;DR

Single-Path Vision Transformer pruning (SPViT) is a novel compression method that automatically transforms computationally expensive global self-attention layers into efficient, local convolutional layers. By using a clever weight-sharing scheme, SPViT slashes computational costs (FLOPs) by up to 52% while actually improving model accuracy on ImageNet.

What Problem Does This Paper Address?

Vision Transformers (ViTs) have taken the computer vision world by storm, but they suffer from two major drawbacks:

  1. High Computational Cost: The Multi-Head Self-Attention (MSA) layers scale quadratically with the number of image patches, making them memory and compute-hungry.
  2. Lack of Inductive Bias: Unlike Convolutional Neural Networks (CNNs), ViTs don't inherently understand "locality"—the idea that neighboring pixels are highly related. They have to learn this from scratch.

Standard pruning methods simply drop less important attention heads or tokens, which can hurt performance. Neural Architecture Search (NAS) can find efficient hybrid (CNN-Transformer) models, but training separate "paths" for convolutions and attentions is incredibly expensive. The authors ask: Can we automatically prune a pre-trained ViT into an efficient hybrid model without the massive search cost?

Methods

The authors introduce SPViT, which unifies pruning and locality injection into a single framework using three core components:

  • Single-Path Weight-Sharing: Instead of treating convolutions and attentions as separate entities, the authors prove that a bottleneck convolution can be mathematically expressed as a subset of MSA parameters. This allows them to initialize convolution kernels directly from pre-trained MSA weights.
  • Unified Search Space with Binary Gates: The entire network is wrapped into a single-path search space. Learnable binary gates (optimized via a computational complexity loss) decide whether a layer should remain a global MSA, switch to a local bottleneck convolution (with $1\times1$ or $3\times3$ kernels), or become a skip-connection. Similar gates are applied to the Feed-Forward Networks (FFNs) to prune individual hidden dimensions dynamically.
  • CNN-Targeted Knowledge Distillation: Because the pruned model now contains convolutional layers, the authors use a pre-trained CNN (like RegNetY) as a teacher during fine-tuning to better guide the newly introduced local structures.
[Pre-trained MSA Layer] ───► [Single-Path Search Space] ───► [Optimized Hybrid Layer]
                                 (Binary Gates Choose)          (MSA or Convolution)

Datasets

The method was evaluated on the standard image classification benchmark:

  • ImageNet-1k: Contains 1.28 million training images and 50,000 validation images across 1,000 classes.

Key Insights and Ideas

  • Locality belongs in the shallows: The search algorithm consistently chose to prune MSA layers into convolutions in the shallow (early) blocks of the network, while keeping the deep (later) layers as global attention. This confirms that early layers naturally benefit from local feature extraction (edges, textures), while later layers need global context.
  • Weight-sharing eases optimization: Initializing convolutional layers with pre-trained MSA weights provides an excellent starting point, cutting the architecture search cost by more than 50% compared to traditional multi-path NAS.
  • FFN redundancy depends on architecture type: In standard ViTs (like DeiT), the final FFN layers are highly redundant and can be aggressively pruned. In hierarchical ViTs (like Swin), shallower layers within each stage require more capacity to handle the feature space changes caused by token merging.

Key Results

SPViT achieves state-of-the-art (SOTA) pruning performance across multiple ViT backbones on ImageNet-1k:

  • DeiT-B: Trimmed 52.0% of FLOPs and reduced parameters from 86.4M to 41.6M, while achieving a 0.6% top-1 accuracy gain (82.4% vs. 81.8% baseline) when paired with distillation.
  • DeiT-S: Reduced FLOPs by 28.3% with a 0.4% accuracy boost.
  • Swin-S: Reduced FLOPs by 29.9% while maintaining identical baseline accuracy (83.0%).

Compared to token-compression methods, SPViT significantly reduces the physical size (parameters) of the model, making it much more suitable for edge deployment.

Limitations and Future Work

  • Coarse Granularity: Currently, SPViT operates at an "all-or-nothing" layer level—transforming the entire MSA layer into a convolution. The authors note that integrating fine-grained head pruning (keeping some attention heads global while turning others local within the same layer) is a promising next step.
  • Convolution Variants: The current weight-sharing scheme is limited to standard bottleneck convolutions. Extending this math to support depth-wise or group convolutions could yield even lighter models.

Summary updated

BibTeX
@article{he2024pruning,
  author = {Haoyu He and Jianfei Cai and Jing Liu and Zizheng Pan and Jing Zhang and Dacheng Tao and Bohan Zhuang},
  title = {{Pruning Self-Attentions Into Convolutional Layers in Single Path}},
  journal = {IEEE Trans. Pattern Anal. Mach. Intell.},
  year = {2024},
  url = {https://openreview.net/forum?id=MfzCrnlgE5},
}
Figure