Abstract
Vision Transformers (ViTs) have demonstrated state-of-the-art performance in computer vision but suffer from high computational costs due to the quadratic complexity of self-attention. This paper proposes Prune and Merge (PM-ViT), a novel token compression framework designed for hardware efficiency. By integrating token pruning with a learnable merging mechanism, PM-ViT maintains spatial resolution and information density. Experimental results show that PM-ViT achieves a 1.64× speedup on DeiT-Small with a negligible 0.2% accuracy drop on ImageNet-1k, outperforming existing pruning and merging techniques in both speed and accuracy.
Introduction
The primary bottleneck in deploying Vision Transformers (ViTs) on edge devices is the computational overhead of processing a large number of image patches (tokens). Existing reduction strategies typically follow two paths: Token Pruning, which discards unimportant tokens, and Token Merging, which aggregates similar tokens. While pruning is fast, it often leads to irreversible information loss and disrupts spatial structure. Conversely, merging preserves more data but frequently relies on iterative, hardware-unfriendly algorithms like clustering.
PM-ViT addresses these limitations by combining the strengths of both approaches into a unified, matrix-based module that is optimized for standard AI accelerators.
Methodology: The Prune and Merge Module
The core innovation of PM-ViT is the replacement of complex sorting or matching algorithms with standard linear algebra operations.
Learnable Compression
- Merge Matrix ($M$): Instead of iterative clustering, PM-ViT uses a learnable matrix to compress $N$ tokens into $M$ tokens via simple matrix multiplication. This ensures high throughput on GPUs.
- Reconstruct Matrix ($M^+$): To maintain spatial resolution for downstream tasks like segmentation, the Moore-Penrose pseudoinverse of the merge matrix is used to "un-merge" tokens at the end of a transformer block.
- Shortcut Connections: Information from pruned tokens is not discarded. Instead, it is preserved through a shortcut connection that bypasses the heavy transformer layers and is reintegrated during the reconstruction phase.
Importance Scoring
To identify critical tokens, the authors employ Gradient-weighted Attention Scoring. By combining traditional attention maps with gradient information (via a first-order Taylor expansion), the model captures the global impact of each token on the final prediction. This scoring mechanism is learned during training, introducing zero overhead during inference.
Key Results
The effectiveness of PM-ViT was validated on ImageNet-1k for classification and ADE20K for semantic segmentation.
- Classification Performance: On DeiT-Small, PM-ViT achieved a 1.64× speedup with only a 0.2% drop in Top-1 accuracy. For DeiT-Tiny, it reached a 1.51× speedup with a similar 0.2% drop, consistently outperforming methods like ToMe and Evo-ViT.
- Semantic Segmentation: On the ADE20K dataset, PM-ViT demonstrated superior trade-offs between mean Intersection over Union (mIOU) and computational cost (GFLOPs/FPS).
Discussion and Insights
Hardware Compatibility
A significant advantage of PM-ViT is its reliance on matrix multiplication rather than operations like argsort or iterative loops. This design choice translates directly into higher actual throughput (images per second) on real-world hardware compared to theoretically efficient but practically slow competitors.
Pruning as Regularization
Interestingly, the study found that pruning a small percentage of low-scoring tokens can sometimes improve accuracy. This suggests that pruning acts as a form of noise reduction or regularization, helping the model focus on the most salient features of the image.
Limitations
The method shows some sensitivity to target positions; heavy random cropping during data augmentation can disrupt the "prior knowledge" encoded in the learnable matrices. Future work may involve making the importance scoring more dynamic and image-specific without sacrificing the current speed advantages.
Conclusion
PM-ViT provides a mathematically elegant and hardware-efficient solution for ViT token compression. By unifying pruning and merging through learnable matrix operations, it achieves significant speedups while preserving the spatial information necessary for both classification and dense prediction tasks.
Summary updated