Local Representative Token Guided Merging (ReToM)
- Local Representative Token Guided Merging (ReToM) is an adaptive token merging technique that partitions tokens into local windows to reduce the quadratic cost of self-attention.
- It employs cosine similarity to select a representative token per window, ensuring that salient visual features are preserved during the merge.
- Empirical results on Stable Diffusion demonstrate improved FID and CLIP scores with efficient near-linear scaling in attention computations.
Local Representative Token Guided Merging (ReToM) is a token merging strategy designed to accelerate attention-based text-to-image generation models, specifically targeting the computational bottleneck in the self-attention layers of architectures such as Stable Diffusion’s U-Net. ReToM introduces local adaptive windowing, representative token selection grounded in window-level similarity dynamics, and similarity caching, aiming to reduce the quadratic cost of attention while preserving visual fidelity and salient feature detail. Experimentally, ReToM improves both FID and CLIP scores over prior merging methodologies with comparable inference times and without requiring additional training (Lee et al., 17 Jul 2025).
1. Motivation and Limitations of Prior Work
The computational inefficiency of self-attention in U-Net architectures—a core component in models like Stable Diffusion—is due to the scaling with respect to the number of input tokens . For high-resolution image synthesis, this cost results in slow generation and heavy memory consumption. Token merging strategies, such as ToMeSD [Bolya & Hoffman ’23], attempt to reduce this cost by grouping similar tokens for attention, but these methods exhibit several limitations:
- Fixed windowing: Prior approaches commonly employ a fixed region size throughout all attention layers, neglecting the changing receptive field across the U-Net’s depth.
- Suboptimal token destination selection: Merging source tokens into destination tokens is typically performed via random selection or bipartite matching, risking the loss of salient local structures.
- Computational redundancy: Similarity computations are performed in every diffusion timestep, maintaining a significant quadratic complexity burden.
ReToM addresses these constraints by employing adaptive local windows, selection of a single representative token per window based on similarity, and cached similarity updates at reduced temporal frequency (Lee et al., 17 Jul 2025).
2. Local Window Partitioning Formalism
At any given attention layer in the U-Net Transformer, denote the sequence of tokens as . ReToM partitions the index set into non-overlapping windows:
Each window contains tokens, with window size adaptively chosen per layer.
When tokens map to an 0 grid (common in vision Transformer applications), the window 1 is constructed as:
2
where 3 and indices traverse to exhaustively and non-overlappingly cover all positions.
3. Representative Token Selection within Windows
Within each local window 4, ReToM performs all-pairs cosine similarity analysis and, for each token 5 in 6, computes its average similarity to all other tokens:
7
8
The representative token 9 is the one maximizing the above similarity criterion:
0
All tokens in 1 are deemed possible sources for merging into 2, concentrating window-level context into locally salient features.
4. Merging and Processing Algorithm
Merging is executed only every 3 diffusion timesteps, leveraging cached window-level similarities for computational amortization.
For each window 4 at a merge timestep 5:
- Compute or load (if 6) 7 for all 8.
- Select 9, the representative token as per the maximal average similarity.
- Determine the number of source tokens, 0, using a merge ratio 1.
- Select the top 2 non-representative tokens in 3 by ranking 4.
- The merged token is computed as:
5
where 6 is a balancing hyperparameter and 7 are ranked source tokens.
- 8 is replaced by 9 for window 0.
- The modified token set is then used in conventional multi-head self-attention, drastically reducing per-window compute.
5. Complexity and Efficiency Analysis
The baseline U-Net self-attention at each layer requires 1 operations. By constraining self-attention to merged tokens per window (size 2 post-merge), per-window cost drops from 3 to 4. The major overhead becomes the computation of similarities for determining representative tokens, yet this is amortized across 5 timesteps.
Total per-layer amortized cost becomes:
6
where 7 is average window size at layer 8. Setting 9 sufficiently large and keeping windows small in early/late layers brings near-linear scaling for attention on most timesteps while accommodating context in deeper layers with larger windows.
6. Empirical Results and Ablations
All experiments were performed on Stable Diffusion with 50 sampling steps on 512×512 ImageNet images (guidance=7.5). The following summarizes the key quantitative results:
| Method | FID | CLIP | Speed (s/im) |
|---|---|---|---|
| Baseline SD | 37.02 | 38.10 | 2.62 |
| ToMeSD (fixed 2, rand) | 37.20 | 36.00 | 2.10 |
| ReToM (fixed 2, rep) | 35.00 | 37.90 | 2.25 |
| ReToM (adaptive + rep) | 34.89 | 39.40 | 2.17 |
- ReToM with adaptive windows and representative selection achieves FID = 34.89 (–5.8% vs. baseline), CLIP = 39.40 (+1.3), and 2.17 s/im inference speed.
- Excessively large fixed windows (size 16) degrade FID to 36.53, demonstrating the need for adaptive window sizing.
- Substituting the selection of the “most representative” with the “least representative” token raises FID and lowers SSIM (0.72→0.74), confirming the necessity of the optimal average similarity criterion.
- Visualizations show cosine similarities within windows remain above 0.9 over 0 steps, supporting the temporal caching approach.
7. Summary and Significance
ReToM institutes a scalable, adaptive local merging paradigm for U-Net Transformers, distinguished by local window partitioning per receptive field, maximally representative token selection via average similarity, top-r token convex merging, and efficient similarity caching. This methodology yields improved generation metrics and substantial reduction in quadratic attention cost over prior approaches—accomplishing efficiency and fidelity gains without supplementary training phases or fine-tuning (Lee et al., 17 Jul 2025).