SF-Mamba: Rethinking State Space Model for Vision
Organizations: Sony Group Corporation, Tokyo, Japan.
Abstract
The realm of Mamba for vision has been advanced in recent years to strike for the alternatives of Vision Transformers (ViTs) that suffer from the quadratic complexity. While the recurrent scanning mechanism of Mamba offers computational efficiency, it inherently limits non-causal interactions between image patches. Prior works have attempted to address this limitation through various multi-scan strategies; however, these approaches suffer from inefficiencies due to suboptimal scan designs and frequent data rearrangement. Moreover, Mamba exhibits relatively slow computational speed under short token lengths, commonly used in visual tasks. In pursuit of a truly efficient vision encoder, we rethink the scan operation for vision and the computational efficiency of Mamba. To this end, we propose SF-Mamba, a novel visual Mamba with two key proposals: auxiliary patch swapping for encoding bidirectional information flow under an unidirectional scan and batch folding with periodic state reset for advanced GPU parallelism. Extensive experiments on image classification, object detection, and instance and semantic segmentation consistently demonstrate that our proposed SF-Mamba significantly outperforms state-of-the-art baselines while improving throughput across different model sizes. We will release the source code after publication.
Figures & tables
| Model | Mixer | Params | MACs | img/s | Acc. (%) |
|---|---|---|---|---|---|
| ConvNeXt-T | C | 29M | 4.5G | 3990 | 82.1 |
| MambaOut-T | C | 27M | 4.5G | 3031 | 82.7 |
| Swin-T | A | 29M | 4.5G | 2863 | 81.3 |
| Twins-S | A | 24M | 2.9G | 2669 | 81.7 |
| EfficientFormer-L3 | P+A | 31M | 3.9G | 3246 | 82.4 |
| FasterViT-0 | C+A | 31M | 3.3G | 5651 | 82.1 |
| impl. opt. | BFold | conv | img/s | |
|---|---|---|---|---|
| 6662 | ||||
| ✓ | 6989 | |||
| ✓ | ✓ | 1 | ✓ | 7601 |
| ✓ | ✓ | 4 | ✓ | 7641 |
| ✓ | ✓ | adaptive | 7279 | |
| ✓ | ✓ | adaptive | ✓ | 7685 |
| swap | aux. token | discard timing | IN1K | ADE20K | img/s |
|---|---|---|---|---|---|
| 82.2 | 46.0 | 7645 | |||
| learnable | before attn | 82.1 | 46.2 | 7613 | |
| ✓ | learnable | before attn | 82.3 | 46.5 | 7585 |
| ✓ | data-dependent | before attn | 82.4 | 46.8 | 7602 |
| ✓ | data-dependent | after 1st attn | 82.5 | 47.2 | 7600 |
| ✓ | data-dependent | after attn | 82.4 | 46.6 | 7597 |
| macro-arch. | MambaVision-T | MambaVision-T w/o Attention | ||||||
|---|---|---|---|---|---|---|---|---|
| scan | Params | MACs | img/s | acc. | Params | MACs | img/s | acc. |
| uni-scan | 31.8M | 4.4G | 6979 | 82.2 | 29.4M | 4.2G | 6238 | 80.2 |
| series bi-scan | 31.8M | 4.4G | 6911 | 82.3 | 29.4M | 4.2G | 6113 | 80.4 |
| series bi-scan+gap token (Adventurer) | 31.8M | 4.5G | 6856 | 82.3 | 29.4M | 4.3G | 6027 | 80.7 |
| parallel bi-scan (cat) | 31.8M | 4.4G | 6834 | 82.2 | 29.4M | 4.2G | 5987 | 80.8 |
| parallel bi-scan (add) | 31.9M | 4.5G | 6235 | 82.3 | 29.7M | 4.3G | 5138 | 81.1 |
Appendix figures & tables14 assets
Supplementary material from the paper’s appendix.
Appendix
| Configuration | SF-Mamba-T | SF-Mamba-S | SF-Mamba-B |
|---|---|---|---|
| Optimizer | LAMB ( You et al., 2019 ) | LAMB | LAMB |
| Base learning rate | 5e-3 | 5e-3 | 5e-3 |
| Learning rate schedule | Cosine | Cosine | Cosine |
| Warmup epochs | 20 | 20 | 35 |
| Warmup learning rate | 1e-6 | 1e-6 | 1e-6 |
| Minimum learning rate | 5e-6 | 5e-6 | 5e-6 |
| Tiny-size | Small-size | Base-size | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Backbone | Para | FLOPs | mIoU | fps | Para | FLOPs | mIoU | fps | Para | FLOPs | mIoU | fps |
| Swin | 60M | 945G | 44.5 | 40.0 | 81M | 1038G | 47.6 | 25.7 | 121M | 1188G | 48.1 | 25.4 |
| Focal | 62M | 998G | 45.8 | 38.9 | 85M | 1130G | 48.0 | 24.0 | 126M | 1354G | 49.0 | 23.4 |
| MambaVision | 62M | 1085G | 46.0 | 45.0 | 81M | 1166G | 48.2 | 40.9 | 130M | 1520G | 49.1 | 37.3 |
| SF-Mamba | 62M | 1085G | 47.2 | 47.9 | 81M | 1166G | 48.5 | 45.4 | 130M | 1520G | 50.1 | 42.6 |
| SF-Mamba | 62M | 950G | 46.5 | 48.7 | 81M | 1014G | 48.1 | 47.3 | 130M | 1180G | 49.1 | 42.7 |
| Backbone | Params | FLOPs | fps | AP b | AP | AP | AP m | AP | AP |
|---|---|---|---|---|---|---|---|---|---|
| Swin-T | 86M | 745G | 26.3 | 50.4 | 69.2 | 54.7 | 43.7 | 66.6 | 47.3 |
| ConvNeXt-T | 86M | 741G | 32.1 | 50.4 | 69.1 | 54.8 | 43.7 | 66.5 | 47.3 |
| MambaVision-T | 89M | 1118G | 19.4 | 51.1 | 70.0 | 55.6 | 44.3 | 67.3 | 47.9 |
| SF-Mamba-T | 89M | 741G | 27.8 | 51.0 | 69.9 | 55.3 | 44.2 | 67.1 | 48.0 |
| SF-Mamba -T | 89M | 659G | 28.3 | 50.9 | 69.9 | 55.0 | 44.1 | 66.9 | 47.7 |
| Swin-S | 107M | 838G | 18.7 | 51.9 | 70.7 | 56.3 | 45.0 | 68.2 | 48.8 |
| Backbone | AP box | fps |
|---|---|---|
| RegNetX-3.2GF | 39.9 | 31.6 |
| MambaVision-T | 42.4 | 37.2 |
| SF-Mamba-T | 43.2 | 41.7 |
| MambaVision-S | 43.9 | 37.2 |
| SF-Mamba-S | 44.9 | 40.8 |
| MambaVision-B | 46.2 | 30.0 |
| Backbone | AP | AP | FPS |
|---|---|---|---|
| VMamba-T | 47.3 | 42.7 | 29.9 |
| MambaVision-T | 43.1 | 40.0 | 35.5 |
| SF-Mamba-T | 43.8 | 40.3 | 40.9 |
| VMamba-S | 48.7 | 43.7 | 23.3 |
| MambaVision-S | 44.4 | 41.0 | 33.4 |
| SF-Mamba-S | 45.3 | 41.5 | 41.0 |
| number of window | ADE20K | COCO | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| arch. | w/o pad | A3 | A4 | M3 | M4 | FLOPs | mIoU | FLOPs | mAP b | mAP m |
| w/o swap | 1085G | 46.0 | 1118G | 50.9 | 44.1 | |||||
| w/ swap | 1085G | 47.2 | 1118G | 51.2 | 44.5 | |||||
| w/ swap | ✓ | 950G | 45.8 | 741G | 51.0 | 44.2 | ||||
| w/ swap | 4 | 950G | 46.2 | 741G | 50.9 | 44.0 | ||||
| w/ swap | ✓ | 4 | 942G | 45.6 | 736G | 50.9 | 44.0 | |||
| size | scan | Params | MACs | img/s | acc. |
|---|---|---|---|---|---|
| S | parallel-bi scan (Vim) | 26M | 5.3G | 1079 | 80.3 |
| S | uni-scan | 26M | 4.9G | 1639 | 79.3 |
| S | uni-scan + swap (ours) | 26M | 5.0G | 1614 | 80.1 |
| S | uni-scan + swap (ours) + Bfold (ours) | 26M | 5.0G | 2022 | 80.1 |
| T | parallel-bi scan (Vim) | 7M | 1.5G | 2094 | 76.3 |
| Model (batch size) | 224 | 448 | 896 | 1792 | 3584 |
|---|---|---|---|---|---|
| VMamba-T (bs=32) | 1384 | 402 | 107 | 5 | OOM |
| FasterViT-0 (bs=32) | 1415 | 1400 | 418 | 99 | OOM |
| MambaVision-T (bs=32) | 3770 | 1578 | 324 | 50 | 5 |
| SF-Mamba-T (bs=32) | 3962 | 1777 | 397 | 61 | 6 |
| SF-Mamba -T (bs=32) | - | - | 427 | 105 | 27 |
| VMamba-T (bs=1) | 62 | 62 | 62 | 24 | 5 |
| Arch. | 1 | 32 | 128 | 256 | 512 | 1024 |
|---|---|---|---|---|---|---|
| MambaVision-T | 119 | 3770 | 6662 | 7025 | 7134 | 7271 |
| ours-T | 126 | 3962 | 7600 | 7801 | 8009 | 8190 |
| MambaVision-B | 96 | 2798 | 2974 | 3128 | 3176 | 3206 |
| ours-B | 98 | 3168 | 3534 | 3592 | 3641 | 3685 |
| Arch. | Params | img/s | acc. |
|---|---|---|---|
| Attention only | 34.2M | 7803 | 82.3% |
| SSM only | 29.4M | 6238 | 80.2% |
| SSM only (w/ our Bfold and swap) | 29.4M | 7306 | 81.0% |
| Hybrid | 31.8M | 6979 | 82.2% |
| Hybrid (w/ our Bfold and swap) | 31.8M | 7600 | 82.5% |
Visual SSMs
Visual state-space models use recurrent sequence dynamics to process images and video while aiming for efficient, long-range context modeling.
See all 79 papers