A 2-Dimensional State Space Layer for Spatial Inductive Bias

Ethan Baron, Itamar Zimerman, Lior WolfICLR 2024

Introduction

Researchers have developed a novel 2D State Space Model (SSM) layer designed to inject a powerful spatial "inductive bias" into computer vision models. By extending control-theory-based 1D SSMs into two dimensions, this layer allows Vision Transformers (ViTs) and Convolutional Neural Networks (CNNs) to capture both local and global dependencies more effectively. The result is a significant performance gain with almost zero parameter overhead, yielding models robust enough to function even without traditional positional encodings.

The Inductive Bias Dilemma

In computer vision, "inductive bias" refers to the prior knowledge baked into a model about how images are structured—specifically, that nearby pixels are highly correlated and that visual patterns are often translation-invariant.

Historically, architectures have fallen into two extremes:

  1. CNNs: Possess a strong 2D bias via local convolutional kernels. However, their fixed-size filters struggle to capture long-range, global dependencies without stacking an excessive number of layers.
  2. Vision Transformers (ViTs): Offer extreme flexibility and excel at global context but suffer from a "weak" inductive bias. They treat images as flattened sequences of patches and rely heavily on 1D positional encodings to understand spatial relationships.

While 1D State Space Models (like S4 or Mamba) have revolutionized sequence modeling by efficiently capturing long-range dependencies, extending them to 2D has proven difficult. Previous attempts, such as S4ND, simply ran 1D models across rows and columns independently. This paper introduces a "true" 2D SSM that models horizontal and vertical dependencies simultaneously.

Methodology: The 2D-SSM Layer

The authors base their 2D-SSM layer on Roesser’s model for multidimensional state spaces, a foundational concept from 1970s control theory.

Overview of the 2D-SSM layer, illustrating its dual recurrent/convolutional nature, spatial context capabilities, and drop-in architecture for ViTs and CNNs.

Key technical innovations include:

  • True 2D Recurrence: Unlike previous methods that factorize 2D data into two separate 1D passes, this model uses a system of four matrices ($A_1$ through $A_4$). This allows information to flow diagonally and across both axes within a single, unified framework.
  • Efficient Parameterization: To make the mathematics computationally tractable, the system matrices are diagonalized. This reduces computational complexity from exponential to linear relative to the state dimension.
  • Stability Mechanisms: The authors introduce a "divide-by-two" normalization and a "kernel relaxation" scheme. These prevent the 2D kernels from exploding or becoming overly biased toward the diagonal during training.
  • FFT-based Computation: During training, the 2D recurrence is unrolled into a massive 2D convolutional kernel. This enables the use of Fast Fourier Transforms (FFT) to perform operations in the frequency domain, dramatically accelerating computation for large kernels compared to standard 2D convolutions.

Key Insights and Capabilities

  • Generalization of S4ND: The authors mathematically prove that their 2D-SSM is a strict generalization of S4ND. While S4ND can only express kernels of "rank 1," the 2D-SSM can express full-rank kernels, making it significantly more expressive.
  • Inherent Position Awareness: Because the layer is built on spatial recurrence, it inherently "knows" its location within the 2D grid. This is a unique property that standard convolutions or self-attention layers lack. Strikingly, ViTs equipped with the 2D-SSM maintain high accuracy even when explicit positional encodings are entirely removed.
  • The "Drop-In Booster" Effect: The layer is designed for seamless integration. It can be placed at the start of a Transformer block or used to replace the $7 \times 7$ filters in a ConvNeXt block, acting as a universal performance booster with negligible computational cost.

Empirical Results

The model was rigorously evaluated across diverse benchmarks, including ImageNet-1K, CIFAR-100, Celeb-A, and the Long Range Arena (LRA).

  • Transformer Enhancements: Adding the layer to a DeiT-Tiny model improved ImageNet-100 accuracy from 78.21% to 81.16% (+2.95%). On Swin-T, accuracy was boosted from 81.06% to 82.29%.
  • CNN Improvements: Replacing standard convolutions in ConvNeXt-Nano with the 2D-SSM improved CIFAR-100 accuracy from 79.10% to 80.16%.
  • State-of-the-Art Long-Range Modeling: On the LRA CIFAR-10 Grayscale task, the MEGA 2D-SSM variant achieved 91.31%, outperforming specialized models like Hyena and S4ND.
  • Efficiency: The 2D-SSM layer accounts for only about 20.5% of the inference latency in a single ViT block but scales much better than self-attention. As image resolution increases, the memory usage of the 2D-SSM grows linearly, whereas self-attention grows quadratically.

Limitations and Future Directions

While inference is highly efficient, the current training implementation is relatively slow because it does not yet utilize multi-dimensional parallel scanners—a primary target for future optimization. Additionally, the current "divide-by-two" normalization, while effective, may not be optimal. Future work will explore more sophisticated normalization schemes tailored to 2D recurrence and expand testing beyond classification to complex spatial tasks like object detection, segmentation, and image inpainting.

Summary updated

BibTeX
@inproceedings{baron2024dimensional,
  author = {Ethan Baron and Itamar Zimerman and Lior Wolf},
  title = {{A 2-Dimensional State Space Layer for Spatial Inductive Bias}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=BGkqypmGvm},
}
Figure