Skip to main content
QUICK REVIEW

[Paper Review] Learning to Merge Tokens in Vision Transformers

Cédric Renggli, André Susano Pinto|arXiv (Cornell University)|Feb 24, 2022
Multimodal Machine Learning ApplicationsComputer Science24 citations
TL;DR

Introduces PatchMerger, a learnable module that reduces token count between transformer blocks in ViT and V-MoE models, achieving similar accuracy with 40-60% compute savings.

ABSTRACT

Transformers are widely applied to solve natural language understanding and computer vision tasks. While scaling up these architectures leads to improved performance, it often comes at the expense of much higher computational costs. In order for large-scale models to remain practical in real-world systems, there is a need for reducing their computational overhead. In this work, we present the PatchMerger, a simple module that reduces the number of patches or tokens the network has to process by merging them between two consecutive intermediate layers. We show that the PatchMerger achieves a significant speedup across various model sizes while matching the original performance both upstream and downstream after fine-tuning.

Motivation & Objective

  • Motivate and address the growing computational cost of Vision Transformers at scale.
  • Propose PatchMerger to merge tokens between encoder blocks to reduce token count.
  • Demonstrate invariant output-token count while enabling fine-tuning at different resolutions.
  • Show that PatchMerger preserves performance while delivering substantial FLOPs and runtime savings.

Proposed method

  • PatchMerger places a learnable merging layer between two encoder blocks that outputs a fixed small number of tokens M (e.g., 8) from N input tokens.
  • Compute Y = softmax(W^T X^T) X with a learned W ∈ R^{D×M} and input X ∈ R^{N×D} after layer normalization, effectively performing bottom-up attention-like merging.
  • The output token count M is fixed regardless of input token count N, enabling flexible fine-tuning across resolutions.
  • A layer norm follows the PatchMerger to stabilize scale when input/output token counts differ.
  • Evaluates on ViT and V-MoE backbones trained on JFT, with downstream transfer to ImageNet (few-shot and full finetuning).
  • Assesses design choices: placement location (which encoder block) and target output token count (8 vs other values).

Experimental results

Research questions

  • RQ1Can a lightweight module merge tokens to reduce computational cost without harming accuracy in Vision Transformers?
  • RQ2Where in the network should token merging occur for best trade-offs between cost and performance?
  • RQ3How many output tokens should PatchMerger produce to balance efficiency and accuracy?
  • RQ4Does PatchMerger maintain transfer performance to downstream tasks (e.g., ImageNet) after pretraining on a large dataset?
  • RQ5How do PatchMerger variants perform for standard ViT versus mixture-of-experts (V-MoE) backbones?

Key findings

  • PatchMerger achieves comparable upstream and downstream performance to backbone ViT and V-MoE models while substantially reducing compute (40-60% for large models).
  • Merger ViT variants dominate the ViT Pareto frontier in FLOPs vs. accuracy, with notable gains at large scales (e.g., ViT-H/14 vs Merger ViT-H/14).
  • At full ImageNet finetuning, large Merger models (L/32, L/16, H/14) match backbone performance, with substantial FLOPs/runtime savings (e.g., ViT-H/14: 51.6% FLOPs, 63.5% runtime).
  • For ViT-H/11 (more initial tokens), the Merger variant still outperforms the standard backbone in upstream, few-shot, and finetuning accuracy while remaining cheaper.
  • Large V-MoE Merger models achieve substantial compute savings (around 53% FLOPs and 44% runtime) with comparable or improved downstream results on ImageNet.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.