{"notes":[{"id":"lightweight/mobilevit","category":"lightweight","legacyPath":"lightweight/2110-mobilevit","legacySlug":"2110-mobilevit","legacyPaths":[],"title":"MobileViT","subtitle":"Changing the Design of Convolution Kernels","author":"Z. Yuan","paperDate":"2021-10-05","publishedOn":"2024-09-04","paperTitle":"MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer","paperUrl":"https://arxiv.org/abs/2110.02178","bibliography":{"title":"MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer","authors":["Sachin Mehta","Mohammad Rastegari"],"url":"https://arxiv.org/abs/2110.02178","pdfUrl":"https://arxiv.org/pdf/2110.02178","codeUrl":null,"preprint":{"id":"2110.02178","submittedOn":"2021-10-05","url":"https://arxiv.org/abs/2110.02178"},"publication":{"venue":"ICLR","year":2022,"kind":"conference","url":"https://arxiv.org/abs/2110.02178"},"citation":"@misc{lightweightmobilevit2021,\n  title = {{MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer}},\n  author = {Sachin Mehta and Mohammad Rastegari},\n  year = {2021},\n  eprint = {2110.02178},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2110.02178}\n}\n","citationPath":"/content/papers/citations/lightweight/mobilevit.f81f40aca27f.bib"},"thumbnail":{"src":"/content/papers/assets/4b04c873571d684cc92c774de290e347e8cd46c3dda6d9e3faa2028258cbbb20.jpg","width":1686,"height":400},"locale":"en","path":"/content/papers/en/lightweight/mobilevit.25c1c9353500.md","headings":[{"id":"problem-definition","text":"Problem Definition","depth":2},{"id":"solution","text":"Solution","depth":2},{"id":"convolution-review","text":"Convolution Review","depth":3},{"id":"mobilevit-architecture","text":"MobileViT Architecture","depth":3},{"id":"experimental-setup","text":"Experimental Setup","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"performance-on-imagenet","text":"Performance on ImageNet","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"lightweight/mobile-former","relation":"comparison","topic":"Combining lightweight convolutions and attention"},{"id":"reparameterization/fastvit","relation":"comparison","topic":"Combining lightweight convolutions and attention"}]},{"id":"lightweight/mobile-former","category":"lightweight","legacyPath":"lightweight/2108-mobile-former","legacySlug":"2108-mobile-former","legacyPaths":[],"title":"Mobile-Former","subtitle":"Bidirectional Bridge","author":"Z. Yuan","paperDate":"2021-08-12","publishedOn":"2024-09-03","paperTitle":"Mobile-Former: Bridging MobileNet and Transformer","paperUrl":"https://arxiv.org/abs/2108.05895","bibliography":{"title":"Mobile-Former: Bridging MobileNet and Transformer","authors":["Yinpeng Chen","Xiyang Dai","Dongdong Chen","Mengchen Liu","Xiaoyi Dong","Lu Yuan","Zicheng Liu"],"url":"https://arxiv.org/abs/2108.05895","pdfUrl":"https://arxiv.org/pdf/2108.05895","codeUrl":null,"preprint":{"id":"2108.05895","submittedOn":"2021-08-12","url":"https://arxiv.org/abs/2108.05895"},"publication":{"venue":"CVPR","year":2022,"kind":"conference","url":"https://arxiv.org/abs/2108.05895"},"citation":"@misc{lightweightmobileformer2021,\n  title = {{Mobile-Former: Bridging MobileNet and Transformer}},\n  author = {Yinpeng Chen and Xiyang Dai and Dongdong Chen and Mengchen Liu and Xiaoyi Dong and Lu Yuan and Zicheng Liu},\n  year = {2021},\n  eprint = {2108.05895},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2108.05895}\n}\n","citationPath":"/content/papers/citations/lightweight/mobile-former.e0fa77029109.bib"},"thumbnail":{"src":"/content/papers/assets/0e6780b6892b71f46efb8e71a58ef01488f230f81775b453e08e9471354e9a3e.jpg","width":1224,"height":1068},"locale":"en","path":"/content/papers/en/lightweight/mobile-former.74524e27174d.md","headings":[{"id":"problem-definition","text":"Problem Definition","depth":2},{"id":"solution","text":"Solution","depth":2},{"id":"how-do-the-two-paths-communicate","text":"How Do the Two Paths Communicate?","depth":3},{"id":"reading-the-layer-table","text":"Reading the Layer Table","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"imagenet-check-the-comparison-conditions","text":"ImageNet: Check the Comparison Conditions","depth":3},{"id":"ablating-the-bridge-activation-and-token-count","text":"Ablating the Bridge, Activation, and Token Count","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{"model-architecture":"how-do-the-two-paths-communicate","architecture-parameters":"reading-the-layer-table","performance-on-imagenet":"imagenet-check-the-comparison-conditions","ablation-studies":"ablating-the-bridge-activation-and-token-count"},"guide":null,"relatedReading":[{"id":"lightweight/mobilevit","relation":"comparison","topic":"Combining lightweight convolutions and attention"},{"id":"reparameterization/fastvit","relation":"comparison","topic":"Combining lightweight convolutions and attention"}]},{"id":"reparameterization/fastvit","category":"reparameterization","legacyPath":"reparameterization/2303-fastvit","legacySlug":"2303-fastvit","legacyPaths":[],"title":"FastViT","subtitle":"Reparameterized ViT Experiments","author":"Z. Yuan","paperDate":"2023-03-24","publishedOn":"2024-07-16","paperTitle":"FastViT: A Fast Hybrid Vision Transformer using Structural Reparameterization","paperUrl":"https://arxiv.org/abs/2303.14189","bibliography":{"title":"FastViT: A Fast Hybrid Vision Transformer using Structural Reparameterization","authors":["Pavan Kumar Anasosalu Vasu","James Gabriel","Jeff Zhu","Oncel Tuzel","Anurag Ranjan"],"url":"https://arxiv.org/abs/2303.14189","pdfUrl":"https://arxiv.org/pdf/2303.14189","codeUrl":null,"preprint":{"id":"2303.14189","submittedOn":"2023-03-24","url":"https://arxiv.org/abs/2303.14189"},"publication":{"venue":"ICCV","year":2023,"kind":"conference","url":"https://arxiv.org/abs/2303.14189"},"citation":"@misc{reparameterizationfastvit2023,\n  title = {{FastViT: A Fast Hybrid Vision Transformer using Structural Reparameterization}},\n  author = {Pavan Kumar Anasosalu Vasu and James Gabriel and Jeff Zhu and Oncel Tuzel and Anurag Ranjan},\n  year = {2023},\n  eprint = {2303.14189},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2303.14189}\n}\n","citationPath":"/content/papers/citations/reparameterization/fastvit.0b2741f99b2b.bib"},"thumbnail":{"src":"/content/papers/assets/095c905b22b0b0e80a3fdb19b68680885648cdd70aa6ff754434e08a3a1aa78a.jpg","width":1618,"height":1038},"locale":"en","path":"/content/papers/en/reparameterization/fastvit.78850b950b9b.md","headings":[{"id":"problem-definition","text":"Problem Definition","depth":2},{"id":"solution","text":"Solution","depth":2},{"id":"model-architecture","text":"Model Architecture","depth":3},{"id":"model-configurations","text":"Model Configurations","depth":3},{"id":"training-and-evaluation-strategy","text":"Training and Evaluation Strategy","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"performance-on-imagenet","text":"Performance on ImageNet","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"lightweight/mobilevit","relation":"comparison","topic":"Combining lightweight convolutions and attention"},{"id":"lightweight/mobile-former","relation":"comparison","topic":"Combining lightweight convolutions and attention"},{"id":"reparameterization/repvit","relation":"comparison","topic":"Fast visual backbones for deployment"}]}],"text":"Almost two months after Microsoft introduced **Mobile-Former**, Apple proposed another way to bring vision transformers to mobile devices: **MobileViT**.\n\n## Problem Definition\n\nThe question is how to train a small ViT effectively within a limited parameter and compute budget, while keeping mobile inference practical. Compared with Mobile-Former’s two-way bridge between parallel branches, MobileViT borrows the “unfold, local processing, fold” view of convolution and uses a Transformer to build global relationships across patches. This is a design analogy, not a mathematically equivalent replacement of a convolution kernel’s matrix multiplication.\n\nTo better understand how MobileViT works, let’s first review the convolution process.\n\n## Solution\n\n### Convolution Review\n\nOne convolution implementation uses **unfold → matrix multiplication → output reshaping**. This method is more efficient under certain conditions.\n\n- **1. Unfold Operation**\n\n  The unfold operation, also called \"im2col,\" reshapes the input tensor (e.g., an image) into a form suitable for matrix multiplication.\n\n  For example, consider a $3 \\times 3$ input matrix $X$:\n\n  $$\n  X = \\left[\\begin{matrix}\n  1 & 2 & 3 \\\\\n  4 & 5 & 6 \\\\\n  7 & 8 & 9\n  \\end{matrix}\\right]\n  $$\n\n  Suppose we have a $2 \\times 2$ kernel $K$. We use the cross-correlation convention common in deep learning, without flipping the kernel, at stride 1 with no padding:\n\n  $$\n  K = \\left[\\begin{matrix}\n  1 & 0 \\\\\n  0 & -1\n  \\end{matrix}\\right]\n  $$\n\n  Normally, the kernel slides across the input matrix to compute convolution values. However, with unfold, we transform this process into matrix multiplication. Using a $2 \\times 2$ sliding window, we extract four $2 \\times 2$ patches from $X$:\n\n  $$\n  \\left[\\begin{matrix}\n  1 & 2 \\\\\n  4 & 5\n  \\end{matrix}\\right],\n   \\left[\\begin{matrix}\n  2 & 3 \\\\\n  5 & 6\n  \\end{matrix}\\right],\n  \\left[\\begin{matrix}\n  4 & 5 \\\\\n  7 & 8\n  \\end{matrix}\\right],\n  \\left[\\begin{matrix}\n  5 & 6 \\\\\n  8 & 9\n  \\end{matrix}\\right]\n  $$\n\n  We then flatten these patches into row vectors, forming a matrix:\n\n  $$\n  X_{\\text{unfold}} = \\left[\\begin{matrix}\n  1 & 2 & 4 & 5 \\\\\n  2 & 3 & 5 & 6 \\\\\n  4 & 5 & 7 & 8 \\\\\n  5 & 6 & 8 & 9\n  \\end{matrix}\\right]\n  $$\n\n- **2. Matrix Multiplication**\n\n  Next, we multiply the unfolded input matrix $X_{\\text{unfold}}$ by the flattened convolution kernel $K$:\n\n  $$\n  K_{\\text{flat}} = \\left[\\begin{matrix} 1 & 0 & 0 & -1 \\end{matrix}\\right]\n  $$\n\n  Here $X_{\\text{unfold}}$ is $4\\times4$ and $K_{\\text{flat}}$ is $1\\times4$, so the product is a $4\\times1$ vector:\n\n  $$\n  Y_{\\text{flat}} = X_{\\text{unfold}} \\times K_{\\text{flat}}^T\n  $$\n\n  $$\n  Y_{\\text{flat}} = \\left[\\begin{matrix}\n  1 \\cdot 1 + 2 \\cdot 0 + 4 \\cdot 0 + 5 \\cdot (-1) \\\\\n  2 \\cdot 1 + 3 \\cdot 0 + 5 \\cdot 0 + 6 \\cdot (-1) \\\\\n  4 \\cdot 1 + 5 \\cdot 0 + 7 \\cdot 0 + 8 \\cdot (-1) \\\\\n  5 \\cdot 1 + 6 \\cdot 0 + 8 \\cdot 0 + 9 \\cdot (-1)\n  \\end{matrix}\\right]\n  =\n  \\left[\\begin{matrix}\n  -4 \\\\\n  -4 \\\\\n  -4 \\\\\n  -4\n  \\end{matrix}\\right]\n  $$\n\n- **3. Fold Operation**\n\n  Here, “fold” simply means reshaping the result into the output grid. A library Fold operation generally sums overlapping patches and is not automatically the inverse of Unfold. In this example we reshape to a $2 \\times 2$ matrix:\n\n  $$\n  Y = \\left[\\begin{matrix}\n  -4 & -4 \\\\\n  -4 & -4\n  \\end{matrix}\\right]\n  $$\n\n**Unfold → matrix multiplication → output reshaping** is one way to implement convolution. Its actual speed depends on tensor layout, memory traffic, and the runtime.\n\nThe sliding windows in this example overlap. MobileViT's unfold step below instead arranges **non-overlapping** patches, so the two unfold operations should not be treated as identical.\n\n### MobileViT Architecture\n\n![Paper Figure 1b: local convolutions, unfolding, cross-patch Transformer, folding and fusion in a MobileViT block](/content/papers/assets/4b04c873571d684cc92c774de290e347e8cd46c3dda6d9e3faa2028258cbbb20.jpg)\n\nThe preceding convolution example makes the block easier to read. MobileViT first mixes nearby positions with an $n\\times n$ convolution, then projects the features to $d$ dimensions with a 1×1 convolution. It rearranges non-overlapping patches into $P\\times N\\times d$, where $P=hw$ is the number of positions per patch and $N=HW/P$ is the number of patches. For each relative position within a patch, the Transformer attends across patches; it does not directly compare every pair of pixels in the entire feature map.\n\nThe results are folded into a spatial map, projected with a 1×1 convolution, concatenated with the input, and fused by a local convolution. Under the paper's patch/kernel settings, local mixing and cross-patch attention together yield a global receptive field; a single attention operation does not directly compare every pair of pixels.\n\nSince self-attention is more computationally expensive, it is applied selectively. The authors chose specific layers to apply this substitution, as shown below:\n\n![Paper Figure 1: standard ViT, the MobileViT block and the full network with three MobileViT stages](/content/papers/assets/e4de61274930a2a312edd9874ec2d4736400e12be0977325e862abe68d54026f.jpg)\n\nMobileViT blocks operate at the last three spatial scales, alongside retained convolutions and MobileNetV2 blocks. The MobileNetV2 blocks chiefly handle downsampling. This supports a shallower, narrower hybrid network.\n\n### Experimental Setup\n\nThe authors trained MobileViT on the ImageNet-1k dataset, which includes 1.28 million training images and 50,000 validation images. Training was conducted using PyTorch on eight NVIDIA GPUs for 300 epochs. They used the AdamW optimizer and cross-entropy loss with a label smoothing factor of 0.1. The effective batch size was 1,024 images, with a learning rate that gradually increased from 0.0002 to 0.002 over the first 3,000 iterations, then decayed back to 0.0002 following a cosine schedule. L2 weight decay was set at 0.01.\n\nThe multi-scale sampler improves accuracy by about **0.5 percentage points** and training efficiency by adapting batch size to resolution. It is another contribution of the paper; this note focuses on architecture. Training uses random resized crops and horizontal flips; evaluation reports single-crop top-1 accuracy with an exponential moving average of model weights.\n\n## Discussion\n\n### Performance on ImageNet\n\n![Paper Figure 8: ImageNet top-1 accuracy and parameter comparisons with lightweight and larger CNNs](/content/papers/assets/3107c46c05675453bc6157b5d9f713c488bde2a72de5ff7d1491e6f6f1e57861.jpg)\n\n- **MobileViT Outperforms Lightweight CNNs**:\n\n  - Across different model sizes, MobileViT consistently outperformed lightweight CNN models such as MobileNetv1, MobileNetv2, ShuffleNetv2, ESPNetv2, and MobileNetv3.\n  - In Figure 8(b), MobileViT-XS has 2.3M parameters and 74.8% top-1. Against models with roughly 2.3–2.6M parameters, it is:\n    - **5 percentage points** higher accuracy than MobileNetv2,\n    - **5.4 percentage points** higher than ShuffleNetv2,\n    - **7.4 percentage points** higher than MobileNetv3.\n\n- **MobileViT Outperforms Heavier CNNs**:\n\n  - Figure 8(c) puts MobileViT-S (5.6M parameters, 78.4%) above the listed DenseNet-169, ResNet-101, ResNet-101-SE, and the similarly sized EfficientNet-B0.\n  - EfficientNet-B0 has 5.3M parameters and 76.3% top-1, a gap of **2.1 percentage points**. This historical comparison concerns these model configurations and training conditions, not every larger CNN.\n\n---\n\n![Paper Figure 9: ImageNet top-1 accuracy, parameters and augmentation for MobileViT and ViT variants](/content/papers/assets/184332ce2c2b1cbbb2057f4e2800112dcfa35411b752271301b33527a6277595.jpg)\n\nRed denotes advanced augmentation and green denotes basic augmentation; the table columns read `Advanced` and `Basic`. Advanced recipes may include Mixup, CutMix, and RandAugment. The models do not all share an otherwise identical training recipe.\n\n- **Comparison with ViT Variants**:\n\n  - MobileViT was compared against various ViT variants trained from scratch, including DeIT, T2T, PVT, CAIT, DeepViT, CeiT, CrossViT, LocalViT, PiT, ConViT, ViL, BotNet, and Mobile-Former.\n  - In Figure 9(b), MobileViT-XS uses basic augmentation and has 2.3M parameters, about 40% of the 5.7M-parameter DeiT configuration trained with advanced augmentation. It scores **2.6 percentage points** higher (74.8% versus 72.2%). This compares two specified configurations; other ViT variants in the figure score higher.\n\nThe authors take this as evidence of CNN-like trainability. They separately evaluate MobileViT as a detection and segmentation backbone.\n\n\n> [!TIP]\n> \n> These are the original paper's comparisons. Training recipes and model versions affect the gaps; they are not permanent rankings of entire architecture families. The latest advancements can be found in the MobileNet-V4 paper.\n> \n> - [**[24.04] MobileNet-V4: A Legacy After Five Years**](/blog/papers/lightweight/mobilenet-v4)\n\n\n## Conclusion\n\n![Paper Table 3: parameters, FLOPs, latency and ImageNet top-1 on the iPhone 12 Neural Engine](/content/papers/assets/d8e363c81324f62761414e946c39e7af54c853ca6cc278bb4722213ac8c4a581.jpg)\n\nWhile MobileViT outperforms many lightweight and heavyweight CNN models on ImageNet-1k, its inference speed on mobile devices remains a challenge.\n\nThe table reports iPhone 12 Neural Engine results at batch size 1: MobileViT-XS takes 7.28 ms versus MobileNetV2's 0.92 ms, a latency ratio of about 7.9. However, MobileViT uses 256×256 inputs while the others use 224×224, so this is not a controlled equal-resolution comparison or a universal ViT/CNN ratio. The MobileNetV2 accuracy result in the table also uses a multi-scale sampler. The authors discuss two possible factors:\n\n1. Transformers benefit from dedicated CUDA kernels on GPUs, but these optimizations do not automatically carry over to phones.\n2. CNNs benefit from device-level optimizations, such as fusing convolutions with batch normalization, which improve latency and memory access.\n\nUnder the paper's runtimes, MobileViT was more accurate yet slower than MobileNetV2 on this phone. Later hardware and software optimizations may change that trade-off; parameters or FLOPs alone cannot determine real latency.\n","imageSizes":{"/content/papers/assets/4b04c873571d684cc92c774de290e347e8cd46c3dda6d9e3faa2028258cbbb20.jpg":{"width":1686,"height":400},"/content/papers/assets/e4de61274930a2a312edd9874ec2d4736400e12be0977325e862abe68d54026f.jpg":{"width":1224,"height":796},"/content/papers/assets/3107c46c05675453bc6157b5d9f713c488bde2a72de5ff7d1491e6f6f1e57861.jpg":{"width":1494,"height":544},"/content/papers/assets/184332ce2c2b1cbbb2057f4e2800112dcfa35411b752271301b33527a6277595.jpg":{"width":1486,"height":654},"/content/papers/assets/d8e363c81324f62761414e946c39e7af54c853ca6cc278bb4722213ac8c4a581.jpg":{"width":1384,"height":414}}}
