TL;DR
This paper introduces PiToMe, a novel token merging technique for Vision Transformers (ViTs) that prioritizes preserving important image features. By introducing an "energy score" to identify and protect informative tokens, PiToMe significantly reduces model size and computational cost while achieving better performance than existing methods like ToMe, especially in deeper network layers.
What Problem Does This Paper Address?
Vision Transformers (ViTs) have revolutionized computer vision, but their substantial memory and computational requirements hinder their widespread adoption, especially for larger models. While techniques like token merging (e.g., ToMe) offer a way to compress these models by reducing the number of tokens processed at each layer, they face challenges. Specifically, existing methods like ToMe rely on simple token-splitting strategies that can lead to the merging of important tokens with less relevant ones, particularly in deeper layers where informative tokens are crucial. This can degrade model performance. The paper aims to address this by developing a more intelligent token merging strategy that actively protects essential information.
Methods
The core innovation of PiToMe lies in its "energy score" mechanism, inspired by graph cutting algorithms. Instead of relying solely on token similarity for merging, PiToMe first models the transformer's token interactions as a graph. Each token is assigned an "energy score" that reflects its importance and connectivity.
Here's a breakdown of the process:
- Graph Construction: The input graph is formed using key vectors from the attention block as nodes. Edge weights are determined by cosine similarity between these vectors.
- Energy Score Calculation: For each node (token), an energy score is computed. This score is a normalized measure of its edge weights to neighboring nodes. A special function
f(x)is used to selectively consider nearby neighbors and downplay distant ones, with a tunable marginmthat adapts across layers. - Token Protection and Merging: Tokens with high energy scores are identified as potentially important and are "protected" from merging. The remaining tokens are then split into two sets (A and B), and tokens in set A are merged with their closest neighbors in set B, weighted by their energy scores. This ensures that important tokens are less likely to be merged away.
Datasets
The paper evaluates PiToMe on standard benchmarks for two tasks:
- Image Classification: ImageNet-1k dataset.
- Image-Text Retrieval: Flickr30k and MSCOCO datasets.
The experiments utilize pre-trained ViT backbones of various sizes (tiny, small, base, large, huge) trained with different pre-training strategies like MAE and DEIT.
Key Insights and Ideas
- Beyond Simple Similarity: The paper convincingly argues that relying solely on token similarity for merging is insufficient, especially in deeper layers. Informative tokens can be lost if they happen to be similar to less important ones.
- Energy Score as a Guardian: The "energy score" acts as a crucial safeguard, allowing the model to identify and preserve tokens that are vital for understanding the image content, even if they have high similarity to other tokens.
- Layer-Adaptive Merging: The energy score calculation incorporates a layer-dependent margin, allowing the merging strategy to adapt as the network progresses through its layers, becoming more conservative with informative tokens in deeper stages.
- Off-the-Shelf Effectiveness: PiToMe demonstrates strong performance even when applied directly to pre-trained models without retraining, highlighting its practical utility for accelerating existing architectures.
Key Results
PiToMe shows significant improvements over the ToMe baseline and other BSM-based approaches:
- Image Classification: Achieved up to a 50% memory reduction with only a 1.71% average performance drop, compared to a 2.6% drop for ToMe.
- Image-Text Retrieval: Achieved a 1.35% average performance drop, significantly outperforming ToMe's 6.89% drop.
- Qualitative Results: Visualizations show PiToMe better preserving attention maps on important image regions (e.g., the cat in the car example) compared to ToMe, which can sometimes merge these critical features.
Limitations and Future Work
- Scope: The current work focuses on encoder-only ViT models for image classification and image-text retrieval.
- Future Directions: The authors suggest extending PiToMe to decoder models for tasks like stable diffusion, image captioning, text classification, and summarization. They also plan to explore more sophisticated graph-based approaches for token merging.
Summary updated