Paper commentary
Vision Mamba: Efficient Visual Representation Learning with Bidirectional State Space Model
Vim replaces self-attention with bidirectional state space models for vision
- 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
- What we show
- Paper info and commentary
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}
}