Files
myWiki/concepts/mamba-ssm.md

60 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Mamba (State Space Model)"
created: 2025-04-15
updated: 2026-06-18
type: concept
tags: ["ssm", "linear-complexity", "architecture", "sequence-modeling"]
sources: ["https://arxiv.org/abs/2312.00752"]
---
# Mamba
## 定义
Mamba 是 Gu & Dao (2024) 提出的**选择性状态空间序列模型**,第一个在线性复杂度下真正达到 Transformer 质量的语言建模架构。核心创新是将 SSM 从线性时间不变LTI升级为**输入依赖的选择性参数化**S6结合硬件感知并行算法。
## 核心机制
### 选择机制S6
传统 S4 的关键局限:参数 (A, B, C, Δ) 对所有时间步固定 → 状态更新规则不随输入内容改变 → **无法选择性关注或忽略信息**
Mamba 的 S6 将 B, C, Δ 变为输入的函数:
```
B_t = s_B(x_t) C_t = s_C(x_t) Δ_t = τ(Δ + s_Δ(x_t))
```
效果:模型能根据当前 token 内容决定传播或遗忘信息——实现 **[[content-based-reasoning]]**。
### 硬件感知算法
选择机制消除卷积等价性 → 必须循环计算。Mamba 通过**并行关联扫描([[hardware-aware-algorithm]]**在 GPU SRAM 中高效完成,避免 HBM IO 瓶颈。
### 极简架构
Mamba block = LayerNorm → Linear(expand) → Conv1d → SiLU → SSM(S6) → 与门控分支逐元素乘 → Linear(project) → 残差。**无注意力、无 MLP**。
## 关键性质
- **线性复杂度**:训练 O(n),推理每步 O(1)(无需 KV cache
- **5× 推理吞吐** vs 同规模 Transformer
- **长序列外推**Selective Copying 和 Induction Heads 外推到 >1M tokens
- **多模态**:语言、音频、基因组学均达 SOTA
## 相关概念
- [[selective-state-space]] — 选择机制S6的详细分析
- [[structured-state-space-models]] — S4 前身
- [[hardware-aware-algorithm]] — 并行 scan 实现
- [[state-space-models]] — SSM 家族总览
- [[hippo]] — 数学基础
- [[content-based-reasoning]] — Mamba 解决的核心弱点
- [[gu-mamba|Mamba 论文]] — 原始论文
## 参考
- [[gu-mamba|Mamba: Linear-Time Sequence Modeling with Selective State Spaces]] (Gu & Dao, 2024)
- [[dao-transformers-are-ssms-2024|Transformers are SSMs (Mamba-2)]] (Dao & Gu, 2024)
- [[mamba-2|Mamba-2 架构]] — 2-8x 加速的改进版
- 代码https://github.com/state-spaces/mamba