[Paper Review] Learning to (Learn at Test Time): RNNs with Expressive Hidden States
The paper introduces Test-Time Training (TTT) layers where the hidden state is a learnable model updated via self-supervised learning during test time, yielding linear-time, expressive sequence models (TTT-Linear and TTT-MLP) that can rival or exceed Transformer and Mamba on long-context language modeling.
Self-attention performs well in long context but has quadratic complexity. Existing RNN layers have linear complexity, but their performance in long context is limited by the expressive power of their hidden states. We present a practical framework for instantiating sequence modeling layers with linear complexity and expressive hidden states. The key idea is to make the hidden state a machine learning model itself, and the update rule a step of self-supervised learning. Since the hidden state is updated by training even on test sequences, our layers are called Test-Time Training (TTT) layers. We consider two instantiations: TTT-Linear and TTT-MLP, whose hidden state is a linear model and a two-layer MLP respectively. We evaluate our instantiations at the scale of 125M to 1.3B parameters, comparing with a strong Transformer and Mamba, a modern RNN. Similar to Transformer, TTT-Linear and TTT-MLP can keep reducing perplexity by conditioning on more tokens, while Mamba cannot after 16k context. TTT-MLP still faces challenges in memory I/O, but shows larger potential in long context, pointing to a promising direction for future research.
Motivation & Objective
- Propose a new class of sequence modeling layers with linear complexity and expressive hidden states.
- Make the hidden state itself a learnable model updated by self-supervised learning during test time.
- Provide practical instantiations (TTT-Linear and TTT-MLP) and show empirical gains over strong baselines.
- Improve wall-clock efficiency through mini-batch TTT and a dual computation form.
- Analyze theoretical equivalences between TTT variants and existing approaches (e.g., linear attention, self-attention, nonparametric learners).
Proposed method
- Frame sequence modeling as compressing historical context into a hidden state that is a model with update via gradient steps on a self-supervised loss.
- Define two instantiations: TTT-Linear (hidden model is linear) and TTT-MLP (hidden model is a two-layer MLP) with inner-loop optimization.
- Design self-supervised loss as a multi-view reconstruction objective with training view, label view, and test view (ell-based loss with corrupted input).
- Enable end-to-end training of the outer network while the inner loop updates W within each TTT layer.
- Introduce mini-batch TTT to parallelize gradient computations across time steps, and a dual form to exploit matmul efficiency on modern accelerators.
- Show theoretical connections: TTT-Linear with batch GD is equivalent to linear attention; TTT with nonparametric learners can recover self-attention under certain settings.

Experimental results
Research questions
- RQ1Can TTT layers provide competitive perplexity and longer-context utilization with linear-time per-token cost compared to Transformers and modern RNNs?
- RQ2Do mini-batch training and a dual computation form yield practical wall-clock speedups on large-scale language models?
- RQ3What are the theoretical relationships between TTT instantiations and existing architectures such as linear attention and self-attention?
- RQ4How do learnable initialization and inner-loop learning rate affect stability and performance of TTT layers?
- RQ5What is the effect of different outer-loop configurations (views, datasets) on the self-supervised task and final language modeling performance?
Key findings
- TTT-Linear and TTT-MLP match or exceed Transformer and Mamba baselines across a scale from 125M to 1.3B parameters.
- TTT-Linear can outperform Transformer in perplexity with fewer FLOPs and maintains benefits as context grows beyond 16k tokens, unlike Mamba.
- With modest hardware optimizations, TTT-Linear is faster than Transformer at 8k context and matches Mamba in wall-clock time.
- Mini-batch TTT (e.g., batch size 16) provides the largest perplexity improvements and practical speedups for TTT-Linear.
- Theoretical equivalences show TTT-Linear with batch GD equals linear attention, and a nonparametric TTT (Nadaraya-Watson) recovers self-attention, unifying several sequence modeling paradigms.
![Figure 2: Comparing to Mamba, TTT-Linear has better perplexity and fewer FLOPs (left), and better use of long context (right). Evaluations follow Kaplan et al. [ 40 ] . Left: Scaling trends on Books, zoomed in between 350M and 1.3B parameters. At 760M and 1.3B, TTT-Linear outperforms Mamba in perple](https://ar5iv.labs.arxiv.org/html/2407.04620/assets/x2.png)
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.