WHY continuous? Even though we process discrete tokens, the continuous formulation gives us powerful tools from control theory and signal processing. We'll discretize it carefully.
For neural networks processing discrete sequences, we need to discretize the continuous dynamics. Using the zero-order hold assumption (input is constant between timesteps), the exact solution is:
WHY this specific discretization? The matrix exponential eAΔ is the exact solution to the ODE for constant input. Using simpler methods (like Euler) would accumulate errors over long sequences.
HOW to compute eAΔ? For general matrices this is expensive, but S4 uses structured matrices (next section) where it becomes efficient.
The original SSM approach hit a wall: the state dimension N needs to be large (thousands) to have sufficient memory capacity, but this makes the A matrix huge and expensive.
Here's the crucial dual perspective: the SSM can be viewed as either:
Recurrent: hk=Aˉhk−1+Bˉxk (for generation)
Convolutional: y=Kˉ∗x (for training)
The SSM convolution kernel is:
WHY convolutional view? Convolutions can be computed in O(nlogn) using FFT, and they parallelize perfectly across the sequence (unlike the recurrent form). Training uses convolution, inference uses recurrence.
HOW does DPLR structure help? With diagonal-plus-low-rank A, the powers Aˉk and kernel Kˉ can be computed efficiently using the Cauchy kernel trick and FFT. The details involve complex analysis, but the result is O(NlogN) computation per layer.
S4 was a breakthrough but had a key limitation: the matrices Aˉ,Bˉ,C are input-independent. The same filter is applied to every token.
WHY selective? Consider processing a document: the model might want to remember a name mentioned in the first sentence for the entire sequence, but forget filler words immediately. Fixed SSMs can't make this choice—Mamba can.
HOW is this computed efficiently? This breaks the convolution view (kernel is now input-dependent), so we can't use FFT. Mamba uses specialized hardware-aware kernels that fuse the recurrent computation with careful memory management, achieving speed comparable to FFT-based S4 despite being recurrent.
Linear Attention: Some linear attention variants are mathematically equivalent to certain SSM configurations
Mixture of Experts: Mamba can be combined with MoE for even greater efficiency
Recall Explain to a 12-year-old
Imagine you're listening to a long song and trying to remember it. Your brain doesn't remember every single sound equally—some parts (the chorus, the melody) you remember strongly, while other parts (a quiet drum beat) you forget quickly.
A Transformer is like writing down every single sound on a huge piece of paper and constantly looking back at the whole paper. If the song is really long (like 100,000 notes!), your paper becomes gigantic and it takes forever to check everything.
A State-Space Model (SSM) is like having a small notebook where you keep summary notes. When you hear a new sound, you update your notebook based on the old notes and the new sound. Your notebook stays small no matter how long the song is!
S4 made the notebook super organized (structured) so you can flip through it really fast. Mamba made it even smarter: when an important sound comes (like the singer saying "I love you"), the notebook says "Write this in pen!" so it stays there a long time. When boring sounds come, it says "Write in pencil" so they fade away quickly.
This is why SSMs can handle super duper long sequences (like reading an entire Harry Potter book at once!) while Transformers would get tired halfway through.
Kˉ=(CBˉ,CAˉBˉ,CAˉ2Bˉ,…,CAˉL−1Bˉ)—the impulse response of the system
What is the key innovation of Mamba over S4?
Mamba makes SSM parameters input-dependent (selective): Bˉ(x),C(x),Δ(x) depend on the input token, allowing the model to choose what to remember
How does Mamba's selectivity mechanism work?
The timestep parameter Δ(x) is computed per-token via a learned linear layer; large Δ gives slow decay (long memory), small Δ gives fast decay (quick forgetting)
Why can't Mamba use the FFT-based convolution trick from S4?
Because the kernel is now input-dependent (different for each sequence), breaking the time-invariance required for FFT convolution
What is the per-token computational cost of SSM inference vs Transformer inference?
SSMs: O(1) (just update fixed-size state). Transformers: O(n) (attend to all previous tokens)
What initialization strategy helps SSMs maintain long-term memory?
HiPPO initialization, which sets the eigenvalues of A to specific values that create stable memory channels
At what sequence length do SSMs typically become faster than Transformers?
Around 4K-8K tokens, depending on hardware and implementation details; for <2K tokens, optimized Transformers (FlashAttention) are often faster
State-space models (SSMs) ek bahut hi powerful alternative hai Transformers ke liye, especially jab sequence bohot lambi ho. Socho aise—Transformer ko puri sequence yad rakhni padti hai har step pe, jaise tum ek bohot badi book ko har page khol ke dekhte raho. Jitni badi book, utna zyada kaam. But SSMek smart notebook rakhta hai jo continuously update hota rehta hai. Sirf ek chhoti si "state" yad rakhni hai, aur har naye token ke sath usko update kar lo. Yeh concept signal processing aur control theory se ata hai—hum ek continuous dynamical system banate hain jo time ke saath evolve hota hai.