Introduction
Vision Transformers (ViTs) have fundamentally changed the landscape of computer vision. However, they possess an inherent limitation: "spatial blindness." Unlike Convolutional Neural Networks (CNNs), which utilize a 2D inductive bias to understand local pixel relationships, standard ViTs treat images as 1D sequences of patches. While positional encodings are typically used to mitigate this, they often provide only a weak bias. Conversely, while CNNs excel at local spatial awareness, they often struggle to capture long-range dependencies efficiently.
Researchers from Tel Aviv University have introduced the 2D-SSM layer, a novel spatial module designed to bridge this gap. By building on multidimensional State Space Models (SSMs), the 2D-SSM layer provides ViTs with a strong 2D inductive bias—position awareness and locality—without sacrificing the global context and parameter efficiency characteristic of SSMs.
The 2D-SSM Layer
The core of this work is the adaptation of Roesser’s model for multidimensional state spaces into a practical neural network layer.
Technical Formulation
The 2D-SSM layer moves beyond simple 1D SSMs applied independently to rows and columns. Instead, it utilizes a coupled system of horizontal ($x^h$) and vertical ($x^v$) states that interact at every patch location. To ensure computational efficiency and numerical stability, the authors implemented several key innovations:
- Diagonalization & Normalization: System matrices are diagonalized, and a "divide by two" normalization scheme is employed to prevent convolutional kernels from exploding as they scale.
- Dual Views: The layer can be viewed as a 2D linear recurrence for inference or as a large 2D global convolutional kernel for training. The convolutional implementation leverages Fast Fourier Transforms (FFTs) for high-speed processing.
- Architectural Integration: The layer is designed as a "drop-in booster," typically placed at the start of a Transformer block to act as a spatial pre-processor for the self-attention mechanism.
Experimental Evaluation
The 2D-SSM was rigorously tested across diverse benchmarks:
- Image Classification: On CIFAR-100 and Tiny-ImageNet, integrating 2D-SSM into a Swin Transformer led to accuracy gains of 3.25% and 4.25%, respectively.
- Long-Range Dependencies: In the Long Range Arena (LRA) Image task, the "MEGA 2D-SSM" model achieved a state-of-the-art accuracy of 91.31%, outperforming other advanced architectures like Hyena and S4ND.
- Attribute Classification: On the Celeb-A dataset, the complex-valued version of the layer consistently outperformed real-valued baselines, providing a 1.41% boost over DeiT-Tiny.
Key Insights
Expressiveness and Full-Rank Kernels
A major theoretical contribution is the proof that 2D-SSM can express full-rank kernels. This distinguishes it from previous multidimensional SSMs like S4ND, which are restricted to rank-1 kernels (the outer product of two 1D kernels). This increased expressiveness allows the model to learn far more complex spatial patterns.
Replacing Positional Encodings
Perhaps the most significant finding is the layer's ability to render traditional positional encodings redundant. In ablation studies, removing positional encodings from a standard ViT caused accuracy to drop by nearly 7%. In contrast, a ViT equipped with 2D-SSM layers saw a negligible drop of less than 0.1%, indicating that the layer inherently encodes spatial structure.
Controllable Spatial Context
The parameters of the SSM allow the model to dynamically adjust its receptive field. It can focus on horizontal, vertical, or diagonal dependencies depending on the specific requirements of the task.
Conclusion and Future Directions
The 2D-SSM layer represents a significant step forward in making Vision Transformers more spatially aware. It adds minimal parameter overhead (often <1%) and maintains efficient inference. While training times currently lag behind standard convolutions, the authors suggest that future implementations using multi-dimensional parallel scanners could bridge this gap. Beyond classification, the 2D-SSM holds promise for more complex vision tasks such as object detection and segmentation, where precise spatial reasoning is paramount.
Summary updated