Paper · 2024-07-10 · cs.CV
MambaVision: A Hybrid Mamba-Transformer Vision Backbone
MambaVision is a hierarchical image backbone: two convolutional stages, then two stages that mix a redesigned Mamba (SSM) block with self-attention, with attention in the last half of each stage. The Mamba mixer adds a convolutional branch beside the SSM branch. Author-reported: 82.3% ImageNet-1K top-1 at 6298 img/s for the 31.8M-parameter Tiny model, and 84.2% for Base.
State-space model (SSM)Vision Transformer (ViT) backbonesSelf-attentionEfficient vision backbonesbackbonehybrid-architecturestate-space-modelimage-classificationobject-detectionsemantic-segmentation
arXivPDFCodeMarkdown17 min read
AI-compiled by claude-haiku-5-5 on 2026-10-18, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
Image models have mostly been built from two kinds of layers. Convolutions look at small neighbourhoods and are cheap. Attention lets every patch of an image look at every other patch, which sees the whole picture but gets expensive as the picture grows. A newer layer type, Mamba, handles long sequences cheaply, but it reads its input one step at a time, so it has a harder time taking in the whole image at once.
MambaVision is a hybrid. The early layers are plain convolutions, which are cheap at high resolution. The later layers mix Mamba-style blocks with attention blocks. The authors found that putting attention in the final layers gave the model much better understanding of long-range structure. Each Mamba-style block also gets a second, convolutional branch next to the sequence branch, and the two are joined before the output.
On ImageNet classification, the authors report a better accuracy-versus-speed trade-off than comparable Mamba, convolutional and transformer models. They also use the same network as a backbone for object detection and segmentation.
TL;DR
- Hierarchical four-stage backbone. Stages 1-2 are convolutional residual blocks; stages 3-4 mix a redesigned Mamba mixer with multi-head self-attention §3.1 §3.2.2.
- The Mamba mixer runs a selective scan on one half of its channels and a convolutional gate on the other half, then concatenates them eq. 7.
- Author-reported ImageNet-1K top-1: 82.3% (Tiny, 31.8M params, 6298 img/s) up to 85.3% (L2, 241.5M params, 1021 img/s), on an A100 at batch 128 tab. 1.
- Official code is non-commercial (NVIDIA Source Code License-NC). Implement from the paper and this card; do not copy code.
Problem
Transformers are costly on long inputs because self-attention scales quadratically with sequence length §1. Mamba, a state space model, scales linearly and matches or beats Transformers on language tasks §1. For vision, the authors argue that Mamba's sequential, autoregressive processing fits images poorly: pixels have no single natural order, and a step-by-step scan has limited access to global context in one pass §1. Bidirectional variants such as Vim add latency and do not always improve accuracy, according to the authors §1 §2. The gap the paper targets is the accuracy and throughput of pure Mamba vision backbones relative to ViT and CNN backbones §1.
Method
Macro architecture
MambaVision has four stages §3.1 app. B.
- Stem. Two consecutive 3×3 convolutions with stride 2, each followed by BatchNorm and ReLU, map the image to H/4 × W/4 × C §3.1 mamba_vision.py.
- Stages 1 and 2. Residual convolutional blocks eq. 1. Each block is conv 3×3, BN, GELU, conv 3×3, BN, plus the input eq. 1 mamba_vision.py.
- Stages 3 and 4. Layers of pre-normalised residual blocks eq. 6. Tokens are cut into non-overlapping windows before the layers and reassembled after them mamba_vision.py.
- Between stages. A 3×3 convolution with stride 2 halves the resolution §3.1 mamba_vision.py.
In stages 3 and 4, with N layers in a stage, the first N/2 layers use the MambaVision mixer and the last N/2 use self-attention §3.2.2. The ablation in tab. 5 finds that placing self-attention in the last N/2 layers of each stage works best (82.3%) §5.3.
The paper's supplementary architecture table tab. S.2 is useful but does not agree with the code in several places. See Paper vs code.
Mamba preliminaries
A discrete state space model updates a hidden state with a zero-order-hold discretisation of learned continuous parameters §3.2.1 eq. 3. Mamba makes the input and step-size parameters input-dependent (selectivity) §3.2.1. The paper gives the discretisation formulas but does not give implementation details of the scan; it refers to the original Mamba paper §3.2.1.
\bar{A} = \exp(\Delta A), \quad \bar{B} = (\Delta A)^{-1}(\exp(\Delta A) - I)\cdot(\Delta B), \quad \bar{C} = C eq. 3
MambaVision mixer
The mixer replaces Mamba's causal convolution with a regular convolution, since a causal convolution restricts influence to one direction §3.2.2. It adds a symmetric branch with no SSM, made of one convolution and a SiLU activation, to recover content the sequential scan may lose §3.2.2. Each branch projects to C/2 channels, the branches are concatenated, and a final linear layer maps back to C §3.2.2 eq. 7.
\begin{aligned} X_1 &= \mathrm{Scan}\big(\sigma(\mathrm{Conv}(\mathrm{Linear}(C,\tfrac{C}{2})(X_{in})))\big) \\ X_2 &= \sigma\big(\mathrm{Conv}(\mathrm{Linear}(C,\tfrac{C}{2})(X_{in}))\big) \\ X_{out} &= \mathrm{Linear}(\tfrac{C}{2}, C)\big(\mathrm{Concat}(X_1, X_2)\big) \end{aligned} eq. 7
Here σ is SiLU and Scan is the selective scan of §3.2.1 §3.2.2. The paper gives a PyTorch-like listing of the mixer alg. 1. It is not runnable as written. Use the steps below and the code citations.
# MambaVision mixer [eq. 7]
# Input: tokens (B, L, C), where L tokens form one window in row-major order
# Output: tokens (B, L, C)
def mambavision_mixer(tokens):
# One linear map from C to C, split into two halves of C/2 each [eq. 7]
# [code: mambavision/models/mamba_vision.py#L404-L406]
projected = linear(tokens) # (B, L, C)
seq_half, gate_half = split(projected, 2) # (B, L, C/2) each
# Depthwise 1D convolution over the L tokens, then SiLU, per branch [eq. 7]
seq_half = silu(depthwise_conv1d(seq_half)) # (B, L, C/2)
gate_half = silu(depthwise_conv1d(gate_half)) # (B, L, C/2)
# Selective scan on the sequence branch only [eq. 7] [§3.2.1]
seq_half = selective_scan(seq_half) # (B, L, C/2)
# Concatenate both branches, then project back to C [eq. 7]
mixed = concat(seq_half, gate_half) # (B, L, C)
return linear(mixed) # (B, L, C)Layer
Each layer is pre-normalised. The mixer and the MLP each sit inside a residual connection eq. 6. Layer normalisation is used for the norm §3.2.2. The MLP expansion ratio is 4 in the code mamba_vision.py mamba_vision.py.
\begin{aligned} \hat{X}^{n} &= \mathrm{Mixer}(\mathrm{Norm}(X^{n-1})) + X^{n-1} \\ X^{n} &= \mathrm{MLP}(\mathrm{Norm}(\hat{X}^{n})) + \hat{X}^{n} \end{aligned} eq. 6
# One layer of stage 3 or 4 [eq. 6]
# The mixer is the MambaVision mixer or self-attention (see Hyperparameters)
def layer(x):
# Token mixing with a residual connection [eq. 6]
x = x + mixer(layer_norm(x))
# Channel MLP with a residual connection [eq. 6]
x = x + mlp(layer_norm(x))
return xSelf-attention
Attention is standard multi-head self-attention, computed within windows §3.2.2 eq. 8. The paper's text says d_h is the number of heads; the scaling in the code uses the per-head dimension instead (see Pitfalls).
\mathrm{Attention}(Q, K, V) = \mathrm{Softmax}\!\left(\frac{Q K^{\mathsf{T}}}{\sqrt{d_h}}\right) V eq. 8
Stage-level sketch
# MambaVision forward pass [§3.1] [app. B]
# Input: image (B, 3, H, W)
def mambavision(image):
# Stem: two stride-2 3x3 convolutions [§3.1]
x = stem(image) # (B, C, H/4, W/4)
for stage in stages:
if stage.uses_convolution:
# Stages 1-2: residual convolutional blocks [eq. 1]
x = conv_blocks(x)
else:
# Stages 3-4: windowed layers [eq. 6]
x = windowed_layers(x)
# Downsample between stages, not after the last stage [§3.1]
if not stage.is_last:
x = downsample(x) # 3x3 conv, stride 2
# Head: batch norm, global average pool, linear classifier [code: ...#L691]
x = batch_norm(x)
x = global_average_pool(x)
return linear(x)Hyperparameters
Model variants
Values are taken from the constructors in the code. The paper gives the same family in tab. S.2 but does not list depths or head counts in its text. mamba_vision.py
| Variant | Width C (stage 1 conv) | Depths (4 stages) | Heads (4 stages) | Stem out (in_dim) | Drop path | Source |
|---|---|---|---|---|---|---|
| T | 80 | 1, 3, 8, 4 | 2, 4, 8, 16 | 32 | 0.2 | mamba_vision.py |
| T2 | 80 | 1, 3, 11, 4 | 2, 4, 8, 16 | 32 | 0.2 | mamba_vision.py |
| S | 96 | 3, 3, 7, 5 | 2, 4, 8, 16 | 64 | 0.2 | mamba_vision.py |
| B | 128 | 3, 3, 10, 5 | 2, 4, 8, 16 | 64 | 0.3 | mamba_vision.py |
| L | 196 | 3, 3, 10, 5 | 4, 8, 16, 32 | 64 | 0.3 | mamba_vision.py |
| L2 | 196 | 3, 3, 12, 5 | 4, 8, 16, 32 | 64 | 0.3 | mamba_vision.py |
Stage widths are C, 2C, 4C, 8C for each variant mamba_vision.py.
Stages 1 and 2 are convolutional (conv = i in (0, 1)) mamba_vision.py.
Window sizes for classification are 8, 8, 14, 7 for the four stages
mamba_vision.py app. A. At 224 input, stage 3
is 14×14 and stage 4 is 7×7, so each fits in one window (derived from the code).
Attention blocks are placed in the last ⌊N/2⌋ layers of stages 3 and 4, where
the code takes range(depth//2, depth) for even depth and range(depth//2+1, depth) for odd depth mamba_vision.py.
Mamba mixer and attention (code-defined)
The paper does not state these. They come from the code.
| Name | Value | Source | Notes |
|---|---|---|---|
| SSM state size N | 8 | mamba_vision.py | Used in the stage 3-4 mixer blocks |
| Conv kernel | 3 | mamba_vision.py | Depthwise, padding "same" |
| Expansion | 1 (inner width = C) | mamba_vision.py | Each branch has C/2 channels |
| dt rank | ceil(C/16) | mamba_vision.py | |
| dt init range | [0.001, 0.1], floor 1e-4 | mamba_vision.py mamba_vision.py | Log-uniform |
| A init | A = −exp(A_log), A_log = log(1..N) | mamba_vision.py | |
| D init | ones | mamba_vision.py | |
| Δ activation | softplus, with dt bias | mamba_vision.py | |
| Conv bias | none | mamba_vision.py | conv_bias//2 evaluates to 0 |
| in/out projection bias | none | mamba_vision.py mamba_vision.py | |
| Attention qkv bias | True | mamba_vision.py mamba_vision.py | |
| Attention scale | 1/sqrt(head_dim) | mamba_vision.py | Passed to fused SDPA, no mask |
| Head dim, stage 3 and 4 (T) | 40 (derived: 320/8, 640/16) | mamba_vision.py | |
| Norms | LayerNorm in layers; BatchNorm in stem and conv blocks (eps 1e-4 stem, 1e-5 conv blocks); BatchNorm before pooling | mamba_vision.py mamba_vision.py mamba_vision.py mamba_vision.py | |
| Conv activation | GELU, tanh approximation | mamba_vision.py | Paper eq. 1 writes GELU eq. 1 |
| Layer scale | off | mamba_vision.py mamba_vision.py | |
| Init | trunc. normal std 0.02 for Linear; BN weight 1, bias 0 | mamba_vision.py | |
| Stochastic depth | linear rule up to drop path rate | mamba_vision.py |
ImageNet-1K training
| Name | Paper | Code (Tiny config) | Source |
|---|---|---|---|
| Epochs | 300 app. C | 310 | mambavision_tiny_1k.yaml |
| Optimizer | LAMB app. C | lamb | mambavision_tiny_1k.yaml |
| Global batch | 4096 app. C | 128 per process; 4096 over 32 GPUs | mambavision_tiny_1k.yaml |
| Learning rate | 4e-3 app. C | 0.005 | mambavision_tiny_1k.yaml |
| Weight decay | not stated | 0.05 | mambavision_tiny_1k.yaml |
| Schedule | not stated | cosine; warmup 20 epochs from 1e-6; min LR 5e-6 | mambavision_tiny_1k.yaml mambavision_tiny_1k.yaml mambavision_tiny_1k.yaml |
| Gradient clipping | not stated | norm, 5.0 | mambavision_tiny_1k.yaml |
| Label smoothing | not stated | 0.1 | mambavision_tiny_1k.yaml |
| Mixup / CutMix | not stated | 0.8 / 1.0 | mambavision_tiny_1k.yaml mambavision_tiny_1k.yaml |
| RandAugment | not stated | rand-m9-mstd0.5-inc1 | mambavision_tiny_1k.yaml |
| Random erasing | not stated | probability 0.25 | mambavision_tiny_1k.yaml |
| EMA | not stated | decay 0.9998 | mambavision_tiny_1k.yaml |
| MESA-style distillation | not stated | weight 0.5, from 25% of training | mambavision_tiny_1k.yaml train.py |
| Precision | not stated | AMP | mambavision_tiny_1k.yaml |
| Hardware | 32 A100 GPUs app. C | not in code | |
| Eval crop | not stated | 0.875 (script default), 1.0 (Tiny YAML) | train.py mambavision_tiny_1k.yaml |
Downstream training
| Name | Object detection (COCO) | Semantic segmentation (ADE20K) | Source |
|---|---|---|---|
| Head | Cascade Mask R-CNN §5.2 | UperNet §5.2 | |
| Optimizer | AdamW, β=(0.9, 0.999), wd 0.05 | AdamW, β=(0.9, 0.999), wd 0.01 | cascade_mask_rcnn_mamba_vision_tiny_3x_coco.py mamba_vision_160k_ade20k-512x512_tiny.py |
| Learning rate | 1e-4 | 5e-5 | same as above |
| Schedule | 36 epochs; linear warmup 1000 iters from ×0.001; ×0.1 at epochs 27 and 33 | 160k iters; linear warmup 1500 iters from 1e-6; poly (power 1) | cascade_mask_rcnn_mamba_vision_tiny_3x_coco.py mamba_vision_160k_ade20k-512x512_tiny.py |
| Drop path | 0.2 | 0.3 (Tiny) | cascade_mask_rcnn_mamba_vision_tiny_3x_coco.py mamba_vision_160k_ade20k-512x512_tiny.py |
| Window sizes | (8, 8, 112, 56) | (8, 8, 64, 32) | cascade_mask_rcnn_mamba_vision_tiny_3x_coco.py mamba_vision_160k_ade20k-512x512_tiny.py |
| Input | 1280×800 crop tab. 2 | 512×512 crop tab. 3 | |
| Batch | 16 app. C | 16 (1 image per GPU on 16 GPUs in the config) | [code: object_detection/configs/base/datasets/coco_instance.py#L38] mamba_vision_160k_ade20k-512x512_tiny.py |
Results
All numbers are author-reported. Throughput is measured on one A100 GPU at batch 128 for classification tab. 1.
ImageNet-1K classification tab. 1
Setup: 224×224 input unless noted; throughput on an A100 at batch 128 tab. 1.
| Model | Image size | Params (M) | FLOPs (G) | Throughput (img/s) | Top-1 (%) |
|---|---|---|---|---|---|
| Conv-based | |||||
| ConvNeXt-T | 224 | 28.6 | 4.5 | 3196 | 82.0 |
| ConvNeXt-S | 224 | 50.2 | 8.7 | 2008 | 83.1 |
| ConvNeXt-B | 224 | 88.6 | 15.4 | 1485 | 83.8 |
| RegNetY-040 | 288 | 20.6 | 6.6 | 3227 | 83.0 |
| ResNetV2-101 | 224 | 44.5 | 7.8 | 4019 | 82.0 |
| EfficientNetV2-S | 384 | 21.5 | 8.0 | 1735 | 83.9 |
| Transformer-based | |||||
| Swin-T | 224 | 28.3 | 4.4 | 2758 | 81.3 |
| Swin-S | 224 | 49.6 | 8.5 | 1720 | 83.2 |
| SwinV2-T | 256 | 28.3 | 4.4 | 1674 | 81.8 |
| SwinV2-S | 256 | 49.7 | 8.5 | 1043 | 83.8 |
| SwinV2-B | 256 | 87.9 | 15.1 | 535 | 84.6 |
| TNT-S | 224 | 23.8 | 4.8 | 1478 | 81.5 |
| Twins-S | 224 | 24.1 | 2.8 | 3596 | 81.7 |
| Twins-B | 224 | 56.1 | 8.3 | 1926 | 83.1 |
| Twins-L | 224 | 99.3 | 14.8 | 1439 | 83.7 |
| DeiT-B | 224 | 86.6 | 16.9 | 2035 | 82.0 |
| DeiT3-L | 224 | 304.4 | 59.7 | 535 | 84.8 |
| PoolFormer-M58 | 224 | 73.5 | 11.6 | 884 | 82.4 |
| Conv-Transformer | |||||
| CoaT-Lite-S | 224 | 19.8 | 4.1 | 2269 | 82.3 |
| CrossViT-S | 240 | 26.9 | 5.1 | 2832 | 81.0 |
| CrossViT-B | 240 | 105.0 | 20.1 | 1321 | 82.2 |
| Visformer-S | 224 | 40.2 | 4.8 | 3676 | 82.1 |
| NextViT-S | 224 | 31.7 | 5.8 | 3834 | 82.5 |
| NextViT-B | 224 | 44.8 | 8.3 | 2926 | 83.2 |
| NextViT-L | 224 | 57.8 | 10.8 | 2360 | 83.6 |
| EfficientFormer-L1 | 224 | 12.3 | 1.31 | 6220 | 79.2 |
| EfficientFormer-L3 | 224 | 31.4 | 3.9 | 2845 | 82.4 |
| EfficientFormer-L7 | 224 | 82.2 | 10.2 | 1359 | 83.4 |
| MaxViT-B | 224 | 120.0 | 23.4 | 507 | 84.9 |
| MaxViT-L | 224 | 212.0 | 43.9 | 376 | 85.1 |
| FasterViT-1 | 224 | 53.4 | 5.3 | 4188 | 83.2 |
| FasterViT-2 | 224 | 75.9 | 8.7 | 3161 | 84.2 |
| FasterViT-3 | 224 | 159.5 | 18.2 | 1780 | 84.9 |
| Mamba-based | |||||
| Vim-T | 224 | 7.0 | - | 3957 | 76.1 |
| Vim-S | 224 | 26.0 | - | 1974 | 80.5 |
| EfficientVMamba-T | 224 | 6.0 | 0.8 | 2904 | 76.5 |
| EfficientVMamba-S | 224 | 11.0 | 1.3 | 1610 | 78.7 |
| EfficientVMamba-B | 224 | 33.0 | 4.0 | 1482 | 81.8 |
| SiMBA-S | 224 | 15.3 | 2.4 | 826 | 81.7 |
| SiMBA-B | 224 | 22.8 | 4.2 | 624 | 83.5 |
| VMamba-T | 224 | 30.0 | 4.9 | 1282 | 82.6 |
| VMamba-S | 224 | 50.0 | 8.7 | 843 | 83.6 |
| VMamba-B | 224 | 89.0 | 15.4 | 645 | 83.9 |
| MambaVision | |||||
| MambaVision-T | 224 | 31.8 | 4.4 | 6298 | 82.3 |
| MambaVision-T2 | 224 | 35.1 | 5.1 | 5990 | 82.7 |
| MambaVision-S | 224 | 50.1 | 7.5 | 4700 | 83.3 |
| MambaVision-B | 224 | 97.7 | 15.0 | 3670 | 84.2 |
| MambaVision-L | 224 | 227.9 | 34.9 | 2190 | 85.0 |
| MambaVision-L2 | 224 | 241.5 | 37.5 | 1021 | 85.3 |
ImageNet-21K pre-training (values from the text only; the plot in fig. 4 was not read): MambaVision-B rises from 84.2% to 84.9% at 224; L rises from 85.0% to 86.1% at 224; L3 (739.6M params) reaches 87.3% at 256 and 88.1% at 512 §5.3.
Object detection and instance segmentation, MS COCO tab. 2
Cascade Mask R-CNN, 3× schedule, crop 1280×800 tab. 2.
| Backbone | Params (M) | FLOPs (G) | AP box | AP50 box | AP75 box | AP mask | AP50 mask | AP75 mask |
|---|---|---|---|---|---|---|---|---|
| DeiT-Small/16 | 80 | 889 | 48.0 | 67.2 | 51.7 | 41.4 | 64.2 | 44.3 |
| ResNet-50 | 82 | 739 | 46.3 | 64.3 | 50.5 | 40.1 | 61.7 | 43.4 |
| Swin-T | 86 | 745 | 50.4 | 69.2 | 54.7 | 43.7 | 66.6 | 47.3 |
| ConvNeXt-T | 86 | 741 | 50.4 | 69.1 | 54.8 | 43.7 | 66.5 | 47.3 |
| MambaVision-T | 86 | 740 | 51.1 | 70.0 | 55.6 | 44.3 | 67.3 | 47.9 |
| X101-32 | 101 | 819 | 48.1 | 66.5 | 52.4 | 41.6 | 63.9 | 45.2 |
| Swin-S | 107 | 838 | 51.9 | 70.7 | 56.3 | 45.0 | 68.2 | 48.8 |
| ConvNeXt-S | 108 | 827 | 51.9 | 70.8 | 56.5 | 45.0 | 68.4 | 49.1 |
| MambaVision-S | 108 | 828 | 52.3 | 71.1 | 56.7 | 45.2 | 68.5 | 48.9 |
| X101-64 | 140 | 972 | 48.3 | 66.4 | 52.3 | 41.7 | 64.0 | 45.1 |
| Swin-B | 145 | 982 | 51.9 | 70.5 | 56.4 | 45.0 | 68.1 | 48.9 |
| ConvNeXt-B | 146 | 964 | 52.7 | 71.3 | 57.2 | 45.6 | 68.9 | 49.5 |
| MambaVision-B | 145 | 964 | 52.8 | 71.3 | 57.2 | 45.7 | 68.7 | 49.4 |
Semantic segmentation, ADE20K tab. 3
UperNet, crop 512×512 tab. 3.
| Backbone | Params (M) | FLOPs (G) | mIoU |
|---|---|---|---|
| DeiT-Small/16 | 52 | 1099 | 44.0 |
| Swin-T | 60 | 945 | 44.5 |
| ResNet-101 | 86 | 1029 | 44.9 |
| Focal-T | 62 | 998 | 45.8 |
| MambaVision-T | 55 | 945 | 46.0 |
| Swin-S | 81 | 1038 | 47.6 |
| Twins-SVT-B | 89 | - | 47.7 |
| Focal-S | 85 | 1130 | 48.0 |
| MambaVision-S | 84 | 1135 | 48.2 |
| Swin-B | 121 | 1188 | 48.1 |
| Twins-SVT-L | 133 | - | 48.8 |
| Focal-B | 126 | 1354 | 49.0 |
| MambaVision-B | 126 | 1342 | 49.1 |
Ablations
Token mixer design tab. 4. Setup: MambaVision-T layout; COCO with Mask R-CNN and 1× schedule tab. 4 §5.3.
| Mixer | ImageNet top-1 | COCO AP box | COCO AP mask | ADE20K mIoU |
|---|---|---|---|---|
| causal conv1, no conv2 | 80.5 | 44.8 | 40.4 | 44.2 |
| conv1, no conv2 | 80.9 | 45.0 | 40.8 | 44.7 |
| conv1, conv2, no concat (gated) | 81.3 | 45.3 | 41.0 | 45.7 |
| conv1, conv2, concat (final) | 82.3 | 46.4 | 41.8 | 46.0 |
Hybrid integration pattern tab. 5. S = self-attention, M = MambaVision mixer. All variants have 31.8M params tab. 5.
| Pattern | Layers | ImageNet top-1 |
|---|---|---|
| Random | - | 81.3 |
| First N/2 | SSSSMMMM | 81.5 |
| Mixed-1 | SMSMSMSM | 81.4 |
| Mixed-2 | MSMSMSMS | 81.6 |
| Last N/4 | MMMMMMSS | 81.9 |
| Last N/2 | MMMMSSSS | 82.3 |
Window size tab. S.1 app. A. MambaVision-T, classification, COCO and throughput.
| Window (stage 3, stage 4) | Throughput (img/s) | ImageNet top-1 | COCO AP box | COCO AP mask |
|---|---|---|---|---|
| 7, 7 | 6318 | 82.2 | 46.4 | 41.7 |
| 14, 7 (default) | 6298 | 82.3 | 46.4 | 41.8 |
Paper vs code
Official code: https://github.com/NVlabs/MambaVision, linked from the abstract. Read at commit 7860a506b2eb844eaaae676f08461ce8c3c26f43.
The repository is under the NVIDIA Source Code License-NC, which excludes
commercial use LICENSE. The pretrained weights are CC BY-NC-SA 4.0
README.md. This card cites the code by path and line only. It quotes
no code and uses no weights.
Differences found by comparing the paper's text, tables and appendix with the code:
- Stem. Text: two stride-2 3×3 convolutions §3.1. Code: the same mamba_vision.py. Table tab. S.2 gives the second convolution no stride and lists the stem at 112×112. Follow the text and code.
- Stage widths and block counts in tab. S.2. The table's widths are twice the code's widths for every variant. For T, the table lists 160, 320, 640, 1280 channels, and the code uses 80, 160, 320, 640 mamba_vision.py. Each table row pairs a stage's blocks with the downsampling convolution that feeds it. The code's stage at 56×56 is at width 80, stage at 28×28 at 160, and so on.
- Last-stage block counts. For T, tab. S.2 lists 4 MambaVision + 4 self-attention blocks in the last stage. The code's depth there is 4, and its rule gives 2 + 2 mamba_vision.py. For S (depth 5) and B (depth 5), the table lists 6 blocks tab. S.2; the code has 5. The parameter count in tab. 1 (31.8M for T) can settle which is intended, by instantiating the constructor and counting. Not done here.
- Activation. Paper eq. 1 writes GELU. The code uses the tanh approximation mamba_vision.py.
- Mixer convolution. The paper says "regular convolution" §3.2.2. The code uses depthwise 1D convolution (groups equal the channel count) with kernel 3 mamba_vision.py mamba_vision.py.
- Δ activation and bias. The paper's equations do not show a softplus or a learned Δ bias. The code applies softplus to Δ and adds the dt projection bias mamba_vision.py.
- Windowing of the Mamba blocks. The paper describes windowed attention §3.2.2. The code windows every block of stages 3 and 4, including the Mamba mixers, so the SSM scan runs within each window mamba_vision.py.
- Algorithm 1. The listing uses
self.d_model,dt_min,dt_max,Dandn -> d nwithout defining them, and omits the softplus and dt bias. The code mamba_vision.py is the reference. - Attention scale. The appendix says d_h is the number of heads app. A. The code scales by the per-head dimension mamba_vision.py.
- ImageNet recipe. Paper: 300 epochs, LR 4e-3 app. C. Tiny config: 310 epochs, LR 0.005 mambavision_tiny_1k.yaml mambavision_tiny_1k.yaml. The example script uses LR 5e-4 and batch 256 with 8 GPUs train.sh; it is an example, not the recipe. The Base config also has 310 epochs and LR 0.005 mambavision_base_1k.yaml mambavision_base_1k.yaml.
- Training additions not in the paper. Distillation against an EMA teacher, weight 0.5, from 25% of training mambavision_tiny_1k.yaml train.py. EMA decay 0.9998 mambavision_tiny_1k.yaml. Mixup, CutMix, RandAugment and random erasing also appear there and are not in the paper.
- Crop. Training script default crop 0.875 train.py; Tiny config 1.0 mambavision_tiny_1k.yaml. Not stated in the paper.
- Drop path. The Tiny config has
drop_path: nullmambavision_tiny_1k.yaml, and the script's default isNonetrain.py. The model function defaults to 0.2 only if the key is absent mamba_vision.py. Set the value explicitly. - Segmentation. The paper says 8 A100 GPUs §4. The config is trained on 16 GPUs with one image per GPU mamba_vision_160k_ade20k-512x512_tiny.py.
- Detection batch. The paper says batch 16 app. C. The base dataset config uses 2 per GPU [code: object_detection/configs/base/datasets/coco_instance.py#L38]. The GPU count is not stated.
- Window sizes per task. Classification uses 14/7 for stages 3/4 mamba_vision.py. Detection uses 112/56 cascade_mask_rcnn_mamba_vision_tiny_3x_coco.py. Segmentation uses 64/32 mamba_vision_160k_ade20k-512x512_tiny.py. The paper gives window sizes only for classification.
- Dependency. The code calls
selective_scan_fnfrom the externalmamba_ssmpackage mamba_vision.py. The scan is not implemented in this repository. Pure-PyTorch scans are not provided here.
Text claims that disagree with the paper's own tables:
- Ablation text: causal-conv baseline ADE20K mIoU "44.2% (−1.4)" app. A. Table 4 shows 44.2 against 46.0, a gap of −1.8 tab. 4.
- Ablation text: baseline mask AP "40.2 (−1.6)" §5.3. Table 4 says 40.4 tab. 4.
- Ablation text: concatenation gives "+0.9 in mIoU" §5.3. Table 4 gives 46.0 against 45.7, a gain of +0.3 tab. 4.
- Text: MambaVision-B has "56% less GFLOPs than MaxViT-B" §5.1. Table 1 gives 15.0 against 23.4 G, a reduction of about 36%.
- Text: Swin-B 83.5% top-1 §5.1 does not appear in tab. 1.
No discrepancy was found in the detection and segmentation mIoU/AP values versus the text §5.2.
Pitfalls
- Global attention and scan at 224 input. Stages 3 and 4 are 14×14 and 7×7 at 224 input, and their windows are 14 and 7 mamba_vision.py. Each stage is one window, so attention and the SSM scan see the whole map. This follows from the code and window partitioning mamba_vision.py. Window size matters only at other resolutions.
- Padding is not masked. When a feature map is not a multiple of the window size, zeros are added mamba_vision.py. Attention is called without a mask mamba_vision.py, and the SSM scan runs over the padded tokens. Padded positions influence outputs. Detection with 1280×800 input, after downsampling, triggers this padding cascade_mask_rcnn_mamba_vision_tiny_3x_coco.py.
- Token order. Tokens inside a window are scanned in row-major order mamba_vision.py. The paper does not state the order.
- Convolution bias. The mixer's convolutions are built with
bias=conv_bias//2mamba_vision.py. Withconv_bias=Truethe expression is 0, so no bias is created. Adding a bias would deviate from the code. - Algorithm 1 is not a drop-in implementation. See Paper vs code, item 8.
- Mamba placement. The first N/2 layers of each of stages 3 and 4 use the
Mamba mixer and the last N/2 use attention §3.2.2 tab. 5. For odd depth
the rule is
range(depth//2+1, depth), so the extra layer goes to the Mamba side mamba_vision.py. - Throughput depends on the scan kernel. Throughput figures are measured on
an A100 at batch 128 tab. 1. The code uses the external
mamba_ssmCUDA kernel mamba_vision.py. Expect different numbers with another scan implementation. - Equation numbers. They were counted from the LaTeX source order. The compiled PDF was not read. Check them against the PDF.
- Figures. Figures are described in words only: fig. 1 is the Pareto plot of top-1 against throughput, fig. 2 the macro architecture, fig. 3 the MambaVision block, fig. 4 ImageNet-21K scaling, fig. 5 self-attention maps, and fig. S.1 attention visualisations §5.3 app. A.
- Licensing of the code. The code is NC. Reimplement from the paper and the parameter values on this card, citing paths for facts only.
Lineage
- Builds on Mamba: Gu and Dao, 2023, arXiv:2312.00752 §3.2.1 [bib gu2023mamba]. No card exists for it, so only its arXiv link is given.
- Related Mamba vision backbones compared in the tables: VMamba (Liu et al., arXiv:2401.10166) §2 tab. 1; Vim (Zhu et al.) §2 tab. 1; EfficientVMamba §2 tab. 1; SiMBA §2 tab. 1.
- Transformer and convolutional baselines: Swin Transformer §2, ConvNeXt §2, NextViT §2, FasterViT §2, MaxViT tab. 1. None has a card here.
- Superseded by: not known from this wiki's content.
Source and license
Adapted from “MambaVision: A Hybrid Mamba-Transformer Vision Backbone” by Ali Hatamizadeh, Jan Kautz (arXiv:2407.08083), used under CC BY-SA 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. This page is licensed under CC BY-SA 4.0. Code citations refer to https://github.com/NVlabs/MambaVision at commit 7860a506b2eb (NVIDIA Source Code License-NC (non-commercial)). Any quoted code is shown under that license.