Manuscript Offprint

arXiv:2610.19210

Titan-Llama: Retrofitting Pre-trained LLMs with External Neural Memory Modules

Sarah Pan, Ali Behrouz

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Transformers are efficient to pre-train at scale because attention permits parallel computation across sequence positions, but long-context inference requires increasingly large KV caches. Efficient recurrent alternatives reduce the asymptotic complexity of inference, but their sequential dependence limits token-wise parallelism during training, making them harder to scale. Further, the current paradigm of extending long context tasks creates competing notions of retaining information precisely and keeping long-context inference efficient. To address this gap, we introduce Titan-Llama, a post-training method for retrofitting attention-based language models with a hierarchical memory architecture that updates parameters at test-time. Titan-Llama applies a blockwise attention mask and preserves full-fidelity attention over recent tokens while compressing historical context into recurrent, fixed-size neural memory modules (NMMs). Our formulation allows pre-trained attention layers to be replaced without training a new language model from scratch. On Llama-3.2-1B-Instruct, Titan-Llama raises accuracy over segmented attention windows from 23.87% to 40.51% on QuALITY and from 14.50% to 40.75% on LongHealth. Inference benchmarks show more than 20% faster prefill, 37% faster decode at medium context lengths, and 24% lower steady-state decode memory usage in the evaluated configurations. Together, these results demonstrate that incorporating memory architecture mechanisms that utilize test-time training effectively modulates long-context behavior of pre-trained models, offering a practical route to adapting pre-trained transformers for efficient long-context inference. Our code is released on GitHub.

1 INTRODUCTION

Transformers are efficient to train at scale because attention permits parallel computation across sequence positions. At inference time, however, retaining keys and values for an increasingly long context cause the KV cache to grow. Linear attention and state-space models offer more efficient recurrent inference, but adopting a different architecture generally requires training a new model rather than reusing a pre-trained attention backbone (Katharopoulos et al., 2020; Gu & Dao, 2024). Scaling large language models requires advances in both representational capacity and inference efficiency, which naturally motivates retrofitting the architecture of transformer-based models to better suit them for inference.

The growing KV cache raises the question of how should a pre-trained transformer best retain information from distant tokens without necessarily storing every historical key and value. Titans (Behrouz et al., 2024) represents distant information in an RNN dubbed the neural memory module (NMM), effectively parameterizing historical tokens as fast weight updates to a fixed-size NMM. This motivates our design in using full attention for local windows and representing older tokens in a fixed-size MLP. It is also worth noting that work in KV cache compaction similarly argues that exacting inference tasks do not necessarily require full fidelity on the KV cache (Zhang et al., 2023; Zweiger et al., 2026).

Our work combines these two ideas and develops a method to post-train lightweight, external modules to improve inference efficiency. We partition attention into local and historical contributions, preserve the local contribution, and train a neural memory module (NMM) to provide information

Figure

Figure 1: Titan-Llama architecture at a glance. Left: The inner loss generates gradients at test-time w.r.t. MLP weights, teaching it to memorize historical attention key-value bindings. Right: The query associated with a local hidden state is used to retrieve a value from the NMM. This value, approximating the historical attention output, is then used as a residual and injected into the lambda-gated output stream.

from historical context. At test time, a self-supervised key-value reconstruction loss updates the NMM as new chunks arrive. This objective supplies a self-supervised learning signal without labels, although reconstructing key-value pairs does not guarantee exact reproduction of historical attention. Notably, we keep the pre-trained backbone frozen and are able to recover significant performance while training external weights amounting to only 1% of the total parameter footprint.

Two main considerations guide our design:

  1. How can we post-train a pre-trained LLM to use Titans as a means to achieve fixed-size context compaction?

  2. How can we make the resulting model efficient in practice, accounting for the cost of updating memory during prefill as well as storing and reading it during decode?

References (46)