
📺 Today’s recommended deep-dive video: https://www.youtube.com/watch?v=9dSkvxS2EB0
Mamba: The New King of Linear-Time Sequence Modeling?
For years, Transformers have dominated AI, but their quadratic scaling makes processing long sequences prohibitively expensive for most researchers. Enter Mamba, a selective state space model that promises Transformer-level performance with linear-time efficiency and constant-time inference.
Core Question: Can selective input-dependency bridge the gap between efficient state space models and high-performance Transformers?
Highlights
- Selective State Spaces (S6) allow the model to filter information based on current inputs.
- Hardware-aware parallel scans optimize memory throughput between GPU HBM and SRAM.
- Linear scaling in sequence length enables context windows of up to 1 million tokens.
- Outperforms standard Transformer recipes and other attention-free models at the 1.3B parameter scale.
⏱️ Reading time: approx. 6 minutes · Saves you about 35 minutes vs. watching.
Want to take notes while watching? Click the image below and let AI Notebook capture the key points for you 👇
The Evolution of Sequence Models
Beyond the Transformer Bottleneck
Sequence modeling has historically faced a brutal trade-off between the infinite memory of RNNs and the precise, albeit expensive, global attention of Transformers. While Transformers excel at selectively focusing on specific past tokens, their quadratic memory cost makes processing massive datasets like DNA sequences or audio waveforms nearly impossible for standard hardware.
Traditional State Space Models offered a linear alternative by treating sequences as continuous systems, yet they lacked the dynamic reasoning required for complex language tasks.
This paper introduces Mamba, an architecture that utilizes “Selective State Spaces” to bridge the efficiency of linear models with the expressive power of attention-based systems. By allowing the model to decide what information to store or discard based on the current input, the authors have created a framework that scales linearly with sequence length while maintaining the high performance typically reserved for massive Transformer models.
💡 Digging Deeper
Q: Why is “quadratic scaling” such a problem for Transformers?
A: As the sequence length doubles, the memory and computation required quadruples, making long-form content like books or long videos computationally unreachable.
Q: How do RNNs differ from this new approach?
A: RNNs process information step-by-step and often struggle with vanishing gradients; Mamba uses a parallelizable “scan” that mimics the speed of Transformers during training.
The Mamba Innovation: Selective State Spaces
Breaking the Input-Invariance Rule
The core weakness of prior State Space Models (SSMs) like S4 was their inability to perform context-based reasoning because their transition matrices were fixed for every token in a sequence. In a standard SSM, the way the model updates its hidden state is the same regardless of whether it is reading a technical manual or a poem.
Mamba introduces “Selection,” making the A, B, and C matrices functions of the input rather than static parameters.
This change is subtle but transformative. By making the discretization parameter $Delta$ and the input/output projections dependent on the current token, the model can effectively “choose” to remember important information and ignore noise. This brings SSMs closer to the gated logic of LSTMs but retains the structural properties needed for massive parallelization.

💡 Digging Deeper
Q: Is Mamba dependent on the previous hidden state like an LSTM?
A: No, the parameters are dependent on the current input token, which allows for more efficient parallel computation than hidden-state-dependent models.
Q: What is “discretization” in this context?
A: It is the mathematical process of turning a continuous-time differential equation (the SSM theory) into a discrete-time formula that a computer can calculate.
Hardware Awareness and Computational Efficiency
Optimizing for the GPU Hierarchy
Making the model input-dependent breaks the ability to use standard convolutions, which are the primary way older SSMs achieved their speed. To solve this, the authors developed a hardware-aware algorithm that leverages the different memory speeds on a GPU.
The bulk of the work involves moving data between the slow High Bandwidth Memory (HBM) and the fast, but small, SRAM cache.
By loading the core parameters into SRAM and performing the recurrence there—rather than writing intermediate states back to the slow HBM—Mamba achieves a speedup that makes its selective scan as fast as a Transformer’s optimized flash attention. This implementation ensures that the model doesn’t just look good on paper but actually runs faster on real-world hardware.

💡 Digging Deeper
Q: What is a “Parallel Scan”?
A: It is a technique (also known as a prefix sum) that allows a computer to calculate the cumulative results of a sequence in parallel rather than one by one.
Q: Does Mamba require a KV cache for inference?
A: No, unlike Transformers, it only needs to store the last hidden state, significantly reducing the memory footprint during generation.
Key Takeaways
Mamba represents a significant shift in sequence modeling by proving that attention is not the only way to achieve high-quality language understanding. By introducing selectivity into the state space framework, the authors have addressed the “reasoning” gap that previously held SSMs back from competing with Transformers on benchmarks like the Pile or WikiText.
The architecture’s linear scaling is particularly exciting for modalities that require massive context, such as genomics or high-resolution audio. As models continue to grow, the ability to maintain constant-time inference and linear-time training will likely become a requirement rather than a luxury. Mamba demonstrates that hardware-aware algorithmic design can overcome theoretical bottlenecks, paving the way for a new generation of efficient, long-context AI.
Q&A
Q1: What exactly makes Mamba “selective”?
A1: Unlike previous models where the transition matrices were fixed, Mamba makes the matrices $B$, $C$, and the step size $Delta$ functions of the input token, allowing the model to focus or forget dynamically.
Q2: How does Mamba’s training speed compare to a Transformer?
A2: It scales linearly, meaning for very long sequences, it is significantly faster and uses less memory than the quadratic scaling of a Transformer.
Q3: Can Mamba handle 1 million tokens of context?
A3: Yes, the authors demonstrated performance improvements on real data for sequences up to 1 million tokens, which is far beyond the reach of standard Transformers.
Q4: What is the main difference in the Mamba block compared to a Transformer block?
A4: A Mamba block replaces the attention mechanism with a selective SSM layer, while keeping features like 1D convolutions and gating mechanisms.
Q5: Is Mamba better than Transformers for small-scale models?
A5: At 1.3 billion parameters, Mamba matches or exceeds the performance of state-of-the-art Transformer recipes like Llama-based architectures.
Q6: Why is the “Parallel Scan” important for Mamba?
A6: Since Mamba is recurrent, it would normally be slow to train (one step at a time); the parallel scan allows the GPU to compute all steps of the sequence simultaneously.
Q7: What modalities benefit most from Mamba?
A7: Modalities with very long sequences and dense data, such as DNA genomics, audio waveforms, and long-form video, where Transformers become prohibitively expensive.
