# Vision Mamba: Efficient Visual Representation Learning with Bidirectional State Space Model

Vim replaces self-attention with bidirectional state space models for vision

Lianghui Zhu, Bencheng Liao, Qian Zhang, Xinlong Wang, Wenyu Liu, Xinggang Wang · arXiv · 2024-1-17

- **Problem** Self-attention's cost grows quadratically with token count, so high-resolution images are slow and memory-hungry. Mamba, an SSM, scans one direction only and lacks position awareness for images.
- **Method** Vim splits an image into patches, adds position embeddings, and stacks blocks that scan the tokens forward and backward instead of using self-attention.
- **Results** Vim-Ti reaches 76.1 top-1 on ImageNet against 72.2 for DeiT-Ti, and is 2.8× faster than DeiT on large images.

## Why attention-free visual backbones

Self-attention lets every visual token see the whole image, which gives input-dependent global context, but the cost of that view rises fast with resolution. The number of visual tokens a Transformer can handle is limited by its quadratic complexity, which is why high-resolution inputs are hard for ViT-style models. State space models take a different route: they handle long sequences with near-linear computation, and Mamba adds input-dependent parameters and a hardware-aware algorithm.

Mamba had shown its value on language, but a generic backbone built purely from SSMs had not been explored for images and videos.

Applying Mamba to images raises two problems: it scans the sequence in one direction only, and it has no built-in sense of where each token sits. The study asks whether a backbone made only of bidirectional SSM blocks can match DeiT on ImageNet classification, and then carry over to dense tasks while staying cheaper on large inputs. The two additions in the design, bidirectional scanning and position embeddings, correspond to those two problems.

## How the SSM recurrence works

An SSM is described as a continuous system that maps a one-dimensional input x(t) to an output y(t) through a hidden state h(t) in R^N. Its evolution matrix is A in R^{N×N}, its input projection is B in R^{N×1} and its output projection is C in R^{1×N}, and the system follows h′(t) = Ah(t) + Bx(t) with y(t) = Ch(t).

A step size Δ turns the continuous A and B into discrete matrices by zero-order hold, with \\( \\bar{A} = \\exp(\\Delta A) \\) and \\( \\bar{B} = (\\Delta A)^{-1}(\\exp(\\Delta A) - I)\\cdot \\Delta B \\), where the paper writes the discrete matrices with the same letters A and B. Stepping through the discrete form gives h\_t = A h\_{t-1} + B x\_t and y\_t = C h\_t, so each output depends on a state carried forward from earlier tokens.

With fixed parameters the same recurrence unrolls into a global convolution with kernel \\( K = (CB, CAB, \\ldots, CA^{M-1}B) \\) and output \\( y = x \\ast K \\), where M is the sequence length. When Δ, B and C depend on the input, as in Mamba, that convolution no longer holds, so the recurrence is evaluated directly.

## From image patches to tokens

An image of size H×W×C is cut into J flattened patches \\( x\_p \\), each of length \\( P^2 \\cdot C \\), where P is the patch size. The position embeddings are there because the recurrence over patches has no inherent sense of location.

The token sequence passes through L Vim blocks, and each block adds its output to its input as a residual, \\( T\_l = \\mathrm{Vim}(T\_{l-1}) + T\_{l-1} \\). The projection layer uses a 16×16 kernel and produces non-overlapping patch embeddings, following ViT and DeiT.

## What one bidirectional Vim block computes

Each block first normalizes the incoming tokens and projects them into two branches, x and z, each of width E. The x branch is handled once for the forward direction and once for the backward direction: a Conv1d followed by SiLU produces x′\_o, and linear layers produce B\_o, C\_o and the timescale Δ\_o. Δ\_o passes through a softplus-type activation to stay positive, and it is combined with the learned parameter matrix to give the per-token discrete A\_o and B\_o of size (B, M, E, N).

Within each direction the state, initialized to zero, is updated token by token from its previous value and the current input, and the output is read out with C\_o. The forward and backward outputs are each multiplied by SiLU(z), added together, passed through a linear projection, and added to the block input as a residual. The default configuration adds a backward Conv1d before the backward SSM, which the bidirectional ablation identifies as the best variant.

## Model sizes and depth

The default configuration stacks L = 24 Vim blocks with an SSM dimension N = 16. The tiny variant uses D = 192 and E = 384 to align with DeiT's tiny size, and the small variant uses D = 384 and E = 768.

## Keeping memory and time linear in sequence length

The discrete A\_o and B\_o have size (B, M, E, N), so a naive implementation that writes them to slow HBM would need memory IO on the order of O(BMEN). Following Mamba, Vim reads only the smaller inputs Δ\_o, A\_o, B\_o and C\_o into fast SRAM, forms the discrete matrices there, runs the scan in SRAM and writes back the (B, M, E) output, which reduces IO to O(BME + EN).

The reason SRAM is used is its larger bandwidth, while HBM offers a larger capacity.

For memory, the (B, M, E, N) intermediate states are recomputed during the backward pass instead of being stored, and activations of activation functions and convolutions are recomputed as well. With the default E = 2D, the per-layer costs are \\( \\Omega(\\text{self-attention}) = 4MD^2 + 2M^2D \\) and \\( \\Omega(\\text{SSM}) = 3M(2D)N + M(2D)N \\).

The self-attention cost has a term quadratic in M, while the SSM cost is linear in M for a fixed N, which is 16 by default. These are counts of operations per layer, and the measured speed and memory appear in the efficiency results.

## ImageNet classification results

Models are trained on the 1.28M ImageNet-1K training images and evaluated on the 50K validation images, reporting top-1 accuracy. Training follows DeiT's recipe with random cropping, horizontal flipping, label smoothing, mixup and random erasing, and uses AdamW with weight decay 0.05 and a total batch size of 1024.

The long-sequence setting is a separate fine-tuning stage of 30 epochs after pretraining.

Vim-Ti reaches 76.1 top-1, against 72.2 for DeiT-Ti, which is the 3.9-point gap the text gives for the tiny sizes. Vim-S reaches 80.3 against 79.8 for DeiT-S, and Vim-B reaches 81.9 against 81.8 for DeiT-B, gaps of 0.5 and 0.1 points. Vim-S reaches 80.3 against 76.2 for ResNet-50, which is 4.1 points higher. Compared with S4ND-ViT-B, Vim achieves similar top-1 accuracy with 3× fewer parameters.

After long-sequence fine-tuning Vim-Ti† reaches 78.3, Vim-S† reaches 81.4 and Vim-B† reaches 83.2, with Vim-S† close to DeiT-B's 81.8. Rows marked † are fine-tuned checkpoints under the long-sequence setting, so they are separate from the plain rows that come from pretraining alone.

## Speed and memory at high resolution

Speed and memory are measured for batch feature extraction, comparing tiny Vim with tiny DeiT across input resolutions. At 512×512 Vim matches DeiT in both FPS and memory. At 1248×1248 Vim is 2.8× faster than DeiT and saves 86.8% GPU memory.

With an FPN appended for downstream frameworks, the efficiency curves show the same comparison trend as the pure backbone, with Vim's FPS rising relative to DeiT as resolution increases. The gap is linked to the linear scaling of Vim in sequence length, which makes high-resolution downstream use practical.

## ADE20K segmentation results

Segmentation is run on ADE20K with UperNet at 512×512 input, with Vim and DeiT as backbones. Vim-Ti reaches 41.0 mIoU against 39.2 for DeiT-Ti, which is 1.8 mIoU higher. Vim-S reaches 44.9 mIoU against 44.0 for DeiT-S, which is 0.9 mIoU higher. Vim-S matches the 44.9 mIoU of the ResNet-101 backbone with nearly 2× fewer parameters.

## COCO detection and instance segmentation

Detection and instance segmentation use Cascade Mask R-CNN on the COCO 2017 val set. Vim-Ti reaches 45.7 box AP against 44.4 for DeiT-Ti, and 39.2 mask AP against 38.1. The text states these as gains of 1.3 box AP and 1.1 mask AP.

For middle-sized objects APbox rises from 47.4 to 49.0, and for large objects it rises from 61.8 to 63.2. DeiT is given 2D window attention at 1024×1024, while Vim runs on the full sequence without a 2D prior. The authors describe the accuracy gain as non-trivial for this reason, since the comparison pits a window-attention backbone against a pure sequence model.

## Bidirectional design ablation

The bidirectional ablation uses ImageNet-1K classification and ADE20K transfer through a two-layer Segmenter head. The class token is not used in these runs, so their classification numbers are not the main-table settings. None is the plain Mamba block with forward direction only, while Bidirectional Layer alternates forward and backward blocks.

Bidirectional SSM adds a backward SSM to each block, and Bidirectional SSM + Conv1d also adds a backward Conv1d before that SSM. A random flip of the visual sequence during training is described as a further strategy, but Table 4 has no row for it.

None reaches 73.2 top-1 and 32.3 mIoU. Bidirectional SSM + Conv1d reaches 73.9 top-1 and 35.9 mIoU. Adding the backward Conv1d on top of Bidirectional SSM raises top-1 from 72.8 to 73.9 and mIoU from 33.2 to 35.9.

The Bidirectional Layer row gives 70.9 top-1 and 33.6 mIoU, so it is below None on classification and above it on segmentation by 1.3 mIoU. The text describes the alternating-block strategy as 7 points lower in top-1, but the table gives 70.9 against 73.2 for that row, so the text's gap and the table do not agree.

## Classification readout ablation

Five readout strategies are compared on ImageNet-1K. Mean pool averages the output of the last Vim block, and max pool applies a head to each token and takes the maximum over the sequence. Head class token places the class token at the front of the sequence, double class token adds a second one at the tail, and middle class token inserts one at the middle of the sequence.

Mean pool reaches 73.9, max pool 73.4, head class token 75.2, double class token 74.3 and middle class token 76.1 top-1. The authors connect the middle-token result to the recurrent nature of the SSM and to the central object prior in ImageNet. Only ImageNet-1K classification was used for this comparison, so the advantage is shown for that task alone.

## Limitations

The FPS and GPU memory comparison with DeiT covers only the tiny-size variants of Vim and DeiT. Segmentation uses UperNet and detection uses Cascade Mask R-CNN, with one framework for each task in the reported comparisons.

The Bidirectional Block drop is given as 7 points in the text, which the table values for the Bidirectional Layer row do not match. The bidirectional ablation runs do not use the class token, so their accuracies are not the same settings as the main ImageNet table.

Unsupervised pretraining such as mask image modeling and CLIP-style multimodal pretraining are left as future work.

## Paper info

- **Authors**: Lianghui Zhu, Bencheng Liao, Qian Zhang, Xinlong Wang, Wenyu Liu, Xinggang Wang
- **Venue**: arXiv · Preprint
- **First published**: 2024-1-17
- **Added**: 2026-11-12
- **Updated**: 2024-11-14
- **Version**: v3
- **arXiv**: 2401.09417
- **Category**: cs.CV · 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/2401.09417v3) · [PDF ↗](https://arxiv.org/pdf/2401.09417v3)

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

Lianghui Zhu, Bencheng Liao, Qian Zhang, Xinlong Wang, Wenyu Liu, Xinggang Wang (2024). Vision Mamba: Efficient Visual Representation Learning with Bidirectional State Space Model. arXiv:2401.09417v3. https://arxiv.org/abs/2401.09417v3

**BibTeX**

```
@misc{zhu2024vision,
  title = {{Vision Mamba: Efficient Visual Representation Learning with Bidirectional State Space Model}},
  author = {Lianghui Zhu and Bencheng Liao and Qian Zhang and Xinlong Wang and Wenyu Liu and Xinggang Wang},
  year = {2024},
  eprint = {2401.09417},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2401.09417v3}
}
```

## Other paper commentary

- [Semantic Understanding of Scenes through the ADE20K Dataset](https://refivu.com/en/papers/3862d7db-bf28-4590-ab09-839bcbf7ccaa-semantic-understanding-of-scenes-through-the-ade20k-dataset.md)
- [Prompt-to-Prompt Image Editing with Cross Attention Control](https://refivu.com/en/papers/a18cb3bd-2a1b-4adf-9a2a-f866c7f83edf-prompt-to-prompt-image-editing-with-cross-attention.md)
- [TotalSegmentator: robust segmentation of 104 anatomical structures in CT images](https://refivu.com/en/papers/38d65e87-91c3-4285-bca2-9755328de70d-totalsegmentator-robust-segmentation-of-104-anatomical.md)
- [RMPE: Regional Multi-person Pose Estimation](https://refivu.com/en/papers/a258675a-c286-4c65-9760-3d72305d7120-rmpe-regional-multi-person-pose-estimation.md)
- [Memorizing Normality to Detect Anomaly: Memory-augmented Deep Autoencoder for Unsupervised Anomaly Detection](https://refivu.com/en/papers/b6435fab-e010-4a4f-aeb8-b125ca06e94a-memorizing-normality-to-detect-anomaly-memory-augmented-deep.md)
- [LLNet: A Deep Autoencoder Approach to Natural Low-light Image Enhancement](https://refivu.com/en/papers/1b58b4f0-48b5-40db-be28-ecd8cf270c6f-llnet-a-deep-autoencoder-approach-to-natural-low.md)
- [Hyperband: A Novel Bandit-Based Approach to Hyperparameter Optimization](https://refivu.com/en/papers/cc73f821-5462-49b8-9631-4daf8cba448c-hyperband-a-novel-bandit-based-approach-to-hyperparameter.md)
- [SCAFFOLD: Stochastic Controlled Averaging for Federated Learning](https://refivu.com/en/papers/a21677f5-6e53-4724-a456-85f6bf3b0caf-scaffold-stochastic-controlled-averaging-for-federated.md)
- [Learning Dexterous In-Hand Manipulation](https://refivu.com/en/papers/8f01a51e-a6e2-4461-a855-c35b36cbc49e-learning-dexterous-in-hand-manipulation.md)
- [Scheduled denoising autoencoders](https://refivu.com/en/papers/d63c0765-833a-4313-9ce1-c45516b7d22a-scheduled-denoising-autoencoders.md)
- [AttnGAN: Fine-Grained Text to Image Generation with Attentional Generative Adversarial Networks](https://refivu.com/en/papers/a0260608-3d36-436c-af24-a535c7e4e5ef-attngan-fine-grained-text-to-image-generation-with.md)
- [Stochastic Variational Inference](https://refivu.com/en/papers/36c9d62c-308d-476e-8657-7d699cf4658e-stochastic-variational-inference.md)

## Terms in this paper

- [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)
- [Image classification](https://refivu.com/en/terms/e15c43f3bb32-image-classification)
- [ImageNet-1K](https://refivu.com/en/terms/d8d6444bd460-imagenet-1k)
- [FPS](https://refivu.com/en/terms/e6b895af6e27-fps)
- [Vision Transformer](https://refivu.com/en/terms/143abf165d88-vision-transformer)
- [DeiT](https://refivu.com/en/terms/24b9f164881b-deit)
- [position embeddings](https://refivu.com/en/terms/340cd7d12eb0-position-embeddings)
- [Mamba](https://refivu.com/en/terms/cc8b7f3226dc-mamba)
- [State Space Model](https://refivu.com/en/terms/565437c56b7b-state-space-model)
- [Cascade Mask R-CNN](https://refivu.com/en/terms/91bd24b3f04f-cascade-mask-r-cnn)
- [UPerNet](https://refivu.com/en/terms/d07802fe3627-upernet)
- [class token](https://refivu.com/en/terms/5290d74b3faf-class-token)
- [COCO 2017](https://refivu.com/en/terms/d7d6496ff636-coco-2017)
- [GPU Memory](https://refivu.com/en/terms/6012aa2bffa6-gpu-memory)
- [Segmenter](https://refivu.com/en/terms/48d22c7db3c3-segmenter)
- [state space model (SSM)](https://refivu.com/en/terms/c6a285a14cfc-state-space-model-ssm)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/178fce5e-d4f5-44ae-8265-df3fb75ee87b-vision-mamba-efficient-visual-representation-learning-with)
