Separable Self-attention for Mobile Vision Transformers

Sachin Mehta, Mohammad Rastegari
6/6/2022
cs.CVcs.AIcs.LG

Official code: apple-aiml-research/ml-cvnets (1,995 stars, PyTorch, last commit 2026-09-11).

Abstract

Mobile vision transformers (MobileViT) can achieve state-of-the-art performance across several mobile vision tasks, including classification and detection. Though these models have fewer parameters, they have high latency as compared to convolutional neural network-based models. The main efficiency bottleneck in MobileViT is the multi-headed self-attention (MHA) in transformers, which requires $O(k^2)$ time complexity with respect to the number of tokens (or patches) $k$. Moreover, MHA requires costly operations (e.g., batch-wise matrix multiplication) for computing self-attention, impacting latency on resource-constrained devices. This paper introduces a separable self-attention method with linear complexity, i.e. $O(k)$. A simple yet effective characteristic of the proposed method is that it uses element-wise operations for computing self-attention, making it a good choice for resource-constrained devices. The improved model, MobileViTv2, is state-of-the-art on several mobile vision tasks, including ImageNet object classification and MS-COCO object detection. With about three million parameters, MobileViTv2 achieves a top-1 accuracy of 75.6% on the ImageNet dataset, outperforming MobileViT by about 1% while running $3.2\times$ faster on a mobile device. Our source code is available at: \url{https://github.com/apple/ml-cvnets}

View on arXivView PDF

Code Implementations(1)

PyTorch

CVNets: A library for training computer vision networks

1,995257Python, MakefileOct 21, 20211 months agoNOASSERTION
ade20kclassificationcomputer-visiondeep-learningdetection+6 more

Similar Papers

Cite this paper

@article{mehta2022separable,
  title  = {Separable Self-attention for Mobile Vision Transformers},
  author = {Sachin Mehta and Mohammad Rastegari},
  year   = {2022},
  eprint = {2206.02680},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2206.02680}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2206.02680.svg)](https://codeofpaper.com/paper/2206.02680)

Discussion