Mamba-ND: Selective State Space Modeling for Multi-Dimensional Data

Shufan Li, Harkanwar Singh, Aditya Grover

Abstract

In recent years, Transformers have become the de-facto architecture for sequence modeling on text and a variety of multi-dimensional data, such as images and video. However, the use of self-attention layers in a Transformer incurs prohibitive compute and memory complexity that scales quadratically w.r.t. the sequence length. A recent architecture, Mamba, based on state space models has been shown to achieve comparable performance for modeling text sequences, while scaling linearly with the sequence length. In this work, we present Mamba-ND, a generalized design extending the Mamba architecture to arbitrary multi-dimensional data. Our design alternatively unravels the input data across different dimensions following row-major orderings. We provide a systematic comparison of Mamba-ND with several other alternatives, based on prior multi-dimensional extensions such as Bi-directional LSTMs and S4ND. Empirically, we show that Mamba-ND demonstrates performance competitive with the state-of-the-art on a variety of multi-dimensional benchmarks, including ImageNet-1K classification, HMDB-51 action recognition, and ERA5 weather forecasting.

Introduction

The Transformer architecture has dominated deep learning for years, yet it faces a significant bottleneck: the self-attention mechanism. The computational complexity of self-attention scales quadratically ($O(L^2)$) with the sequence length ($L$), making the processing of high-resolution images or long video sequences prohibitively expensive.

Recently, State Space Models (SSMs) like Mamba have emerged as a compelling alternative, offering performance comparable to Transformers with linear scaling ($O(L$)). However, Mamba was originally designed for 1D sequences like text. Multi-dimensional data, such as 2D images or 3D videos, lacks a single "natural" order. Simply flattening an image into a 1D line breaks spatial context, as vertically adjacent pixels become distant in the sequence. Mamba-ND addresses this by finding an effective way to "unravel" multi-dimensional data for 1D SSM processing without losing its structural essence.

Methods

The core innovation of Mamba-ND is an "Alternating-Directional" design at the block level. Rather than modifying the underlying Mamba mathematics, the researchers focused on how data is scanned across layers.

Flattening via Scan Orderings

The design defines a "scan ordering" as a permutation of axes (e.g., width then height) and a direction (forward or backward). For 2D data, the model alternates between four orderings: Height+, Height-, Width+, and Width-. For 3D data, it adds Time+ and Time- to the sequence.

Architecture Design

Mamba-ND uses standard 1D Mamba layers as modular components. These layers are stacked, with the scan order changing for each successive layer. This approach was found to be superior to more complex designs, such as "Bi-SSM" (processing two directions in a single layer) or "Multi-head SSM" (parallel processing of different directions). The simplicity of alternating directions allows for greater model depth within the same parameter budget.

The Mamba-ND architecture showing the sequence of alternating directional blocks.

Key Insights

  • Depth Over Complexity: Simple alternating layers outperformed complex multi-directional layers. This suggests that "effective depth"—the number of sequential operations—is more critical than parallel operations within a single layer.
  • Global Receptive Field: Unlike Convolutional Neural Networks (CNNs), every layer in Mamba-ND possesses a global receptive field, allowing it to link distant pixels or frames theoretically.
  • Linear Scaling Advantage: Linear scaling allows Mamba-ND to handle smaller patch sizes (higher resolution) more efficiently than Transformers. On ImageNet, reducing patch size from 16 to 8 significantly improved accuracy without the memory explosion typical of Transformers.

Experimental Results

The authors validated Mamba-ND across diverse multi-dimensional tasks, including ImageNet-1K (2D), HMDB-51 (3D video), ERA5 (3D scientific data), and BTCV (3D medical segmentation).

Performance comparison of Mamba-ND vs. Transformers across various benchmarks.
  • Efficiency: On ImageNet-1K, Mamba-2D-S achieved 81.7% accuracy, outperforming ViT-B (77.9%) while using 72% fewer parameters.
  • Scientific and Medical Data: On the ERA5 weather dataset, Mamba-3D outperformed the Cli-ViT transformer while reducing parameters by 44.5%. For BTCV 3D segmentation, it achieved a superior DICE score than UNETR with 64% fewer parameters.
  • Video Recognition: On Kinetics-400, Mamba-3D reached 81.9% accuracy using only 44% of the parameters required by comparable Video Swin Transformers.

Conclusion and Future Work

Mamba-ND demonstrates that the efficiency of SSMs can be successfully extended to multi-dimensional domains. While the current work focuses on row-major orderings, future research could explore more complex scan patterns like space-filling curves. Additionally, developing hardware-optimized kernels for multi-dimensional scanning could further enhance the speed advantages of Mamba-ND over traditional Transformer architectures.

Summary updated

BibTeX
@inproceedings{li2024mamba,
  author = {Shufan Li and Harkanwar Singh and Aditya Grover},
  title = {{Mamba-ND: Selective State Space Modeling for Multi-Dimensional Data}},
  booktitle = {European Conference on Computer Vision},
  year = {2024},
  doi = {10.1007/978-3-031-73414-4\_5},
}
Figure