# VMamba: Visual State Space Model

VMamba adapts the Mamba state-space model into a linear-time vision backbone

Yue Liu, Yunjie Tian, Yuzhong Zhao, Hongtian Yu, Lingxi Xie, Yaowei Wang and 3 more · arXiv · 2024-1-18

- **Problem** Self-attention cost grows quadratically with token count, which is heavy for large images. Mamba's selective scan needs a fixed order, and image patches have none.
- **Method** VMamba stacks VSS blocks that replace Mamba's scan with SS2D. SS2D unfolds the patch grid into four sequences, scans each, and merges them back.
- **Results** VMamba-B ran at 646 img/s on an A100 GPU, against 458 img/s for Swin-B.

## Why a state space backbone for images

Self-attention gives vision Transformers global reach and input-dependent weights, but its cost grows quadratically with the number of tokens, which becomes a heavy burden on tasks with large spatial resolutions. Cheaper variants that restrict the effective receptive field or replace the softmax with linear attention have either narrowed that reach or lost accuracy across tasks.

Mamba keeps linear cost on long sequences, which makes its core operation attractive for an alternative backbone. Its selective scan, however, consumes data in a fixed order, and image patches have no inherent sequence, so the operation has to be reshaped before it can cover the whole grid.

## From state space recurrence to the selective scan

A continuous state space model maps an input u(t) to an output y(t) through a hidden state h(t), with the dynamics given by \\( h'(t)=Ah(t)+Bu(t) \\) and \\( y(t)=Ch(t)+Du(t) \\), where A, B, C and D are the weighting parameters. To run such a system inside a deep network, the continuous equations are discretized using a step size Δ, which turns the update into a recurrence over discrete steps.

The discrete form is said to approximate the zero-order hold method, which is commonly used for SSM-based models.

Plain SSMs are linear time-invariant, so their weights stay fixed across inputs and the response can be written as a convolution. Mamba's S6 makes the weights depend on the input, which rules out a convolution, but the recurrence can still be evaluated with associative scan algorithms in linear time.

## How SS2D traverses the patch grid

SS2D starts with Cross-Scan, which unfolds the input patches into four sequences along four distinct traversal paths. Each of the four sequences is handled by its own S6 block, and these blocks run in parallel, so each path builds its own compressed hidden state.

Cross-Merge reshapes the four processed sequences and combines them into a single 2D feature map. The authors argue that the complementary 1D paths let each pixel draw information from every other pixel in some direction, which yields a global receptive field in 2D.

The design keeps the input-dependent weights, global reach and linear cost of S6 from the Mamba block. The change relative to S4ND is that S4ND extends the kernel to 2D with an outer product, which fixes the weights, whereas SS2D keeps the selective scan and applies it along four orders.

## VSS blocks and the four-stage layout

The input image is partitioned into patches by a stem that gives a feature map at H/4 by W/4, and no positional embeddings are added. Four stages then produce feature maps at H/4, H/8, H/16 and H/32, where every stage after the first begins with a down-sampling layer followed by a stack of VSS blocks.

A VSS block starts from a Mamba block and replaces its S6 module with SS2D. The authors also remove the multiplicative branch, arguing that the selectivity of SS2D already provides the gating effect, so the block becomes a single branch with two residual modules, close to a Transformer block.

VMamba is built at three scales, Tiny, Small and Base, and the layer configurations of each are given in the appendix.

## Accelerating the vanilla model

The vanilla VMamba-T reached 82.2% top-1 with 22.9M parameters and 5.6G FLOPs, but its throughput was only 426 images/s. The authors treat this throughput and the high memory cost as the main obstacle to deploying VMamba.

The speed-up is organized as a sequence of steps, each reported as a change in top-1 accuracy and in images per second. Re-implementing Cross-Scan and Cross-Merge in Triton added 41 img/s without changing accuracy, and adapting the selective scan CUDA kernel to take float16 input and produce float32 output raised training throughput from 165 to 184.

Replacing the einsum in the selective scan with a linear layer and switching to a (B, C, H, W) tensor layout added 174 img/s with no accuracy change.

The architectural steps add an MLP and remove the DWConv layers, which costs 0.6% accuracy for 175 img/s, while reducing ssm-ratio from 2.0 to 1.0 and removing the multiplicative branch adds 0.6% and 366 img/s. Restoring DWConv and lowering d\_state from 16.0 to 1.0 changes accuracy by 0.3% and throughput by 161 img/s, and the final step changes ssm-ratio to 1.0 while using the layer configuration \[2,2,8,2\].

The end result listed in the table is VMamba-T at 82.6 top-1 and 1686 throughput.

## ImageNet-1K classification

VMamba-T reached 82.6 top-1 on ImageNet-1K with 224 × 224 inputs, at 4.9G FLOPs and 1686 images/s.

VMamba-S reached 83.6 top-1 at 877 images/s.

Throughput was measured with an A100 GPU and an AMD EPYC 7542 CPU, and the table pairs each model's accuracy and throughput with the same row. Under that measurement, VMamba-B ran at 646 img/s while Swin-B ran at 458 img/s.

Against SSM baselines, VMamba-T's throughput is 1.47× that of S4ND-Conv-T and 1.08× that of Vim-S. Its top-1 lead over those two models is 0.4% and 2.1%.

## Detection and segmentation on COCO and ADE20K

Under the 1× Mask R-CNN schedule on MSCOCO, VMamba-T, VMamba-S and VMamba-B reached box AP of 47.3, 48.7 and 49.2.

Mask AP for the same 1× setting is 42.7, 43.7 and 44.1 for VMamba-T, VMamba-S and VMamba-B.

On ADE20K with crop size 512, VMamba-T reached 47.9 mIoU in single-scale testing and 48.8 in multi-scale testing, against 44.5 single-scale for Swin-T. The authors report VMamba-T at 3.4 points above Swin-T and 1.9 above ConvNeXt-T in the single-scale setting. VMamba-S and VMamba-B reached 50.6 and 51.0 single-scale mIoU, which the text places 2.6 and 2.5 points above NAT-S and NAT-B.

Both dense tasks use Mask R-CNN for detection and UperNet for segmentation, following the cited frameworks.

## Behaviour at larger input resolutions

Without fine-tuning, VMamba reached 74.7% top-1 at a 768 × 768 input resolution, and 79.2% with linear tuning, and the authors describe its drop across resolutions as modest.

The resolution study compares FLOPs, throughput and memory against Swin-T tested with scaled window sizes. The authors report that VMamba keeps linear growth in FLOPs and memory and maintains high throughput as resolution rises, which they connect to Mamba's efficiency on long sequences.

## Reading SS2D as attention and checking its receptive field

Consider the SSM variables for a response span of length T, mapped to V, K and Q, where each step's weight w\_i is a cumulative product along the scanning path. The mask M is a T by T temporal mask with ones in its lower triangular part and zeros elsewhere.

In Eq. 5, the products of Q, K and V have the same form as self-attention, even though the weight w is included in them.

For a query patch inside a foreground object, the QK^T map activates all earlier scanned foreground tokens. Including w concentrates the map near the query patch, and the per-path map keeps patches scanned early, such as sheep far to the left, active.

Effective receptive fields were compared for the central pixel before and after training. Only DeiT, HiViT, Vim and VMamba show global ERFs in that comparison, and VMamba's ERF is more uniform and 2D-aware than Vim's. The authors note that VMamba has linear cost, while DeiT and HiViT incur quadratic cost in the number of input patches.

## Comparing scan orders

Cross-Scan was compared with unidirectional, bidirectional and cascade scanning, where cascade scanning runs row-wise and then column-wise. Feature dimensions were adjusted so that the patterns have similar parameters and FLOPs.

The authors report that Cross-Scan gives better speed and accuracy than the other three patterns, and that removing DWConv further strengthens that advantage. Throughput of Cross-Scan and Bidi-Scan is close in the figure values, so the speed gain over Bidi-Scan is small.

## Limitations

Limited computational resources kept the authors from exploring a Large-scale VMamba architecture and from running a fine-grained hyperparameter search. Pre-training on large datasets such as ImageNet-21K was not studied for SSM-based VMamba, and pre-training methods suited to such models remain unexplored.

The authors note that SS2D makes no particular assumption about input layout or modality, but its use in more general tasks was not tested, and a more general scanning pattern for vision tasks is left open. The main experiments follow the hyperparameter settings used for Swin.

## Paper info

- **Authors**: Yue Liu, Yunjie Tian, Yuzhong Zhao, Hongtian Yu, Lingxi Xie, Yaowei Wang, Qixiang Ye, Jianbin Jiao, Yunfan Liu
- **Venue**: arXiv · Preprint
- **First published**: 2024-1-18
- **Added**: 2026-11-12
- **Updated**: 2024-12-29
- **Version**: v4
- **arXiv**: 2401.10166
- **Category**: cs.CV
- **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.10166v4) · [PDF ↗](https://arxiv.org/pdf/2401.10166v4)

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

Yue Liu, Yunjie Tian, Yuzhong Zhao, Hongtian Yu, Lingxi Xie, Yaowei Wang, Qixiang Ye, Jianbin Jiao, Yunfan Liu (2024). VMamba: Visual State Space Model. arXiv:2401.10166v4. https://arxiv.org/abs/2401.10166v4

**BibTeX**

```
@misc{liu2024vmamba,
  title = {{VMamba: Visual State Space Model}},
  author = {Yue Liu and Yunjie Tian and Yuzhong Zhao and Hongtian Yu and Lingxi Xie and Yaowei Wang and Qixiang Ye and Jianbin Jiao and Yunfan Liu},
  year = {2024},
  eprint = {2401.10166},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2401.10166v4}
}
```

## Other paper commentary

- [Speed/accuracy trade-offs for modern convolutional object detectors](https://refivu.com/en/papers/d59f0ced-71a6-4425-a177-e2e9ad7b8370-speed-accuracy-trade-offs-for-modern-convolutional-object.md)
- [Building Machines That Learn and Think Like People](https://refivu.com/en/papers/1c62e17f-b645-4165-8400-ffcbcd4abc96-building-machines-that-learn-and-think-like-people.md)
- [EnlightenGAN: Deep Light Enhancement without Paired Supervision](https://refivu.com/en/papers/1b24a8a7-0c9f-4dc7-b6db-20e08b8a1feb-enlightengan-deep-light-enhancement-without-paired.md)
- [Unsupervised Learning of Depth and Ego-Motion from Video](https://refivu.com/en/papers/c545cc84-bdea-4ac2-ba9d-bf5f4a19568c-unsupervised-learning-of-depth-and-ego-motion-from.md)
- [YOLOv11: An Overview of the Key Architectural Enhancements](https://refivu.com/en/papers/d7fa1568-31c6-4ca5-a11e-c69df2a96ef2-yolov11-an-overview-of-the-key-architectural-enhancements.md)
- [Convolutional Pose Machines](https://refivu.com/en/papers/544048ce-4f7c-4027-9775-b611791faf11-convolutional-pose-machines.md)
- [Learning Multi-Domain Convolutional Neural Networks for Visual Tracking](https://refivu.com/en/papers/5b8779fe-6230-4bef-9d38-11634c64c64a-learning-multi-domain-convolutional-neural-networks-for.md)
- [Ensemble Adversarial Training: Attacks and Defenses](https://refivu.com/en/papers/c363c126-7d65-4e0a-aa01-0b7a02e39200-ensemble-adversarial-training-attacks-and-defenses.md)
- [Towards Federated Learning at Scale: System Design](https://refivu.com/en/papers/5a416c7f-9637-4efb-9bcc-4ff43e95b3bd-towards-federated-learning-at-scale-system-design.md)
- [A Prompt Pattern Catalog to Enhance Prompt Engineering with ChatGPT](https://refivu.com/en/papers/188edd2a-83fb-45cc-adcf-4ddabef4e43b-a-prompt-pattern-catalog-to-enhance-prompt-engineering.md)
- [A Contextual-Bandit Approach to Personalized News Article Recommendation](https://refivu.com/en/papers/8024ed96-4fed-4baf-950b-7340e29feb0a-a-contextual-bandit-approach-to-personalized-news-article.md)
- [Learning Efficient Convolutional Networks through Network Slimming](https://refivu.com/en/papers/d840aead-455e-4eaf-8f2c-7e4bff390606-learning-efficient-convolutional-networks-through-network.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)
- [Mask R-CNN](https://refivu.com/en/terms/6da881f24c0c-mask-r-cnn)
- [Average Precision](https://refivu.com/en/terms/1764eaa249a6-average-precision)
- [ADE20K](https://refivu.com/en/terms/5adea765479c-ade20k)
- [MSCOCO](https://refivu.com/en/terms/a45c43d66cae-mscoco)
- [Mamba](https://refivu.com/en/terms/cc8b7f3226dc-mamba)
- [State Space Model](https://refivu.com/en/terms/565437c56b7b-state-space-model)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/4032560e-3e65-4a0f-b564-34cb12bd1c92-vmamba-visual-state-space-model)
