Abstract
State Space Models (SSMs) like Mamba have emerged as efficient, linear-time alternatives to Transformers for sequence modeling. However, their inherent causality limits their performance on bidirectional tasks such as language understanding and computer vision. This paper introduces Hydra, a novel sequence model that generalizes SSMs to bidirectional contexts. By framing sequence models as "Matrix Mixers," we identify Sequence Alignment (SAM) as a critical property for model success. We demonstrate that while causal SSMs correspond to semiseparable matrices, bidirectional models are naturally represented by quasiseparable matrices. Hydra implements this principled approach, outperforming BERT and Vision Transformers (ViT) while maintaining linear-time complexity and superior parameter efficiency.
Introduction
The Transformer architecture, powered by Attention, has set the standard for modern AI. However, its $O(L^2)$ computational complexity poses significant challenges for long-sequence processing. Structured State Space Models (SSMs) offer a linear-time $O(L)$ alternative but are primarily designed for causal, autoregressive tasks. Previous attempts to adapt SSMs for bidirectional tasks—where the model must process the entire context simultaneously—have largely relied on heuristic "add-and-sum" approaches that lack theoretical grounding.
The Matrix Mixer Framework
We propose a unifying Matrix Mixer Framework, viewing sequence models as linear maps where an input sequence $X$ is transformed by a structured mixer matrix $M$. This perspective allows us to categorize models based on the mathematical properties of $M$, moving beyond simple low-rank or sparse approximations.
A key finding is the importance of Sequence Alignment (SAM). SAM ensures that the parameters of the mixer matrix are tied to specific sequence elements, enabling data-dependence and the ability to handle sequences longer than those seen during training. Our analysis shows that data-dependent, aligned models consistently outperform data-independent alternatives like MLP-Mixer or FNet.
Hydra: Principled Bidirectionality
Standard causal SSMs are represented by semiseparable matrices, which are lower-triangular. To achieve principled bidirectionality, we identify quasiseparable matrices as the natural generalization. Unlike "ad-hoc" bidirectional SSMs that simply sum forward and backward passes, Hydra parameterizes the sequence mixer as a true quasiseparable matrix.
Hydra combines forward and backward SSM components with a diagonal residual term using specific shift and flip operations. This structure is more expressive than previous bidirectional SSMs and significantly more parameter-efficient because it allows for shared projection layers across the sequence mixing block.
Experimental Evaluation
Hydra was evaluated across natural language processing and computer vision benchmarks to test its bidirectional capabilities:
- Natural Language Processing (GLUE): Pretrained on the C4 corpus, Hydra achieved an average score of 84.3, surpassing BERT-Base (83.5) by 0.8 points. It also significantly outperformed other efficient models like MLP-Mixer and FNet.
- Computer Vision (ImageNet-1K): When used as a drop-in replacement for Attention in a Vision Transformer (ViT) architecture, Hydra reached 81.0% Top-1 accuracy, a 2.2% improvement over the standard ViT-Base (78.8%).
In these settings, Hydra maintains the $O(L)$ efficiency of SSMs while providing a theoretically sound foundation for bidirectional modeling that is nearly twice as parameter-efficient as naive bidirectional implementations.
Discussion and Future Work
While Hydra offers significant efficiency gains, structured matrices may be less expressive than dense Softmax Attention for tasks requiring perfect memorization of extremely long sequences. Additionally, current hardware optimizations for "selective scans" lag behind the highly tuned matrix multiplication kernels used by Transformers. Future research will focus on further optimizing hardware kernels for quasiseparable operations and exploring even more complex matrix structures within the Matrix Mixer Framework to push the boundaries of efficient sequence modeling.
Summary updated