State space models (SSMs) and transformer-based neural networks have fundamentally different underlying mathematical structures, not just different training procedures.
Key Mathematical Differences:
Transformers use attention mechanisms where each position in a sequence can directly attend to every other position. The core computation involves:
- Query, Key, and Value matrices derived from input embeddings
- Attention scores computed as softmax(QK^T/√d)
- Output as a weighted sum of values based on attention scores
This creates a fully connected computational graph where information can flow directly between any two positions in the sequence.
State Space Models are based on linear dynamical systems theory. They model sequences using:
- A hidden state h(t) that evolves according to: h'(t) = Ah(t) + Bx(t)
- An output equation: y(t) = Ch(t) + Dx(t)
- Where A, B, C, D are learned parameter matrices
The key insight is that these continuous-time equations can be discretized and computed efficiently using convolutions, making them linear in sequence length rather than quadratic like attention.
Practical Implications:
-
Computational complexity: SSMs scale linearly with sequence length (O(n)), while transformers scale quadratically (O(n²))
-
Inductive bias: SSMs have a strong recurrent/temporal inductive bias, while transformers treat positions more symmetrically
-
Long-range dependencies: Transformers can easily model arbitrary long-range dependencies through direct attention. SSMs must propagate information through the hidden state, though modern variants like S4 and Mamba have developed techniques to handle this effectively
-
Parallelization: Both can be parallelized during training, but SSMs achieve this through convolution while transformers use parallel attention computation
Modern SSM architectures like Mamba have shown competitive performance with transformers on many tasks while being more efficient for long sequences. The architectural differences are substantial - they represent fundamentally different approaches to sequence modeling.