Sequence modeling in large language models has long been caught in a fundamental trade-off between attention mechanisms and recurrent architectures. Softmax attention provides precise associative recall over all tokens in the active context window, but incurs quadratic computational and memory complexity, , with respect to sequence length . Conversely, linear recurrent models, such as State Space Models (Mamba, Mamba-2) and linear Transformers (GLA, RetNet, DeltaNet), compress sequence history into fixed-size vector or matrix hidden states. While achieving linear computational complexity and constant inference memory, their finite state capacity creates an information bottleneck that degrades long-range retrieval and multi-hop reasoning over extended horizons.
In January 2025, researchers from Google Research (Ali Behrouz, Peilin Zhong, and Vahab Mirrokni) introduced Titans, a family of neural architectures that resolves this trade-off by treating memory through an online meta-learning framework. Rather than compressing history into passive recurrent vectors or maintaining unbounded key-value caches, Titans deploy a deep neural long-term memory module that actively learns to memorize, retrieve, and forget information during test-time inference.

The Three-Tier Memory Hierarchy
Human cognition relies on a confederation of distinct memory systems operating over varying temporal scales and representations. Titans operationalize this principle by decomposing sequence modeling into three interconnected memory modules:
- Short-Term Memory (Attention): High-precision associative recall over local context windows using standard causal or sliding-window attention. It captures exact token dependencies within immediate token neighborhoods.
- Long-Term Memory (Neural Memory Module): A parameter-based associative memory implemented as a multi-layer neural network (such as a multi-layer perceptron). Its weights are dynamically updated at test time through gradient descent on incoming data.
- Persistent Memory (Meta-Task Inductive Bias): A set of learnable, data-independent prefix vectors prepended to the sequence. These vectors store immutable task-level knowledge, emulate feed-forward network key-value priors, and eliminate attention sink artifacts at sequence beginnings.
By delegating long-range historical context to neural parameter updates while retaining local attention for exact short-range dependencies, Titans decouple context length from attention compute overhead.
Mathematical Foundations of Neural Long-Term Memory
The Long-Term Memory Module (LMM), denoted as , acts as an associative memory function parameterized by weights . Unlike classical fast weight programmers or linear RNNs that store representations in linear matrices (), can be a deep non-linear network whose parameter trajectory encodes sequence history.
1. Associative Memory Loss Formulation
Given an input sequence , the model projects each token into key and value representations via learnable linear projections :
The objective of the neural memory at step is to bind the key to its corresponding value . The associative reconstruction error is defined by the squared Euclidean loss:
In the meta-learning hierarchy, the outer loop optimizes global parameters (including projection matrices ) across training corpora, while the inner loop optimizes the memory weights on-the-fly during inference.
2. Surprise-Driven Gradient Updates with Momentum
In biological memory systems, events that deviate significantly from prior expectations produce heightened neural plasticity and stronger encoding. Titans formalize this concept by defining momentary surprise as the gradient of the associative loss with respect to current memory parameters:
If memory parameters were updated solely via standard stochastic gradient descent (), two pathologies arise:
- Momentary Volatility: A single aberrant token could corrupt the entire memory state.
- Gradient Vanishing in Plateaus: After several high-surprise steps, gradients may vanish in flat optimization regions, causing the model to miss subsequent context shifts.
To preserve temporal coherence across token streams, Titans introduce a momentum accumulator , which maintains a memory of surprise:
Here, is a data-dependent learning rate (controlling momentary surprise absorption), and is a data-dependent momentum decay factor (controlling historical surprise persistence). When a prompt switches topics or contexts, flushes past surprise; when processing cohesive passages, accumulates gradient trajectories.

3. Adaptive Forgetting Gate
Even deep neural networks possess finite parameter capacity. To prevent memory saturation over multi-million-token contexts, Titans integrate an adaptive forgetting mechanism that functions as generalized dynamic weight decay:
The scalar gating parameter is dynamically predicted from input token features :
- When , memory weights are preserved without decay.
- When , the historical memory state is cleared, enabling clean context resets.
Combining the momentum update and forgetting gate yields the complete inner-loop recurrence:
4. Memory Retrieval
To retrieve context relevant to the current query without perturbing the learned parameters, the model computes a query projection and evaluates a pure forward pass through the updated memory state :
The asterisk notation denotes forward evaluation without triggering backward weight updates.
Persistent Memory and Inductive Bias
Contextual memory modules are strictly data-dependent. However, sequence modeling also requires invariant, task-level abstractions (such as syntactic rules, reasoning protocols, or output formatting constraints).
Titans incorporate Persistent Memory, defined as a matrix of learnable, data-independent parameter vectors prepended to the sequence representation:
Persistent memory fulfills three key architectural functions:
- Task Knowledge Storage: It stores static procedural priors independent of input sequence dynamics, behaving analogously to key-value pairs in feed-forward layers ().
- Attention Sink Mitigation: Causal attention mechanisms naturally concentrate disproportionate probability mass on initial sequence tokens (the attention sink phenomenon). Learnable prefix parameters absorb this structural bias without degrading real token embeddings.
- Warm-Start Condition for Neural Memory: Prefix vectors provide stable initial hidden states and projection baselines before long-range sequence context accumulates.
Architectural Integration Variants
Titans explore three architectural topologies for combining neural long-term memory with attention:
1. Memory as Context (MAC)
In the MAC topology, the sequence is partitioned into segments of chunk size . Before processing segment , the previous memory state is queried to retrieve historical context summary .
The retrieved vector is concatenated with persistent memory and the active segment :
The composite representation is passed through full self-attention (), and the resulting contextualized representation is used to update the neural memory for subsequent segments:
MAC enables standard attention to filter which historical information is relevant, preventing redundant token memorization.
2. Memory as Gating (MAG)
MAG processes the input sequence through two parallel branches:
- Branch A executes prefix-augmented sliding-window attention ().
- Branch B executes the neural long-term memory recursion ().
The two representations are combined via learned non-linear gating:
This formulation creates a multi-head hybrid structure where attention heads capture high-frequency local syntax while memory heads maintain broad sequence continuity.
3. Memory as a Layer (MAL)
MAL stacks the neural memory module sequentially within the transformer layer pipeline, alternating between LMM layers and sliding-window attention blocks:
This configuration mirrors hybrid models such as H3 and Griffin, serving as a direct drop-in replacement for standard linear recurrent or convolution blocks.
Hardware-Efficient Parallel Training
A recurring bottleneck for recurrent architectures with test-time updates is execution latency during training. While naive recurrent formulation requires sequential step-by-step weight updates ( sequential operations), Titans leverage chunkwise tensorization and parallel associative scans.
Chunkwise Mini-Batch Formulation
Dividing a sequence of length into sub-chunks of size , the unrolled gradient descent update across a chunk can be expressed in closed algebraic form:
where represents the chunk boundary index, and represents cumulative forgetting decay factors.
For linear memory weights , the intra-chunk gradient sum collapses into matrix multiplications over chunk matrices :
where and encodes decay ratios.
Because the momentum recurrence is a first-order linear recurrence over pre-computed gradient terms , it satisfies associative properties. It is computed across GPU/TPU hardware using a parallel associative scan, maintaining span complexity per chunk and saturating tensor core matrix multiplication units.
Theoretical Expressivity and Empirical Evaluation
Beyond Circuit Complexity
Standard Transformers (without chain-of-thought) and diagonal linear recurrent models (such as Mamba, S4, and DeltaNet) are theoretically constrained to the circuit complexity class for constant-depth configurations. Consequently, they cannot solve certain multi-step state tracking problems (such as parity checks or graph connectivity) without intermediate reasoning tokens.
- Theorem 4.1: Titans equipped with deep neural memory modules transcend the complexity barrier, providing strictly higher computational expressivity for dynamic state tracking and algorithmic sequence modeling.
Empirical Benchmarks
Experimental evaluations across language modeling, long-context retrieval, genomics, and time-series benchmarks demonstrate:
- Needle-In-A-Haystack and BABILong: Titans scale effectively beyond 2,000,000 (2M+) tokens in context window length, achieving near-perfect retrieval accuracy where standard sliding-window Transformers, Mamba-2, and linear recurrent baselines experience catastrophic recall decay.
- Language Modeling Perplexity: Across standard pre-training benchmarks (such as The Pile and SlimPajama), Titans achieve lower validation perplexity than LLaMA-style Transformers and Mamba architectures at equivalent parameter and FLOP budgets.
- Ablation on Deep Memory: Multi-layer non-linear memory modules () systematically outperform single-layer linear memory matrices (), validating the necessity of deep non-linear parameter spaces for complex historical context compression.
Conclusion and Future Directions
Titans demonstrate that the dichotomy between attention mechanisms and recurrent compression is not insurmountable. By framing long-term memory as an online optimization process driven by surprise gradients, momentum accumulators, and adaptive forgetting, Titans offer a principled foundation for million-token context processing with constant inference memory footprints and parallel training throughput.
Sources
- Behrouz, Zhong, & Mirrokni (2025). Titans: Learning to Memorize at Test Time. arXiv:2501.00663
- Sun et al. (2024). Learning to (Learn at Test Time): RNNs with Expressive Hidden States. arXiv:2407.04620
- Dao & Gu (2024). Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality. arXiv:2405.21060
- Yang et al. (2024). Gated Linear Attention Transformers with Hardware-Efficient Training. arXiv:2312.06635
- Vaswani et al. (2017). Attention Is All You Need. NeurIPS 2017
- Sukhbaatar et al. (2019). Augmenting Self-Attention with Persistent Memory. arXiv:1907.01470
