# MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer

Light-weight vision transformer beats CNNs on phones

Sachin Mehta, Mohammad Rastegari · arXiv · 2021-10-5

- **Problem** Light-weight CNNs remain the default for mobile vision because shrinking vision transformers to a mobile budget still leaves them less accurate. Operation counts also fail to predict phone latency.
- **Method** MobileViT keeps the unfold, process and fold structure of a convolution. It swaps the local step for transformer layers across patches, then fuses the result back with the input.
- **Results** On ImageNet-1k, MobileViT reaches 78.4 percent top-1 accuracy with about 6 million parameters. That is 3.2% above MobileNetv3 and 6.2% above DeIT at a similar size.

## Why light-weight ViTs lag behind CNNs

Light-weight CNNs are the usual backbone for mobile vision because their built-in spatial bias lets them learn useful features with few parameters and optimize easily. Shrinking vision transformers to a mobile-sized budget does not close the gap: at about 5-6 million parameters, DeIT is 3% less accurate than MobileNetv3.

Dense prediction is also expensive: a ViT-based segmentation network with 345 million parameters reaches performance similar to DeepLabv3 at 59 million. The authors suggest that much of the extra capacity is needed because ViTs lack the image-specific inductive bias that CNNs carry.

Operation counts are a poor guide to phone latency, because memory access, parallelism and platform characteristics also set the speed.

The design goal is therefore a network that is light-weight, general-purpose and low latency at once, rather than one tuned for FLOPs. The approach combines what CNNs do well, such as spatial bias and tolerance to weaker augmentation, with what ViTs do well, such as input-adaptive weighting and global processing.

## How the MobileViT block mixes local and global processing

A standard convolution can be read as three steps: unfolding the input into local windows, a local processing step, and folding the result back. The MobileViT block keeps that unfold-process-fold skeleton but swaps the local processing for transformer layers, so it keeps convolution-like properties while gaining global reach.

With the input written as X in R^{H×W×C}, the block applies an n×n convolution that encodes local spatial information, followed by a 1×1 convolution that lifts the tensor to X\_L in R^{H×W×d}, where d is greater than C. X\_L is unfolded into N non-overlapping flattened patches of P pixels each, giving X\_U with shape P×N×d, where P = wh and h and w are at most n.

For each of the P pixel positions inside a patch, a transformer runs across the N patches: \\\\( X\_G(p) = \\\\mathrm{Transformer}(X\_U(p)), \\\\quad 1 \\\\le p \\\\le P \\\\). Because each position is handled separately, both the order of the patches and the spatial order of pixels inside each patch are kept, which plain ViTs lose.

The globally processed tensor is folded back to H×W×d and projected to C channels with a 1×1 convolution. That result is concatenated with the original input X and fused by another n×n convolution. Each pixel of X\_G carries information gathered from the local n×n region and from the same location in every patch, so the effective receptive field of the block covers the whole H×W tensor.

## Why the block can stay light-weight

The authors argue that ViTs which turn each patch into a linear combination of pixels lose the image-specific bias of CNNs and therefore need more capacity. Because the MobileViT block keeps convolutions for local structure, the network can be shallow and narrow instead.

DeIT uses L=12 transformer layers with d=192, while the MobileViT model uses L={2, 4, 3} and d={96, 120, 144} at the 32×32, 16×16 and 8×8 spatial levels. The MV2 blocks, which are MobileNetv2 blocks, do most of the downsampling and hold a very small share of the parameters.

The stem is a strided 3×3 convolution followed by MV2 blocks and MobileViT blocks, with n=3, h=w=2 at every spatial level and Swish as the activation.

In theory the self-attention cost of MobileViT is \\\\(O(N^2 P d)\\\\), against \\\\(O(N^2 d)\\\\) for a ViT, so the block should be less efficient per layer. In the measured comparison, MobileViT-XS uses 0.7 G FLOPs against 1.3 G for DeIT. The text gives a 1.8% accuracy gain and a 1.85× speedup over DeIT, while Table 3 gives 74.8 against 72.2 top-1 and 7.28 ms against 10.99 ms; these figures do not match and the text does not explain the difference.

## Multi-scale training without fine-tuning

CNN multi-scale training often changes resolution at a fixed interval, and YOLOv2 does so every 10th iteration with one resolution shared across GPUs. Because the batch size is fixed by the largest resolution, smaller resolutions leave GPUs under-used and slow training down. ViTs face a different issue, since fine-tuning across input sizes needs interpolated positional embeddings whose effect depends on the interpolation method.

MobileViT has no positional embeddings, so it can be trained at varying resolutions without fine-tuning. On each GPU and at each iteration, a resolution (Ht, Wt) is drawn from a sorted set S, and the batch size for that iteration is set inversely to its pixel count. The batch size is \\\\( b\_t = \\\\frac{H\_n W\_n \\\\, b}{H\_t W\_t} \\\\), where b is the batch size at the largest resolution (Hn, Wn).

Smaller resolutions therefore receive larger batches, so each epoch needs fewer optimizer updates. ImageNet-1k training uses S = {(160, 160), (192, 192), (256, 256), (288, 288), (320, 320)}.

In the training-efficiency measurement, the multi-scale sampler needed 232 k optimizer updates against 375 k for the standard sampler, and epoch time fell from 380 sec to 270 sec. The standard sampler here is PyTorch's DistributedDataParallel sampler. The authors report that performance improves by about 0.5% with the multi-scale sampler, and that the same network does better across evaluation resolutions.

The sampler also improves MobileNetv2, so the gain is not specific to MobileViT.

## ImageNet-1k classification results

MobileViT models are trained from scratch on ImageNet-1k for 300 epochs on 8 GPUs with an effective batch size of 1,024, using AdamW and label smoothing cross-entropy with smoothing 0.1 together with the multi-scale sampler. The learning rate rises from 0.0002 to 0.002 over the first 3k iterations and then follows a cosine schedule back to 0.0002, with L2 weight decay of 0.01.

Only basic augmentation is used, and accuracy is single-crop top-1 with an exponential moving average of weights at inference. The MobileNetv3 recipe is 600 epochs with a batch size of 4096, against 300 epochs and 1024 for MobileViT, so the two recipes differ.

At about 2.5 million parameters, MobileViT is 5% above MobileNetv2, 5.4% above ShuffleNetv2 and 7.4% above MobileNetv3 on the ImageNet-1k validation set.

PiT scores 72.4 with basic augmentation and 78.1 with advanced augmentation, so ViT variants gain a lot from the richer recipe. MobileViT-XS is 2.5× smaller than DeIT R3 and 2.6 points higher in top-1 (74.8 against 72.2). The authors conclude that MobileViTs are easy and robust to optimize on these comparisons.

## Detection with SSDLite

MobileViT is the backbone of SSD, with the standard head convolutions replaced by separable convolutions, forming SSDLite. The detector is fine-tuned on MS-COCO at 320×320 input with AdamW, using 117k training images and 5k validation images. Localization uses smooth L1 loss and classification uses cross-entropy, and mAP is taken over IoU thresholds 0.50:0.05:0.95 on the validation set.

Using MobileViT instead of MNASNet gives 1.8 mAP more and a model 1.8× smaller.

## Semantic segmentation with DeepLabv3

MobileViT is the backbone of DeepLabv3, fine-tuned with AdamW and cross-entropy loss on PASCAL VOC 2012. Extra annotations from Hariharan et al. (2011) and extra data from Lin et al. (2014) are used following standard practice, and mean intersection over union is measured on the validation set.

The authors describe MobileViT-S as competitive with ResNet-101 while using about 9× fewer parameters.

## Latency on an iPhone 12

Latency was measured on an iPhone 12 for pre-trained full-precision models converted to CoreML, averaged over 100 iterations. Two patch-size configurations were timed: Config-A with patch sizes 2, 2, 2 and Config-B with 8, 4, 2, where each value is the patch height at output stride 8, 16 and 32.

Config-A models are more accurate because Config-B models cannot encode information from all pixels. Config-B is faster at the same parameter budget: larger patches mean fewer patches and more parallel work per patch, even though the theoretical cost \\\\(O(N^2 P d)\\\\) is the same in both. Linear self-attention is mentioned as a way to cut latency further, but it is not tested here.

All configurations run in real time on the phone, at 30 FPS or more, except MobileViT-S for segmentation, which processes 512×512 inputs against 256×256 for classification and 320×320 for detection.

In Table 3, MobileNetv2 takes 0.92 ms, DeIT 10.99 ms, PiT 10.56 ms and MobileViT-XS 7.28 ms on the same device. The MobileNetv2 row was trained with the multi-scale sampler, while the MobileViT row is the 2.3 M XS model with 74.8 top-1. MobileViT-XS is therefore slower than MobileNetv2 on this device, though faster than DeIT and PiT.

The authors find that ViT-based networks, including MobileViT, run slower than MobileNetv2 on phones, which contrasts with earlier GPU results on ViT scalability. They attribute the gap to dedicated CUDA kernels for transformers on GPUs and to device-level CNN optimizations such as batch normalization fusion, neither of which exists yet for transformers on mobile devices.

The authors expect the inference speed of MobileViT and ViTs to improve once device-level operations for transformers are available.

## Limits of the efficiency and speed evidence

The efficiency argument is partly theoretical: the self-attention cost of MobileViT, \\\\(O(N^2 P d)\\\\), is higher than the ViT cost \\\\(O(N^2 d)\\\\), so in theory the block is less efficient than ViTs. The measured FLOPs and timings favour MobileViT-XS over DeIT only in the compared settings.

Latency was measured on one device, an iPhone 12, with models converted to CoreML. The ViT-based models in the timing table, MobileViT included, are slower than MobileNetv2 there, and the authors attribute this to missing device-level operations for transformers.

The general-purpose claim is tested with one SSDLite setup on MS-COCO and one DeepLabv3 setup on PASCAL VOC 2012. MobileViT-S is not real time for segmentation on the phone. FLOP reduction with DynamicViT and linear self-attention are pointed to as options, but neither is tested in the paper.

Several ViT rows in the comparison table use advanced augmentation, so the ImageNet gaps mix different training recipes.

## Paper info

- **Authors**: Sachin Mehta, Mohammad Rastegari
- **Venue**: arXiv · Preprint
- **First published**: 2021-10-5
- **Added**: 2026-11-12
- **Updated**: 2022-3-4
- **Version**: v2
- **arXiv**: 2110.02178
- **Category**: cs.CV · cs.AI · cs.LG
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2110.02178v2) · [PDF ↗](https://arxiv.org/pdf/2110.02178v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Sachin Mehta, Mohammad Rastegari (2021). MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer. arXiv:2110.02178v2. https://arxiv.org/abs/2110.02178v2

**BibTeX**

```
@misc{mehta2021mobilevit,
  title = {{MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer}},
  author = {Sachin Mehta and Mohammad Rastegari},
  year = {2021},
  eprint = {2110.02178},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2110.02178v2}
}
```

## Other paper commentary

- [FairMOT: On the Fairness of Detection and Re-Identification in Multiple Object Tracking](https://refivu.com/en/papers/081a3a22-90c6-4c70-a7df-d2e70b35ad22-fairmot-on-the-fairness-of-detection-and-re.md)
- [Is Space-Time Attention All You Need for Video Understanding?](https://refivu.com/en/papers/b6bd7278-3728-4d96-9fe0-5f483de3f3bd-is-space-time-attention-all-you-need-for.md)
- [Return of Frustratingly Easy Domain Adaptation](https://refivu.com/en/papers/0a776e2c-6337-4850-9be1-86de976005d2-return-of-frustratingly-easy-domain-adaptation.md)
- [Celeb-DF: A Large-scale Challenging Dataset for DeepFake Forensics](https://refivu.com/en/papers/127fcad1-737e-4bb9-b7b5-7c87f1ab7614-celeb-df-a-large-scale-challenging-dataset-for.md)
- [Cascade R-CNN: High Quality Object Detection and Instance Segmentation](https://refivu.com/en/papers/484c94a6-ca7a-4e4d-a933-9ea5ec919a68-cascade-r-cnn-high-quality-object-detection-and.md)
- [DSSD : Deconvolutional Single Shot Detector](https://refivu.com/en/papers/800d2066-c083-45ac-bb3d-507e72445f62-dssd-deconvolutional-single-shot-detector.md)
- [PointConv: Deep Convolutional Networks on 3D Point Clouds](https://refivu.com/en/papers/c9a5b52f-78bd-452f-b508-b85a37101523-pointconv-deep-convolutional-networks-on-3d-point-clouds.md)
- [Man is to Computer Programmer as Woman is to Homemaker? Debiasing Word Embeddings](https://refivu.com/en/papers/54f76c5c-e7e0-4849-8c34-62d4d7e29119-man-is-to-computer-programmer-as-woman-is.md)

## Terms in this paper

- [Object detection](https://refivu.com/en/terms/113bfdb14049-object-detection)
- [Semantic segmentation](https://refivu.com/en/terms/00dfce7ec404-semantic-segmentation)
- [Top-1 accuracy](https://refivu.com/en/terms/653c0b9eaa58-top-1-accuracy)
- [self-attention](https://refivu.com/en/terms/426589b81077-self-attention)
- [mIoU](https://refivu.com/en/terms/901dcc5384c2-miou)
- [mAP](https://refivu.com/en/terms/477dad058d88-map)
- [FLOPs](https://refivu.com/en/terms/14c405888d5b-flops)
- [ImageNet-1K](https://refivu.com/en/terms/d8d6444bd460-imagenet-1k)
- [MS-COCO](https://refivu.com/en/terms/3c7d75a4a2eb-ms-coco)
- [PASCAL VOC 2012](https://refivu.com/en/terms/269f59a1eb03-pascal-voc-2012)
- [SSDLite](https://refivu.com/en/terms/3738056cc5f2-ssdlite)
- [MobileNetV3](https://refivu.com/en/terms/bcf9b567a140-mobilenetv3)
- [vision transformers](https://refivu.com/en/terms/5e44b403c2e7-vision-transformers)
- [standard convolution](https://refivu.com/en/terms/ee11d8c17da6-standard-convolution)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/c76255ba-9c87-4edc-80cc-28d59c4ccfc5-mobilevit-light-weight-general-purpose-and-mobile-friendly)
