[Paper Review] SwiftFormer: Efficient Additive Attention for Transformer-based Real-time Mobile Vision Applications
SwiftFormer proposes an efficient additive attention mechanism that replaces quadratic matrix multiplications in self-attention with linear element-wise operations, enabling high-accuracy, low-latency vision transformers on mobile devices. The method achieves 78.5% top-1 ImageNet-1K accuracy with only 0.8 ms inference latency on iPhone 14, outperforming MobileViT-v2 and EfficientFormer in both speed and accuracy.
Self-attention has become a defacto choice for capturing global context in various vision applications. However, its quadratic computational complexity with respect to image resolution limits its use in real-time applications, especially for deployment on resource-constrained mobile devices. Although hybrid approaches have been proposed to combine the advantages of convolutions and self-attention for a better speed-accuracy trade-off, the expensive matrix multiplication operations in self-attention remain a bottleneck. In this work, we introduce a novel efficient additive attention mechanism that effectively replaces the quadratic matrix multiplication operations with linear element-wise multiplications. Our design shows that the key-value interaction can be replaced with a linear layer without sacrificing any accuracy. Unlike previous state-of-the-art methods, our efficient formulation of self-attention enables its usage at all stages of the network. Using our proposed efficient additive attention, we build a series of models called "SwiftFormer" which achieves state-of-the-art performance in terms of both accuracy and mobile inference speed. Our small variant achieves 78.5% top-1 ImageNet-1K accuracy with only 0.8 ms latency on iPhone 14, which is more accurate and 2x faster compared to MobileViT-v2. Code: https://github.com/Amshaker/SwiftFormer
Motivation & Objective
- To address the high computational cost of self-attention in vision transformers, especially on mobile devices.
- To eliminate expensive matrix multiplication operations in self-attention while preserving or improving accuracy.
- To enable the use of self-attention at all stages of a vision transformer backbone, not just in later, low-resolution stages.
- To achieve a superior speed-accuracy trade-off for real-time mobile vision applications.
- To develop a generic, efficient backbone model suitable for diverse vision tasks on resource-constrained devices.
Proposed method
- Introduce an efficient additive attention mechanism that replaces query-key-value matrix multiplication with linear element-wise operations.
- Decompose self-attention into query-key interaction followed by a learnable linear projection, eliminating explicit key-value interaction.
- Use only query and key features to compute context vectors via element-wise multiplication, reducing computational complexity to linear time.
- Design the attention block to be lightweight and compatible with all stages of a vision transformer, enabling global context modeling throughout the network.
- Construct a family of models called SwiftFormer by stacking the proposed efficient attention blocks, optimized for mobile inference.
- Train and evaluate the models on ImageNet-1K, COCO, and ADE20K benchmarks to validate performance across classification, detection, and segmentation tasks.
![Figure 1 : Latency vs Accuracy Comparison . Compared to the recent EfficientFormer-L1 [ 20 ] , our SwiftFormer-L1 achieves an absolute gain of 1.7% in terms of top-1 accuracy with the same latency and without requiring any neural architecture search.](https://ar5iv.labs.arxiv.org/html/2303.15446/assets/Figures/Swiftformer_performance_3.png)
Experimental results
Research questions
- RQ1Can self-attention be made efficient enough for real-time deployment on mobile devices without sacrificing accuracy?
- RQ2Can the quadratic complexity of self-attention be reduced to linear complexity while preserving global context modeling?
- RQ3Can efficient attention be applied at all stages of a vision transformer, not just in later, low-resolution stages?
- RQ4Does replacing matrix multiplication with element-wise operations in self-attention lead to better speed-accuracy trade-offs on mobile hardware?
- RQ5Can a mobile-optimized transformer backbone outperform existing state-of-the-art models like MobileViT-v2 and EfficientFormer in both accuracy and latency?
Key findings
- SwiftFormer-L1 achieves 78.5% top-1 accuracy on ImageNet-1K with only 0.8 ms latency on iPhone 14, outperforming MobileViT-v2 in both speed and accuracy.
- The small SwiftFormer model is 2× faster than MobileViT-v2 while being 0.5% more accurate, and 3× faster than MobileViT-v2 ×2.0 with a 1.8% accuracy gain.
- SwiftFormer-L3 achieves 83.0% top-1 accuracy with 1.9 ms latency on iPhone 14, setting a new SOTA for mobile vision models.
- On COCO object detection, SwiftFormer-L1 achieves 41.2 AP box, surpassing EfficientFormer-L1 by 3.3 points and ResNet18 by 7.2 points.
- For instance segmentation, SwiftFormer-L1 achieves 38.1 AP mask, which is 2.7 points higher than the previous SOTA.
- On ADE20K semantic segmentation, SwiftFormer-L1 achieves 41.4% mIoU, 2.5 percentage points higher than EfficientFormer-L1 and 8.5 points above ResNet18.
![Figure 2 : Comparison with different self-attention modules . (a) is a typical self-attention used in ViTs [ 9 ] . (b) is the transpose self-attention used in EdgeNeXt [ 29 ] , where the self-attention operation is applied across channel feature dimensions (d $\times$ d) instead of the spatial dimen](https://ar5iv.labs.arxiv.org/html/2303.15446/assets/x1.png)
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.