ToDo: Token Downsampling for Efficient Generation of High-Resolution Images

Ethan Smith, Nayan Saxena, Aninda Saha

Abstract

High-resolution image generation in diffusion models is often bottlenecked by the quadratic computational complexity of the self-attention mechanism. We introduce ToDo (Token Downsampling), a training-free, post-hoc optimization that accelerates high-resolution synthesis in Stable Diffusion by up to 4.5x. By exploiting spatial redundancy, ToDo downsamples key and value tokens via simple strided operations while preserving the full resolution of query tokens. This strategy significantly reduces VRAM usage and latency without the "quality tax" of blurriness associated with existing token-merging techniques.

Introduction

The attention mechanism is the engine behind modern image diffusion models, but it comes with a heavy price: quadratic computational complexity. As image resolution increases, the memory and time required to process attention maps explode. For instance, generating a $2048 \times 2048$ image can require nearly 70 GB of VRAM for a single U-Net block—far exceeding the capacity of most consumer GPUs.

Existing solutions like Token Merging (ToMe) attempt to solve this by combining similar tokens. However, ToMe introduces its own bottlenecks: it requires expensive $O(n^2)$ similarity calculations to decide which tokens to merge, and its "merge-unmerge" cycle often leads to a loss of fine detail and image blurriness. ToDo addresses these challenges by providing a simpler, faster, and more fidelity-preserving alternative.

Methods

ToDo is built upon two primary innovations designed to prune redundant information efficiently:

1. Spatial Contiguity-Based Downsampling

Instead of calculating a complex similarity matrix between every pair of tokens, ToDo assumes that adjacent pixels in an image are naturally similar. It uses a simple, strided downsampling function (Nearest-Neighbor) to reduce the number of tokens. This turns an $O(n^2)$ search into a lightning-fast $O(n)$ operation.

2. Refined Attention Mechanism

In standard attention, the model processes Queries ($Q$), Keys ($K$), and Values ($V$). Previous methods reduced all three. ToDo makes a clever distinction: it downsamples $K$ and $V$ but keeps the full set of original Queries ($Q$).

Visualization of the ToDo attention mechanism: full-resolution query tokens (blue) attend to a downsampled set of key/value tokens (red).

By keeping all queries, the model maintains the high-resolution "requests" for information, while the downsampled keys and values provide a compressed "database" to look up. This mathematical tweak ensures that the output maintains the integrity and detail of the original resolution while drastically reducing the size of the matrices involved in the computation.

Experimental Setup

The researchers evaluated ToDo using the DreamshaperV7 model (a popular finetuned version of Stable Diffusion) on a single NVIDIA A6000 GPU. Benchmarks were conducted at resolutions of $1024 \times 1024$, $1536 \times 1536$, and $2048 \times 2048$. Performance was measured using Mean Squared Error (MSE) to measure deviation from a baseline and High Pass Filter (HPF) scores to quantify how well the method preserved sharp textures and fine details.

Results and Discussion

Efficiency and Speed

ToDo achieved a 2x speedup for common image sizes and a massive 4.5x speedup for $2048 \times 2048$ resolutions. By reducing the token count from over 65,000 to just 4,096 in the largest blocks, ToDo makes ultra-high-res generation feasible on hardware that would otherwise crash.

Fidelity and Sharpness

Compared to ToMe at the same compression ratios, ToDo consistently produced lower MSE, meaning it stayed truer to the original model's intent. In HPF tests, ToDo maintained values very close to the baseline (e.g., 4.73 vs 4.84), whereas ToMe's scores dropped significantly (to ~4.00), indicating a visible loss of texture and "crispness."

Key Insights

  • Neighborly Redundancy: Latent features in the U-Net are highly redundant. Even in the "worst-case" scenarios, cosine similarity remained above 0.7, justifying simple spatial downsampling.
  • Queries are Sacred: Preserving the full resolution of Queries ($Q$) is the secret to maintaining image sharpness. When $Q$ is downsampled, the model loses the ability to place fine details accurately.
  • Dynamic Redundancy: Redundancy changes across denoising timesteps. It is highest early in the process when sketching broad shapes and decreases as the model begins to refine distinct textures.

Conclusion

ToDo provides a powerful "plug-and-play" optimization for high-resolution diffusion. By prioritizing query resolution and leveraging spatial contiguity, it achieves significant speedups without sacrificing image quality. Future work includes making the downsampling process differentiable for potential fine-tuning and exploring its application in other attention-based generative models like video generators.

Summary updated

BibTeX
@inproceedings{smith2024todo,
  author = {Ethan Smith and Nayan Saxena and Aninda Saha},
  title = {{ToDo: Token Downsampling for Efficient Generation of High-Resolution Images}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2024},
}
Figure