Preprint 2026 · pre-registered · code, models and every number public

What a Transformer Learns When It Adapts to Unknown Physics In-Context: Probing, Patching and Controlling

Anuar Zhambakin

Independent researcher

Three panels. Left: a linear probe reads the Bayes estimate from the attention key-value memory with R squared 0.85 to 0.9, from the residual stream at most about 0.6. Middle: swapping only the context keys and values of blocks 3 and 4 transfers about 0.92 of another episode's behaviour, block 1 about 0.12. Right: the in-context controller has a competitive median cost but fails on 10 percent of plants.
Left: where the Bayes estimate is linearly readable (128-d residual-stream readouts in grey, the attention key-value memory in blue). Middle: replacing only the context keys and values of a block with another episode's; blocks 3 and 4 together carry almost all of the behaviour. Right: the in-context controller against classical adaptive controllers.

In one paragraph

A small transformer gets 48 steps of a system it has never seen: unknown mass, unknown friction, unknown sign of the input. It has to predict the next state, or control the system, with no gradient steps. We pre-registered what we expected to find inside and then tested it with exact optimal references and causal interventions. The model is Bayes-optimal while data are scarce. The mechanism we bet on, a parameter estimate written into the residual stream, is not there. What is there: the sufficient statistics of the context, stored in the attention key-value memory of the last two blocks, where swapping them moves the model's behaviour almost completely.

Findings

Abstract

Sequence models that adapt to unknown dynamics from their own history are common in robot learning, but what they compute is unclear. We study small transformers trained from scratch, in a pre-registered design with exact optimal references and causal interventions, on linear systems with unknown parameters, one-degree-of-freedom MuJoCo systems with contact, and linear adaptive control. The predictors are Bayes-optimal while data are scarce, then settle at an approximation floor (1.59× the Bayes excess risk). Our pre-registered mechanism, a linearly readable and causally used parameter estimate in the residual stream, is rejected (probe R² = 0.19; steering and patching have no effect). Exploratory analyses locate the sufficient statistics of the context in the attention key–value memory of the last two blocks: they are read from it with R² = 0.92, against 0.68–0.71 for the best residual-stream readout, and replacing only those keys and values with another episode's transfers 0.91–0.94 of its behaviour. MuJoCo physical parameters show the same pattern, with system-dependent margins. A controller trained by imitation and then on closed-loop cost excites the plant without an identification objective, though less than dithered certainty equivalence, and is competitive in median cost but fails on 10.0% of plants, almost all open-loop unstable, against 1.4% for dithered certainty equivalence. Code, pre-registration and every number are public.

The pre-registered scoreboard

Thirteen tests, committed before the main experiments and Holm-corrected. Seven held up and six did not, including the headline mechanism. All of them stay in the paper.

TestResultVerdict
H1a, H1b: closer to Bayes than to OLS / one-step gradient descentby 0.27 / 0.55supported
H1c: excess risk within 1.25× of Bayes1.59× [1.56, 1.62]rejected
H2a: residual-stream probe for the estimate, R² > 0.80.19 [0.17, 0.21]rejected
H2b: the probe reads the Bayes estimate better than the true parameters+0.005supported
H2c: sufficient statistics readable at an earlier block than the estimate3 of 3 seedssupported
H3a, H3b: steering along the probe / swapping its subspace changes the prediction0.00 / 0.0001rejected
H4a: pushed block, transformer beats physics-feature RLS0.0058 vs 0.019supported
H4c, H4d: physical parameters linearly readable and steerable on both systemsno / norejected
H5a: controller beats the best constant gain (mean cost)by 584 [147, 1179]supported
H5b: controller beats certainty equivalence (mean cost)112 [−149, 343]not supported
H5d: controller gathers more information than certainty equivalence by t = 8+4.2 nats [4.06, 4.31]supported

Every change after the pre-registration, including two bugs found in our own code and the analyses added after an external review, is listed in DEVIATIONS.md.

Prediction on linear systems

Excess risk against context length for the transformer and the exact Bayes predictor, held-out residual-stream probes by block, and activation patching by layer.
(a) Excess risk vs context length: the transformer tracks the exact Bayes predictor while data are scarce, then flattens at an approximation floor; the Bayes curve follows the parameter-free n p σ²/t law. (b) Held-out linear probes of the residual stream: the estimate is barely decodable, the posterior uncertainty is. (c) Activation patching: the query token carries the other episode's behaviour only from layer 3 on; the probe subspace carries nothing.

Where the estimate lives

The query Jacobian matches the Bayes estimate; probes by block show the key-value fast weights above the residual stream even at 128 dimensions; patching only context keys and values of blocks 3 and 4 transfers over 90 percent of behaviour.
(a) The predictor's Jacobian with respect to its query matches the Bayes estimate. (b) Probes for the estimate by block: projected to 128 dimensions, the key-value fast weights still beat the residual stream over all 48 positions. (c) Patching only the context keys and values of blocks 3–4, with every activation at the query untouched, transfers over 90% of the other episode's behaviour; keys or values alone transfer about half.

Physics in MuJoCo

One-step error against context length on the pendulum and the pushed block, and probe R squared for physical parameters from the key-value fast weights and the residual stream.
(a, b) One-step error vs context length. On the pendulum the transformer is on par with physics-feature RLS, which there has the true model class; on the stick–slip block it beats it by 3.2×. (c) Physical parameters read from the key-value fast weights vs from the residual stream (P: pendulum, K: block, B: bouncing ball).

In-context control

Normalised control cost for each controller, failure rates on open-loop stable and unstable plants, and information gathered in the first 8 steps.
(a) Normalised cost J/Joracle on 4096 paired test plants. Certainty equivalence without excitation never moves the input, so it learns nothing about B. (b) Failure rate on open-loop stable vs unstable plants. (c) Information gathered in the first 8 steps.

Try it

Live demo: the main model runs in this browser, next to the exact Bayes estimator, on systems you pick. The quickstart notebook reruns the three headline checks on fresh episodes in a few minutes on a CPU. All 51 trained checkpoints are on the release; one command reproduces the whole paper:

git clone https://github.com/nonberw/suss.git && cd suss
pip install -r requirements.txt
bash scripts/run_all.sh   # about a day on a 4 GB laptop GPU

Cite

@misc{zhambakin2026suss,
  author       = {Zhambakin, Anuar},
  title        = {What a Transformer Learns When It Adapts to Unknown Physics In-Context:
                  Probing, Patching and Controlling},
  year         = {2026},
  howpublished = {Preprint},
  doi          = {10.5281/zenodo.24031898},
  url          = {https://github.com/nonberw/suss}
}