Skip to main content
Home › Categories › Artificial Intelligence & Computing › Sequence Modeling Beyond Attention: RNNs, LSTMs, GRUs, and State-Space Models (Mamba)

Sequence Modeling Beyond Attention: RNNs, LSTMs, GRUs, and State-Space Models (Mamba)

Author: ZUVDEX Team 4 min read
rnn lstm vs state space models mamba long short term memory gates gated recurrent unit gru structured state space s4 mamba linear attention rwkv hybrid jamba mamba transformer

Modeling ordered sequences—speech waveforms, genomic base pairs, financial ticks, and natural language—pits two fundamental computational trade-offs against each other: parallel training throughput versus constant-memory inference state. Classical Recurrent Neural Networks (LSTMs and GRUs) compress history into a fixed-size state at O(1) per-step inference cost but train sequentially, Transformers parallelize training via O(L²) attention at the price of growing KV caches, and modern Selective State-Space Models (such as Mamba) achieve both parallel associative-scan training and linear O(L) scaling.

Key Highlights

  • Sepp Hochreiter and Jürgen Schmidhuber’s Long Short-Term Memory (LSTM, 1997) solved vanishing recurrent gradients via an additive cell-state highway controlled by input, forget, and output gates.
  • Classical RNNs/LSTMs cannot parallelize across time steps during training because hidden state h_t depends non-linearly on h_{t−1}.
  • Structured State-Space Models (S4) and Selective State-Space Models (Mamba) formulate linear recurrences solvable in parallel via hardware-aware GPU prefix scans while maintaining O(1) per-token generation memory.
  • Hybrid architectures interleaving Mamba layers with periodic full self-attention layers combine constant-state speed on long sequences with exact associative needle-in-a-haystack recall.

From LSTM Additive Cell Highways to Selective State Spaces

In vanilla Elman RNNs, multiplying the same recurrent weight matrix across hundreds of steps exponentially shrinks or explodes eigenvalues. LSTMs introduced an additive conveyor belt—the cell state—modulated by multiplicative sigmoid gates, while Kyunghyun Cho’s GRU streamlined that design into reset and update gates that still power ultra-compact embedded audio wake-word and battery-telemetry microcontrollers today.

Albert Gu and Tri Dao’s Mamba derived discrete recurrences from continuous-time control state equations h'(t) = Ah(t) + Bx(t), making transition matrices input-dependent ("selective") so the model dynamically chooses which tokens to remember and which filler words to forget—fused directly inside GPU SRAM to avoid HBM memory bottlenecks.

Architecture Training Parallelism Sequence Complexity Exact Copy / Recall vs State Size
LSTM / GRU Sequential O(L) steps O(L) time, O(1) inference state Bounded by fixed hidden vector; slow long-sequence training
Transformer (Full Attention) 100% Parallel across tokens O(L²) prefill, O(L) KV cache Exact arbitrary token lookup; heavy VRAM at 128k–1M context
Mamba / Mamba-2 (SSM) Parallel associative scan O(L) prefill, O(1) inference state Blazing long-sequence throughput; finite state compresses exact verbatim recall
Hybrid (Mamba + Attention) 100% Parallel across tokens Near-linear time, 8× smaller KV cache Balances fast linear compression with periodic exact attention lookup

Engineering Selection: Audio, Genomics, and Hybrid LLMs

Pure fixed-state models face an information-theoretic trade-off: compressing a 100,000-token legal contract into a fixed-kilobyte state vector inevitably loses arbitrary six-digit invoice numbers compared with a Transformer’s explicit KV cache. Interleaving roughly seven Mamba state-space blocks per one shared-KV attention block captures the best of both worlds—slashing KV-cache memory by 85% while retaining razor-sharp associative retrieval.

  • Use tiny quantized GRUs/LSTMs (<500 KB) on Cortex-M microcontrollers for continuous sensor filtering and voice-activity detection.
  • Use Mamba or bidirectional SSMs on million-base-pair DNA/RNA sequences and high-sample-rate audio where quadratic attention is prohibitive.
  • Benchmark hybrid SSM-Transformer models on needle-in-a-haystack and multi-query associative recall tasks before replacing full attention.

FAQs

How can Mamba train in parallel if it is still a recurrent model at inference?

Because Mamba’s hidden-state recurrence omits non-linear activations between consecutive hidden states (applying non-linearities around the SSM block instead), sequential linear state updates are mathematically associative and execute in parallel via logarithmic GPU prefix-sum scans.

Are LSTMs completely obsolete today?

Not in embedded ultra-low-power signal processing, real-time hearing aids, and low-dimensional industrial control loops where sub-megabyte memory footprints, strict deterministic microsecond latency, and tiny training sets favor compact gated RNNs.

References & Sources

  • Hochreiter, Sepp; Schmidhuber, Jürgen (1997) — Long Short-Term Memory, Neural Computation, 9(8), 1735–1780.
  • Gu, Albert; Goel, Karan; Ré, Christopher (2022) — Efficiently Modeling Long Sequences with Structured State Spaces (S4), ICLR.
  • Gu, Albert; Dao, Tri (2024) — Mamba: Linear-Time Sequence Modeling with Selective State Spaces, COLM.