From Linear Attention to Test-Time Training
Linear attention reduces the quadratic cost of standard attention to linear, which is great. But can we do better?
This blog post is based on the CVPR 2026 paper ViT: Unlocking Test-Time Training in Vision.
In this post, we explore the connection between attention and sequence modeling, and how it leads to a new paradigm called test-time training (TTT). First, let’s start with a brief review of standard softmax attention and linear attention.
Softmax Attention
Let be the query and key matrices, and let be the value matrix. Standard scaled dot-product attention is
where the softmax is applied row-wise. Computing all pairwise query-key scores is , and mixing the values is . We usually summarize this as : the quadratic dependence on makes long contexts expensive.
Linear Attention
Linear attention replaces the softmax similarity with a factorized kernel. It uses a feature map , applied row-wise to and , to define
In some variants, approximates the exponential softmax kernel; in others, it is a different kernel chosen for efficiency.
Substituting this into the attention formula gives:
where
Here, is a fixed-size summary of the key-value pairs, while acts as a normalization term.
Here, , , and . Once and have been computed, evaluating one output costs . Computing all outputs therefore costs . In the common case , this becomes : linear in the sequence length .
This kernel-based formulation is described in Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention.
Causal Linear Attention
In autoregressive generation, only a prefix of the sequence is visible, and the sequence grows over time. Linear attention can maintain the corresponding summary incrementally:
Constructing the summary for a prefix of length costs when . Each new token then updates the state as follows:
Each update costs , so processing a sequence of length remains overall.
A Different View of Attention
We can reformulate the two types of attention in the following way. When and are fixed, softmax attention computes
where can be viewed as an input to the linear layer , followed by a softmax activation, and then a linear layer without activation. This is a two-layer MLP with a nonlinearity in between.
For linear attention, we can consider the simplest unnormalized form, and deliberately omitting the feature map. By associativity, we have
Similarly, we can consider as an input to a linear layer (whose weights can be precomputed), without any intervening activation. This is a single-layer MLP.
The pattern is clear: build a model with and as parameters, then apply the model to to get the output. This is an important reformulation of the attention mechanism.
The MLP in the middle can be viewed as a sequence-modeling function. Under this perspective, the key difference between softmax and linear attention is that softmax attention keeps the individual keys and values available to each query, whereas linear attention first reduces them to a fixed-size summary. This compression makes linear attention more efficient, but can limit the information available to each query.
Sequence modelling can therefore be viewed as a compression problem: build a compact representation of the observed sequence, then use it to predict future tokens. The central trade-off is between the fidelity of that representation and the cost of constructing and evaluating it. Naturally, one might ask: can we learn a compression function more expressive than the hand-designed linear attention while still keeping the cost linear?
One possible answer is to use a neural network. Self-supervised learning can encode a large training set in model weights while capturing useful structures and relationships in the data. This idea leads to the concept of Test-Time Training (TTT).
The connection between attention and an inner learner was introduced in Learning to (Learn at Test Time) and was further developed in Learning to (Learn at Test Time): RNNs with Expressive Hidden States.
The Test-Time Training Paradigm
TTT treats the key-value pairs as a small dataset. At inference time, an inner model is optimized to map to using a loss , thereby compressing the current sequence into its parameters. The queries are then fed to this adapted model to produce . Because this optimization happens during inference, it is called test-time training.
Formally, let be the inner model with temporary parameters . A full-sequence inner-model update can be written as
The update aims to compress the current sequence into . In a causal setting, the same idea updates the state from each growing prefix:
The Outer Loop
During ordinary training, the outer loop optimizes the task loss, but in order to do so, it must also “optimize” the inner loop. It learns the projections that produce , , and , sometimes along with the inner-model initialization — these all affect the inner-loop optimization.
At deployment, outer-loop parameters are frozen, while the inner model is adapted to each new sequence at test time. The outer loop is therefore, in some sense, a meta-learning objective: it learns parameters that make the inner-loop adaptation more effective.
In principle, the inner model can be any differentiable neural-network architecture, which creates a large design space. ViT: Unlocking Test-Time Training in Vision studies this design space for vision.
Practical Limitation
TTT avoids materializing all query-key interactions, but linear scaling in does not make it free. A linear inner model still typically costs and, because it is adapted at runtime, also requires a backward pass, which significantly increases the computational burden and puts pressure on memory throughput. The inner model must therefore be small enough to be practical, and the outer loop must learn an initialization that makes the inner model effective with only a few gradient steps.