Efficient Visual Transformer by Learnable Token Merging

Yancheng Wang, Yingzhen Yang

Abstract

Vision Transformers (ViTs) have set new benchmarks in computer vision, yet their quadratic computational scaling with token count limits deployment on edge devices. We introduce Learnable Token Merging (LTM), a novel framework that accelerates ViTs by merging redundant tokens into a compact, informative set. Grounded in Information Bottleneck (IB) theory, LTM employs a learnable mask module to optimize the compression-information trade-off. Our results show that LTM consistently reduces FLOPs and inference latency while often improving top-1 accuracy, providing a superior Pareto frontier compared to existing heuristic-based pruning and merging methods.

Introduction

While Vision Transformers have revolutionized the field, their high computational cost remains a significant barrier for resource-constrained applications. Existing efficiency solutions generally fall into two categories: token pruning (discarding tokens) and token merging (combining tokens). However, these methods often rely on simple feature similarity or heuristic averaging, creating a "principled gap" where task-critical information may be inadvertently lost.

To address this, we propose a strategy that is both learnable and theoretically grounded, ensuring that the most task-relevant data is preserved during the reduction process.

Methodology: Learnable Token Merging

The core of our approach is the LTM Block, designed as a "drop-in" replacement for standard transformer blocks. Unlike static merging, LTM treats token reduction as an optimization problem guided by the Information Bottleneck (IB) principle. The goal is to compress the input $X$ into a representation $\tilde{X}$ that retains maximum information about the target label $Y$ while discarding irrelevant noise.

The LTM Architecture

Every LTM block utilizes a learnable mask module to generate a merging mask $G^{(l)}$. This mask produces "target tokens" which are informative weighted averages of the original tokens. To make this computationally feasible, we derive a novel, separable variational upper bound for the IB loss, allowing the merging mask to be updated via standard Stochastic Gradient Descent (SGD) during training.

Architecture of LTM blocks for global (left) and local (right) attention mechanisms.

As shown in the figure above, the LTM block is compatible with both global attention (standard ViT/Swin) and local attention (MobileViT/EfficientViT) through unfolding and folding operations. This universal compatibility allows LTM to enhance a wide variety of backbone architectures.

Experimental Results

We evaluated LTM-Transformer on standard benchmarks, including ImageNet-1k for classification and MS-COCO for downstream tasks like object detection and instance segmentation.

Classification Performance

LTM-Transformer consistently achieves a better balance between accuracy and speed than vanilla models and competing methods like ToMe or ToFu.

Performance comparison of LTM against baseline models and existing token reduction methods on ImageNet-1k.

Key highlights from our ImageNet evaluation include:

  • LTM-MobileViT-S achieved 79.7% top-1 accuracy with 1.17G FLOPs, significantly outperforming the vanilla MobileViT-S (78.4% accuracy at 1.40G FLOPs).
  • LTM-Swin-T reached 81.8% accuracy with 3.8G FLOPs, compared to the original Swin-T's 81.3% at 4.5G FLOPs.
  • Across all tested models, LTM reduced inference time by approximately 10-20% per batch.

The "Accuracy Bonus"

One of the most striking findings is that LTM often outperforms the original full-token models. This suggests that the IB-guided merging acts as a form of regularization, effectively filtering out redundant or distracting background information that could otherwise lead to overfitting. Visualization confirms that LTM successfully focuses on critical object features, such as the eyes of an animal or the wheels of a vehicle, while aggressively compressing background noise.

Conclusion and Future Work

LTM-Transformer bridges the gap between efficiency and performance by framing token merging as an iterative optimization of the Information Bottleneck. While the training process introduces a marginal overhead due to the calculation of variational distributions, the resulting models are faster and more accurate for inference.

Future research will focus on further optimizing the training efficiency of the mask module and exploring the potential of LTM in even more diverse multimodal architectures. Currently, the compression ratio remains a hyperparameter that requires careful tuning; automating this selection could further streamline the deployment of efficient Transformers.

Summary updated

BibTeX
@article{wang2024efficient,
  author = {Yancheng Wang and Yingzhen Yang},
  title = {{Efficient Visual Transformer by Learnable Token Merging}},
  journal = {IEEE Trans. Pattern Anal. Mach. Intell.},
  year = {2024},
}
Figure