Memory

End-to-End Test-Time Training for Long Context

First page
End-to-End Test-Time Training for Long Context
Paper summary

This paper reframes long-context language modeling as a continual learning problem rather than architecture design. TTT-E2E uses a standard Transformer with sliding-window attention that continues learning at test time via next-token prediction, compressing context into its weights rather than storing all key-value pairs.

Ask this paper

Key points
01

Test-time training approach: The model learns at test time by predicting next tokens on the given context, compressing information into weights. This is combined with meta-learning at training time to prepare the model’s initialization for test-time learning.

02

End-to-end in two ways: The inner loop directly optimizes next-token prediction loss, while the outer loop optimizes the final loss after TTT via gradients of gradients. This contrasts with prior TTT methods and dynamic evaluation approaches.

03

Scaling with context length: For 3B models trained on 164B tokens, TTT-E2E scales with context length the same way as full attention Transformers, while alternatives like Mamba 2 and Gated DeltaNet do not maintain performance in longer contexts.

04

Efficient inference: Similar to RNNs, TTT-E2E has constant inference latency regardless of context length, making it 2.7x faster than full attention for 128K context on H100 while achieving comparable or better loss.

Abstract

We formulate long-context language modeling as a problem in continual learning rather than architecture design. Under this formulation, we only use a standard architecture – a Transformer with sliding-window attention. However, our model continues learning at test time via next-token prediction on the given context, compressing the context it reads into its weights. In addition, we improve the model’s initialization for learning at test time via meta-learning at training time. Overall, our method, a form of Test-Time Training (TTT), is End-to-End (E2E) both at test time (via next-token prediction) and training time (via meta-learning), in contrast to previous forms. We conduct extensive experiments with a focus on scaling properties. In particular, for 3B models trained with 164B tokens, our method (TTT-E2E) scales with context length in the same way as Transformer with full attention, while others, such as Mamba 2 and Gated DeltaNet, do not. However, similar to RNNs, TTT-E2E has constant inference latency regardless of context length, making it 2.7× faster than full attention for 128K context. Our code is publicly available.8K 16K 32K 64K 128K Context length 0.01 0.00 0.01 0.02 0.03 0.04 0.05 Loss with full attention Transformer with full attention Sliding-Window Attention (SWA) Hybrid SWA and full (5:1) Mamba 2 (Dao and Gu) Gated DeltaNet (Yang et al.) TTT-KVB (Zhang et al.) TTT-E2E (ours)8K 16K 32K 64K 128K Context length 0.02 0.03 0.04 0.05 0.06 0.07 Latency (sec per 1k tokens) for prefill Transformer with full attention Sliding-Window Attention (SWA) Hybrid SWA and full (5:1) Mamba 2 (Dao and Gu) Gated DeltaNet (Yang et al.) TTT-KVB (Zhang et al.) TTT-E2E (ours) Figure 1. Scaling with context length, in terms of test loss (left) and latency (right). Left: Our method (TTT-E2E) turns the worst line (green) into the best (blue) at 128K context length. Loss ∆ (↓), the y-value, is computed as (loss of the reported method) − (loss of Transformer with full attention), so loss ∆ of full attention itself (orange) is the flat line at y = 0. While other methods produce worse loss ∆ in longer context, TTT-E2E maintains the same advantage over full attention. All models have 3B parameters and are trained with 164B tokens. Right: Similar to SWA and the RNN baselines, TTT-E2E has constant inference latency regardless of context length, making it 2.7× faster than full attention for 128K context on an H100. ∗ Core contributors. See statement of contributions before references. Correspondence to: arnuv@stanford.edu, kdalal@berkeley.edu, yusun@cs.stanford.edu. 1

Every Monday
Get next week’s papers.
Subscribe on Substack