VMamba — Scanning an Image Four Ways
- 1Mamba — Selective State Spaces, Step by Step
- 2Mamba-2 — When a State Space Model Is a Masked Attention Matrix
- 3Mamba-3 — A Better Step, a Turning State, More Work per Byte
- 4VMamba — Scanning an Image Four Ways
- 5Mamba in RT-DETRv4 — What Could Make It Faster
Summary
A scan reads one token after another, and an image has no first pixel. VMamba reads every feature map four ways, across and down, forwards and backwards, and adds the answers. This post shows which pixels one, two and four scans let a pixel see, the released VSS block with its state of size one, VMamba's results, and MambaOut's check of whether vision needs the scan at all.
Table of Contents
- 1. Why One Scan Is Not Enough2
- 2. SS2D: Four Routes, One Sum2
- 3. The VSS Block: What Is Left of Mamba?3
- 4. Results3
- 5. MambaOut: Do We Even Need the Scan?3
- 6. Conclusion3
- 7. References3
- 8. Connections3
The selective scan of Mamba — Selective State Spaces, Step by Step is causal: token t only hears the tokens before it. Fine for text. A flattened image has no order, and the pixel just above you sits a whole row back.
Think of a crossword. Read only the "across" clues and you never meet the letters running "down", even though they share your squares. VMamba [LIU24] reads every grid across and down, forwards and backwards, and lets each square keep all four readings.
Brush up ;)
- S6, Δ, B, C and the scan: Mamba — Selective State Spaces, Step by Step [GU23].
- Patches as tokens: An Image Is Worth 16×16 Words — ViT, Patch by Patch [DOSO20]. Stages: Swin Transformer — Windows, Shifts and a Pyramid for Dense Prediction [LIU21].
Width is D here (VMamba writes C, but C is already the scan's read-out), state size N, expansion ratio r.
1. Why One Scan Is Not Enough
Take a 4 × 4 grid flattened row by row, and the pixel at row 2, column 2:
- One scan (rows, left to right): it hears 6 of 16 pixels. Nothing below it.
- Two scans (rows, both ways): 16 of 16.
- Four scans (rows and columns, both ways): still 16 of 16, but the pixel above is now 1 step away instead of 4.
So two directions give reach; four give nearness in both axes.
Toy
The shaded cells are what the ringed pixel can hear. Press "two scans", then "four scans", and watch the step count to the pixel above.
Vim [ZHU24] was the two-way answer: ViT patches, and each block scans forwards and backwards with its own conv and S6, then adds the two. Its ablation (Tab. 4, tiny model): a backward scan with its own conv moves ImageNet top-1 from 73.2 to 73.9 and ADE20K mIoU from 32.3 to 35.9. The gain shows most on segmentation.
2. SS2D: Four Routes, One Sum
VMamba's module is SS2D, the 2-D selective scan. On a 3 × 3 map:
- route 1, rows: 1, 2, 3, 4, 5, 6, 7, 8, 9;
- route 2, columns: 1, 4, 7, 2, 5, 8, 3, 6, 9;
- routes 3 and 4: the same two, reversed.
NOTE: these are raster orders, not snakes. At the end of each row the scan jumps back to the start of the next (Fig. 2, and the released code).
Each route gets its own S6; unscan folds it back onto the grid, and the four are summed:
- Four routes, four sets of S6 weights (Δ, B, C projections and A).
- The merge is a plain sum, no learned weights, then a LayerNorm.
How near is near? A toy: give every step the same decay aΔ and see how much of each pixel survives to the ring.
Toy
At aΔ = 0.2 on 7 × 7, the pixel to the left keeps 0.819 with any route. The pixel above keeps 0.247 with one or two scans, 0.819 with four. Diagonals stay far. In the real model Δ depends on the input, so this is a picture, not a measurement. The measurement is Tab. 10:
| Scan | top-1, with DWConv | top-1, without | img/s |
|---|---|---|---|
| Rows, one way | 82.26 | 80.88 | 1682 |
| Rows, both ways | 82.49 | 81.80 | 1687 |
| Rows, then columns | 82.42 | 81.71 | 998 |
| Four routes | 82.60 | 82.25 | 1686 |
Table. 1 Scan patterns on VMamba-T, with and without the 3 × 3 depthwise conv; throughput with the conv (Tab. 10 of [LIU24]).
- With the conv, four routes buy +0.34 over one; without it, +1.37. The 3 × 3 conv already carries much of the 2-D picture.
- Four routes side by side cost almost nothing over one. Chaining rows into columns costs 41 % of the throughput.
3. The VSS Block: What Is Left of Mamba?
The released block is two residual halves, like a Transformer block:
- The gate is gone. The authors say the selectivity of SS2D already does its job (§4.1).
- No position embeddings (§4.1).
- State N = 1, against Mamba's 16. Tab. 12 (at r = 2): N = 1 / 2 / 4 gives 82.49 / 82.50 / 82.51 top-1 while throughput falls. So the memory is one decaying running sum per channel per route; the selection (Δ, B, C from the token) stays.
The first block was closer to Mamba: state 16, the gate, no FFN. Tab. 5 walks from it to the released one, one change at a time:
- 426 → 1,686 img/s (3.96×) for +0.43 top-1 (82.17 → 82.60).
- The biggest single jump is state 16 → 1: +778 img/s for −0.44. Later width and depth changes win the accuracy back.
4. Results
The layout is Swin's: four stages at strides 4, 8, 16 and 32, VSS blocks inside. Throughput on one A100.
| Model | Params | img/s | ImageNet top-1 | COCO box AP | ADE20K mIoU |
|---|---|---|---|---|---|
| Swin-T | 28 M | 1244 | 81.3 | 42.7 | 44.5 |
| ConvNeXt-T | 29 M | 1198 | 82.1 | 44.2 | 46.0 |
| VMamba-T | 30.2 M | 1686 | 82.6 | 47.3 | 47.9 |
| VMamba-S | 50.1 M | 877 | 83.6 | 48.7 | 50.6 |
| Swin-B | 88 M | 458 | 83.5 | 46.9 | 48.1 |
| VMamba-B | 88.6 M | 646 | 83.9 | 49.2 | 51.0 |
Table. 2 ImageNet at 224², COCO with Mask R-CNN [HE17] 1× schedule, ADE20K with UperNet single scale (Tabs. 1, 2 and 4 of [LIU24]; Swin [LIU21] and ConvNeXt [LIU22] as it quotes them).
- VMamba-T beats Swin-T by 1.3 top-1 and 4.6 box AP.
- VMamba-B beats Swin-B and runs 646 against 458 img/s.
- Trained at 224 and tested at 768 with no fine-tuning, VMamba-T keeps 74.66 top-1 against DeiT-S's [TOUV21] 60.98 (Tab. 9). Its cost grows with the pixel count, not its square.
5. MambaOut: Do We Even Need the Scan?
MambaOut [YU24] deletes the SSM from the Mamba block. What is left is a Gated CNN [DAUP17] with a 7 × 7 depthwise conv.
- Its rule: a sequence is long when L > 6D, where a Transformer block's L² term passes its linear ones.
- Its claim: the SSM is not needed for ImageNet (short sequences), but may still help detection and segmentation (long ones).
A hierarchical backbone is long early. L / 6D per VMamba-T stage, my arithmetic:
- 224 × 224: 5.44, 0.68, 0.09, 0.01;
- 800 × 1280 (COCO): 111, 13.9, 1.74, 0.22.
Stage 1 is already "long" at 224². On a COCO image three of the four stages are.
RT-DETRv4 only
Press "VMamba-T at 640" and look at stage 1: global attention there is 126.8 G multiply-adds for one mixer, SS2D 0.73 G.
Now MambaOut against the final VMamba (its own tables quote earlier versions):
| Size | ImageNet: MambaOut | VMamba | COCO box: MambaOut | VMamba | ADE20K SS: MambaOut | VMamba |
|---|---|---|---|---|---|---|
| Tiny | 82.7 | 82.6 | 45.1 | 47.3 | 47.4 | 47.9 |
| Small | 84.1 | 83.6 | 47.4 | 48.7 | 49.5 | 50.6 |
| Base | 84.2 | 83.9 | 47.4 | 49.2 | 49.6 | 51.0 |
Table. 3 Tabs. 1–3 of [YU24] against Tabs. 1–2 of [LIU24]. The Tiny pairing is mine.
- ImageNet: MambaOut ahead at every size, by 0.1 to 0.5.
- COCO and ADE20K: VMamba ahead, by 1.3 to 2.2 box AP and 0.5 to 1.4 mIoU.
Both of MambaOut's hypotheses hold: no scan needed on ImageNet, and a real gap on the dense tasks, where most stages are long.
6. Conclusion
- A causal scan on a flattened image only hears what came before, and the pixel above is a row away.
- VMamba reads each map along four raster routes and sums them: every pixel is reached, and its four neighbours are one step away.
- The released block keeps the selection, drops the gate, adds an FFN and shrinks the state to N = 1, for 3.96× the first block's speed.
- MambaOut wins ImageNet with no scan and loses COCO and ADE20K.
Next: does any of this belong in a real-time detector? Mamba in RT-DETRv4 — What Could Make It Faster works it out. Stay tuned.
7. References
- [LIU24] Liu et al. VMamba: Visual State Space Model. NeurIPS 2024, arXiv 2401.10166 (v4).
- [ZHU24] Zhu et al. Vision Mamba: Efficient Visual Representation Learning with Bidirectional State Space Model. ICML 2024, arXiv 2401.09417.
- [YU24] Yu, Wang. MambaOut: Do We Really Need Mamba for Vision? arXiv 2405.07992.
- [GU23] Gu, Dao. Mamba: Linear-Time Sequence Modeling with Selective State Spaces. arXiv 2312.00752.
- [DAUP17] Dauphin et al. Language Modeling with Gated Convolutional Networks. ICML 2017, arXiv 1612.08083.
- [DOSO20] Dosovitskiy et al. An Image is Worth 16x16 Words. arXiv 2010.11929.
- [TOUV21] Touvron et al. Training data-efficient image transformers & distillation through attention. arXiv 2012.12877.
- [LIU21] Liu et al. Swin Transformer. arXiv 2103.14030.
- [LIU22] Liu et al. A ConvNet for the 2020s. arXiv 2201.03545.
- [HE17] He, Gkioxari, Dollár, Girshick. Mask R-CNN. arXiv 1703.06870.
8. Connections
What this page builds on, cites or links to, and what points back at it. A plain box is a “builds on”; “cited” and “linked in the text” are the lighter links. Hover a box for a preview.
Related
- Read · this builds on it
- Read · builds on this (next in the series)
- Paper · this builds on it (earlier in the series)
- Paper · this builds on it
- Paper · explains a paper this cites
- Paper · this builds on it
Go deeper
-
Start withRead
-
Paper
-
Paper
-
Paper
-
Paper
-
Read
-
Read
-
Paper
-
Read
-
Paper
-
Paper
-
Paper
-
Paper
-
Paper
-
Read
-
Paper
-
Paper
-
Read
-
Paper
-
Paper
-
Paper
-
You are hereVMamba — Scanning an Image Four WaysPaper
-
ThenRead
Go broader
- Sits under
- SeriesMambapart 4 of 5 · start from the first part
- Its tags on the map
- Ask the mapWhat connects VMamba and …type the other page's name; the map answers with the chain of links between them