TTT-E2E

Context: TTT and Fast Weights

Early work by Mikolov et al. in 2013 2013 and Krause et al. in 2018 2018 pioneered updating models during test-time evaluation to adapt to local sequence statistics.

Then, the idea of "fast" weights (FWPs) updated on relevant data dates back to the 1980s 1980 seconds. TTT-E2E is a specialized case where the "fast" weights are the model parameters themselves.

Prior versions of Test-Time Training focused on Key-Value Binding, compressing context into weights by reconstructing values from keys.

TTT-E2E: End-to-End Test-Time Training for Long Context

TTT-E2E removes these layer-wise losses in favor of a single end-to-end objective..

Instead of designing complex new layers, the authors utilize a standard Transformer with Sliding-Window Attention (SWA) and treat the long context as a training set for the model's weights.

  1. TTT-E2E: The model performs next-token prediction on its own context at test time, effectively "compressing" the context into its MLP weights.

  2. Meta-Learning (Outer Loop): To ensure the model is "ready" to learn at test time, the initial weights are optimized via meta-learning at training time

  3. Hybrid Efficiency: By combining SWA for short-term memory and TTT-updated weights for long-term memory, the model achieves linear computational complexity.

Implementation Details

  • Only MLP layers are updated. Embedding and attention layers are frozen.

  • Only the last 1 1/4 4 of the blocks are updated to balance compute cost and storage capacity.

  • There are two MLPs per block—one static MLP to preserve pre-trained knowledge and one dynamic MLP for TTT.

Mathematics: The Test-Time Objective

The process is divided into an Inner Loop (test-time) and an Outer Loop (training-time meta-learning).

  1. Inner Loop (Test-Time Update): For each token step t t, the next-token prediction loss ℓt script l sub t, is calculated using the current weights Wt-1 W sub t minus 1:

    ℓt⁡(W)=CE⁡(ƒ⁢(xt-1;W),xt) script l sub t of W equals CE of open paren f with hook times open paren x sub t minus 1 semicolon W close paren comma x sub t close paren

    The weights are then updated via gradient descent:

    Wt=Wt-1+η∇ℓt⁡(Wt-1) W sub t equals W sub t minus 1 plus eta nabla script l sub t of open paren W sub t minus 1 close paren

    However, to improve parallelism and stability, the gradient descent is actually performed in mini-batches. GIven a context sequence x1,…,xT x sub 1 comma dot dot dot comma x sub T, the sequence is partitioned into Tb T over b batches. For each batch i=1,…,Tb i equals 1 comma dot dot dot comma T over b, the weights W W are updated as follows:

    Wi=Wi-1-ηb⁢∑t=(i-1)⁢b+1ib(∇ℓt⁡(Wi-1)) W sub i equals W sub i minus 1 minus eta over b the sum from t equals open paren i minus 1 close paren b plus 1 to ib of open paren nabla script l sub t of open paren W sub i minus 1 close paren close paren

    The update uses the average gradient of the next-token prediction loss ℓt script l sub t​ calculated over all tokens within the current mini-batch. Crucially for performance, all gradients within a mini-batch are computed using the same weights (Wi-1) open paren W sub i minus 1 close paren​) from the previous batch, rather than updating them token-by-token.

  1. Interaction with SWA: Because the weights are static during the processing of a mini-batch, the model would behave like a "bigram" for tokens inside that batch if it relied solely on the MLP for memory. The architecture includes a SWA layer with a window size k k (where k≥b) k is greater than or equal to b close paren. This ensures that the model can use its short-term (attention) memory to "remember" the context within the current mini-batch before the TTT update has a chance to compress that information into the weights

  2. Outer Loop (Meta-Learning): During training, the initialization W0 W sub 0​ is optimized to minimize the total loss accumulated after the inner-loop updates:

    L⁢(W0;X)=1T⁢∑t=1Tℓt⁡(Wt-1) L times open paren W sub 0 semicolon X close paren equals 1 over T the sum from t equals 1 to T of script l sub t of open paren W sub t minus 1 close paren

    For mini-batches, the loss is updated to:

    L⁡(W0:X)=1T⁢∑i=1T/b∑t=(i-1)⁢b+1ibℓt⁡(Wi-1) L of open paren W sub 0 colon X close paren equals 1 over T the sum from i equals 1 to T divided by b of the sum from t equals open paren i minus 1 close paren times b plus 1 to ib of script l sub t of open paren W sub i minus 1 close paren

Impact: Performance and Scaling

The paper focuses on scaling properties for 3 3B models trained on 164 164B tokens, evaluating performance across context lengths up to 128 128K.

  • Context Scaling: While RNNs like Mamba2 degrade in performance as context grows, TTT-E2E maintains a constant advantage over full attention, effectively scaling in the same manner as the full Transformer.

  • Constant Latency: Unlike full attention, which has O⁡(T) O of T decoding complexity, TTT-E2E has O⁡(1) O of 1 decoding latency. At 128k 128 k context, it is 2.7x 2.7 xfaster than full attention.

  • Compression Trade-off: While TTT-E2E excels at language modeling, it underperforms in Needle in the Haystack tasks compared to full attention as compression naturally discards details that full attention caches explicitly.

Discussions

Titan/MIRAS paper Differences

In the Titans architecture and the broader MIRAS framework, the mechanism of learning at test time is driven by "surprisal," an info-theoretic signal that determines if something is worth committing to memory. This treats the model's parameters as a dynamic storage system.

  • Example: If during pre-training phase, the model has seen an entire encyclopedia and model learns to memorize that encyclopedia in its memory (Persistent Memory). In prefill, if we show the same encyclopedia to the model, the gradient is very small and the model wouldn't receive any update.

  1. Inner-Loop Objective:

    • Titans uses Associative Memory where it commits information to memory by optimizing an associative mapping of keys (kt) open paren k sub t close paren to values (vt) open paren v sub t close paren. The ℓ script l at time t t measures how well the current memory state Mt-1 M sub t minus 1 can reconstruct the value from the key:

      ℓ⁡(Mt-1;xt)=‖Mt-1⁡(kt)-vt‖22 script l of open paren M sub t minus 1 semicolon x sub t close paren equals the metric of M sub t minus 1 of open paren k sub t close paren minus v sub t sub 2 squared

    • TTT-E2E uses Next-Token Prediction where it updates weights by directly optimizing the main language modeling task (cross-entropy CE) CE close paren on the current context:

      ℓt⁡(W)=CE⁡(ƒ⁢(xt-1;W),xt) script l sub t of W equals CE of open paren f with hook times open paren x sub t minus 1 semicolon W close paren comma x sub t close paren

  2. Update Dynamics:

    • Titans refines the update using momentum (St) open paren S sub t close paren to capture context flow and adaptive weight decay (αt open paren alpha sub t​) to manage capacity. This allows the model to consider "past surprise" alongside "momentary surprise":

      Mt=(1-αt)⁢Mt-1+St M sub t equals open paren 1 minus alpha sub t close paren times M sub t minus 1 plus S sub t
      St=η⁢St-1-θt∇ℓ⁡(Mt-1;xt) S sub t equals eta S sub t minus 1 minus theta sub t nabla script l of open paren M sub t minus 1 semicolon x sub t close paren

    • TTT-E2E standard gradient descent, in mini-batches (b) b to improve hardware utilization (see Mathematics section).

  3. Analogy:

    • Titans is closer to "noise-cancelling" memory whereas TTT-E2E is like an "endless learner".

Test-Time Training on Decoding

What about test-time training on self-generated tokens (which may not be the default for this method)?

  • How much effort is put into the meta-learning to be good for both pre-fill and decoding? Since we base the gradient descent / cross-entropy loss on xt+1 x sub t plus 1 which is "generated from nature."