NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Token Merging for Fast Stable Diffusion

Daniel Bolya, Judy Hoffman · DOI

Abstract

The landscape of image generation has been forever changed by open vocabulary diffusion models. However, at their core these models use transformers, which makes generation slow. Better implementations to increase the throughput of these transformers have emerged, but they still evaluate the entire model. In this paper, we instead speed up diffusion models by exploiting natural redundancy in generated images by merging redundant tokens. After making some diffusion-specific improvements to Token Merging (ToMe), our ToMe for Stable Diffusion can reduce the number of tokens in an existing Stable Diffusion model by up to 60% while still producing high quality images without any extra training. In the process, we speed up image generation by up to 2× and reduce memory consumption by up to 5.6×. Furthermore, this speed-up stacks with efficient implementations such as xFormers, minimally impacting quality while being up to 5.4× faster for large images.

Introduction

State-of-the-art image generators like Stable Diffusion rely on Transformer architectures. While powerful, Transformers suffer from a "quadratic bottleneck": the computational cost grows with the square of the number of tokens (essentially the number of pixels). As users demand higher-resolution images, generation becomes prohibitively slow and memory-intensive.

Existing solutions like Flash Attention or xFormers optimize how the math is handled on the GPU, but they still process every single token. The authors argue this is wasteful because images contain massive amounts of redundant information (e.g., many blue tokens in a clear sky). The challenge is reducing the token count to save time without "breaking" the spatial structure required to reconstruct a coherent image.

Methods

The authors adapt Token Merging (ToMe)—originally designed for image classification—to the generative world of Stable Diffusion. Their approach involves three key technical innovations:

  1. Unmerging for Dense Prediction: Unlike classification, diffusion models must predict noise for every pixel. To handle this, the authors merge similar tokens before expensive operations (like Self-Attention), perform the computation on the reduced set, and then "unmerge" them back to their original positions before the next stage of the network.
  2. Randomized 2×2 Partitioning: To preserve global structure, the authors introduced a "random 2×2" strategy: they divide the image into 2×2 grids and randomly pick one "destination" token in each grid to merge others into.
  3. Strategic Application: ToMe is applied only to Self-Attention modules and focused on the highest-resolution layers of the U-Net to provide the best balance of speed and fidelity.
Comparison of Token Merging vs Token Pruning

A critical insight of this work is that Merging > Pruning. As shown in the figure above, simply deleting "unimportant" tokens (pruning) destroys image quality. Merging them (averaging the features of similar tokens) preserves the information needed to maintain the scene's context.

Key Insights

  • Zero-Shot Speedup: This method requires no retraining. It can be applied immediately to off-the-shelf Stable Diffusion models.
  • The "Stacking" Effect: ToMe is complementary to existing optimizations. When combined with xFormers, the speed gains are multiplicative.
  • Consistency is Key: For techniques like Classifier-Free Guidance, the random token partitioning must be identical for both passes to prevent the images from diverging.

Results

The researchers evaluated their method using Stable Diffusion v1.5 on ImageNet-1k. At 50% token reduction, the FID score remained very close to the baseline (33.02 vs 33.12), meaning the speedup comes with almost no perceptible loss in image quality for most scenes.

Speedup comparison between Baseline, xFormers, and xFormers + ToMe

As illustrated in the comparison above, ToMe achieves significant performance gains. It provides up to a 2× speedup on standard 512×512 images. For massive 2048×2048 images, the combination of ToMe and xFormers was 5.4× faster than the baseline, generating a high-res image in just 28 seconds on an RTX 4090. Memory usage was also reduced by up to 5.6× when merging 60% of tokens.

Limitations and Future Work

While highly effective, at very high reduction rates (above 60%), fine details can start to blur. Future directions include exploring more sophisticated "unmerging" strategies to better recover fine details and applying these merging techniques to other "dense" tasks like video generation or object detection.

Summary updated

BibTeX
@misc{bolya2023token,
  author = {Daniel Bolya and Judy Hoffman},
  title = {{Token Merging for Fast Stable Diffusion}},
  year = {2023},
  eprint = {2303.17604},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2303.17604},
}
Figure