xLSTM: How Exponential Gating and Matrix Memory Scale Recurrent Neural Networks

xLSTM: How Exponential Gating and Matrix Memory Scale Recurrent Neural Networks For over two decades following its introduction by Hochreiter and Schmidhuber (1997), the Long Short-Term Memory (LSTM) network served as the dominant architecture for sequence modeling. By introducing the constant error carousel and multiplicative gating, LSTMs mitigated the vanishing gradient problem that plagued vanilla recurrent neural networks. However, the emergence of the Transformer architecture (Vaswani et

10 min
xLSTM: How Exponential Gating and Matrix Memory Scale Recurrent Neural Networks

xLSTM: How Exponential Gating and Matrix Memory Scale Recurrent Neural Networks

For over two decades following its introduction by Hochreiter and Schmidhuber (1997), the Long Short-Term Memory (LSTM) network served as the dominant architecture for sequence modeling. By introducing the constant error carousel and multiplicative gating, LSTMs mitigated the vanishing gradient problem that plagued vanilla recurrent neural networks. However, the emergence of the Transformer architecture (Vaswani et al., 2017) eclipsed recurrent networks across natural language processing and frontier foundation models.

The Transformer's dominance stemmed from two fundamental advantages: parallel training across entire sequence dimensions and dynamic retrieval via self-attention mechanisms. While recurrent architectures maintain a constant computational complexity O(1)O(1) and memory footprint per token during inference, canonical LSTMs failed to scale to modern foundation model regimes due to structural memory bottlenecks and sequential training constraints.

In May 2024, researchers led by Maximilian Beck and Sepp Hochreiter introduced Extended Long Short-Term Memory, or xLSTM (Beck et al., 2024). The architecture addresses the core architectural deficiencies of traditional LSTMs by introducing exponential gating, running normalizer states, and matrix-valued associative memory cells. xLSTM establishes a mathematical duality between recurrent state updates and parallel chunkwise linear attention, enabling parallel training on modern accelerator hardware while retaining constant-memory autoregressive generation.

xLSTM architectural schematic showing memory cells and state updates

1. Structural Limitations of Canonical LSTMs

To understand why the canonical LSTM architecture struggled at frontier scale, consider the standard update equations for an LSTM cell at time step tt:

z~t=tanh(Wzxt+Rzht1+bz)\tilde{z}_t = \tanh(W_z x_t + R_z h_{t-1} + b_z)

it=σ(Wixt+Riht1+bi)i_t = \sigma(W_i x_t + R_i h_{t-1} + b_i)

ft=σ(Wfxt+Rfht1+bf)f_t = \sigma(W_f x_t + R_f h_{t-1} + b_f)

ot=σ(Woxt+Roht1+bo)o_t = \sigma(W_o x_t + R_o h_{t-1} + b_o)

ct=ftct1+itz~tc_t = f_t \odot c_{t-1} + i_t \odot \tilde{z}_t

ht=ottanh(ct)h_t = o_t \odot \tanh(c_t)

where xtRdx_t \in \mathbb{R}^d is the input vector, ctRdc_t \in \mathbb{R}^d is the cell state, htRdh_t \in \mathbb{R}^d is the hidden output state, and σ()\sigma(\cdot) denotes the sigmoid activation function.

Three structural limitations restrict this formulation:

  1. Inability to Revise Stored Values: The input and forget gates use the sigmoid function σ(z)=11+ez\sigma(z) = \frac{1}{1 + e^{-z}}, restricting values strictly to (0,1)(0, 1). When the network processes a critical token early in a context and writes it to cell state ctc_t, subsequent tokens can only scale down the existing memory via ft<1f_t < 1 or additively superimpose new information via itz~ti_t \odot \tilde{z}_t. If the model encounters a token that directly contradicts or supersedes past context, it cannot amplify the new incoming value relative to historical state or dynamically reset past state without step-by-step decay.
  2. Scalar Memory Capacity Bottleneck: The cell state ctc_t is a 1D scalar vector of dimension dd. Information storage scales linearly O(d)O(d) with hidden state width. In contrast, multi-head self-attention retains the complete historical Key-Value cache of shape T×dT \times d, permitting associative retrieval across all past tokens. A 1D vector cannot bind complex multi-entity relationships without destructive interference across overlapping feature channels.
  3. Sequential Training Dependency: The recurrence ht=ottanh(ct)h_t = o_t \odot \tanh(c_t) feeds directly into the affine transformations of the subsequent step (Rzht1R_z h_{t-1}, Riht1R_i h_{t-1}, Rfht1R_f h_{t-1}). This hidden-to-hidden recurrence creates an unbroken dependency chain across sequence length TT. Training cannot be parallelized via matrix multiplications over the time dimension, forcing backpropagation through time (BPTT) and underutilizing GPU tensor cores.

2. sLSTM: Scalar Memory with Exponential Gating and Normalization

The first core building block of xLSTM is the scalar LSTM (sLSTM). The sLSTM preserves a 1D vector cell state but fundamentally alters the gating mechanism and output normalization.

Exponential Gating

Rather than using sigmoid activations, sLSTM equips input and forget gates with exponential functions:

it=exp(i~t),where i~t=Wixt+Riht1+bii_t = \exp(\tilde{i}_t), \quad \text{where } \tilde{i}_t = W_i x_t + R_i h_{t-1} + b_i

ft=exp(f~t)orσ(f~t)f_t = \exp(\tilde{f}_t) \quad \text{or} \quad \sigma(\tilde{f}_t)

By taking the exponential of the gate pre-activations, the input gate can output values significantly greater than 1. This property allows sLSTM to implement dynamic memory revision: when an incoming token is assigned high relevance, its exponentiated gate weight iti_t dominates the accumulated historical state, effectively overriding prior stored values.

The Normalizer State and Numerical Stabilization

Unbounded exponential functions introduce immediate numerical instability and gradient explosions during backpropagation. To stabilize activations, sLSTM introduces a scalar normalizer state ntRdn_t \in \mathbb{R}^d and a running maximum tracker mtRdm_t \in \mathbb{R}^d.

The normalizer state accumulates the history of input gate activations weighted by all subsequent forget gates:

nt=ftnt1+itn_t = f_t \odot n_{t-1} + i_t

The unnormalized cell state is computed as:

ct=ftct1+itztc_t = f_t \odot c_{t-1} + i_t \odot z_t

where zt=Wzxt+Rzht1+bzz_t = W_z x_t + R_z h_{t-1} + b_z (without the tanh\tanh squashing). The hidden state is then normalized by dividing the cell state by the normalizer state:

h~t=ctnt,ht=oth~t\tilde{h}_t = \frac{c_t}{n_t}, \quad h_t = o_t \odot \tilde{h}_t

To maintain floating-point stability across thousands of steps, sLSTM computes activations in log-space relative to running maximum state mtm_t:

mt=max(f~t+mt1,i~t)m_t = \max(\tilde{f}_t + m_{t-1}, \tilde{i}_t)

The stabilized updates then become:

ct=exp(f~t+mt1mt)ct1+exp(i~tmt)ztc_t = \exp(\tilde{f}_t + m_{t-1} - m_t) \odot c_{t-1} + \exp(\tilde{i}_t - m_t) \odot z_t

nt=exp(f~t+mt1mt)nt1+exp(i~tmt)n_t = \exp(\tilde{f}_t + m_{t-1} - m_t) \odot n_{t-1} + \exp(\tilde{i}_t - m_t)

This normalization closely mirrors the online softmax trick used in FlashAttention (Dao et al., 2022). It ensures that the elements of ctc_t and ntn_t remain numerically bounded while allowing the relative weighting between past context and current input to span multiple orders of magnitude.

Multi-Head Memory Mixing

Unlike traditional LSTMs where hidden dimensions operate independently across cells, sLSTM structures hidden states into multiple heads. Within each head, recurrence is scalar, but across heads, affine projections Ri,Rf,Rz,RoR_i, R_f, R_z, R_o mix representations. This head-wise communication allows sLSTM to route features dynamically across parallel memory tracks.


3. mLSTM: Matrix Memory and the Parallel Dual Formulation

While sLSTM solves memory revision, its storage capacity remains bounded by O(d)O(d). To achieve associative memory storage capable of competing with self-attention, xLSTM introduces the Matrix LSTM (mLSTM).

Comparison between scalar memory updates in sLSTM and outer-product associative matrix memory in mLSTM

Associative Matrix Cell State

The mLSTM replaces the scalar cell state ctRdc_t \in \mathbb{R}^d with a matrix-valued cell state CtRd×dC_t \in \mathbb{R}^{d \times d}.

Input tokens are projected into Query (qtq_t), Key (ktk_t), and Value (vtv_t) vectors:

qt=Wqxt+bqq_t = W_q x_t + b_q

kt=1d(Wkxt+bk)k_t = \frac{1}{\sqrt{d}} (W_k x_t + b_k)

vt=Wvxt+bvv_t = W_v x_t + b_v

The matrix memory update utilizes an outer product (covariance update rule) to store Key-Value associations:

Ct=ftCt1+it(vtktT)C_t = f_t C_{t-1} + i_t (v_t k_t^T)

where ft=exp(f~t)f_t = \exp(\tilde{f}_t) (or σ(f~t)\sigma(\tilde{f}_t)) and it=exp(i~t)i_t = \exp(\tilde{i}_t). The normalizer state vector ntRdn_t \in \mathbb{R}^d accumulates the historical key vectors:

nt=ftnt1+itktn_t = f_t n_{t-1} + i_t k_t

Memory retrieval is executed by multiplying the matrix state CtC_t by the query vector qtq_t:

h~t=Ctqtmax(ntTqt,1)\tilde{h}_t = \frac{C_t q_t}{\max(n_t^T q_t, 1)}

ht=oth~th_t = o_t \odot \tilde{h}_t

By storing information as an outer product vtktTv_t k_t^T, mLSTM implements a continuous associative memory. Storing multiple key-value pairs in a single matrix CtC_t enables the network to retrieve specific facts when queried with matching keys, expanding the effective memory capacity from O(d)O(d) to O(d2)O(d^2) per head.

The Parallel Dual Form

In mLSTM, the hidden-to-hidden recurrent connections (ht1hth_{t-1} \to h_t) are eliminated. Gates and projections depend exclusively on current input xtx_t. This architectural decision unlocks the parallel dual formulation.

Unrolling the matrix recurrence from t=1t=1 to TT:

CT=t=1T(τ=t+1Tfτ)itvtktTC_T = \sum_{t=1}^T \left( \prod_{\tau=t+1}^T f_\tau \right) i_t v_t k_t^T

Evaluating the retrieval at step TT with query qTq_T:

CTqT=t=1T(τ=t+1Tfτ)itvt(ktTqT)=t=1T(τ=t+1Tfτ)it(qTTkt)vtC_T q_T = \sum_{t=1}^T \left( \prod_{\tau=t+1}^T f_\tau \right) i_t v_t (k_t^T q_T) = \sum_{t=1}^T \left( \prod_{\tau=t+1}^T f_\tau \right) i_t (q_T^T k_t) v_t

Let SRT×TS \in \mathbb{R}^{T \times T} be a causal decay matrix defined by:

Si,j={(τ=j+1ifτ)ijif ij0if i<jS_{i,j} = \begin{cases} \left( \prod_{\tau=j+1}^i f_\tau \right) i_j & \text{if } i \ge j \\ 0 & \text{if } i < j \end{cases}

The sequence-wide hidden state representation HRT×dH \in \mathbb{R}^{T \times d} can then be computed entirely in parallel as:

H=((QKT)S)VH = ( (Q K^T) \odot S ) V

This formulation is mathematically equivalent to causal linear attention with exponential decay (Katharopoulos et al., 2020). During training, the entire sequence computation can be executed on tensor cores using parallel associative prefix scans and block-chunked matrix multiplications, identical to chunked algorithms in State Space Models such as Mamba (Gu and Dao, 2023).


4. xLSTM Block Architecture and Residual Stacking

The individual sLSTM and mLSTM cells are integrated into residual blocks to form full deep network architectures.

sLSTM Block Structure

An sLSTM block incorporates convolutional pre-processing and post-up-projection:

  1. Layer Normalization: Input xRdx \in \mathbb{R}^d is normalized via LayerNorm or RMSNorm.
  2. Causal 1D Convolution: A depthwise causal 1D convolution with small kernel size (e.g., k=4k=4) mixes local context across neighboring tokens.
  3. sLSTM Cell: The multi-head sLSTM processes the temporally convolved representations.
  4. Gated Feed-Forward Projection: The cell output is passed through a GeLU/Swish activation, projected upward to an expanded dimension (e.g., factor 2 or 4), and gated before being projected back to hidden width dd.
  5. Residual Connection: The processed output is added to the skip input.

mLSTM Block Structure

The mLSTM block mirrors modern Transformer decoder and State Space Model blocks:

  1. Pre-LayerNorm: Normalizes input xx.
  2. Up-Projection: Projections expand the representation width by expansion factor pp (typically p=2p=2).
  3. Causal 1D Convolution: A depthwise causal 1D convolution acts on Key and Value paths.
  4. mLSTM Cell: The matrix memory processes queries, keys, and values across multiple heads.
  5. Group Normalization and Output Gating: Output heads are normalized and modulated by output gate oto_t.
  6. Down-Projection and Skip Addition: Projected back to model dimension dd and combined with the residual path.
       Input x
          │
    ┌─────┴─────────────────────────┐
    │                               │
[Pre-LN]                         [Skip]
    │                               │
[Up-Projection (2x)]                │
    │                               │
[Causal 1D Conv (k=4)]              │
    │                               │
[mLSTM Matrix Memory Cell]          │
  C_t = f_t C_t-1 + i_t (v_t k_t^T) │
  h_t = (C_t q_t) / (n_t^T q_t)     │
    │                               │
[GroupNorm & Output Gate]           │
    │                               │
[Down-Projection (1/2x)]            │
    │                               │
    ▼                               │
  [ + ] <───────────────────────────┘
    │
 Output y

Hybrid Stacking: xLSTM[a:b] Topologies

Empirical evaluations in Beck et al. (2024) demonstrate that pure mLSTM networks excel at associative memory and global context aggregation, while sLSTM layers excel at tracking state transitions, counting, and non-linear tracking over time.

To combine both capabilities, xLSTM models are constructed as hybrid stacks denoted by xLSTM[a:b], representing the ratio of mLSTM blocks to sLSTM blocks. For instance, an xLSTM[7:1] configuration interleaves seven mLSTM blocks with one sLSTM block throughout the depth of the network.


5. Architectural Comparison: xLSTM vs. Transformers and State Space Models

Comparing xLSTM against dominant foundation model paradigms highlights distinct computational profiles:

  • Canonical LSTM: Maintains a 1D state of size dd. Training is strictly sequential O(Td)O(T \cdot d), while inference requires O(1)O(1) constant time and O(d)O(d) memory. Gating is restricted to sigmoid decay with no dynamic revision or outer-product storage.
  • Standard Transformer: Retains a full Key-Value cache of shape T×dT \times d. Training is fully parallel O(T2d)O(T^2 \cdot d) with exact softmax self-attention. Inference step compute scales with context length O(T)O(T), and KV memory grows linearly O(Td)O(T \cdot d).
  • State Space Models (Mamba): Uses a continuous state dimension expanded by factor NN (state size NdN \cdot d). Training is parallelized via associative scans in O(Td)O(T \cdot d) time. Inference requires O(1)O(1) constant compute and O(Nd)O(N \cdot d) constant memory per layer.
  • xLSTM (mLSTM / sLSTM): Uses an outer-product matrix state of size d×dd \times d (or H×dk×dkH \times d_k \times d_k) in mLSTM and a 1D vector state in sLSTM. Training is parallelized via chunkwise linear attention scans in O(Td)O(T \cdot d) time. Inference operates in strictly O(1)O(1) constant time and O(d2)O(d^2) constant memory per layer.

Inference Memory and Throughput Trade-Offs

During autoregressive generation, standard Transformers require maintaining an active KV cache that expands linearly with sequence length TT and batch size BB. For context lengths spanning 32k to 128k tokens, the KV cache dominates GPU High Bandwidth Memory (HBM), necessitating complex paging mechanisms, KV cache compression, and multi-node sharding.

In contrast, xLSTM maintains a constant inference state per layer:

  • For sLSTM layers, the state comprises ct,nt,mtRdc_t, n_t, m_t \in \mathbb{R}^d, requiring O(d)O(d) storage.
  • For mLSTM layers with HH heads each of dimension dkd_k, the state comprises matrix CtRH×dk×dkC_t \in \mathbb{R}^{H \times d_k \times d_k} and vector ntRH×dkn_t \in \mathbb{R}^{H \times d_k}.

Because CtC_t does not grow with context length TT, xLSTM executes token generation in strictly O(1)O(1) memory and O(1)O(1) compute per step. A model processing a 100,000-token prompt occupies the exact same memory footprint during token 100,001 as it did during token 10.


6. Empirical Scaling and Benchmark Results

In the initial 300B-token pre-training evaluations conducted by Beck et al. (2024) across parameter scales from 125M to 1.3B, xLSTM demonstrated competitive performance against strong baseline architectures:

  1. Language Modeling Perplexity: xLSTM achieved lower validation perplexity on the SlimPajama corpus compared to open-source Transformer architectures (including LLaMA configurations) and State Space Models (Mamba and RWKV-4/5) at matched compute budgets.
  2. Associative Recall Tasks: In synthetic multi-query associative recall (MQAR) benchmarks, canonical LSTMs fail completely once sequence length exceeds a few hundred tokens. mLSTM maintained 100% retrieval accuracy across long sequence contexts, matching full softmax attention up to the tested limits.
  3. Long Context Extrapolation: Due to exponential gating and running normalizer states, xLSTM exhibited stable perplexity curves when evaluated on sequences longer than its training context window, avoiding the catastrophic loss degradation common in un-windowed recurrent networks.

Subsequent work scaling the architecture to 7 billion parameters (Beck et al., 2025) confirmed that these scaling properties hold at production scale, demonstrating high throughput on GPU clusters when training with chunkwise kernel implementations.


7. Summary of Core Principles

The xLSTM architecture revitalizes recurrent neural networks for foundation model workloads through four primary innovations:

  • Exponential Gating: Replaces bounded sigmoid gates with exponential functions, granting the network the mathematical expressivity to revise stored memory dynamically.
  • Normalizer and Max States: Introduces running denominator ntn_t and maximum tracker mtm_t to prevent numerical overflow, stabilizing training across deep stacks.
  • Associative Matrix Memory (mLSTM): Upgrades scalar storage to outer-product key-value matrix accumulation (Ct=ftCt1+itvtktTC_t = f_t C_{t-1} + i_t v_t k_t^T), expanding memory capacity to O(d2)O(d^2).
  • Parallel Dual Formulation: Drops recurrent hidden-to-hidden connections in mLSTM, enabling O(T)O(T) chunked parallel training via associative scans while preserving O(1)O(1) constant-memory autoregressive inference.

Sources

  • Beck, M., Pöppel, K., Spanring, M., Auer, A., Prudnikova, O., Kopp, M. K., Klambauer, G., Brandstetter, J., and Hochreiter, S. (2024). xLSTM: Extended Long Short-Term Memory. arXiv:2405.04517.
  • Beck, M., Pöppel, K., Lippe, P., Kurle, R., Blies, P. M., Klambauer, G., Böck, S., and Hochreiter, S. (2025). xLSTM 7B: A Recurrent LLM for Fast and Efficient Inference. arXiv:2503.13427.
  • Hochreiter, S., and Schmidhuber, J. (1997). Long Short-Term Memory. Neural Computation, 9(8), 1735-1780. Bioinf JKU Publication Archive.
  • Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, Ł., and Polosukhin, I. (2017). Attention Is All You Need. arXiv:1706.03762.
  • Dao, T., Fu, D. Y., Ermon, S., Rudra, A., and Ré, C. (2022). FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness. arXiv:2205.14135.
  • Gu, A., and Dao, T. (2023). Mamba: Linear-Time Sequence Modeling with Selective State Spaces. arXiv:2312.00752.
  • Katharopoulos, A., Vyas, A., Pappas, N., and Fleuret, F. (2020). Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention. arXiv:2006.16236.

Written by

More to read

  • Hallucination Detection and Faithfulness Verification in Production RAG: Architecture, NLI Claim Decomposition, and Runtime Guardrail Economics

    Retrieval-Augmented Generation (RAG) is commonly deployed under the assumption that grounding generation in retrieved passages eliminates factual inaccuracies. In practice, grounding provides an evidence boundary but does not guarantee factual fidelity. Production language models regularly synthesize claims absent from the retrieved context (extrinsic hallucinations) or directly assert statements conflicting with retrieved premises (intrinsic contradictions). As enterprise RAG pipelines scale i

    1 min
  • Sparse Attention and BigBird: How Window, Global, and Random Graphs Preserve Turing Completeness in Linear Time

    Standard self-attention in transformer architectures scales quadratically with sequence length. Computing full pairwise interactions between n tokens requires evaluating an n x n attention matrix, yielding O(n^2) computational complexity and memory consumption. While hardware accelerators and IO-aware tiling algorithms like FlashAttention optimize memory traffic, the quadratic compute and KV footprint remains a barrier for processing long contexts, document-level summarization, and genomic seque

    1 min
  • Oxford Study Details Chinese Gray-Market Proxies Reselling Claude Tokens at 90% Discounts

    An investigation by the Oxford China Policy Lab reveals that Chinese developers routinely access Anthropic's frontier Claude models at discounts between 70% and 90% below list price, bypassing geographical blocks, payment filters, and biometric identity verification through a decentralized network of API proxies known locally as "transfer stations" (中转站). The analysis, authored by Oxford researcher Zilan Qian and published via ChinaTalk, outlines the modular supply chain and economic mechanics

    1 min