Incremental Learning in Transformers for In-Context Associative Recall

Aditya Varre, Nicolas FlammarionNeurIPS 2026

TL;DR

When you train a transformer, its loss doesn’t glide smoothly downward—it often stalls on frustratingly flat plateaus before plunging in sudden "aha!" moments. By marrying the physics of optimization with mechanistic interpretability, this paper derives exact mathematical equations explaining why transformers linger on these plateaus, when they jump off, and how they build complex memory circuits piece by piece.

What Problem Does This Paper Address?

One of the transformer's neatest party tricks is in-context learning (ICL)—figuring out a brand-new task from examples in its prompt without updating a single weight. Under the hood, ICL relies on specialized wiring like induction heads, which scan past context to copy and complete repeating patterns (like seeing [A][B] ... [A] and predicting [B]).

Empirically, we know these circuits don't form gradually. Instead, training loss flatlines for ages, then drops like a stone as a circuit abruptly snaps into place. While researchers have dissected fully trained models (mechanistic interpretability) and studied toy linear models (optimization theory), we’ve lacked a unified theory for multi-head softmax transformers. Specifically: Why does the model learn partial, suboptimal solutions first? What determines the exact order in which attention heads wake up? And what controls how long we're stuck waiting on each plateau?

Figure 2: Dynamics of the full transformer (n = 2). (a) Loss curve, exhibiting two abrupt drops. (b–d) Attention patterns of Heads 1 and 2 across the three stages. At t=400 the head attends nowhere in particular; in the second stage (t=1100) Head 2 learns to attend to the (−1)-token at every response position; in the final stage (t=2800) Head 1 attends to the (−2)-token, solving the task.

Methods

To make the notoriously messy math of multi-layer softmax transformers solvable without losing the magic of stage-wise learning, the authors bridge full transformers and solvable differential equations:

  • Observing the Full Model: They first train a standard two-layer transformer (with MLPs, LayerNorm, and skip connections) and observe that Layer 1 heads purely learn relative positions (e.g., "look 1 token back"), while Layer 2's Query-Key ($Q^\top K$) matrix naturally organizes into clean super-diagonal blocks that compare those positions.
  • Principled Simplification: Guided by what the full model actually learns, they strip away MLPs and LayerNorms into a standard "disentangled" attention-only architecture. Novel to this setup, they parameterize Layer 1 directly with relative-position weights and Layer 2 along its observed super-diagonal block manifold ($\beta$), swapping cross-entropy for a dot-product loss.
  • Gradient-Flow Dynamics: Taking the continuous-time limit of gradient descent (gradient flow) at small initialization scales ($\epsilon$), they leverage symmetries in the data and architecture to derive closed-form ordinary differential equations (ODEs) governing how both layers evolve together.

Datasets

Rather than scraping the web, the authors introduce a clean, synthetic in-context associative recall task based on permutations.

Every prompt contains all $n!$ permutations of $n$ symbols, each paired with a random response token from a set $\mathcal{R}$. At the end of the prompt sits a query permutation, and the model must retrieve its matching response from earlier in the context (e.g., seeing [0][1][A] [1][0][B] ... [1][0] and predicting [B]). Because permutations have no duplicate symbols, matching $k = n - 1$ positions uniquely determines the sequence. This preserves the exact multi-head induction mechanism needed for $n$-gram language modeling, while giving the data clean mathematical symmetries.

Key Insights and Ideas

  • Plateaus are Partial Sub-Circuits: Training follows "saddle-to-saddle" dynamics. Each plateau isn't dead time—it corresponds to a near-stationary point where the model has wired up a partial circuit! On the first plateau, one head activates to match the last query token; on the next, a second head activates to match two tokens, narrowing down candidates step-by-step until the full $k$-head circuit crystallizes.
  • A Cross-Layer Conservation Law: Just as physics has conservation of energy, the authors discover an exact mathematical invariant binding the sharpness of Layer 1’s positional attention ($\alpha$) to the scale of Layer 2’s routing weights ($\beta$). Neither layer can race ahead alone; they are locked in a coupled dance across the softmax nonlinearity.
  • Initialization Dictates the Curriculum: Why do heads specialize in a specific sequence? At small initialization scales ($\epsilon$), the relative starting magnitudes of the Layer 2 weights ($\beta$) act as an implicit curriculum—the largest initial weight wakes up first, claiming an offset, while the others wait their turn.

Key Results

  • Exact Plateau Durations: Using their conservation law, the authors prove that near the initial saddle point, parameter growth follows a Riccati equation. Consequently, the time required to escape a plateau scales inversely with initialization size: $\Theta(1/\epsilon)$. Shrink your initialization by half, and your plateau lasts twice as long.
  • Post-Jump Slowdown: Once a head escapes its plateau and specializes, the dynamics switch regimes—attention sharpness ($\alpha$) slows way down, growing at a leisurely $\log \log T$ rate while remaining heads stay quiet at $O(\epsilon)$ until their own jump.
  • Empirical Validation Across Relaxations: The theoretical predictions hold up outside the simplified sandbox. Testing up to $k \le 5$ heads (and $n=2$ to $n=5$ task orders) using mini-batch SGD with momentum and cross-entropy loss, loss curves cleanly collapse onto one another when time is rescaled as $t/\epsilon$, and full transformers with MLPs exhibit the exact same sequential head specialization.

Limitations and Future Work

The authors are admirably transparent about the boundaries of their math:

  • Architectural Assumptions: Assuming a pre-structured block matrix in Layer 2 is their biggest mathematical shortcut. While experiments (and a partial proof) show randomly initialized $Q, K$ matrices naturally gravitate toward this block structure, proving this globally for arbitrary initializations remains an open problem. Similarly, later jumps assume a fixed last-token embedding; bounding the approximation error along a fully coupled multi-jump trajectory is still open.
  • Loss & Optimization Gaps: The exact $\Theta(1/\epsilon)$ escape-time proof relies on dot-product loss and continuous gradient flow; while the conservation law extends to cross-entropy loss, the cross-entropy timescale and robustness to SGD noise are currently backed empirically rather than analytically.
  • Task Scaling: Because prompt length grows factorially ($l = (n+1)n!
  • n$), experiments are limited to $k \le 5$. Extending the theory to prompts with incomplete sets of permutations—where preliminary experiments already show promising robustness—is a natural next step.

Summary updated

Abstract

Transformers acquire in-context learning abilities through abrupt phases during training, often unfolding over multiple stages in which key circuits, such as induction heads, emerge. In this work, we characterize the dynamics underlying the emergence of such circuits across these stages. We focus on a synthetic associative recall task, where sequences are drawn from random maps between a permutation group and a vocabulary, and the model is required to complete the mapping of a permutation by retrieving the corresponding association from context. For this task, we study the gradient-flow trajectories of a simplified two-layer attention-only transformer. Leveraging symmetries in both the transformer architecture and the data distribution, we derive *closed-form parameter dynamics* for both attention layers. We identify a conservation law that couples parameters across layers and governs their joint learning. This law reveals how initialization controls the *timescales* over which such circuits emerge. In the vanishing-initialization limit, we characterize the gradient-flow trajectory, showing how training jumps from saddle to saddle. Finally, we provide empirical evidence across different architectural choices, validating our simplifications and extending the insights from our analysis beyond the simplified setting.
BibTeX
@inproceedings{varre2026incremental,
  author = {Aditya Varre and Nicolas Flammarion},
  title = {{Incremental Learning in Transformers for In-Context Associative Recall}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=hH5NAvxmMz},
}
Figure