Papers
Topics
Authors
Recent
Search
2000 character limit reached

Mamba: Linear-Time Sequence Modeling with Selective State Spaces

Published 1 Dec 2023 in cs.LG and cs.AI | (2312.00752v2)

Abstract: Foundation models, now powering most of the exciting applications in deep learning, are almost universally based on the Transformer architecture and its core attention module. Many subquadratic-time architectures such as linear attention, gated convolution and recurrent models, and structured state space models (SSMs) have been developed to address Transformers' computational inefficiency on long sequences, but they have not performed as well as attention on important modalities such as language. We identify that a key weakness of such models is their inability to perform content-based reasoning, and make several improvements. First, simply letting the SSM parameters be functions of the input addresses their weakness with discrete modalities, allowing the model to selectively propagate or forget information along the sequence length dimension depending on the current token. Second, even though this change prevents the use of efficient convolutions, we design a hardware-aware parallel algorithm in recurrent mode. We integrate these selective SSMs into a simplified end-to-end neural network architecture without attention or even MLP blocks (Mamba). Mamba enjoys fast inference (5×\times higher throughput than Transformers) and linear scaling in sequence length, and its performance improves on real data up to million-length sequences. As a general sequence model backbone, Mamba achieves state-of-the-art performance across several modalities such as language, audio, and genomics. On language modeling, our Mamba-3B model outperforms Transformers of the same size and matches Transformers twice its size, both in pretraining and downstream evaluation.

Authors (2)
Citations (1,577)

Summary

  • The paper introduces an input-dependent selection mechanism that transforms static state space models into dynamic ones, enabling linear scaling and Transformer-level accuracy.
  • It presents a hardware-aware parallel algorithm, Selective Scan, which efficiently computes recurrent states without relying on attention mechanisms or standard MLP blocks.
  • Empirical evaluations show Mamba’s superiority across language modeling, audio, and genomics tasks, including perfect generalization on million-length sequences.

The paper introduces Mamba, a novel sequence modeling architecture based on selective state space models (SSMs) that aims to address the limitations of Transformers in terms of computational efficiency and long-range dependency modeling. The core innovation lies in incorporating an input-dependent selection mechanism into structured SSMs, enabling the model to selectively attend to or filter out information along the sequence dimension. This selectivity allows Mamba to achieve Transformer-level performance while maintaining linear scaling in sequence length.

The authors identify the inability to perform content-based reasoning as a key weakness in existing subquadratic-time architectures, such as linear attention, gated convolution, recurrent models, and structured SSMs. To address this, they propose parameterizing the SSM parameters as functions of the input, enabling the model to selectively propagate or forget information based on the current token. While this modification prevents the use of efficient convolutions, the authors design a hardware-aware parallel algorithm in recurrent mode to maintain computational efficiency.

The resulting Mamba architecture integrates these selective SSMs into a simplified end-to-end neural network design, eliminating the need for attention mechanisms or even MLP blocks. This streamlined architecture offers several advantages:

  • Fast inference: Mamba achieves a 5x higher throughput compared to Transformers.
  • Linear scaling: Computation and memory scale linearly with sequence length.
  • Long context: Performance improves on real data with sequences up to million-length.

The authors validate Mamba's effectiveness across various modalities and settings:

  • Synthetic tasks: Mamba excels at tasks such as selective copying and induction heads, demonstrating its ability to extrapolate solutions indefinitely. On the Selective Copying task, S6-based models achieved >97% accuracy, while baseline LTI models struggled (18.3% accuracy for S4 without gating). On the Induction Heads task, Mamba was able to generalize perfectly to million-length sequences, 4000x longer than its training sequence length.
  • Audio and genomics: Mamba outperforms state-of-the-art models like SaShiMi, Hyena, and Transformers in modeling audio waveforms and DNA sequences, achieving significant improvements in downstream metrics such as FID.
  • Language modeling: Mamba achieves Transformer-quality performance in language modeling tasks, with the Mamba-3B model outperforming Transformers of the same size and matching Transformers twice its size in both pretraining and downstream evaluation. Mamba-3B quality matches Transformers twice its size, such as a 4-point increase on average on common sense reasoning when compared to Pythia-3B and outperforming Pythia-7B.

The paper provides a detailed explanation of structured state space models (S4) and their relation to RNNs, CNNs, and classical state space models. S4 models are defined by four parameters (A,A,B,C)(A, A, B, C), which define a sequence-to-sequence transformation. The "continuous parameters" (A,A,B)(A, A, B) are transformed to "discrete parameters" (A,B)(A, B) through fixed formulas using a discretization rule. The model can then be computed as a linear recurrence or a global convolution.

A key contribution of the paper is the introduction of a selection mechanism that addresses the limitations of LTI models. By making the SSM parameters input-dependent, the model can selectively filter out irrelevant information and remember relevant information indefinitely. This is achieved by parameterizing A,B,A, B, and CC as functions of the input, resulting in time-varying SSMs. The authors specifically choose SB(x)=LinearN(x)S_B(x) = \text{Linear}_N(x), SC(x)=LinearN(x)S_C(x) = \text{Linear}_N(x), SA(x)=BroadcastD(Linear1(x))S_A(x) = \text{Broadcast}_D(\text{Linear}_1(x)), and tA=softplust_A = \text{softplus}.

To address the computational challenges posed by time-varying SSMs, the authors develop a hardware-aware algorithm called Selective Scan that computes the model recurrently using a scan instead of convolution. This algorithm leverages kernel fusion, parallel scan, and recomputation techniques to optimize performance on modern GPUs. The fused selective scan layer has the same memory requirements as an optimized Transformer implementation with FlashAttention.

The paper also presents a simplified SSM architecture called Mamba, which combines the design of prior SSM architectures with the MLP block of Transformers into a single block. This architecture involves expanding the model dimension DD by a controllable expansion factor (A,A,B)(A, A, B)0.

The authors discuss the connection between the selection mechanism and classical gating mechanisms in RNNs, highlighting that RNN gating is an instance of the selection mechanism for SSMs.

The paper includes an extensive empirical evaluation of Mamba on various tasks. On language modeling, Mamba achieves state-of-the-art performance, matching the performance of strong Transformer models while scaling linearly in sequence length. The authors also demonstrate Mamba's effectiveness on DNA modeling and audio generation tasks.

Additional ablations investigated the effects of the architecture and inner SSM layer. Among previous non-selective (LTI) SSMs, performance was similar. Replacing the complex-valued S4 variant with a real-valued one did not affect performance much. Replacing any of these with a selective SSM (S6) significantly improved performance. The Mamba architecture performed similarly to the H3 architecture.

The paper concludes by discussing related work, limitations, and future directions. The authors express excitement about the broad applications of selective state space models in building foundation models for different domains, particularly in emerging modalities requiring long context.

Whiteboard

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Tweets

Sign up for free to view the 132 tweets with 5746 likes about this paper.

YouTube

Mamba: Linear-Time Sequence Modeling with Selective State Spaces (Paper Explained) 179K views
Mamba Might Just Make LLMs 1000x Cheaper... 146K views
4 Reasons AI in 2024 is On An Exponential: Data, Mamba, and More 134K views
MAMBA and State Space Models explained | SSM explained 100K views
【生成式AI時代下的機器學習(2025)】第四講:Transformer 的時代要結束了嗎?介紹 Transformer 的競爭者們 95K views
GAME OVER! New AGI AGENT Breakthrough Changes Everything! (Q-STAR) 86K views
I Read The Top 10 AI Research Papers of 2024 53K views
The Largest Mamba LLM Experiment Just Dropped 44K views
10 TENDENCIAS sobre INTELIGENCIA ARTIFICIAL 🚀 ¿Qué nos espera en 2024? 31K views
LSTM: The Comeback Story? 28K views
Mamba Architecture Lobotomy Kaisen 26K views
[Paper Review] Mamba: Linear-Time Sequence Modeling with Selective State Spaces 24K views
The Algorithm That IS The Scientific Method [Dr. Jeff Beck] 22K views
Mamba, Mamba-2 and Post-Transformer Architectures for Generative AI with Albert Gu - 693 16K views
A Mamba Primer 14K views
State Space Models (S4, S5, S6/Mamba) Explained 13K views
Mamba: Linear-Time Sequence Modeling with Selective State Spaces 11K views
Mamba STRIKES again!!! 11K views
Mamba, SSMs & S4s Explained in 16 Minutes 7.3K views
Mamba vs. Transformers: The Future of LLMs? | Paper Overview & Google Colab Code & Mamba Chat 7K views
Enfin une mémoire à long terme pour l’IA : MAMBA, SSM, S4, S6 & Transformers 5.9K views
Mamba sequence model - part 1 5.9K views
松田語録:Mamba〜Tranformerに変わる新しいAIアーキテクチャ、小規模モデルではTransformerより高性能らしい 3.9K views
Mamba: il successore dell'architettura Transformer 3K views
MAMBA Explained Part-1: The Next-Gen Sequence Model for Deep Learning—State Space, Gates & More 2.9K views
Mamba part 2 - Can it replace Transformers? 2.8K views
Mamba part 4 - System Details and Implementation 2.5K views
Mamba part 3 - Details of Mamba and Structured State Space 1.8K views
Top 5 AI Breakthroughs of 2023 (Explained) 1.7K views
Mathstral y Codestral Mamba: Los TITANES de Mistral que DESTACAN en matemáticas y programación 1.6K views
[논문 리뷰] Mamba: Linear-Time Sequence Modeling with Selective State Spaces 1.3K views
Panoram'IA - Février 2024 1.2K views
IA 2023 : Ce qu'il faut retenir 1.1K views
学生带我读论文[第1期]Mamba 846 views
适合个人电脑的迷你“大模型”LLM — Mamba模型 836 views
KapiBara: Mój najwspanialszy i najgorszy projekt 762 views
Mamba: Linear-Time Sequence Modeling with Selective State Spaces 741 views
ทำความรู้จักกับ Mamba: Architecture ที่จะมาโค่น transformer | #LAYN ep12 | Part1 665 views
状態空間モデルNN③Mamba: Linear-Time Sequence Modeling with Selective State Spaces 579 views
Mamba | فكرة جديدة لترانسفورمرز أكفأ 501 views
Will Mamba Replace Transformers? The Future of AI is Here! 🔥 #Shorts 501 views
学生带我读论文[第9期]Mamba 496 views
How Continual Learning May Be Solved in AI (TITANS Explained) 481 views
Mamba Architecture 328 views
Agora - Travail, Intelligence artificielle et Revenu de base 323 views
三連休明けの社会人勉強記録【社会人勉強Vlog #161】 310 views
Mamba: The AI Model That Might Replace Transformers 306 views
Mamba : A New Brain for AI 300 views
State Space Models are All You Need? Introduction to SSM, S4 and Mamba | Deep Learning 242 views
MAMBA Explained Part-2: The Next-Gen Sequence Model for Deep Learning—State Space, Gates & More 232 views