The Transient Nature of Emergent In-Context Learning in Transformers

Aaditya K. Singh, Stephanie C. Y. Chan, Ted Moskovitz, Erin Grant, Andrew M. Saxe, Felix Hill

Abstract

Transformer neural networks can exhibit a surprising capacity for in-context learning (ICL) despite not being explicitly trained for it. Prior work has provided a deeper understanding of how ICL emerges in transformers, e.g. through the lens of mechanistic interpretability, Bayesian inference, or by examining the distributional properties of training data. However, in each of these cases, ICL is treated largely as a persistent phenomenon; namely, once ICL emerges, it is assumed to persist asymptotically. Here, we show that the emergence of ICL during transformer training is, in fact, often transient. We train transformers on synthetic data designed so that both ICL and in-weights learning (IWL) strategies can lead to correct predictions. We find that ICL first emerges, then disappears and gives way to IWL, all while the training loss decreases, indicating an asymptotic preference for IWL. The transient nature of ICL is observed in transformers across a range of model sizes and datasets, raising the question of how much to "overtrain" transformers when seeking compact, cheaper-to-run models. We find that L2 regularization may offer a path to more persistent ICL that removes the need for early stopping based on ICL-style validation tasks. Finally, we present initial evidence that ICL transience may be caused by competition between ICL and IWL circuits.

Introduction

In-context learning (ICL) is often viewed as a permanent milestone in the development of Large Language Models (LLMs). Once a model demonstrates the ability to solve a task using only the current prompt, it is generally assumed that this capability will persist or improve with further training. However, recent research suggests that ICL may actually be a transient phase. As models are trained beyond the point of initial emergence—a practice known as "overtraining"—they may abandon flexible ICL strategies in favor of rigid "in-weights learning" (IWL), where patterns are memorized directly into the model's parameters.

This shift is particularly relevant given the current trend of training small, efficient models on massive datasets far exceeding standard scaling law recommendations. If overtraining leads to a loss of ICL, these compact models might become less flexible than their larger counterparts, despite having lower training loss.

Experimental Methodology

To investigate the relationship between ICL and IWL, researchers trained standard Transformer models on synthetic tasks where both strategies could lead to correct predictions.

Task Design

The core setup involves "bursty" sequences where specific classes appear multiple times within a single prompt. This structure incentivizes the model to utilize the context provided in the prompt to make predictions.

Experimental setup: A Transformer model is trained on sequences of exemplar-label pairs to predict the label of a final query exemplar.

Datasets

The study utilized two primary synthetic data sources:

  1. Omniglot: Sequences of handwritten character images and their labels. The model must predict the label of a final "query" image based on previous examples in the context.
  2. LLaMA Token Embeddings: To simulate natural language, embeddings from LLaMA models were clustered into "classes," and sequences were constructed similarly to the Omniglot task.
  3. Zipfian Distributions: Datasets were modified to follow power-law distributions, mimicking the frequency of words in natural language where a few items are very common and many are rare.

Training and Regularization

Unlike typical studies that stop training shortly after convergence, these models were trained for up to 50 million steps to observe long-term asymptotic behavior. Additionally, selective L2 regularization (weight decay) was applied to different components (Attention vs. MLP layers) to isolate where ICL and IWL capabilities reside.

The "Hump": Results and Insights

The most striking finding is that ICL accuracy often follows a "hump" trajectory: it rises quickly during the early stages of training (emergence), reaches a peak, and then gradually decays.

The transient nature of in-context learning (ICL) accuracy over training steps, showing the characteristic "hump" followed by decay.

The Competition Between ICL and IWL

As ICL accuracy declines, the training loss continues to decrease. This indicates that the model is not failing to learn, but rather switching strategies. It transitions from using the context (ICL) to relying on memorized patterns in its weights (IWL). The researchers hypothesize that ICL and IWL circuits compete for limited capacity in the transformer's residual stream, with IWL being asymptotically preferred by the optimization process.

Key Findings

  • Ubiquity of Transience: This decay was observed across various model depths (6 to 18 layers), dataset sizes, and input modalities.
  • IWL and the MLP Layers: Applying weight decay specifically to the MLP layers prevented the disappearance of ICL. This suggests that IWL (memorization) primarily utilizes the MLPs, while ICL relies more heavily on the Attention mechanism.
  • Regularization as a Solution: A weight decay of $10^{-4}$ on MLP layers allowed ICL to persist indefinitely, removing the need for early stopping.
  • Model Width: Increasing the embedding dimension (making the model "wider") delayed the decay of ICL, likely because a wider residual stream provides more "room" for both circuit types to coexist.
  • Data Distribution: Naturalistic Zipfian distributions also delayed transience. Because the model cannot easily memorize rare classes, it is forced to rely on ICL for a longer period.

Conclusion and Future Directions

The discovery that ICL can be transient has significant implications for how we train and evaluate models. It suggests that "better" models in terms of loss might actually be "worse" at flexible reasoning if they have been overtrained into a rigid IWL regime.

Future research will focus on whether this phenomenon explains the perceived lack of flexibility in some overtrained small models and on developing training "recipes" that ensure ICL and IWL can coexist harmoniously. Mechanistically mapping the specific circuits (such as induction heads) that are suppressed during IWL dominance remains a key area for further exploration.

Summary updated

BibTeX
@inproceedings{singh2023transient,
  author = {Aaditya K. Singh and Stephanie C. Y. Chan and Ted Moskovitz and Erin Grant and Andrew M. Saxe and Felix Hill},
  title = {{The Transient Nature of Emergent In-Context Learning in Transformers}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=Of0GBzow8P},
}
Figure