マンバの解説
The Gradient の記事は、Transformer の計算コストのボトルネックを解消し、長文脈処理と高速推論を実現する次世代アーキテクチャ「Mamba(State Space Model)」の可能性と、それが AI 業界に与えるインパクトを詳細に解説している。
キーポイント
Transformer の根本的課題の克服
従来の Transformer はトークン間の双方向通信により O(n²) の計算コストと O(n) のメモリ消費を抱えており、長文脈処理が困難だったが、Mamba はこれを線形スケーリングで解決する。
性能と速度の劇的向上
Mamba は Transformer と同等かそれ以上の性能を維持しつつ、推論速度を最大 5 倍に向上させ、100 万トークン単位の超長文脈での学習・推論が現実的なものとなる。
マルチモーダルへの汎用性
言語モデルだけでなく、音声やゲノム解析など複数のモダリティにおいて最先端のパフォーマンスを発揮し、一般シーケンスモデルのバックボーンとして機能することが示されている。
解釈可能性と安全性への新展開
計算効率化だけでなく、このアーキテクチャの変化が AI の内部メカニズムの解釈可能性や安全性研究に新たな視点をもたらす可能性があることが議論される。
状態の定義とマルコフ性
状態とは入力変数と組み合わせることで未来のシステム挙動を完全に決定する変数の集合であり、過去の情報を圧縮したものである。これによりシステムはマルコフ決定過程(MDP)として扱えるようになる。
離散化プロセスと ZOH
連続時間の微分方程式を現実の離散時間ステップに適用するため、ゼロ次ホールド(ZOH)法を用いた離散化が行われる。これは単純な一次近似から導出され、RNN の構造と類似した再帰的な更新式を生み出す。
SSM 行列の直感的解釈
A 行列は状態遷移(不要な情報の忘却)、B 行列は入力から状態へのマッピング(何に注目するか)、C 行列は状態からの出力生成(予測のための利用)をそれぞれ担う。
影響分析・編集コメントを表示
影響分析
この技術は、AI モデルの拡張性と実用性を根本から変える可能性を秘めており、特に大規模な文脈を理解・処理が必要なアプリケーションにおいて、Transformer の独占的な地位に挑戦する強力な代替案となる。業界全体が計算コストとメモリ制約からの解放へと舵を切る中で、Mamba の採用は次世代 AI インフラの標準アーキテクチャ選定における重要な分岐点となり得る。
編集コメント
Transformer に代わる新たなパラダイムとして Mamba が台頭しており、計算効率の飛躍的向上が実証された点は業界全体にとって極めて重要な転換点です。今後の実装動向と、既存モデルとの統合事例に注目が必要です。
トランスフォーマーに挑む状態空間モデル
現在、AIが世界を席巻している。
ここで言うAIとは、トランスフォーマーのことだ。ここ数年におけるAIの大きなブレークスルーのほぼすべては、トランスフォーマーによるものだ。
しかし、Mambaは状態空間モデル(SSM)と呼ばれる別のモデル群の一つである。重要なことに、Mambaは初めて、長いシーケンス長(例えば100万トークン)においても実行可能でありながら、トランスフォーマーと同等の性能(そして決定的に重要なスケーリング則)を約束している。この長いコンテキストを実現するために、Mambaの開発者たちはアテンション・メカニズムにおける「二次のボトルネック」を取り除いた。Mambaはまた高速に動作する - 「トランスフォーマーの最大5倍の速さ」で動作する。
Mambaの開発者であるGuとDaoはこう書いている:
Mambaは高速な推論とシーケンス長に対する線形スケーリングを享受し、その性能は実データにおいて最大100万長のシーケンスまで向上する。一般的なシーケンスモデルのバックボーンとして、Mambaは言語、オーディオ、ゲノミクスなど、いくつかのモダリティにおいて最先端の性能を達成する。言語モデリングにおいて、我々のMamba-3Bモデルは、同じサイズのトランスフォーマーを上回り、その2倍のサイズのトランスフォーマーと同等の性能を、事前学習と下流評価の両方で達成する。
ここでは以下について議論する:
Mamba (🐍) 対 トランスフォーマー (🤖) の利点(と欠点)
Mambaを理解するための類推と直感
解釈可能性、AI安全性、応用にとってMambaが意味するもの
トランスフォーマーの問題点 - もしかするとアテンションだけでは不十分かもしれない
我々はまさに歴史のトランスフォーマー時代にいる。機械学習はかつて猫や犬を検出することだった。今や、トランスフォーマーによって、人間のような詩を生成し、平均的な競技プログラマーよりも優れたコーディングを行い、タンパク質折り畳み問題を解決している。
しかし、トランスフォーマーには一つの核心的な問題がある。トランスフォーマーでは、各トークンは予測を行う際に、それ以前のすべてのトークンを振り返って見ることができる。この「振り返り」のために、我々は各トークンに関する詳細な情報をいわゆるKVキャッシュに保存する。
このペアワイズ(対ごとの)通信は、訓練時の順方向パスがO(n²)の時間計算量(恐るべき二次のボトルネック)であることを意味し、自己回帰的に生成される各新しいトークンはO(n)の時間を要する。言い換えれば、コンテキストサイズが増加するにつれて、モデルは遅くなる。
さらに悪いことに、このキー・バリュー(KV)キャッシュを保存するにはO(n)の空間が必要である。その結果、メモリ使用量が拡大するにつれて、恐るべきCUDAのメモリ不足(OOM)エラーが重大な脅威となる。もし空間だけが問題であれば、より多くのGPUを追加することを検討するかもしれない。しかし、遅延が二次関数的に増加するため、単に計算資源を追加するだけでは実行可能な解決策とはならないかもしれない。
限界的には、スライディング・ウィンドウ・アテンションのような技術や、FlashAttentionのような巧妙なCUDA最適化によって、二次のボトルネックを緩和することができる。しかし最終的に、超長いコンテキストウィンドウ(例えば、あなたが共有したすべての会話を記憶するチャットボット)には、別のアプローチが必要だ。
基盤モデルのバックボーン
根本的に、すべての優れた機械学習アーキテクチャのバックボーンは、二つの重要な操作のためのコンポーネントを持っている:
トークン間の通信
トークン内の計算
トランスフォーマーでは、これはアテンション(通信)とMLP(計算)である。我々はこれら二つの操作を最適化することでトランスフォーマーを改良する。
我々はアテンション・コンポーネントを、トークン間通信を促進する代替メカニズムに置き換えたい。具体的には、Mambaは通信目的で制御理論に着想を得た状態空間モデル(SSM)を採用し、計算には多層パーセプトロン(MLP)型の射影を保持する。
積み重ねられたトランスフォーマー・ブロックで構成されるトランスフォーマーのように、Mambaは上記のような積み重ねられたMamba・ブロックで構成される。
我々はシーケンス変換におけるSSMの選択を理解し、動機付けたい。
Mambaの動機付け - Temple Runへの回帰
Temple Runエージェントを構築していると想像してみよう。それはランナーがいつ左右に移動すべきかを選択する。
正しい方向を選択するためには、周囲の情報が必要だ。関連する情報の集合を状態と呼ぼう。ここでの状態には、おそらく現在の位置と速度、最も近い障害物の位置、天候条件などが含まれるだろう。
主張1: もし現在の世界の状態と、世界がどのように進化しているかを知っていれば、これを用いて移動する方向を決定できる。
ここで、常に画面全体を見る必要はないことに注意してほしい。走っている間、障害物が画面下方に移動することに気づけば、画面の大部分に何が起こるかを把握できる。新しい情報を理解するには画面の上部だけを見ればよく、残りはシミュレートすればよい。
これは自然な定式化につながる。hを隠れ状態、世界に関する関連知識とする。また、xを入力、つまり毎回得られる観測とする。h'は隠れ状態の微分、すなわち状態がどのように進化しているかを表す。我々はy、最適な次の動き(右か左)を予測しようとしている。
さて、主張1は、隠れ状態h、h'、そして新しい観測xから、yを把握できると述べている。
より具体的には、状態hは微分方程式(式1a)として表現できる:
$h’(t) = \mathbf{A}h(t) + \mathbf{B}x(t)$
hを知ることで、次の動きyを決定できる(式1b):
$y(t) = \mathbf{C}h(t) + \mathbf{D}x(t)$
システムの進化は、その現在の状態と新たに獲得された観測によって決定される。状態の大部分は、既知の状態ダイナミクスを以前の状態に適用することで推論できるため、小さな新しい観測で十分である。つまり、画面の大部分は新しいものではなく、単に以前の状態の自然な下方軌道の継続である。状態を完全に理解することで、次の行動yとして最適な選択が可能になる。
画面の上部を観察することで、システムダイナミクスについて多くを学ぶことができる。例えば、この上部の速度が増加していることは、画面の残りの部分も加速していることを示唆するため、ゲームがスピードアップしていると推論できる。このように、ゲームについて何も知らず、限られた観測しか持っていない状態から始めても、画面のダイナミクスを全体的に理解することがかなり迅速に可能になる。
状態とは何か?
ここで状態とは、入力変数と組み合わせることで、将来のシステムの振る舞いを完全に決定する変数を指す。理論的には、状態を一度把握すれば、過去について未来を予測するために他に知る必要はない。この状態の選択により、システムはマルコフ決定過程に変換される。理想的には、状態はシステムの本質的な特性を捉えた、かなり少量の情報である。つまり、状態は過去の圧縮である。
離散化 - 量子化された世界で生きるためにどう対処するか
よし、素晴らしい!つまり、ある状態と入力観測が与えられれば、次の行動を決定する自己回帰型のシステムが得られる。すごい!
しかし実際には、ここに少し問題がある。我々は時間を連続的にモデル化している。しかし実生活では、新しい入力は離散的な時間ステップで得られ、新しい行動も離散的な時間ステップで行われる。
この連続時間の微分方程式を、離散時間の差分方程式に変換したい。この変換プロセスは離散化として知られている。離散化は文献においてよく研究された問題である。Mambaは零次ホールド(ZOH)離散化を使用する。道徳的に何が起こっているかの感覚を与えるために、単純な一次近似を考えてみよう。
式1aから、
$h’(t) = \mathbf{A}h(t) + \mathbf{B}x(t)$
そして小さな∆に対して、
$h’(t) \approx \frac{h(t+\Delta) - h(t)}{\Delta}$
これは微分の定義による。
$h_{t+1} = h(t + \Delta)$
と置き、式1aに代入すると:
$h_{t+1} - h_t \approx \Delta (\mathbf{A}h_t + \mathbf{B}x_t)$ $\Rightarrow h_{t+1} \approx (I + \Delta \mathbf{A})h_t + (\Delta \mathbf{B})x_t$
したがって、係数の名前を変更し、インデックスを再ラベル付けした後、離散表現が得られる:
もし以前にRNNを見たことがあり、これが親しみを感じるなら - あなたの直感を信じてほしい:
いくつかの入力xがあり、それは前の...
原文を表示
The State Space Model taking on Transformers
Right now, AI is eating the world.
And by AI, I mean Transformers. Practically all the big breakthroughs in AI over the last few years are due to Transformers.
Mamba, however, is one of an alternative class of models called State Space Models (SSMs). Importantly, for the first time, Mamba promises similar performance (and crucially similar scaling laws) as the Transformer whilst being feasible at long sequence lengths (say 1 million tokens). To achieve this long context, the Mamba authors remove the “quadratic bottleneck” in the Attention Mechanism. Mamba also runs fast - like “up to 5x faster than Transformer fast”1.
Gu and Dao, the Mamba authors write:
Mamba enjoys fast inference 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 modelling, our Mamba-3B model outperforms Transformers of the same size and matches Transformers twice its size, both in pretraining and downstream evaluation.
Here we’ll discuss:
The advantages (and disadvantages) of Mamba (🐍) vs Transformers (🤖),
Analogies and intuitions for thinking about Mamba, and
What Mamba means for Interpretability, AI Safety and Applications.
Problems with Transformers - Maybe Attention Isn’t All You Need
We’re very much in the Transformer-era of history. ML used to be about detecting cats and dogs. Now, with Transformers, we’re generating human-like poetry, coding better than the median competitive programmer, and solving the protein folding problem.
But Transformers have one core problem. In a transformer, every token can look back at every previous token when making predictions. For this lookback, we cache detailed information about each token in the so-called KV cache.
This pairwise communication means a forward pass is O(n²) time complexity in training (the dreaded quadratic bottleneck), and each new token generated autoregressively takes O(n) time. In other words, as the context size increases, the model gets slower.
To add insult to injury, storing this key-value (KV) cache requires O(n) space. Consequently, the dreaded CUDA out-of-memory (OOM) error becomes a significant threat as the memory footprint expands. If space were the only concern, we might consider adding more GPUs; however, with latency increasing quadratically, simply adding more compute might not be a viable solution.
On the margin, we can mitigate the quadratic bottleneck with techniques like Sliding Window Attention or clever CUDA optimisations like FlashAttention. But ultimately, for super long context windows (like a chatbot which remembers every conversation you’ve shared), we need a different approach.
Foundation Model Backbones
Fundamentally, all good ML architecture backbones have components for two important operations:
Communication between tokens
Computation within a token
In transformers, this is Attention (communication) and MLPs (computation). We improve transformers by optimising these two operations2.
We would like to substitute the Attention component3 with an alternative mechanism for facilitating inter-token communication. Specifically, Mamba employs a Control Theory-inspired State Space Model, or SSM, for Communication purposes while retaining Multilayer Perceptron (MLP)-style projections for Computation.
Like a Transformer made up of stacked transformer blocks, Mamba is made up of stacked Mamba blocks as above.
We would like to understand and motivate the choice of the SSM for sequence transformations.
Motivating Mamba - A Throwback to Temple Run
Imagine we’re building a Temple Run agent4. It chooses if the runner should move left or right at any time.
To successfully pick the correct direction, we need information about our surroundings. Let’s call the collection of relevant information the state. Here the state likely includes your current position and velocity, the position of the nearest obstacle, weather conditions, etc.
Claim 1: if you know the current state of the world and how the world is evolving, then you can use this to determine the direction to move.
Note that you don’t need to look at the whole screen all the time. You can figure out what will happen to most of the screen by noting that as you run, the obstacles move down the screen. You only need to look at the top of the screen to understand the new information and then simulate the rest.
This lends itself to a natural formulation. Let h be the hidden state, relevant knowledge about the world. Also let x be the input, the observation that you get each time. h’ then represents the derivative of the hidden state, i.e. how the state is evolving. We’re trying to predict y, the optimal next move (right or left).
Now, Claim 1 states that from the hidden state h, h’, and the new observation x, you can figure out y.
More concretely, h, the state, can be represented as a differential equation (Eq 1a):
$h’(t) = \mathbf{A}h(t) + \mathbf{B}x(t)$
Knowing h allows you to determine your next move y (Eq 1b):
$y(t) = \mathbf{C}h(t) + \mathbf{D}x(t)$
The system's evolution is determined by its current state and newly acquired observations. A small new observation is enough, as the majority of the state can be inferred by applying known state dynamics to its previous state. That is, most of the screen isn’t new, it’s just a continuation of the previous state's natural downward trajectory. A full understanding of the state would enable optimal selection of the subsequent action, denoted as y.
You can learn a lot about the system dynamics by observing the top of the screen. For instance, increased velocity of this upper section suggests an acceleration of the rest of the screen as well, so we can infer that the game is speeding up5. In this way, even if we start off knowing nothing about the game and only have limited observations, it becomes possible to gain a holistic understanding of the screen dynamics fairly rapidly.
What’s the State?
Here, state refers to the variables that, when combined with the input variables, fully determine the future system behaviour. In theory, once we have the state, there’s nothing else we need to know about the past to predict the future. With this choice of state, the system is converted to a Markov Decision Process. Ideally, the state is a fairly small amount of information which captures the essential properties of the system. That is, the state is a compression of the past6.
Discretisation - How To Deal With Living in a Quantised World
Okay, great! So, given some state and input observation, we have an autoregressive-style system to determine the next action. Amazing!
In practice though, there’s a little snag here. We’re modelling time as continuous. But in real life, we get new inputs and take new actions at discrete time steps7.
We would like to convert this continuous-time differential equation into a discrete-time difference equation. This conversion process is known as discretisation. Discretisation is a well-studied problem in the literature. Mamba uses the Zero-Order Hold (ZOH) discretisation8. To give an idea of what’s happening morally, consider a naive first-order approximation9.
From Equation 1a, we have
$h’(t) = \mathbf{A}h(t) + \mathbf{B}x(t)$
And for small ∆,
$h’(t) \approx \frac{h(t+\Delta) - h(t)}{\Delta}$
by the definition of the derivative.
$h_{t+1} = h(t + \Delta)$
and substitute into Equation 1a giving:
$h_{t+1} - h_t \approx \Delta (\mathbf{A}h_t + \mathbf{B}x_t)$ $\Rightarrow h_{t+1} \approx (I + \Delta \mathbf{A})h_t + (\Delta \mathbf{B})x_t$
Hence, after renaming the coefficients and relabelling indices, we have the discrete representations:
If you’ve ever looked at an RNN before10 and this feels familiar - trust your instincts:
We have some input x, which is combined with the previous hidden state by some transform to give the new hidden state. Then we use the hidden state to calculate the output at each time step.
Understanding the SSM Matrices
Now, we can interpret the A, B, C, D matrices more intuitively:
A is the transition state matrix. It shows how you transition the current state into the next state. It asks “How should I forget the less relevant parts of the state over time?”
B is mapping the new input into the state, asking “What part of my new input should I remember?”11
C is mapping the state to the output of the SSM. It asks, “How can I use the state to make a good next prediction?”12
D is how the new input passes through to the output. It’s a kind of modified skip connection that asks “How can I use the new input in my prediction?”
Additionally, ∆ has a nice interpretation - it’s the step size, or what we might call the linger time or the dwell time. For large ∆, you focus more on that token; for small ∆, you skip past the token immediately and don’t include it much in the next state.
And that’s it! That’s the SSM, our ~drop-in replacement for Attention (Communication) in the Mamba block. The Computation in the Mamba architecture comes from regular linear projections, non-linearities, and local convolutions.
Okay great, that’s the theory - but does this work? Well…
Effectiveness vs Efficiency: Attention is Focus, Selectivity is Prioritisation
At WWDC ‘97, Steve Jobs famously noted that “focusing is about saying no”. Focus is ruthless prioritisation. It’s common to think about Attention positively as choosing what to notice. In the Steve Jobs sense, we might instead frame Attention negatively as choosing what to discard.
There’s a classic intuition pump in Machine Learning known as the Cocktail Party Problem13. Imagine a party with dozens of simultaneous loud conversations:
How do we recognise what one person is saying when others are talking at the same time?14
The brain solves this problem by focusing your “attention” on a particular stimulus and hence drowning out all other sounds as much as possible.
Transformers use Dot-Product Attention to focus on the most relevant tokens. A big reason Attention is so great is that you have the potential to look back at everything that ever happened in its context. This is like photographic memory when done right.15
Transformers (🤖) are extremely effective. But they aren’t very efficient. They store everything from the past so that they can look back at tokens with theoretically perfect recall.
Traditional RNNs (🔁) are the opposite - they forget a lot, only recalling a small amount in their hidden state and discarding the rest. They are very efficient - their state is small. Yet they are less effective as discarded information cannot be recovered.
We’d like something closer to the Pareto frontier of the effectiveness/efficiency tradeoff. Something that’s more effective than traditional RNNs and more efficient than transformers.
The Mamba Architecture seems to offer a solution which pushes out the Pareto frontier of effectiveness/efficiency.
SSMs are as efficient as RNNs, but we might wonder how effective they are. After all, it seems like they would have a hard time discarding only unnecessary information and keeping everything relevant. If each token is being processed the same way, applying the same A and B matrices as if in a factory assembly line for tokens, there is no context-dependence. We would like the forgetting and remembering matrices (A and B respectively) to vary and dynamically adapt to inputs.
The Selection Mechanism
Selectivity allows each token to be transformed into the state in a way that is unique to its own needs. Selectivity is what takes us from vanilla SSM models (applying the same A (forgetting) and B (remembering) matrices to every input) to Mamba, the Selective State Space Model.
In regular SSMs, A, B, C and D are learned matrices - that is
$\mathbf{A} = \mathbf{A}_{\theta}$ etc. (where θ represen
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み