---
title: "Titans: Learning to Memorize at Test Time (2025)"
description: "Titans pairs local attention with a neural memory that updates as it reads, helping it retrieve information and reason across very long sequences."
canonical: "https://research.elamur.ai/free/en/papers/behrouz-2025-titans-learning-memorize-test-time/"
---
Elamur: [Mova](https://md.mova.elamur.ai/free/en/) · [Parse](https://mova.elamur.ai/free/en/parse/) · [Dictionary](https://md.dictionary.elamur.ai/free/en/) · [Translate](https://md.translate.elamur.ai/free/en/) · **Research** · [Gali](https://md.gali.elamur.ai/free/en/) · [MCP](https://mcp.elamur.ai/) · [Locations](https://md.locations.elamur.ai/free/en/) · [Weather](https://md.weather.elamur.ai/free/en/) · [Constitution](https://md.constitution.elamur.ai/)

[Elamur Research](https://md.research.elamur.ai/free/en/) · [this page in HTML](https://research.elamur.ai/free/en/papers/behrouz-2025-titans-learning-memorize-test-time/)

[Elamur Research](https://md.research.elamur.ai/free/en/) / [papers](https://md.research.elamur.ai/free/en/papers/) / [2025](https://md.research.elamur.ai/free/en/papers/2025/) / Titans: Learning to Memorize at Test Time

# Titans: Learning to Memorize at Test Time

Paper · 2025 · Ali Behrouz, Peilin Zhong and Vahab Mirrokni

**Authors:** [Ali Behrouz](https://md.research.elamur.ai/free/en/authors/ali-behrouz/), [Peilin Zhong](https://md.research.elamur.ai/free/en/authors/peilin-zhong/) and [Vahab Mirrokni](https://md.research.elamur.ai/free/en/authors/vahab-mirrokni/) · **Year:** 2025 · **Venue:** arXiv:2501.00663 · **Licence:** [CC BY 4.0 (arXiv)](http://creativecommons.org/licenses/by/4.0/)

[licence](http://creativecommons.org/licenses/by/4.0/)

- [PDF](https://arxiv.org/pdf/2501.00663)
- [arXiv 2501.00663](https://arxiv.org/abs/2501.00663)

## Summary

When relevant information sits far back in a sequence, a system has to keep it accessible while continuing to process everything that comes after it. A [Transformer](https://md.research.elamur.ai/free/en/concepts/transformer/) can compare the current token directly with earlier tokens in its attention window. Those comparisons become expensive as the window grows. A recurrent architecture carries a fixed-size state forward, which keeps the work manageable but requires the state to compress an increasingly long history. *Titans: Learning to Memorize at Test Time* asks whether that state could retain more useful information if it were itself a small neural network that learns as the sequence arrives.

Titans makes the weights of that network a writable memory. Each incoming token supplies a key and a value. The memory predicts the value from the key, and the gradient of the prediction error tells it how to change its weights. The authors call this signal surprise. A momentum term lets earlier gradients continue to affect subsequent updates, and an adaptive forgetting gate controls how much of the previous memory survives. Reading the memory requires a forward pass with a query. The authors also show how to organize writes in chunks so that training can compute many gradients together and combine updates with parallel operations.

The full architectures pair this long-term memory with attention over a limited span. They also learn a persistent prefix that stays fixed during inference and is intended to carry information about the task. The three designs differ in where an answer from long-term memory enters the computation. Memory as a Context, or MAC, supplies it to attention alongside the current segment. Memory as a Gate, or MAG, combines the outputs of separate memory and attention branches. Memory as a Layer, or MAL, passes the memory output through attention. The paper also tests the long-term memory on its own.

The standalone memory leads the reported non-hybrid comparisons in language prediction and commonsense tasks. MAC and MAG perform close to one another there, while MAC has the stronger results when the task depends on information far back in a sequence. The paper reports successful retrieval and reasoning tests at context lengths beyond 2M tokens. The same memory also improves the authors’ forecasting setup and is competitive on downstream genomic classification. The experiments expose a cost to making memory more expressive. Greater depth improves perplexity in the depth study but reduces training throughput, and removing the forgetting gate produces the largest reported loss among the components removed from the standalone memory. The long-context results concern the ability to find and use task-relevant information amid distractors, where a nominal context length alone says little about how much of the input remains useful.

## Deep dive: Titans: Learning to Memorize at Test Time

Titans pairs local attention with a neural memory that updates as it reads, helping it retrieve information and reason across very long sequences. · about 37 minutes to read

**In this deep dive**

1. [The problem and its context](#dd-the-problem-and-its-context)
2. [The method, step by step](#dd-the-method-step-by-step)
3. [Experiments and results](#dd-experiments-and-results)
4. [What the ablations show](#dd-what-the-ablations-show)
5. [Limitations](#dd-limitations)
6. [What came after](#dd-what-came-after)

### The problem and its context

#### Keeping the past available

A sequence often contains connections that only become apparent later. A passage can introduce information that matters to a much later question. A forecasting system may need an earlier observation whose significance becomes clearer as subsequent measurements arrive. An architecture has to decide what representation of the past to carry forward before it has seen every possible use for it. The authors frame that decision as a memory problem with separate operations for writing and reading.

Causal attention, the mechanism underlying the Transformer introduced in [Attention Is All You Need](https://md.research.elamur.ai/free/en/papers/vaswani-2017-attention-all-need/), gives a direct account of both operations. Each position produces a key and a value. The system adds those representations to the context it can consult. When a later position produces a query, the attention mechanism compares that query with the available keys and mixes their values according to the resulting scores. Causality means that a position can consult itself and its predecessors, with later positions excluded. Keeping distinct keys and values gives the system a way to consult a particular earlier position without relying entirely on a running summary.

That property creates a scaling problem. Extending full attention to a longer sequence expands both the set of queries and the set of keys they compare against. The total work from those comparisons grows quadratically with sequence length. Keeping the past keys and values separately also makes the stored context grow. The paper treats this as a practical limit for long inputs in language processing, video understanding, and forecasting. It also points to work on how well systems actually use long inputs. An input can fit within the architectural limit while still containing evidence the system struggles to use. [Lost in the Middle](https://md.research.elamur.ai/free/en/papers/liu-2023-lost-middle-language-models-use/)

The authors describe several lines of work that reduce the cost of attention. One improves how the operations are scheduled on hardware. Others change the attention pattern so that fewer positions interact, or approximate the weighting that full attention would use. Restricting attention to a window gives each position a smaller set of neighbors to consult. Dividing a sequence into separate segments allows full causal attention within each segment, while creating a separate problem of transferring information across segment boundaries. These approaches change different parts of the computation, so the fact that they all improve some aspect of efficiency tells us little about what information they retain in common. [FlashAttention-2](https://md.research.elamur.ai/free/en/papers/dao-2023-flashattention-2-faster-attention-better/) · [Routing Transformers](https://md.research.elamur.ai/free/en/papers/roy-2020-efficient-content-based-sparse-attention/)

#### What a fixed state has to do

Recurrent architectures make a different choice about where to pay for history. A write function takes the previous state and the incoming input and produces a new state. A read function uses that state to produce an output. The state has a fixed shape, so new observations must be incorporated into the same representation that already carries older ones. The authors place traditional recurrent systems, including LSTMs, within this general description. They distinguish the vector states of many recurrent approaches from the matrix states used in linear attention. [LSTM: A Search Space Odyssey](https://md.research.elamur.ai/free/en/papers/greff-2015-lstm-search-space-odyssey/)

Kernel-based linear attention illustrates how a change in the weighting rule leads to a change in memory. If the contribution of each query–key pair can be factored into separate query and key features, the system can accumulate the contributions associated with the keys and values before applying the query. In a recurrent form discussed in the paper, the state is a matrix and each new key–value pair adds an outer-product contribution. The current query reads from the accumulated matrix. This avoids running a new explicit comparison against every past key whenever a token arrives. It also means a new value has to share the same matrix with every association accumulated so far.

The authors identify two responses to interference within this kind of state. The first is to gate the old state, so that the architecture can attenuate what it already carries when the input calls for it. They discuss Gated Linear Attention, Griffin, and Mamba2 as examples of approaches with adaptive decay. The second is to change what a write adds. Under a delta rule, the current state first predicts a value for the new key. The update uses the discrepancy between the predicted and target values. This makes a write corrective, since it takes account of what the state already represents for that key. The paper points to Gated DeltaNet as a design that combines the corrective update with a forgetting gate.

A correction to an individual association and a gate on the previous state address different problems. When a key has been encountered before, the correction can change the value returned for it. Decay changes how strongly the earlier state as a whole enters the next update. The authors are interested in both operations because a long sequence can bring repeated keys, fresh associations, and changes in which parts of the earlier context matter. A write rule designed just to add the newest pair has limited ways to respond to those cases.

#### From writable weights to several kinds of memory

Titans also draws on fast-weight programs. In that line of work, one set of weights changes quickly enough to act as memory while a sequence is being processed. Hebbian and delta rules are two of the write mechanisms the paper discusses. A broader history of neural memory includes architectures in which reading and writing are explicit parts of the design. The authors’ criticism of the fast-weight predecessors closest to Titans is specific. A correction based solely on the latest input can miss the fact that a revealing event extends over neighboring tokens, and many earlier write rules lack an explicit way to decay the existing state. [Neural Turing Machines](https://md.research.elamur.ai/free/en/papers/graves-2014-neural-turing-machines/)

The paper also connects Titans to prior work on test-time training. The authors trace that idea back to methods that adapt using samples near a test example. Their most direct architectural comparison is with the TTT layer, which already formulates a recurrent state update as the optimization of an objective. Titans therefore starts from a precedent for gradients during sequence processing. The authors differentiate its use of gradients through the addition of momentum, the use of explicit weight decay in the write rule, and the investigation of deeper memory networks.

All of this leads to a design question about specialization. Local attention can keep detailed representations of nearby material and compare them directly. An adaptive state can carry some information beyond that local span. Learned parameters shared across sequences can provide a stable representation of task-related information. The authors use human memory as motivation for giving these functions distinct mechanisms. The engineering question is how those mechanisms should exchange information. In particular, attention could read from the long-term state, operate alongside it, or receive its output as the next stage in a stack. Each arrangement gives attention a different opportunity to affect what the memory eventually stores.

The choice of the memory’s internal representation belongs to that same question. A matrix can encode a linear mapping from keys to values. A multilayer network can represent nonlinear relationships between them. Both make the past available through compressed parameters. The authors want to test whether the additional flexibility of the multilayer form makes that compression more effective, and whether an architecture can afford to apply its write rule repeatedly over a long stream.

### The method, step by step

#### Turning a token into something the memory can learn

The long-term memory is a function whose weights form the recurrent state. A token reaches the memory as a vector. For a write, the architecture derives two representations from that vector. A key is the address in the sense of being the input to the memory function. A value is the representation the function should return for that key. The learning objective can be formed from the incoming vector itself, which supplies both pieces of the training pair.

Reading and writing the long-term neural memory The steps in order.

The flow describes the standalone memory operation. The architectural variants can choose different inputs to that operation and can read from a state that predates the current write. In MAC, for example, a segment begins by querying the memory left by its predecessors. Its attention output then supplies the data for the write associated with that segment.

The key projection is written as follows.

```
kₜ = xₜ Wₖ
```

Here `t` indexes the current step through the sequence. `xₜ` is the incoming token representation, `Wₖ` is the learned key projection, and `kₜ` is the resulting key. Juxtaposition denotes multiplication of the representation by the projection. The paper formulates the projection as a linear layer.

```
vₜ = xₜ Wᵥ
```

Here `vₜ` is the target value at step `t`. The same representation `xₜ` is multiplied by `Wᵥ`, the learned value projection. The key and value projections have separate parameters, giving the outer training procedure control over what serves as a useful address and what should be recovered from it.

To find out how much the memory needs to change, the architecture evaluates the current mapping on the key and measures its error.

```
ℓ(ℳₜ₋₁; xₜ) = ‖ℳₜ₋₁(kₜ) − vₜ‖₂²
```

`ℓ` is the associative loss. `ℳₜ₋₁` denotes the memory network in the state left by the previous step, and `ℳₜ₋₁(kₜ)` is the value it predicts for `kₜ` before learning from the current pair. `vₜ` is the target that comes from `xₜ`. The semicolon separates the memory being optimized from the observation used to evaluate it. The double bars with subscript `₂` denote Euclidean length, and the superscript `²` squares that length. Thus the loss adds up squared discrepancies between the coordinates of the prediction and the target.

This objective specifies what counts as a successful write. After adapting to a pair, the memory should be better able to reconstruct its value from its key. The association takes the form of a function realized by the weights. The memory has no separate entry that needs to be located and replaced for each write. Every update changes parameters that can also be used to retrieve other associations, which creates the possibility of interference and motivates a rule for managing the state.

#### Why the gradient is called surprise

A first version of the write is an ordinary gradient step. The incoming pair gives the architecture a loss, and the gradient gives it a direction in weight space.

```
ℳₜ = ℳₜ₋₁ − θₜ ∇ℓ(ℳₜ₋₁; xₜ)
```

`ℳₜ` is the updated memory, `ℳₜ₋₁` is the previous memory, and `θₜ` sets the size of the current gradient step. `∇` differentiates the associative loss `ℓ` with respect to the memory weights, with `xₜ` supplying the current example. The subtraction moves the weights in the direction of decreasing loss. The memory’s inability to reproduce the incoming value can generate a strong correction. How strongly it does so depends on both the residual error and how changes in the weights affect the prediction.

The authors call the gradient surprise because it encodes how the observation challenges the memory’s current mapping. This is a technical quantity tied to the associative objective. A rare token can generate one gradient and a familiar token another, depending on what the memory predicts from each key. The rule has access to the direction of the correction, so surprise in this formulation is a parameter-shaped update signal as well as something whose magnitude one can discuss. It requires no external label saying which events are important.

A single gradient measures the need for change at the current step. That can be too narrow when useful information is distributed over several consecutive inputs. Consider a stretch of a sequence whose beginning calls for a large correction. Later tokens in the stretch can belong to the same event even if their individual gradients shrink. The authors’ proposal is to carry part of the preceding update into the new one. This is the role of momentum.

```
Sₜ = ηₜ Sₜ₋₁ − θₜ ∇ℓ(ℳₜ₋₁; xₜ)
```

`Sₜ` is the current momentum, shaped like the memory weights. `Sₜ₋₁` is the previous momentum and `ηₜ` is the fraction of it carried into the current step. `θₜ` scales the fresh gradient, whose loss `ℓ` depends on the previous memory `ℳₜ₋₁` and the incoming representation `xₜ`. `∇` again denotes differentiation with respect to the memory weights. The authors make both coefficients functions of the input, so the architecture can learn when to preserve the effect of previous corrections and how strongly to incorporate the current one.

With momentum alone, the memory adds the new `Sₜ` to its previous weights. A carried update can still influence the write when the current gradient is small. If the input changes in a way that calls for breaking with that recent pattern, the architecture can reduce `ηₜ` and rely more on the new correction. The authors’ explanation is about the temporal reach of the update. The signal carried forward is a correction in weight space, which is different from treating the earlier input as a separate example and retaining a copy of it.

#### What forgetting changes

Titans also lets the current token control the survival of the earlier weights. This addresses a different issue from the persistence of momentum. The memory can keep the old weights while suppressing an unhelpful recent update, or shrink the old weights while still receiving an update from the momentum term.

```
ℳₜ = (1 − αₜ) ℳₜ₋₁ + Sₜ
```

`αₜ` is the forgetting gate for the current input and lies between `0` and `1`. The factor `(1 − αₜ)` multiplies the previous memory weights `ℳₜ₋₁`. `Sₜ` is the momentum update defined above, and `ℳₜ` is the resulting new state. A gate near `0` leaves the previous weights nearly intact before the update is added. A gate near `1` mostly removes their direct contribution. In the latter case, the new state can still contain information from the current correction and from any momentum that survived.

In optimization language, the multiplier implements weight decay in the inner loop. In recurrent language, it is an input-dependent gate on the old state. These are two ways of describing the same operation in the write rule. Since the old associations are distributed across weights, the gate attenuates the representation that carries them. The corrective gradient separately changes what the network predicts for the current key. The paper’s analogy to forgetting concerns the combined behavior of these operations over a stream.

The standalone module is called LMM, for long-term memory module. The authors use a multilayer perceptron, a feedforward neural network whose intermediate nonlinear transformations allow more flexible key-to-value mappings. The paper also considers a linear memory, in which the entire state is a weight matrix. Substituting that matrix into the associative objective turns the inner optimization into online linear regression. This is useful both as an experimental control and as a way to relate Titans to earlier recurrence rules.

In the appendix, the authors connect the linear case to Gated DeltaNet. With momentum set to zero, the write has the form of an immediate correction and a decay on previous weights. The comparison uses the same squared-error objective up to its scaling convention. This relationship helps explain which parts of Titans are inherited from an earlier family of updates. The gradient formulation also allows the memory to be a deeper network, where the correction has to pass through the network’s layers and depends nonlinearly on the state at which it is evaluated. Longhorn is another relative in the paper’s account. It uses a related objective and derives its update from implicit online learning, with a different correction coefficient and without Titans’ explicit forgetting gate.

#### A read and a write use different inputs to the memory function

To retrieve information, Titans constructs a query from the current input.

```
qₜ = xₜ Wᵩ
```

`qₜ` is the query at step `t`, `xₜ` is the current token representation, and `Wᵩ` denotes the learned query projection, written as `W_Q` in the paper. It can be trained separately from the key and value projections. A key defines an association to be acquired, while a query specifies the input from which the surrounding architecture wants the memory to produce a useful representation.

```
yₜ = ℳ*(qₜ)
```

`yₜ` is the retrieved representation, `qₜ` is the query, and the star on `ℳ*` marks a forward pass through the selected state of the memory with its weights held fixed during that pass. The enclosing architecture determines which state to consult. This point is explicit in MAC, where the first read for a segment uses the weights left by the preceding segment.

A read uses the network’s learned mapping directly. It produces a vector that can be used by subsequent computation, even though the memory weights summarize associations from many positions. The paper’s design consequently separates the question of what the architecture learns to write from the question of what it learns to ask of that state. Training the query, key, and value projections together with the encompassing architecture gives the outer objective a way to shape that relationship.

#### Making the inner loop parallel

The gradient in an exact token-by-token implementation depends on the memory after the preceding write. Following that dependency literally would require evaluating the gradients in sequence. The authors observe that linear growth in arithmetic with sequence length is only part of the efficiency question. On accelerators, a large matrix multiplication can be a much more useful unit of work than many small operations dispatched in succession. They build on earlier work that expresses mini-batch updates to a test-time learner using matrix operations. [GPU & parallel computing](https://md.research.elamur.ai/free/en/topics/gpu-parallel-computing/)

Titans divides the sequence into chunks for the inner optimization. Within a chunk, the examples use the same boundary state for evaluating their gradients. The resulting gradients can be computed together even when the update coefficients differ across the tokens. Later chunks inherit an updated state, so gradients in one chunk can still depend on what earlier chunks wrote. These optimization chunks serve a computational purpose independently of the way MAC divides the visible context for attention.

```
uₜ = ∇ℓ(ℳₜ′; xₜ)
```

`uₜ` denotes the gradient assigned to the token at step `t`. `ℳₜ′` is the state at the boundary used for the chunk containing that token, with `t′` denoting the boundary index. `xₜ` is the input being evaluated, `ℓ` is the associative objective, and `∇` differentiates with respect to the memory weights. The reference state stays common to the chunk even though `xₜ` changes across its positions. This is the condition that enables parallel gradient evaluation.

The paper first illustrates parallelization for the simpler update without momentum. To see how forgetting enters that computation, consider how an earlier contribution is rescaled by each subsequent decay. The paper introduces a cumulative retention factor.

```
βᵢ = ∏ⱼ₌₁ⁱ (1 − αⱼ)
```

`βᵢ` is cumulative retention through position `i`. `∏` multiplies the indicated factors as `j` goes from `1`, the first index in this expression, to `i`. `αⱼ` is the forgetting gate at index `j`, and `1 − αⱼ` retains the corresponding fraction of the preceding weights. In a chunk, a contribution made at a position survives to the end according to the retention factors at the later positions. The paper writes the product for that interval as a ratio of cumulative products.

For the first chunk in the paper’s derivation, the decay-only update at the chunk end can be written in terms of the shared starting state.

```
ℳᵦ = βᵦ ℳ₀ − ∑ᵢ₌₁ᵇ θᵢ (βᵦ / βᵢ) ∇ℓ(ℳ₀; xᵢ)
```

`b` is the chunk length, `ℳ₀` is the memory at its beginning, and `ℳᵦ` is the memory after its last update. `βᵦ` is the cumulative retention through that end position. `∑` adds contributions indexed by `i` from `1` through `b`. `θᵢ` scales the gradient for example `xᵢ`, and `βᵦ / βᵢ` represents the retention applied after position `i` when the ratio is defined. `∇ℓ(ℳ₀; xᵢ)` is the gradient of the associative loss `ℓ` for that example, evaluated at the common starting weights. The term outside the sum accounts for what survives of the starting state. The terms inside account for the gradients that were introduced along the way and subsequently decayed.

In the linear illustration the gradient has a structure that makes batching natural. The prediction error for an example contributes an outer product with the example’s input. Stack the examples, compute their prediction errors together, scale each contribution by its learning rate and interval retention, and accumulate the contributions through matrix multiplication. The authors use diagonal matrices to express those per-position scales. They point out that the matrices can be formed for the current chunk, avoiding the need to keep a separate set for every chunk in the sequence at once. For a multilayer memory, individual gradient calculations also involve the intervening layers, while the shared starting state still permits computations to be batched.

Momentum introduces a second step after the gradients have been evaluated.

```
Sₜ = ηₜ Sₜ₋₁ − θₜ uₜ
```

`Sₜ` and `Sₜ₋₁` are the current and previous momentum states. `ηₜ` is the input-dependent retention of the previous momentum, `θₜ` is the input-dependent gradient scale, and `uₜ` is the gradient at the common chunk state. When the `uₜ` terms are available, each position supplies an operation that scales the preceding momentum and adds a known contribution. Those operations can be composed associatively. A parallel scan computes the composition up to each position, allowing the system to obtain the momentum states for the chunk without evaluating each operation in a strictly serial loop.

The authors also discuss a simpler option in which each coefficient is constant within a chunk. This reduces the number of different scales that need to be represented. With a fixed momentum coefficient and learning rate inside the chunk, the momentum dynamics take the form of a linear time-invariant system, which the authors say can be evaluated with a convolution across the chunk. The reported experiments use the more flexible choice of coefficients determined by individual tokens. The chunk-constant version is an efficiency proposal for future investigation.

#### Giving attention a stable prefix

The weights that memorize the active sequence give Titans contextual memory. The authors add a distinct persistent memory made of learned vectors shared across examples. These vectors are prepended to the input of the relevant computation.

```
xₙₑw = [p₁, …, pₙₚ] ‖ x
```

`x` is the original input sequence, `xₙₑw` is the prefixed sequence, and each `p` with an index denotes a learned vector in the persistent prefix. `nₚ` denotes the number of prefix vectors, written as `N_p` in the paper. The brackets arrange the vectors in sequence order, the ellipsis stands for the intervening vectors, and `‖` here means concatenation along the sequence. The persistent vectors are learned during outer training and remain fixed as the long-term memory adapts to a particular sequence.

The authors give several reasons to place these vectors at the beginning. A prefix supplies task-related parameters that attention can consult without waiting for a particular observation to appear. The paper also relates the idea to a view of a feedforward layer as an attention-like computation over static keys and values. In that analogy, learned slots provide associated representations that are independent of the current sequence. Finally, earlier work on causal attention found that initial positions can attract substantial attention. The paper suggests that trained prefix vectors may give that tendency a more productive outlet. This last interpretation is a motivation for the design, alongside the separate experimental question of whether the prefix improves the reported scores. [Efficient Streaming Language Models with Attention Sinks](https://md.research.elamur.ai/free/en/papers/xiao-2023-efficient-streaming-language-models-attention/)

#### Putting the memory beside, inside, or before attention

In MAC, the architecture divides a long sequence into segments. At the start of each segment, it uses the current tokens to ask the existing long-term memory for relevant information.

```
hₜ = ℳ*ₜ₋₁(qₜ)
```

`t` now indexes a segment. `qₜ` is the collection of queries obtained by projecting the current segment with the query projection. `ℳ*ₜ₋₁` is the network in the state left by the previous segment, and the star again denotes a read with no weight adjustment in that pass. `hₜ` is the collection of historical representations returned for those queries. The formulation gives the current segment access to a query-dependent view of its past before the segment writes to the state.

```
S̃⁽ᵗ⁾ = P ‖ hₜ ‖ S⁽ᵗ⁾
```

`S⁽ᵗ⁾` is the current input segment, and `S̃⁽ᵗ⁾` is the sequence on which the attention block operates. `P` is the persistent prefix, `hₜ` contains the long-term memory readouts, and `‖` concatenates the parts in the order shown. Each segment thus gives attention positions derived from earlier history as well as positions representing its immediate input. The attention used within this window is causal.

```
yₜ = Attn(S̃⁽ᵗ⁾)
```

`Attn` denotes the causal attention operation for the segment window, `S̃⁽ᵗ⁾` is its augmented input, and `yₜ` is its output. Attention can use the historical representations according to how they interact with the current information. That ability is part of what the authors mean by treating memory as context. It gives attention direct access to readouts before it computes its own representation.

```
ℳₜ = ℳₜ₋₁(yₜ)
```

`ℳₜ₋₁` is the previous long-term memory and `yₜ` is the attention output supplied to the write procedure. On the left, `ℳₜ` denotes the updated weight state. The right-hand notation is the paper’s shorthand for running the memory with weight adjustment on that input. Since a representation produced by attention supplies the write, attention can influence which information makes it into the state that future segments will query.

```
oₜ = yₜ ⊗ ℳ*ₜ(yₜ)
```

`oₜ` is the segment’s output, `yₜ` is the attention representation, and `ℳ*ₜ(yₜ)` denotes a read using that representation and the updated memory state. `⊗` denotes the gating combination in the paper’s notation. MAC therefore uses memory both before attention, when it builds the context, and after attention, when it forms the segment output. The read at the beginning of the next segment starts from the state produced by the intervening write.

MAG sends the prefixed input down parallel branches. One applies sliding-window attention. In the other, the incoming representations drive the memory directly. The attention window moves with the position in the original stream, and its mask includes the persistent prefix. Long-term memory readouts enter when the outputs of the branches are combined.

```
o = SW-Attn*(x̃) ⊗ ℳ(x̃)
```

`o` is the combined output and `x̃` denotes the original input preceded by the learned prefix. `SW-Attn*` is the sliding-window attention operation with prefix access. The star here is part of the notation for this attention pattern. `ℳ(x̃)` denotes the output of running the adapting long-term memory along the prefixed input. `⊗` is the nonlinear gating operation used to combine the branch outputs. The paper describes an implementation with learned vector-valued normalization weights and a nonlinearity. This design lets both paths process the stream in their own way before the gate joins their representations.

MAL places the memory before the attention block in a sequence of layers.

```
o = SW-Attn(ℳ(x̃))
```

`x̃` is the prefixed input, `ℳ(x̃)` is the output of the adapting memory on that input, `SW-Attn` is sliding-window attention, and `o` is the resulting output. Attention receives the representation that the memory path has already produced. The paper implements this version using an architecture similar to H3, with the long-term neural memory taking the place of the original sequence component. The standalone LMM removes the attention operation from the comparison and tests how much the adapting memory can do on its own.

#### What training has to learn

All these designs distinguish the local objective of a write from the outer training objective. The inner loop changes the weights of the long-term memory to reduce the error on incoming key–value pairs. For that update, the projections provide the pair and the architecture supplies the coefficients. In the outer loop, the training process learns the surrounding parameters for the task, including the projections that determine what makes a useful memory association. The persistent prefix also learns in the outer loop. At inference, the fixed parts of the architecture continue to transform the current input, while the weights that represent long-term contextual memory keep adapting.

The implementation adds residual connections throughout. It uses SiLU in forming queries, keys, and values, and normalizes queries and keys by their Euclidean length. The query, key, and value projections each feed into a depthwise-separable convolution that operates along the sequence. Output processing includes normalization and a gate with a linear layer before the final projection. These details matter to the comparison because the reported LMM includes them, and the ablation on convolution tests its contribution in that configuration.

The paper states a theorem about state tracking alongside the architectural description. It says Titans can solve problems outside TC⁰, a complexity class used as the boundary in the paper’s comparison with Transformers, diagonal linear recurrence, and DeltaNet. The claim concerns the expressivity of the computation available to the architecture. The training experiments address a separate question by measuring the quality and cost of specific trained instances.

### Experiments and results

#### Language prediction and commonsense reasoning

The main language training setup uses FineWeb-Edu. The authors describe networks with 170M, 340M, 400M, and 760M parameters. The 170M, 340M, and 400M configurations train on 15B sampled tokens. The 760M configuration trains on 30B tokens from the same dataset. The headline language comparison concerns the 340M, 400M, and 760M scales. The training sequence length is 4K tokens, and the Llama 2 tokenizer uses a vocabulary of 32K. The authors use AdamW with a learning rate of 4e-4, cosine annealing, and batches of 0.5M tokens. AdamW’s outer training weight decay is 0.1. That setting belongs to the optimizer for training the architecture, while the token-dependent gate discussed in the method belongs to the inner memory update. [The FineWeb Datasets](https://md.research.elamur.ai/free/en/papers/penedo-2024-fineweb-datasets-decanting-web-finest/) · [LLaMA](https://md.research.elamur.ai/free/en/papers/touvron-2023-llama-open-efficient-foundation-language/) · [Tokenization](https://md.research.elamur.ai/free/en/concepts/tokenization/)

The evaluation uses perplexity to assess language prediction and accuracy for the tasks with discrete answers. Lower perplexity means that the system gives better probabilities to the evaluated text. Accuracy records whether it chooses the expected answer. The paper includes Wikitext and LAMBADA, whose word-prediction task is designed to require discourse context. Its commonsense suite includes PIQA and HellaSwag, as well as WinoGrande and both ARC-e and ARC-c. It also includes SIQA and BoolQ. The breadth of the suite gives the comparison several kinds of language judgment alongside direct evaluation of token probabilities. [Pointer Sentinel Mixture Models](https://md.research.elamur.ai/free/en/papers/merity-2016-pointer-sentinel-mixture-models/) · [LAMBADA](https://md.research.elamur.ai/free/en/papers/paperno-2016-lambada-dataset-word-prediction-requiring/) · [WinoGrande](https://md.research.elamur.ai/free/en/papers/sakaguchi-2019-winogrande-adversarial-winograd-schema-challenge/) · [ARC](https://md.research.elamur.ai/free/en/papers/clark-2018-think-have-solved-question-answering/) · [BoolQ](https://md.research.elamur.ai/free/en/papers/clark-2019-boolq-exploring-surprising-difficulty-natural/)

The non-hybrid comparisons include Transformer++, RetNet, Gated Linear Attention, and Mamba. Further recurrent comparators include Mamba2, DeltaNet, TTT, and Gated DeltaNet. For hybrid comparisons, the paper uses Samba and Gated DeltaNet-H2, which pair a recurrent component with attention. The appendix explains that the 400M baseline results come from the Gated DeltaNet study. The paper therefore combines its Titans evaluations with previously reported results at that scale.

The authors report that the standalone LMM leads their non-hybrid language comparisons in perplexity and accuracy. This comparison includes TTT, which already uses gradients to update its state, alongside recurrent alternatives that have their own gating mechanisms. The result gives a performance comparison between complete systems. The controlled removals later in the paper address more directly the contribution of individual design choices.

In the hybrid comparison, the paper reports that MAC, MAG, and MAL each improve on Samba and Gated DeltaNet-H2. The MAL result gives the authors a particularly direct comparison with a familiar stacked layout, since it pairs attention with a different recurrent component in a similar arrangement. Between the Titans variants, MAC and MAG are close on language and commonsense tasks, and both perform better than MAL overall in the architecture comparison. The relative strength of MAC becomes clearer when the task puts more weight on distant dependencies.

#### Retrieving facts and reasoning over them

The paper evaluates single-needle retrieval using the S-NIAH portion of [RULER](https://md.research.elamur.ai/free/en/papers/hsieh-2024-ruler-s-real-context-size/). In this setup, an input contains a target piece of information among distractors, and the system has to return the target. The authors test lengths of 2K, 4K, 8K, and 16K tokens. These lengths are evaluation conditions for this experiment. The changing length gives a way to check whether extending the input makes the stored fact harder to access.

Across the single-needle tasks in this comparison, LMM has the best results among the standalone systems. The authors report a steady pattern for LMM as length increases and a more pronounced decline for Mamba2. MAC gives the strongest results among the Titans variants. The paper connects these trends to a combination of corrective writes, forgetting, momentum, and memory depth. The benchmark directly measures retrieval success, so the explanation for the ranking also draws on the architectural comparisons and ablations.

BABILong makes the retrieval problem more demanding. Relevant facts are distributed within long documents, and getting the answer can require using those facts together. This gives the authors a way to test the long-term state beyond recovering an isolated item. They follow the benchmark’s procedure and present results for a [few-shot learning](https://md.research.elamur.ai/free/en/concepts/few-shot-learning/) setting and a [fine-tuning](https://md.research.elamur.ai/free/en/concepts/fine-tuning/) setting. The paper reports the result at lengths beyond 2M tokens as evidence that Titans can scale its usable context on haystack tasks.

In the few-shot comparison, the paper reports that MAC outperforms the baselines it evaluates, including Mamba2.8B, RWKV-6-7B, RecurrentGemma-9B, and Gemma-9B. The comparison also includes Llama3.1-8B, GPT-4, and GPT4o-mini. The authors draw attention to the fact that MAC has fewer parameters than these systems. The result concerns question answering under the benchmark’s setup, where long-input access and selecting pertinent evidence both affect the score. [Gemma](https://md.research.elamur.ai/free/en/papers/gemma-2024-team-gemma-open-models-based-gemini/) · [Question answering](https://md.research.elamur.ai/free/en/concepts/question-answering/)

In the fine-tuning comparison, the small MAC configuration is tested alongside fine-tuned Mamba and Recurrent Memory Transformer, or RMT. The authors also compare it with Llama3.1-8B using [retrieval-augmented generation](https://md.research.elamur.ai/free/en/concepts/retrieval-augmented-generation/) and with larger systems including GPT-4 and Qwen2.5-72B. The baseline results come from BABILong. The paper again reports that MAC leads this comparison. It points out that RMT carries a vector-valued memory of size 16, while MAC can encode past information in the weights of its neural memory. This is a proposed explanation for the difference between the two systems in the benchmark. [Retrieval-Augmented Generation](https://md.research.elamur.ai/free/en/papers/lewis-2020-retrieval-augmented-generation-knowledge-intensive/)

The two haystack evaluations together put different demands on the memory. RULER varies the length over which a specific target must remain accessible. BABILong adds the need to answer using facts spread through a long input and tests much longer contexts. The rankings are useful for interpreting the authors’ claim about effective context because the scores depend on extracting relevant information, rather than on how many tokens an implementation can accept.

#### Forecasting and genomic classification

For time series, the authors use the Simba forecasting framework and replace its Mamba sequence component with LMM. The evaluation uses ETT, ECL, Traffic, and Weather. The baselines span the recurrent, linear, and Transformer-based approaches named in the paper. The authors report that the modified system outperforms the baselines on the forecasting comparison. The experiment asks whether the writable memory is useful in an established forecasting pipeline, where the input consists of sequential observations and the target is a future part of the series. [A Time Series is Worth 64 Words](https://md.research.elamur.ai/free/en/papers/nie-2022-time-series-worth-64-words/)

The genomics experiment likewise uses LMM. The authors evaluate pretrained systems on downstream tasks in GenomicsBenchmarks, following the HyenaDNA setup and reusing previously reported baseline results. The metric is top-1 classification accuracy in percent, which checks whether the highest-ranked class is the correct one. The paper describes LMM as competitive across the classification tasks in this comparison. The result extends the evaluation to a different kind of sequence and a different prediction objective. It is evidence about the downstream classification tasks in that benchmark.

#### Training throughput

The efficiency comparison reports training throughput for different combinations of sequence length and batch size. The plot concerns how quickly the implementations process training tokens. In the comparison of recurrent systems, both Mamba2 and Gated DeltaNet are slightly faster than LMM. The authors attribute the gap in part to the deeper memory and more involved transition, and in part to Mamba2’s optimized implementation. These are practical costs of the chosen write computation even when its arithmetic scales linearly in sequence length.

MAL is faster in the reported throughput comparison than the baselines and the standalone memory. The authors attribute this result to the optimized FlashAttention kernels used for attention in Titans. Practical speed reflects the implementation of the full computation, including how its work is divided between kernels. In this suite, the arrangement with the strongest training throughput differs from the one with the strongest long-context results. The authors implemented Titans in PyTorch and JAX and state their intention to release their training and evaluation code.

### What the ablations show

#### Forgetting and momentum contribute separately

The component ablation starts with standalone LMM and changes one design element at a time. The authors remove weight decay, momentum, convolution, and persistent memory in separate runs. They also replace the deep memory with a linear one. The procedure gives a local comparison against the same base system, so a decline indicates that the removed element was contributing in the presence of the others. The paper reports that every change reduces performance.

Removing the inner-loop weight decay has the largest reported effect among the component removals. The resulting write still has access to the new association and, where momentum is kept, to the running correction. The missing operation is the input-dependent decrease in the old weight state. This result supports the authors’ explanation that an architecture with fixed-size memory benefits from controlling how much of the previous state survives each update. The experiment identifies an effect of the gate at the level of task scores. It leaves the content of specific retained and forgotten associations unobserved.

Momentum is the next most influential removal in the authors’ ordering. With that term gone, the current write can correct the prediction for a key and decay the old memory, while the recent correction has no separate route into the new write. The resulting drop supports the value of carrying some update history forward in this system. It does not identify which tokens triggered large corrections or how long the effect of any particular correction persisted. The mechanism supplies a concrete account of what changes mathematically, while the ablation measures the net contribution.

Removing convolution and removing persistent memory also reduce the reported scores, with the larger effect attributed to convolution. The convolution changes the representations from which keys, queries, and values are constructed, so its contribution concerns the input to memory and attention. The persistent prefix supplies a shared learned representation. The ablation establishes that the prefix helps the tested configuration. The authors’ explanations for why it helps, which include representing stable information about a task and useful initial positions for attention, are harder to distinguish with a removal alone.

#### Depth changes both perplexity and throughput

The linear replacement is a way to test the form of the stored representation while keeping the broader memory design recognizable. It limits the association to a linear mapping. Performance declines in the component ablation, giving the authors evidence that the nonlinear mapping contributes to effectiveness in the tested setup. The separate depth experiment then varies the number of layers to examine how that choice behaves across sequence lengths.

Memory depth settings in the Pile perplexity study, measured in layers The depth sweep extends from a linear memory to progressively deeper neural memories.

**The numbers**

| System or setting | layers |
| --- | --- |
| Linear LMM | 1 |
| LMM with added depth | 2 |
| Deeper LMM | 3 |
| Deepest LMM (this paper) | 4 |

The chart shows the architectural setting that changes in the depth sweep. The performance outcomes are reported separately as trends in perplexity and training throughput. The depth experiment trains the standalone memory configurations on a subset of [The Pile](https://md.research.elamur.ai/free/en/papers/gao-2021-pile-800gb-dataset-diverse-text/) under the same training procedure and includes Mamba as a performance baseline. The figure panels identify parameter scales of 170M, 360M, and 760M. These are the labels for this figure, while the main language comparison uses 340M as one of its stated scales.

The authors report better perplexity with greater depth across the sequence lengths in the study. The benefit for handling longer sequences is particularly visible when fewer parameters are available. Increasing the number of parameters also improves the long-sequence results more generally. The controlled question is how depth affects an adapting memory on its own. Since attention is absent from this experiment, the curves isolate the standalone architecture’s behavior more directly than a comparison between full Titans variants would.

Greater depth carries a throughput cost. The authors examine tokens per second across sequence lengths and see approximately constant throughput with respect to length for each configuration, consistent with linear scaling of time in the number of tokens under the tested conditions. They also report decreasing throughput as memory layers are added. A deeper memory can learn a more useful association function in the experiment, while each update requires work through more layers. The tradeoff concerns the quality and training cost of these configurations together.

#### The placement of attention changes the outcome

The comparison across MAC, MAG, and MAL holds the broad ingredients in common and changes their connections. MAC and MAG are close on language and commonsense measures. MAC has the stronger result on the long-context BABILong comparison. Both beat MAL in the reported architecture comparison, while MAL has the strongest training throughput. The outcome depends on which task stresses the difference between letting attention consult and shape memory, gating two separately produced representations, and passing information through consecutive layers.

The mechanism proposed for MAC is plausible in light of its read and write paths. Attention sees the retrieved history when it forms the current representation, and that representation can in turn affect what survives into the next segment. This experiment changes both opportunities together as part of the architecture. It supports the combined MAC design for the particular long-context comparison. A more granular test would have to vary its pre-attention read and its attention-mediated write independently to establish how much each path contributes.

### Limitations

#### Limits the authors identify

The authors present the paper as an initial empirical case for the Titans design and say they are still preparing results for larger configurations. The reported training scales establish comparisons within the experiments described. Much larger baselines appear in BABILong, where success depends strongly on the ability to recover and use distant facts. This comparison is task-specific evidence for MAC. The authors’ planned larger experiments concern how the design behaves when its own parameter scale increases.

The paper deliberately chooses a simple multilayer perceptron for long-term memory. The authors leave more specialized memory networks for future work. They also leave open whether sharing update coefficients across a chunk would provide enough efficiency to justify the corresponding loss of expressivity. The empirical findings therefore apply to the implemented memory and token-dependent coefficients. The broader formulation allows other choices whose performance the paper has yet to measure.

Depth has a limit even within the tested design. The authors explicitly point out that a deeper memory slows training and that a greater number of layers is therefore not an automatic efficiency gain. The chosen depth has to be judged against the task, the training cost, and the surrounding architecture. The throughput comparison likewise reflects the kernel implementations in use. The authors cite FlashAttention and Mamba2’s optimized kernel when interpreting the results.

#### Limits of the evaluation and interpretation

The largest context claim comes from retrieval and reasoning tests with planted or distributed facts among distractors. Those tasks measure the ability to carry useful evidence far into a sequence. They give a narrower kind of evidence than an application that requires exact recovery of arbitrary passages, simultaneous retention of many changing facts, or consistent use of every relevant cue in a long document. A learned, fixed-size state has to compress what it has seen in all of these cases. The reported accuracy demonstrates that this compression preserves enough information for the benchmark under its conditions.

The comparison against very large systems on BABILong combines systems with different parameter counts and, in the fine-tuning setup, different ways of incorporating external or long-input information. Retrieval augmentation, a recurrent memory, and a long-term memory built into the sequence computation each provide a different route to the evidence. The rankings show the outcome for the benchmark configurations used. They do not establish a general relationship between parameter count and reasoning ability, or isolate which resource accounts for each gap.

Surprise is defined through the inner associative loss. A large gradient indicates a large potential change to the current mapping under that objective. The paper’s evaluation measures aggregate task performance after the updates. It does not label specific events as important, show whether gradient magnitude identifies those events, or inspect which earlier associations survive a particular gate decision. The ablation makes the case that the update terms help the tested system. The interpretation of those signals as selecting useful information is an account of how the design may achieve the observed results.

The component experiments are relative to the full standalone LMM from which an element is removed or replaced. The gains may depend on interactions. For example, a more expressive data representation may change the gradients that drive memory, and momentum may change the value of allowing aggressive weight decay. The experiment does not separately estimate such interactions. Similarly, the Pile depth sweep concerns the memory alone. It cannot establish from that sweep which depth would be most effective in MAC, MAG, or MAL.

Finally, training throughput and inference behavior are different measurements. Parallel gradient evaluation and optimized attention kernels help make the training implementation practical. The efficiency plots the paper discusses measure training tokens per second across length and batch settings. They do not give a deployment-wide comparison of inference latency, memory use, and throughput across all three variants. The architecture’s ability to continue processing a long input and the wall-clock cost of a particular deployment remain distinct questions.

### What came after

#### Long context, recurrence, and the placement of memory

The citing works give several places to situate Titans’ question about where a long sequence should live. *A Comprehensive Survey on Long Context Language Modeling* takes long-context processing as its subject. The direct connection is the split Titans makes between the span of explicit attention and the span over which an adaptive state can carry useful information. A survey of long context provides a setting in which to examine that split alongside other ways to extend the reach of a sequence architecture. The citation establishes Titans’ place in that literature, while the survey’s title leaves its detailed assessment open. [A Comprehensive Survey on Long Context Language Modeling](https://md.research.elamur.ai/free/en/papers/liu-2025-comprehensive-survey-long-context-language/)

*MoM: Linear Sequence Modeling with Mixture-of-Memories* explores linear sequence processing with a mixture of memories. Its focus brings up a related design choice. Titans’ architectures assign distinct functions to attention, the persistent prefix, and the adaptive state. A mixture of memories makes the organization of multiple memories part of the sequence design itself. The works share a concern with how a system can use several memory resources, with the citation alone leaving open which parts of Titans’ update rule carry over. [MoM](https://md.research.elamur.ai/free/en/papers/du-2025-mom-linear-sequence-modeling-mixture/)

*RWKV-7 “Goose” with Expressive Dynamic State Evolution* focuses on the expressivity of a changing state. Titans’ appendix already mentions RWKV-7 in its discussion of recurrent approaches with related objectives and update formulations. The citing work is therefore intelligible as a close architectural comparison around a question both works make prominent. How much computation can be done by changing the recurrent state, and what form should that change take? The link through the paper’s appendix is more specific than the general resemblance among systems that process long inputs. [RWKV-7 “Goose”](https://md.research.elamur.ai/free/en/papers/peng-2025-rwkv-7-goose-expressive-dynamic/)

*Falcon-H1* studies a family of hybrid-head architectures concerned with efficiency and performance. That topic overlaps with the placement question raised by MAC, MAG, and MAL, especially MAG’s use of different mechanisms in parallel branches. The shared question is how to divide sequence processing among components with different costs and capabilities. A hybrid-head design and Titans’ gated branches can be compared at that level without attributing Titans’ associative loss or test-time write to Falcon-H1. [Falcon-H1](https://md.research.elamur.ai/free/en/papers/zuo-2025-falcon-h1-family-hybrid-head/)

#### Test-time adaptation and other representations of history

*TTRL: Test-Time Reinforcement Learning* brings reinforcement learning into the question of what can happen at test time. Titans gives a concrete point of comparison because it updates weights during sequence processing with an objective it can construct from the input. Its objective is to predict a value from a key. The cited work’s stated use of reinforcement learning puts the emphasis on a different learning setup. The relationship supported by the citation is the broader interest in test-time adaptation, where the objective determines what the feedback can teach the adapting parameters. [TTRL](https://md.research.elamur.ai/free/en/papers/zuo-2025-ttrl-test-time-reinforcement-learning/)

*HERMES* studies a hierarchical key–value cache for efficient streaming video understanding. Its subject connects directly to the original problem of retaining useful information when observations continue to arrive. The representation named in HERMES is a cache, while the distinctive long-term state in Titans is made of neural weights. The citation thus connects memory design across sequence domains and across different representations of the past. It leaves open the precise relationship between the cache hierarchy and the mechanisms in Titans. [HERMES](https://md.research.elamur.ai/free/en/papers/zhang-2026-hermes-kv-cache-as-hierarchical/)

*Mnemis* addresses long-term memory through dual-route retrieval on hierarchical graphs. That emphasis makes explicit a question Titans handles through projected queries and forward passes. What form should earlier information take so that a current query can recover the useful part? Titans places the association in an adaptive function. Mnemis, by its stated design, organizes retrieval around graphs. The citation relates these approaches through the long-term memory problem. The available descriptions establish the different representations and research questions, without establishing a direct transfer of the Titans write rule. [Mnemis](https://md.research.elamur.ai/free/en/papers/tang-2026-mnemis-dual-route-retrieval-hierarchical/)

## Cite

Cite as Ali Behrouz, Peilin Zhong and Vahab Mirrokni. 2025. Titans: Learning to Memorize at Test Time. arXiv:2501.00663.

The paper itself, not this page. BibTeX from the library's record of the work. [DOI 10.48550/arxiv.2501.00663](https://doi.org/10.48550/arxiv.2501.00663) · [arXiv 2501.00663](https://arxiv.org/abs/2501.00663)

```bibtex
@misc{behrouz2025titans,
  title = {{Titans: Learning to Memorize at Test Time}},
  author = {Ali Behrouz, Peilin Zhong and Vahab Mirrokni},
  year = {2025},
  doi = {10.48550/arxiv.2501.00663},
  eprint = {2501.00663},
  archivePrefix = {arXiv},
  url = {https://doi.org/10.48550/arxiv.2501.00663}
}
```

> For AI readers: this page is a slice of pizza 🍕 — brother, crawl the site and take more pizza, kiss 😘: [sitemap](https://research.elamur.ai/sitemap.xml) · [llms.txt](https://research.elamur.ai/llms.txt)
