[Paper Review] SimA: Simple Softmax-free Attention for Vision Transformers
This paper proposes SimA, a softmax-free attention mechanism for Vision Transformers that replaces the computationally expensive Softmax with ℓ₁-normalization of query and key matrices, enabling dynamic computation ordering at inference time to reduce complexity to O(ND) or O(D²N) based on input resolution. SimA achieves state-of-the-art accuracy on ImageNet, MS-COCO, and self-supervised benchmarks while eliminating the exp(.) operation, significantly improving efficiency on edge devices.
Recently, vision transformers have become very popular. However, deploying them in many applications is computationally expensive partly due to the Softmax layer in the attention block. We introduce a simple but effective, Softmax-free attention block, SimA, which normalizes query and key matrices with simple $\ell_1$-norm instead of using Softmax layer. Then, the attention block in SimA is a simple multiplication of three matrices, so SimA can dynamically change the ordering of the computation at the test time to achieve linear computation on the number of tokens or the number of channels. We empirically show that SimA applied to three SOTA variations of transformers, DeiT, XCiT, and CvT, results in on-par accuracy compared to the SOTA models, without any need for Softmax layer. Interestingly, changing SimA from multi-head to single-head has only a small effect on the accuracy, which simplifies the attention block further. The code is available here: https://github.com/UCDvision/sima
Motivation & Objective
- To reduce the computational cost of Vision Transformers, especially the expensive exp(.) operation in Softmax, for deployment on edge devices.
- To maintain or improve model accuracy while removing the Softmax layer from the attention mechanism.
- To enable dynamic computation reordering at test time based on the number of tokens (N) and channels (D), optimizing for efficiency.
- To explore the feasibility of single-head attention and ReLU activation in place of multi-head and GELU without significant accuracy drop.
- To provide a numerically stable, half-precision compatible attention mechanism that preserves permutation invariance and token significance interpretation.
Proposed method
- Replace the Softmax operation in self-attention with ℓ₁-normalization of query and key matrices before their dot product.
- Compute attention as a simple matrix multiplication: O = (Q_normalized) @ (K_normalized.T) @ V, eliminating the need for exp(.) and Softmax.
- Dynamically choose the computation order at test time: (Q @ K.T) @ V if N > D, or Q @ (K.T @ V) if D > N, to minimize FLOPs.
- Use ℓ₁-normalization to ensure numerical stability, allowing half-precision inference without overflow.
- Preserve permutation invariance by treating tokens as a non-ordered set, enabling use with multi-source inputs like multiple cameras or sensors.
- Apply the SimA block to DeiT, XCiT, and CvT models without architectural changes, maintaining standard training protocols.
Experimental results
Research questions
- RQ1Can a softmax-free attention mechanism maintain state-of-the-art performance in vision transformers?
- RQ2Does replacing Softmax with ℓ₁-normalization of queries and keys preserve model accuracy while reducing computational cost?
- RQ3Can dynamic computation ordering at inference time based on N and D lead to significant efficiency gains?
- RQ4How does single-head attention with ReLU compare to multi-head with GELU in the absence of Softmax?
- RQ5Can the magnitude of normalized query and key vectors serve as a meaningful saliency map for model interpretation?
Key findings
- SimA achieves on-par accuracy with SOTA models on ImageNet classification, MS-COCO object detection and segmentation, and self-supervised learning benchmarks.
- On a 1536×1536 image, SimA is 58% faster than DeiT due to elimination of the Softmax exp(.) overhead.
- With a model dimension of 8192, SimA reduces inference time by 22% compared to XCiT by avoiding Softmax computation.
- Single-head SimA achieves comparable accuracy to multi-head SOTA models, indicating minimal performance loss from head reduction.
- ReLU activation in place of GELU results in only a minor drop in accuracy, suggesting robustness to activation function changes.
- The ℓ₂-norm of normalized query and key vectors produces meaningful saliency maps that highlight important image regions, unlike the flat distributions seen in standard DeiT.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.