# Mamba: Linear-Time Sequence Modeling with Selective State Spaces

入力に応じて情報を選ぶSSMで系列を線形時間で処理する

Albert Gu, Tri Dao · arXiv · 2023年12月1日

- **課題** 従来のSSMは、パラメータが時間によらず固定されているため、入力の内容に応じて必要な情報を選べず、テキストのような情報密度の高いデータでTransformerに及びませんでした。
- **手法** Mambaは、SSMのパラメータを入力から作る関数に変えて、トークンごとに情報を残すか捨てるかを選べるようにします。計算は並列スキャンで行い、系列長に対して線形の処理時間を保ちます。
- **結果** Mamba-3Bは同じ規模のTransformerを上回り、その2倍の規模のTransformerと同等の言語モデル性能を示しました。

## 従来のSSMが離散データで止まる理由

基盤モデルの多くは、Transformerとそのコアとなるアテンションを土台にしています。アテンションは文脈全体を密に参照できる反面、窓の外を扱えず、系列長に対して二乗で計算量が増えるという欠点があります。効率化した変種は数多く提案されていますが、多くは注意機構の強みを手放しており、大規模で広く効くとは示されていません。そこで注目された構造化状態空間モデル（SSM）は、再帰としても畳み込みとしても計算でき、系列長に対して線形からほぼ線形のスケールを持ちます。ところがSSMは、音声や映像のような連続信号では強い一方、テキストのような離散で情報密度の高いデータでは弱いとされてきました。

弱さの原因は、SSMの(Δ, A, B, C)が全時刻で固定されている点にあり、これを線形時間不変性（LTI）と呼びます。LTIのモデルは入力の中身を見て状態への書き込みを変えられないため、必要な情報だけを残すことができません。その違いを見る例がSelective Copyingで、入力の間隔が毎回ずれるため、固定のカーネルでは対応しにくいと論じられています。図2の左にある通常のCopyingは間隔が一定で、時間さえ分かれば解けるため、畳み込みで対応できます。つまり問題は計算量と表現力の両立にあり、どれだけ小さな状態に文脈を圧縮できるかという観点で各モデルを比べられます。

![Figure 2: (Left) The standard version of the Copying task involves constant spacing between input and output elements and is easily solved by time-invariant mo…](https://refivu.com/papers/b149783d-1b22-47f2-94df-544d57bb2621/figures/figure-f518fcc2eceac163139d64b9779d8128.png?thumb=512)

**Figure 2** : (Left) The standard version of the Copying task involves constant spacing between input and output elements and is easily solved by time-invariant models such as linear recurrences and global convolutions. (Right Top) The Selective Copying task has random spacing in between inputs and requires time-varying models that can selectively remember or ignore inputs depending on their content. (Right Bottom) The Induction Heads task is an example of associative recall that requires retrieving an answer based on context, a key ability for LLMs.

[出典](https://arxiv.org/abs/2312.00752v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Albert Gu, Tri Dao · Mamba: Linear-Time Sequence Modeling with Selective State Spaces · 論文の図を引用 · 元のPDFの6ページ目から図の部分を抽出しています。

## 入力依存のパラメータで情報の通し方を決める

鍵になる変更は、SSMのΔ、B、Cを入力から作られる関数にすることです。直感的には、各トークンを見て、覚えるか、状態をリセットして捨てるかを決められるようにしたということです。これにより、無関係な入力を除きつつ、必要な情報を長く保てるとされています。

具体的には、BとCは入力からの線形射影で作り、Δは入力からの射影に学習パラメータを足してsoftplusを通します。\\\[ \\Delta=\\mathrm{softplus}(\\mathrm{Parameter}+s\_\\Delta(x)) \\\]Aは入力によらない構造化された固定パラメータのまま残します。連続パラメータから離散パラメータへの変換にはZOHという規則を使い、次の式で与えられます。\\\[ \\bar{A}=\\exp(\\Delta A),\\qquad \\bar{B}=(\\Delta A)^{-1}(\\exp(\\Delta A)-I)\\cdot \\Delta B \\\]

RNNのゲートとの対応も、この設計の狙いを示します。N=1、A=-1、B=1という特殊な設定では、選択的SSMの再帰はゲート付きRNNと同じ形になります。\\\[ g\_t=\\sigma(\\mathrm{Linear}(x\_t)),\\qquad h\_t=(1-g\_t)h\_{t-1}+g\_t x\_t \\\]g\_tが0に近いと入力を無視し、1に近いと状態をリセットする、と解釈できます。Δも同じ役割で、Δが大きいと状態を入れ替えて現在の入力に集中し、小さいと状態を保って入力を無視します。

選択SSMを組み込むブロックは、H3のブロックとMLPを一つにまとめ、同じブロックを繰り返す形にしています。拡張係数Eは2に固定し、ブロック2つ分でTransformerのMHAとMLPのパラメータ数12D^2に合わせると書かれています。

## 並列スキャンでメモリを節約する

入力依存にすると、パラメータが長さの軸Lを持つため、LTIのような畳み込みとしては計算できなくなります。そこで、再帰を並列に走査するスキャンで計算します。

状態は1チャネルあたりN個の数で表せますが、全チャネルとバッチを合わせると、状態はO(BLDN)の量になります。そこで、パラメータをSRAMに読み込み、離散化と再帰をSRAM上で行い、出力だけをHBMに書き戻すカーネル融合を使います。

非線形でも並列化できる作業効率のよい並列スキャンを使い、逐次の再帰を避けます。中間状態は保存せず、逆伝播の際に入力からSRAMへ再計算します。その結果、融合された選択スキャン層のメモリ要件は、FlashAttentionを使った最適化Transformer実装と同等になると著者らは説明しています。理論上は系列長に対して線形で、畳み込み型SSMの準線形より有利です。実機でもA100上で最大3×高速になると示されています。

## 合成タスクと言語モデリングでの結果

合成タスクのSelective Copyingでは、Mamba（S6層）が99.8、ゲートなしでS6層を使った場合が97.0となりました。一方、H3でS4層を使った場合は57.0、ゲートなしでS4層を使った場合は18.3にとどまります。同じMambaブロックでS4層に替えると56.4まで下がるため、性能差は内側の層を入力依存にしたことから来ていると読めます。

Induction Headsでは、学習長は256で、テストは64から1048576までの長さで行っています。学習時の4000×の長さまで一般化が示されており、他の手法は2×までとされています。

言語では、Pile上で125Mから1.3Bまでの規模を学習し、GPT3の構成に合わせたモデルを比較しました。比較対象には標準的なTransformerとTransformer++があり、Transformer++は回転埋め込みやSwiGLUなどを使う強いレシピです。MambaはアテンションフリーのモデルとしてはじめてTransformer++に並び、系列長が長くなるほどその傾向が強くなります。

![Figure 4: ( Scaling Laws.) Models of size ≈ 125𝑀 to≈ 1.3𝐵 parameters, trained on the Pile. Mamba scales better than all other attention-free models and is the…](https://refivu.com/papers/b149783d-1b22-47f2-94df-544d57bb2621/figures/figure-5e9825f4d4a52366504aab63872abb2a.png?thumb=512)

**Figure 4** : ( Scaling Laws.) Models of size ≈ 125𝑀 to≈ 1.3𝐵 parameters, trained on the Pile. Mamba scales better than all other attention-free models and is the first to match the performance of a very strong “Transformer++” recipe that has now become standard, particularly as the sequence length grows.

[出典](https://arxiv.org/abs/2312.00752v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Albert Gu, Tri Dao · Mamba: Linear-Time Sequence Modeling with Selective State Spaces · 論文の図を引用 · 元のPDFの11ページ目から図の部分を抽出しています。

ゼロショットの下流評価では、Pythiaと同じ語彙とデータ、最大300Bトークンの条件で学習されたモデルと比べています。Mamba-2.8Bは平均63.3となり、Pythia-2.8Bの59.1を上回りました。さらにPythia-6.9Bの61.7も上回ります。この比較は、学習条件を揃えたモデル同士のものであり、同じ条件の中での相対比較です。

音声ではSC09の無条件生成で、FIDがSaShiMiの1.99から、6.1MのMambaで0.94に下がりました。FIDは半分以下に減りました。この音声の事前学習だけは、実数から複素数のパラメータ化に切り替えています。

推論速度では、Transformerと同程度の大きさのモデルより4-5×高いスループットになると示されています。ただし、この速度の計測には学習していないMamba-6.9Bが使われており、精度を測ったモデルとは別条件です。

BとCを入力依存にすると、同じ変化で9.73から8.71まで下がり、状態次元を増やす効果はBとCの選択と組み合わせたときに大きく出ます。

## 限界と未解決の課題

評価は、多くの強いオープンソースLLMの規模より小さいモデルに限られています。RWKVやRetNetが7B級以上で評価されている一方、7B級以上で同じ比較ができるかは、この論文では未検証です。SSMのスケールには、追加のエンジニアリング課題や構造の調整が必要になりうると述べられています。

離散データに強くなった代償として、LTI型SSMが得意な連続信号の性能を損なう可能性があります。音声の事前学習だけは複素数パラメータ化を使っており、他の実験と条件が違う点に注意が必要です。

微調整、プロンプト、RLHFなどのTransformer系基盤モデルの扱いやすさが、SSMにも当てはまるかは未検証です。下流評価の文脈長は2048で、長文脈での言語の下流性能は、この表の範囲では扱っていません。

## 論文情報

- **著者**: Albert Gu, Tri Dao
- **学会・ジャーナル**: arXiv · プレプリント
- **公開日**: 2023年12月1日
- **登録日**: 2026年10月20日
- **更新日**: 2024年5月31日
- **バージョン**: v2
- **arXiv**: 2312.00752
- **カテゴリ**: cs.LG · cs.AI
- **ライセンス**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **掲載内容**: 論文情報・解説・論文の図

[元論文 ↗](https://arxiv.org/abs/2312.00752v2) · [PDF ↗](https://arxiv.org/pdf/2312.00752v2)

この解説は、Refivuの韓国語解説をAIで翻訳したものです。不正確な翻訳や誤りが含まれる可能性があります。論文と図の利用条件は各出典に従います。

## アブストラクト

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.

## 論文の図

![Table 1: (Selective Copying.) Accuracy for combinations of architectures and inner sequence layers](https://refivu.com/papers/b149783d-1b22-47f2-94df-544d57bb2621/figures/figure-a9953b84649616cfac8b218be26b4a60.png?thumb=512)

**Table 1** : (Selective Copying.) Accuracy for combinations of architectures and inner sequence layers.

[出典](https://arxiv.org/abs/2312.00752v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Albert Gu, Tri Dao · Mamba: Linear-Time Sequence Modeling with Selective State Spaces · 論文の図を引用 · 元のPDFの11ページ目から図の部分を抽出しています。

![Table 3: (Zero-shot Evaluations.) Best results for each size in bold. We compare against open source LMs with various tokenizers, trained for up to 300B tokens…](https://refivu.com/papers/b149783d-1b22-47f2-94df-544d57bb2621/figures/figure-5ffda9d09982e8b90158f2d83cc082d5.png?thumb=512)

**Table 3** : (Zero-shot Evaluations.) Best results for each size in bold. We compare against open source LMs with various tokenizers, trained for up to 300B tokens. Pile refers to the validation split, comparing only against models trained on the same dataset and tokenizer (GPT-NeoX-20B). For each model size, Mamba is best-in-class on every single evaluation result, and generally matches baselines at twice the model size.

[出典](https://arxiv.org/abs/2312.00752v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Albert Gu, Tri Dao · Mamba: Linear-Time Sequence Modeling with Selective State Spaces · 論文の図を引用 · 元のPDFの12ページ目から図の部分を抽出しています。

![Figure 5: (DNA Scaling Laws.) Pretraining on the HG38 (human genome) dataset. (Left) Fixing short context length 210 = 1024 and increasing size from≈ 200𝐾 to≈…](https://refivu.com/papers/b149783d-1b22-47f2-94df-544d57bb2621/figures/figure-046290872e985995df39ba3e0f597ae8.png?thumb=512)

**Figure 5** : (DNA Scaling Laws.) Pretraining on the HG38 (human genome) dataset. (Left) Fixing short context length 210 = 1024 and increasing size from≈ 200𝐾 to≈ 40𝑀 parameters, Mamba scales better than baselines. (Right) Fixing model size and increasing sequence lengths while keeping tokens/batch and total training tokens fixed. Unlike baselines, the selection mechanism of Mamba facilitates better performance with increasing context length.

[出典](https://arxiv.org/abs/2312.00752v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Albert Gu, Tri Dao · Mamba: Linear-Time Sequence Modeling with Selective State Spaces · 論文の図を引用 · 元のPDFの13ページ目から図の部分を抽出しています。

![Figure 8: (Efficiency Benchmarks.) (Left) Training: our efficient scan is 40× faster than a standard implementation. (Right) Inference: as a recurrent model, M…](https://refivu.com/papers/b149783d-1b22-47f2-94df-544d57bb2621/figures/figure-ffa357dbbe499c569f61d0cbb3a2320d.png?thumb=512)

**Figure 8** : (Efficiency Benchmarks.) (Left) Training: our efficient scan is 40× faster than a standard implementation. (Right) Inference: as a recurrent model, Mamba can achieve 5× higher throughput than Transformers.

[出典](https://arxiv.org/abs/2312.00752v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Albert Gu, Tri Dao · Mamba: Linear-Time Sequence Modeling with Selective State Spaces · 論文の図を引用 · 元のPDFの15ページ目から図の部分を抽出しています。

![Table 15: (Memory benchmark.) Mamba’s memory footprint is comparable to the most optimized Transformer. Results for 125M models](https://refivu.com/papers/b149783d-1b22-47f2-94df-544d57bb2621/figures/figure-cdd51469f035ce9068ecd1de38e8b98f.png?thumb=512)

**Table 15** : (Memory benchmark.) Mamba’s memory footprint is comparable to the most optimized Transformer. Results for 125M models.

[出典](https://arxiv.org/abs/2312.00752v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Albert Gu, Tri Dao · Mamba: Linear-Time Sequence Modeling with Selective State Spaces · 論文の図を引用 · 元のPDFの36ページ目から図の部分を抽出しています。

## この論文を引用

Albert Gu, Tri Dao (2023). Mamba: Linear-Time Sequence Modeling with Selective State Spaces. arXiv:2312.00752v2. https://arxiv.org/abs/2312.00752v2

**BibTeX**

```
@misc{gu2023mamba,
  title = {{Mamba: Linear-Time Sequence Modeling with Selective State Spaces}},
  author = {Albert Gu and Tri Dao},
  year = {2023},
  eprint = {2312.00752},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.00752v2}
}
```

## この論文の用語

- [Transformer](https://refivu.com/ja/terms/515e8433c447-transformer)
- [perplexity](https://refivu.com/ja/terms/2b204e513801-perplexity)
- [Mamba](https://refivu.com/ja/terms/cc8b7f3226dc-mamba)
- [Pile](https://refivu.com/ja/terms/52bbdb3a0c68-pile)
- [Induction Heads](https://refivu.com/ja/terms/9e3f59843a35-induction-heads)

## ほかの論文解説

- [RWKV: Reinventing RNNs for the Transformer Era](https://refivu.com/ja/papers/f86c302a-2e46-481a-b0a7-850579f6f3c8-rwkv-reinventing-rnns-for-the-transformer-era.md)
- [Highway Networks](https://refivu.com/ja/papers/78251486-9138-48d8-a03c-8447a3433591-highway-networks.md)
- [Rethinking Attention with Performers](https://refivu.com/ja/papers/be31745a-9080-4105-b177-3b88d23e4f59-rethinking-attention-with-performers.md)
- [Decision Transformer: Reinforcement Learning via Sequence Modeling](https://refivu.com/ja/papers/386e76e8-fee6-4cba-84e8-0ef90a33b3b6-decision-transformer-reinforcement-learning-via-sequence.md)
- [Efficiently Modeling Long Sequences with Structured State Spaces](https://refivu.com/ja/papers/9047ef9d-9e54-48f1-8609-ea4ce704605e-efficiently-modeling-long-sequences-with-structured-state.md)
- [Longformer: The Long-Document Transformer](https://refivu.com/ja/papers/095aa21a-9a7f-4317-a80b-f961fdd4e423-longformer-the-long-document-transformer.md)
- [Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification](https://refivu.com/ja/papers/83083238-3fc6-4f4e-a3b1-6db4f84268de-delving-deep-into-rectifiers-surpassing-human-level.md)
- [Direct Preference Optimization: Your Language Model is Secretly a Reward Model](https://refivu.com/ja/papers/b96eaaaa-8c14-4a06-93bf-d13e70a14b14-direct-preference-optimization-your-language-model-is.md)
- [GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding](https://refivu.com/ja/papers/2481fdbe-b100-433d-877a-6976f982ccaa-gshard-scaling-giant-models-with-conditional-computation-and.md)
- [GLUE: A Multi-Task Benchmark and Analysis Platform for Natural Language Understanding](https://refivu.com/ja/papers/a5e0caad-afbf-4fa4-b072-f6f5cab0c916-glue-a-multi-task-benchmark-and-analysis-platform.md)
- [Retentive Network: A Successor to Transformer for Large Language Models](https://refivu.com/ja/papers/ca4ee5c6-87cf-427b-ae91-b593c10e0b48-retentive-network-a-successor-to-transformer-for-large.md)
- [Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks](https://refivu.com/ja/papers/569bb9ab-8345-4766-a539-e7ffb7b1754e-retrieval-augmented-generation-for-knowledge-intensive-nlp.md)

---

AI解説には誤りが含まれることがあります。 [Refivu](https://refivu.com/ja/papers/b149783d-1b22-47f2-94df-544d57bb2621-mamba-linear-time-sequence-modeling-with-selective-state)
