Foundations to Frontier
Tests
E. Deep Learning › E17 State-Space and Recurrent-Revival Models

xLSTM

xLSTM (Beck, Hochreiter and colleagues, NeurIPS 2024) revisits the LSTM with two changes. Exponential gating with a normaliser and a stabiliser lets the network revise its storage decisions: a sufficiently important new input can outweigh everything stored before. A matrix-valued memory (mLSTM) stores key–value outer products, like linear attention, and can be trained in parallel. Combined into residual blocks, sLSTM and mLSTM reach performance comparable to Transformers and state-space models at similar sizes. This page covers exponential gates, normalisers and stabilisers, sLSTM and mLSTM. In the exercises you implement stabilised sLSTM and mLSTM steps, then test whether a memory can keep the most important of 40 values. A sigmoid input gate stayed near R² 0.05. Exponential gating reached 0.50, 0.88 and 0.97 as gate sharpness rose. At extreme sharpness, the naive computation overflowed while the stabilised one reached 0.998.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Let a crucial input override the past

A classic LSTM decides how much of each new input to store with a gate between 0 and 1. Once many inputs have been stored, no single new one can dominate, even if it is far more important. xLSTM uses exponential gates, which can be huge, together with a normaliser that keeps the memory an average. A truly important input can then take over the memory. xLSTM also adds a matrix memory that stores associations, like attention. The demo shows an input-dependent update that writes important tokens firmly.

State-space lab
Final state 0.532. With an input-dependent step, the important token at t = 10 is written strongly and then held. This is Mamba's selection mechanism.
Why engineers care

Recurrent models with constant memory are attractive for streaming and embedded settings. xLSTM brings LSTM-style models back to competitive quality, with better ability to keep the events that matter.

📝 Quick check (Level 0)
0/3 answered
  1. 1. xLSTM's new input gates are…
  2. 2. The normaliser keeps the memory…
  3. 3. mLSTM's memory is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • sLSTM memory: c_t = f_t c_(t−1) + i_t z_t and n_t = f_t n_(t−1) + i_t, with output h̃ = c_t/n_t.
    • With exponential i_t = e^(ĩ_t), this is a weighted average with weights that can differ by orders of magnitude.
    • Values 2 and −1 with equal gates average to 0.5. Adding value 7 with a gate e⁴⁵ times larger gives about 7.
  • Stabiliser: m_t = max(log f_t + m_(t−1), log i_t); store i′ = e^(log i_t − m_t) and f′ = e^(log f_t + m_(t−1) − m_t). The ratio c/n is unchanged and nothing overflows. For example, m = max(3, 5) = 5.
  • mLSTM:
    • C_t = f_t C_(t−1) + i_t v_t k_tᵀ and n_t = f_t n_(t−1) + i_t k_t;
    • h_t = o_t ⊙ C_t q_t / max(|n_tᵀq_t|, 1);
    • the state is d × d + d per head (4160 for d = 64), and training is fully parallel like linear attention.
  • Sigmoid gates are bounded by 1 (sigmoid(0) = 0.5), so no single input can outweigh a long history.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Normalised average of 2 and −1 with equal gates:
  2. 2. Stabiliser m for m_prev = 3, log i = 5, log f = 0:
  3. 3. mLSTM state per head for d = 64:

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

xLSTM in code

Exercise 1.

  • A stabilised sLSTM step averaged equal-gated inputs and let a much larger gate dominate.
  • An mLSTM update and read stored and retrieved a key–value pair.

Practice.

  • The official xlstm package (NX-AI) provides sLSTM and mLSTM blocks; mLSTM has parallel and chunkwise kernels.
  • Typical block layout: pre-norm residual blocks, mLSTM with up-projection (like a gated MLP), and sLSTM with post up-projection and memory mixing across heads.
  • Keep gates in log space and always use the stabiliser.
# stabilised exponential gating (sLSTM cell, per channel)
m_new = torch.maximum(log_f + m, log_i)
i_s, f_s = torch.exp(log_i - m_new), torch.exp(log_f + m - m_new)
c = f_s * c + i_s * z; n = f_s * n + i_s; m = m_new
h = o * (c / n)
🐍 Exercise 1: sLSTM and mLSTM steps
Implement a stabilised sLSTM memory step and the mLSTM matrix-memory update and read.
📝 Quick check (Level 2)
0/3 answered
  1. 1. The official implementation:
  2. 2. Gates are kept in…
  3. 3. Which variant trains fully in parallel?

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Revising storage decisions.

  • With sigmoid gates, each input’s contribution is at most comparable to the others. Many earlier inputs therefore outweigh a crucial new one, and the LSTM cannot “change its mind.”
  • Exponential input gates with a normaliser make the memory a softmax-weighted average over time. As gate pre-activations sharpen, it approaches “keep the most important item,” a selection a sigmoid gate cannot express.

Stability. Exponentials overflow for large pre-activations. Tracking the running maximum m and storing everything relative to it keeps values bounded without changing c/n, the same trick as numerically stable softmax.

mLSTM as gated linear attention. The covariance-style update C += i v kᵀ with read C q is linear attention with exponential input and forget gates. It is therefore parallelisable and can do associative recall, linking xLSTM to RetNet, GLA and Mamba-2.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Exponential gates + normaliser make memory a…
  2. 2. The stabiliser is analogous to…
  3. 3. mLSTM resembles…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Can exponential gating keep the most important item?

History.

  • S. Hochreiter and J. Schmidhuber, “Long short-term memory” (1997).
  • M. Beck et al., “xLSTM: extended long short-term memory” (NeurIPS 2024).

Exercise 2.

  • Task: 40-step streams of values with importance scores. The target is the value with the highest score.
  • Memory: a normalised memory h = c/n with input gate i = sigmoid(β·score) (classic) or exp(β·score) (xLSTM), no forgetting, at β = 2, 8 or 32, scored by R² for the target.
  • Overflow test: at β = 200, the naive exponential version is compared with the stabilised version.
β sigmoid gate R² exponential gate R²
2 0.062 0.502
8 0.056 0.883
32 0.053 0.973

At β = 200: naive exponential gating overflowed (non-finite); stabilised gating gave R² 0.998.

  • Sigmoid gates cannot select: every input gets a gate of at most 1, so the memory stays an almost uniform average (R² 0.05), whatever the sharpness.
  • Exponential gates can: with a normaliser, they form a softmax over importance, and as β grows the memory converges to the most important value (0.97 at β = 32). This is xLSTM’s “revise storage decisions.”
  • The stabiliser is essential: large gates overflow naive arithmetic. With the stabiliser, the extreme case works (0.998).
  • Seeds: seeds 1 and 2 gave the same picture (exponential 0.89/0.98 and 0.88/0.97 at β = 8/32; sigmoid 0.04–0.06).
🐍 Exercise 2 (research): can exponential gating keep the most important item?
Compare sigmoid and exponential input gates in a normalised memory on keeping the most important value, and test the stabiliser.

xLSTM in AI, robotics and aerospace

  • Event-driven monitoring: keep the most significant anomaly seen so far in a long sensor stream with constant memory.
  • Embedded sequence models: recurrent inference with competitive quality for on-device use.
  • Design lesson: bounded gates cap how strongly a model can react to rare, important inputs. Unbounded gates need normalisation and numerical stabilisation.

References

  1. M. Beck et al. (2024). “xLSTM: extended long short-term memory.” NeurIPS.
  2. S. Hochreiter and J. Schmidhuber (1997). “Long short-term memory.” Neural Computation 9.
  3. S. Yang et al. (2024). “Gated linear attention Transformers with hardware-efficient training.” Proc. ICML.