← Back to Deep Learning Mind Map
🧠 Deep LearningID: ssm-mamba

SSM & Mamba

SSM 与 Mamba
🎯Core Definition
State-space models (SSMs, e.g. S4/Mamba) frame sequence modeling as a linear time-invariant system: continuous form h˙(t)=Ah(t)+Bx(t)\dot{h}(t) = Ah(t) + Bx(t), y(t)=Ch(t)y(t) = Ch(t); ZOH (zero-order hold) discretization gives Aˉ=eAΔ\bar{A} = e^{A\Delta}, Bˉ=(eAΔ−I)A−1B\bar{B} = (e^{A\Delta} - I)A^{-1}B, so inference is the linear recurrence ht=Aˉht−1+Bˉxth_t = \bar{A}h_{t-1} + \bar{B}x_t, yt=Chty_t = Ch_t — an O(1)O(1) state update per step with no KV cache. When time-invariant (Aˉ,Bˉ,C\bar{A}, \bar{B}, C independent of the input) it unrolls into a global convolution y=Kˉ∗xy = \bar{K} * x with Kˉ=(CBˉ,CAˉBˉ,…)\bar{K} = (C\bar{B}, C\bar{A}\bar{B}, \ldots), enabling fully parallel training. The key of Mamba is the selective mechanism: Δt,Bt,Ct\Delta_t, B_t, C_t depend on the input xtx_t (e.g. Δt=softplus(WΔxt)\Delta_t = \mathrm{softplus}(W_\Delta x_t)), acting like gating to decide per-token whether to remember or ignore — the cost is losing the convolution form, replaced by parallel scanning (associative scan) in training. Complexity: self-attention is O(L2)O(L^2) in time and memory, Mamba is O(L)O(L) in sequence length, giving a clear edge on long sequences.
💡Use Cases
long-context modeling (50k+ tokens) and linear-time inference on edge devices; staple interview comparisons include Mamba vs Transformer (complexity, parallelism, long-range dependencies), Mamba vs LSTM (selectivity vs gating), and the SSM discretization derivation.
⚡Key Problems Solved
Transformer attention grows quadratically (O(L2)O(L^2)), making long-context training/inference expensive; RNNs (LSTM) are O(L)O(L) but sequential and cannot be trained in parallel. Mamba keeps O(L)O(L) complexity via a linear recurrence, restores training parallelism via the parallel scan, and uses the selective mechanism to overcome the limited expressivity of fixed-parameter recurrences — reaching near-Transformer quality while greatly improving inference throughput and long-sequence memory.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of SSM & Mamba.
Use Cases
In production engineering, what are the primary use cases for SSM & Mamba and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Write the discretized SSM recurrence ht=Aˉht−1+Bˉxth_t = \bar{A}h_{t-1} + \bar{B}x_t and derive the continuous-to-discrete step (Aˉ=eAΔ\bar{A} = e^{A\Delta}, ZOH); what is the role of Δ\Delta?
2
Training parallelism: why is a time-invariant SSM equivalent to a global convolution y=Kˉ∗xy = \bar{K} * x? After adding selectivity, how does the parallel scan (associative scan) restore parallel training?
3
What is the selective mechanism: why must Δt,Bt,Ct\Delta_t, B_t, C_t depend on the input xtx_t? How does it compare with LSTM gating (content-adaptive vs fixed parameters)?
4
Complexity comparison: self-attention is O(L2)O(L^2) in time and memory vs Mamba's O(L)O(L); what does this mean concretely for L=100kL = 100k long context?
5
Why are hybrid Transformer + Mamba architectures popular (Mamba blocks every few layers)? What are the potential weaknesses of pure Mamba?
Updated 2026-08-12
🎯
Verify Mastery: Practice Exam Questions for "SSM & Mamba"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardGRUNext Card →SGD & Momentum

🔗 More Deep Learning Knowledge Cards

引用出处: TalentMe 450+ 工业级 AI 架构考点知识库 (Tech Vault) · 遵循 CC-BY-4.0 知识共享协议
URL: https://talentme.airsota.com/resources/tech/roadmap/mindmap/DL/card/ssm-mamba
中文速览与面试要点

SSM 与 Mamba (SSM & Mamba)

定义: 状态空间模型(SSM, 如 S4/Mamba)把序列建模写成线性时不变系统: 连续形式 h(t) = Ah(t) + Bx(t), y(t) = Ch(t); 用 ZOH(零阶保持)离散化得 A = e^A , B = (e^A - I)A^-1B, 于是推理是线性递推 h_t = Ah_t-1 + Bx_t, 输出 y_t = Ch_t——每步 O(1) 状态更新, 无 KV 缓存。时不变时( A, B, C 与输入无关)可展开为全局卷积 y = K * x(其中 K = (C B, C A B, )), 训练可整段并行。Mamba 的关键是选择性机制: 让 _t, B_t, C_t 依赖输入 x_t(如 _t = softplus(W_ x_t)), 类似门控, 能按内容决定“记住”还是“忽略”——代价是失去卷积形式, 改用并行扫描(associative scan)训练。复杂度: 自注意力 O(L^2)(时间与显存), Mamba O(L)(序列长度线性), 长序列下显存与速度优势显著。 使用场景: 长上下文建模(50k+ token)、边缘设备上的线性时间推理; 面试对比题高频出现: Mamba vs Transformer(复杂度、并行性、长程依赖)、Mamba vs LSTM(选择性 vs 门控)、SSM 离散化推导。 解决的问题: Transformer 的 O(L^2) 注意力随序列长度平方增长, 长上下文训练/推理昂贵; RNN(LSTM)虽 O(L) 但串行无法并行训练。Mamba 用线性递推保持 O(L) 复杂度, 又借并行扫描实现训练并行化, 以选择性机制弥补“固定参数递推”表达力不足——在与同规模 Transformer 相当的质量下, 推理吞吐与长序列显存占用都大幅改善。

核心要点

  • 写出 SSM 离散化递推 h_t = Ah_t-1 + Bx_t 并推导连续→离散( A = e^A 的 ZOH 推导), 起什么作用?
  • 训练并行化: 时不变 SSM 为什么等价于全局卷积 y = K * x? 引入选择性后如何用并行扫描(associative scan)恢复并行训练?
  • 选择性机制是什么: _t, B_t, C_t 为什么必须依赖输入 x_t? 它与 LSTM 门控的异同(内容感知 vs 固定参数)?
  • 复杂度对比: 自注意力 O(L^2) 的时间与显存 vs Mamba 的 O(L); 在 L = 100k 长上下文下分别意味着什么?
  • 为什么流行的是 Transformer + Mamba 混合架构(每几层插入 Mamba 块)? 纯 Mamba 的潜在弱点是什么?