Source-linked AI summary

Learning without training: The implicit dynamics of in-context learning

Benoit Dherin, Michael Munn, Hanna Mazzawi, Michael Wunder, Javier Gonzalvo

arXiv:2507.16003v4cs.CLcs.LG

TL;DR

In-context learning lets language models adapt to prompt examples without changing their weights, though the mechanism remains incompletely understood. The paper analyzes contextual blocks and shows that context can be represented as an implicit low-rank weight update, connecting this account to model editing and prompt compression.

  • Problem

    In-context learning adapts model behavior from prompt information without weight changes, but the mechanisms behind this capability remain incompletely understood.

    Source: §1 · p. 1
  • Method

    The paper analyzes contextual blocks—contextual layers composed with standard neural networks—and derives minimal low-rank weight updates that reproduce contextual effects.

    Source: §2 · p. 2, §1 · p. 2, §2.1 · p. 3
  • Results

    The analysis links steering vectors and rank-1 factual edits to context-induced low-rank modulation, while exact updates depend on the query token.

    Source: §4 · pp. 10–11
  • Takeaways & Limitations

    Least-squares aggregation of query-specific updates can produce a static weight update that approximates the context for any input.

    Source: §4 · p. 11

    The gradient-descent reformulation is an algebraic consequence of the additive structure of the weight updates.

    Source: §2.2 · p. 5

Abstract

from arXiv · show

One of the most striking features of Large Language Models (LLMs) is their ability to learn in-context. Namely at inference time an LLM is able to learn new patterns without any additional weight update when these patterns are presented in the form of examples in the prompt, even if these patterns were not seen during training. The mechanisms through which this can happen are still largely unknown. In this work, we show that the stacking of a self-attention layer with an MLP allows the transformer block to implicitly modify the weights of the MLP layer according to the context. We argue through theoretical analysis and experimentation that this simple mechanism may help explain why LLMs demonstrate capabilities of in-context learning, beyond what is captured during training. Specifically, we show that a standard forward pass with context is mathematically equivalent to a forward pass without context but with the MLP weights updated by a minimal low-rank update representing the context.

1. Introduction

In-context learning adapts behavior from prompt information even though model weights remain unchanged, and its mechanisms are not fully understood. The introduction frames contextual blocks as a way to describe this adaptation through implicit low-rank MLP updates.

1. Introduction

  • Earlier theoretical studies related in-context learning to implicit finetuning using simplified transformers trained on toy linear-regression setups [Dai et al., 2023; von Oswald et al., 2023; Zhang et al., 2024].Source: §1 · p. 1
  • A contextual block’s context acts as a unique, Frobenius-norm-minimizing rank-1 update to MLP weights, called a minimal token-patch.The update is computed from the context’s relative effect.Source: §1 · p. 2
  • The paper introduces contextual blocks as a generalization of transformer information processing and proposes that context implicitly updates the subsequent neural network’s first-layer weights.The block composes a contextual layer with a standard neural network.Source: §1 · pp. 1–2
  • As prompt tokens are consumed, the implicit updates yield a gradient-descent learning dynamics.Source: §1 · p. 2
  • The update perspective connects rank-1 factual edits and steering vectors to context-induced weight modulation.The paper describes the matrix and vector updates as resembling these two kinds of editing techniques.Source: §1 · p. 2

2. Implicit update theory

The section models transformer-like processing as a contextual layer followed by a neural network, then asks whether context can be represented through changes to the network’s weights. It derives minimal token patches and an implicit token-by-token learning dynamic, treating the no-skip, single-block case for simplicity.

2.1. Contextual Blocks and Minimal Token Patches

  • For a query token with nonzero input representation after removing context chunk Y, a unique minimal token-patch achieves pre-activation matching and minimizes the Frobenius norm.The update preserves the original weights in directions orthogonal to that representation.Source: §2.1 · pp. 3–4
  • The context vector measures the layer-output difference with and without a context chunk; it is an analytical counterfactual, not a quantity computed in one forward pass.Source: §2.1 · pp. 3–4
  • In linear attention, a context chunk is accumulated into a static KV-state matrix and projected through a rank-1 transition to form the token-patch.Source: §2.1 · p. 4

2.2. The implicit learning dynamics of ICL

  • A contextual block’s token-by-token weight updates can be written as stochastic gradient updates, with each update reflecting a context token’s marginal effect on the layer output.The gradient-descent form is algebraic; the specific structure of the update is the substantive result.Source: §2.2 · p. 5
  • Under linear-attention assumptions and specified weights, the implicit dynamics exactly match full-batch gradient descent on a least-squares objective.This is an existence proof for a simplified setting, not a general equivalence for nonlinear architectures.Source: §2.2 · p. 6

3. Experiments

The experiments test exact functional equivalence, compare implicit updates with explicit finetuning, diagnose architectural differences, and assess static-patch generalization. Results support equivalence at finite precision and show attention-based updates converge, while static patches become more query-agnostic with larger calibration sets.

3. Experiments

  • The experiments use linear-function ICL to test algebraic equivalence, compare implicit dynamics with finetuning, diagnose architectures, and assess static-patch utility.The numerical-equivalence experiment uses a 10-layer Transformer with LayerNorm and residual connections trained on linear regression.Source: §3 · pp. 6–7, §3.1 · p. 7

3.1. Numerical Verification of Functional Equivalence

  • At 10^-6 precision, intermediate outputs match between the context-conditioned pass and the context-free pass with patched weights.Figure 1 compares training and validation losses and reports mean intermediate-output L2 differences across 100 test tasks.Source: §3.1 · p. 7, Figure 1 · p. 7

3.2. Implicit Dynamics vs. Explicit Finetuning

  • Implicit updates minimize test loss similarly to explicit SGD finetuning, and remain highly aligned with the explicit gradients in weight space.The comparison uses the same context examples for both update procedures.Source: §3.2 · p. 7, Figure 2 · p. 8

3.3. Architectural Diagnostics: Attention vs. RNN

  • Attention-based updates decay smoothly toward convergence as context length grows, whereas RNN-based updates remain unstable and fail to converge.The authors present this difference as a mechanistic explanation for standard RNNs’ weaker ICL performance relative to Transformers.Source: §3.3 · p. 8, Figure 3 · p. 8

3.4. Practical Utility: Static Thought Patches via Least-Squares Approximation

  • A static Thought Patch consolidates query-dependent token updates into one context-specific update intended to approximate behavior across a calibration set.The exact token-patch depends on the query token, so it otherwise must be recomputed for each generated token.Source: §3.4 · p. 9

3.4.1. Experimental Setup: Generalization of the Static Thought Patch

  • As calibration-set size K increases, the static patch’s calibration–test performance gap narrows, shifting from overfit query-specific behavior toward generalization to unseen tokens.The authors interpret this as evidence that the patch captures the context’s structural influence on the transformer’s computation.Source: §3.4.1 · p. 9

4. Conclusion and future directions

The conclusion presents implicit context-driven weight changes as a framework connecting in-context learning with model editing, prompt interactions, interpretability, and architecture design. It also distinguishes query-dependent updates from static fine-tuning and discusses approximating context with a static thought patch.

4. Conclusion and future directions

  • The framework applies without restrictions on self-attention architecture and also covers other contextual layers, although the induced dynamics depend on architecture.The authors report superior convergence for attention-based layers over RNN-based ones in their diagnostic experiment.Source: §4 · pp. 9–10
  • The theory unifies in-context learning with steering vectors and rank-1 factual edits as aspects of context-induced low-rank weight modulation.The authors suggest these editing techniques intervene on a mechanism models use for self-adaptation.Source: §4 · p. 10
  • Prompt-segment factorization formulas map segments to linear operators and concatenation to operator composition, motivating formal study of prompt interactions.The authors identify invertibility and commutativity as operator properties for such study.Source: §4 · p. 10
  • The framework enables extraction of the exact generation meta-gradient, which could support mechanistic interpretability and potentially signal hallucinations or mode collapse.The proposed early-detection use is framed as a possibility from dynamically monitoring gradients.Source: §4 · p. 10
  • Evaluating how contextual layers facilitate or hinder implicit updates may guide development of architectures optimized for in-context adaptability.The authors frame this as a direction toward more efficient architectures.Source: §4 · pp. 10–11
  • Exact updates depend on the query token, while least-squares aggregation yields a single static thought patch that approximates context across inputs.As calibration-set size K grows, the patch-based output converges toward the full context-dependent pass on training and held-out queries.Source: Figure 4 · p. 10, §4 · p. 11

A. Related work

  • The authors argue that standard transformers can exactly map context effects to low-rank MLP-weight updates, even where exact attention-weight compression is resisted.They contrast this result with Chen et al. (2024), who establish impossibility for exact conversion into weights in standard architectures.Source: A. Related work · p. 17

B.1. Minimal update proofs

Appendix B.1 collects proofs of the main results from Sections 2.1 and 2.2 and supplementary characterizations of equivalent token-patches.

B.1. Minimal update proofs

  • This subsection collects proofs of the main results from Sections 2.1 and 2.2, along with supplementary results characterizing the space of equivalent token-patches.Source: §B.1 · p. 18

Proof of Theorem 2.3

The proof establishes a unique minimal-norm token-patch that achieves functional equivalence by matching pre-activations. It also characterizes equivalent rank-1 updates and shows the minimal update leaves orthogonal input directions unchanged.

Proof of Theorem 2.3

  • The unique minimal token-patch achieves functional equivalence by matching pre-activations and minimizing the Frobenius norm.The result applies when the contextual representation without the removed context chunk is nonzero.Source: Proof of Theorem 2.3 · p. 18
  • The minimal update preserves the original weights on every direction orthogonal to the contextual representation without the removed chunk.For any such direction u, applying the patched weights gives the same result as applying W.Source: Proof of Theorem 2.3 · p. 18

Characterization of equivalent rank-1 updates

  • Among functionally equivalent rank-1 updates, choosing the query representation as the defining vector gives the unique minimum-Frobenius-norm update.Other equivalent rank-1 choices require a vector whose inner product with the query representation is nonzero.Source: Characterization of equivalent rank-1… · p. 19

Proof of Proposition 2.6

The proof identifies the iterative implicit weight updates with stochastic gradient updates. The proposition specifies the learning rate and the loss at each step.

Proof of Proposition 2.6

  • The iterative implicit weight updates can be realized as stochastic gradient updates with learning rate 1/∥A(x)∥^2 and a step loss given by the change in contextual-layer output.The loss is the difference between A(c1, …, ci, x) and A(c1, …, ci+1, x).Source: Proof of Proposition 2.6 · p. 19

C.1. Contextual blocks with skip-connections and multiple stacked blocks

With skip connections, contextual blocks can be represented by patches to the first dense-layer weights and final-projection bias; the equivalence extends to stacked blocks and admits an iterative, token-by-token interpretation of implicit learning.

C.1. Contextual blocks with skip-connections and multiple stacked blocks

  • Under the stated nonzero-query assumption, a unique sequence of minimal weight patches and exact bias patches preserves the full-context output across a stack of skip-connected blocks.The residual connection requires both first-dense-layer weight updates and final-projection bias corrections.Source: §C.1 · pp. 20–21
  • The unique minimal weight displacement leaves the layer’s action unchanged on vectors orthogonal to its query representation.The token patch strictly minimizes the Frobenius norm while satisfying pre-activation equivalence.Source: §C.1 · p. 21
  • The stack result follows by applying the single-block equivalence at each layer, preserving each activation and therefore the final output.The proof uses induction over the blocks.Source: §C.1 · p. 22

C.2. An alternative implicit learning dynamics of ICL

  • The alternative dynamics view treats each prompt token as transferring information into the contextual-block weights, with the token’s update vanishing when it has no effect on the block output.The update is linear in the preceding weights.Source: §C.2 · p. 23
  • The iterative token updates yield a factorization for the total implicit weight matrix associated with the context’s effect on the input token.The contextual output can be viewed as if the model underwent rapid context-influenced learning, although its weights are not actually updated during generation.Source: §C.2 · pp. 22–23

D. Experiment Details

The experiment details specify a linear-regression in-context task using prompts of input-output examples and a query token. Inputs and query vectors are Gaussian, and the target function is sampled from a Gaussian weight vector.

D. Experiment Details

  • The experiment-details section describes the architectures, datasets, and training hyperparameters used for the Section 3 results.Source: D. Experiment Details · p. 23

D.1. Task Definition: Linear Regression In-Context

  • The experiments use prompts containing input-output pair token-vectors followed by a query token.The task-definition section specifies this prompt structure.Source: §D.1 · p. 24
  • Inputs and query vectors are sampled from N(0, I_d), while the target is the linear function h(x) = ω^T x with ω sampled from N(0, I_d).The feature dimension is d = 2 and context length is N = 100 unless otherwise specified; training uses MSE batches of size 32.Source: §D.1 · p. 24

D.2. Multi-Layer Pre-LN Transformer Architecture

The appendix specifies the transformer used for numerical verification, the explicit-finetuning comparison setup, and an RNN-based architectural diagnostic.

D.2. Multi-Layer Pre-LN Transformer Architecture

  • Numerical verification uses an autoregressive transformer with 10 blocks, MLP dimension 128, model dimension 32, and 8 attention heads, trained with Adam at learning rate 0.001.The architecture matches the one described in Vaswani et al. (2017).Source: §D.2 · p. 24

D.3. Finetuning Comparison Setup

  • The explicit-finetuning comparison uses a pretrained single-layer baseline, updates its MLP weight matrix with SGD, and tunes the learning rate for a fair comparison with the implicit gradient step.The setup processes one example at a time.Source: §D.3 · p. 24

D.4. RNN Architectural Setup

  • The architectural diagnostic replaces multi-head self-attention with an RNN, matching parameter scale with model dimension 64 and MLP dimension 128.The RNN model is trained at learning rate 0.005 for 10,000 steps.Source: §D.4 · p. 24
Loading 2507.16003v4…