Fair Comparison between Efficient Attentions

Jiuk Hong, Chaehyeon Lee, Soyoun Bang, Heechul JungarXiv 2022 · DOI · arXiv

Abstract

Standard self-attention in Transformers faces a quadratic complexity bottleneck, prompting numerous "efficient" alternatives. This study provides a fair benchmarking of these mechanisms—including Linformer, Performer, and Swin Transformer—within a unified Pyramid Vision Transformer architecture on ImageNet-1K. Results indicate that while efficient variants significantly reduce computational costs, they generally underperform compared to standard self-attention unless augmented with local spatial priors. Notably, the addition of a Local Patch Interaction (LPI) module allows certain efficient models to surpass the baseline, highlighting the importance of architectural synergy over attention math alone.

Introduction: The Quadratic Bottleneck

The "Standard" Transformer relies on self-attention, which has a major flaw: its computational cost grows quadratically ($O(N^2)$) with the number of input tokens. In computer vision, where high-resolution images are processed by breaking them into many small patches, this quadratic bottleneck makes Transformers prohibitively expensive for many real-world applications.

Over the last few years, a "zoo" of efficient attention mechanisms (Linformer, Performer, etc.) has emerged, claiming to reduce this cost to linear complexity ($O(N)$). However, these papers often use different model sizes, training schedules, and data augmentation techniques. This makes it difficult to discern if a performance boost comes from a clever new attention mechanism or simply a better-tuned training recipe. This research provides a "fair" head-to-head comparison by changing only the attention operation within a controlled baseline.

Benchmarking Methodology

The researchers implemented a Pyramid Vision Transformer as their baseline. This architecture processes images in four stages, gradually reducing spatial resolution (the number of tokens) while increasing the number of feature channels.

The Pyramid Vision Transformer baseline architecture used for benchmarking.

They swapped the standard Multi-Head Self-Attention (MSA) with several prominent "efficient" alternatives:

  • Linformer (LA): Projects keys and values into a lower-dimensional space.
  • Efficient Attention (EA): Changes the order of matrix multiplications to achieve linear complexity.
  • Performer (PA): Uses kernel features to approximate the softmax function.
  • XCiT (XCA): Transposes the attention operation to act across feature dimensions rather than tokens.
  • Fastformer (AA): Uses additive attention and element-wise multiplication.
  • Swin Transformer: Uses nested window-based attention.

Crucially, they also tested LPI (Local Patch Interaction), a module consisting of two convolutional layers designed to help transposed attention (XCA) recover spatial information.

Comparative Analysis and Results

All models were trained on ImageNet-1K for 310 epochs using the same AdamW optimizer and data augmentation strategies to ensure the results were strictly due to the attention mechanism used. The authors measured performance using Top-1 Accuracy and GFLOPs (computational cost).

Comprehensive performance comparison of various attention mechanisms on ImageNet-1K.

Key Insights

  • The "No Free Lunch" Theorem: Under fair conditions, standard self-attention (SA) remains the accuracy king. Every efficient variant tested resulted in some drop in Top-1 accuracy compared to the baseline. For example, the baseline (SA-4) achieved 81.80% accuracy at 8.821 GFLOPs, while Efficient Attention (EA-4) reached 79.87% accuracy with a ~50% reduction in computation.
  • The Power of Locality: The most surprising finding was that LPI-7 (XCiT with Local Patch Interaction) actually outperformed the standard baseline by 0.73% when using $7 \times 7$ patches. This suggests that for vision tasks, handling local spatial relationships is often more important than the global attention math itself.
  • Complexity vs. Performance: Performance generally improved as computational complexity increased (e.g., moving from $7 \times 7$ patches to $4 \times 4$ patches), regardless of the specific attention mechanism used.

Discussion and Conclusion

While standard self-attention is robust, efficient variants offer significant computational savings. The study highlights that the "winner" often depends on architectural "helpers" like the LPI module rather than the attention mechanism in isolation.

A limitation of this study is its primary focus on image classification. While classification is a strong benchmark, the real benefit of efficient attention is usually realized in "dense prediction" tasks like object detection or semantic segmentation, where token counts are much higher. Future work will explore how these efficient mechanisms behave when scaled to higher-resolution vision tasks where the $O(N^2)$ penalty of standard attention becomes truly untenable.

Summary updated

BibTeX
@misc{hong2022fair,
  author = {Jiuk Hong and Chaehyeon Lee and Soyoun Bang and Heechul Jung},
  title = {{Fair Comparison between Efficient Attentions}},
  year = {2022},
  eprint = {2206.00244},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2206.00244},
}
Figure