Transformers for dynamical systems learn transfer operators in-context

Anthony Bao, Jeffrey Lai, William GilpinarXiv 2026

TL;DR

By probing a minimal two-layer transformer, this paper reveals that attention-based models forecast unseen dynamical systems in-context by implicitly performing time-delay embedding to reconstruct the system's higher-dimensional manifold. Instead of learning local differential equations, the transformer learns to approximate the global Perron-Frobenius transfer operator directly from tokenized data.

What Problem Does This Paper Address?

Large foundation models for scientific machine learning (SciML) show a remarkable ability to generalize to completely unseen physical systems (out-of-distribution, or OOD) without any weight updates—a phenomenon known as in-context learning (ICL). For example, models trained on low-resolution turbulence can spontaneously forecast high-resolution flows.

However, why and how an attention-based architecture trained on one physical process can suddenly adapt to forecast a completely different one at test time remains a black box. Traditional scientific machine learning models act as surrogates for the specific training distribution. This paper addresses this gap by uncovering the exact mathematical strategies transformers employ to achieve OOD generalization in dynamical systems.

Methods

The authors isolate the mechanistic origin of in-context learning using a beautifully minimal setup:

  • Architecture: A small, two-layer, single-head decoder-only transformer (GPT-style) with relative positional encodings (ALiBi).
  • Tokenization: Continuous univariate time series are uniformly quantized into discrete tokens ($V=100$ bins), mirroring modern time-series foundation models like Chronos.
  • Training: The model is trained via next-token prediction with cross-entropy loss on a single trajectory from one dynamical system (Train-ID).
  • Analysis Framework: To decode the transformer's internal strategy during zero-shot inference on an entirely different system (Test-OOD), the authors use tools from dynamical systems theory, including Takens' embedding theorem, Markov chain approximations, attention rollout stable rank, and Ulam's method for transfer operator estimation.

Datasets

The trajectories are generated from a comprehensive database of chaotic ordinary differential equations (ODEs). To systematically control and test the impact of a system's underlying complexity, the authors heavily utilize the Lorenz-96 system, where the chaotic attractor's manifold dimension ($d_M$) scales linearly with the number of dynamical variables ($D$). The scaling laws are verified across 500 distinct pairs of systems.

Key Insights and Ideas

  • Secondary Double Descent: During training on the in-distribution (ID) system, the out-of-distribution (OOD) test error undergoes an early, distinct "double descent" curve before the standard ID double descent occurs. This reveals a clear phase where generalizable, system-independent forecasting strategies are learned early on, before being overridden by system-specific details later in training.
Double descent curves during training showing the early OOD descent phase
  • In-Context Takens' Embedding: When presented with a single, univariate time series from an unseen system, the transformer automatically "lifts" the low-dimensional data into a higher-dimensional space. It adaptively adjusts its internal representation dimension based on the true, unobserved manifold dimension of the target system.
  • Operators over Integrators: Instead of acting like a traditional numerical integrator (which approximates local time derivatives), the transformer acts as a data-driven approximation of a global transfer operator (the Perron-Frobenius operator), mapping how probability distributions of trajectories evolve globally over the attractor manifold.

Key Results

  • Adaptive Dimension Matching: The effective Markov order of the transformer's predictions and the stable rank of its attention rollout matrix both scale linearly with the true intrinsic dimension ($d_M$) of the unseen system. This proves the model infers attractor dimensionality purely from context.
Scaling of Markov order and attention rollout rank with manifold dimension
  • Spectrum and Eigenfunction Alignment: The leading eigenvalues and eigenfunctions (which represent long-lived invariant sets or metastable states of the system) of the transformer's implied transfer operator match the ground-truth operator exceptionally well.
Comparison of true vs. transformer-learned transfer operator eigenfunctions
  • Context Length Scaling: The error in estimating the invariant distribution decreases with context length $C$ following a clean $O(C^{-1})$ scaling law, matching theoretical bounds derived from eigenvalue perturbation theory.

Limitations and Future Work

The study is intentionally restricted to a minimal setting (2 layers, 1 head, univariate quantized data) to ensure strict mechanistic interpretability. While this successfully isolates the core physics-learning mechanism, real-world foundation models are massive and often operate on continuous or patch-based representations.

The authors note that future work should explore how these insights scale to high-dimensional partial differential equations (PDEs), such as fluid turbulence, and whether larger model architectures maintain this exact transfer-operator strategy or develop more complex internal representations.

Summary updated

BibTeX
@misc{bao2026transformers,
  author = {Anthony Bao and Jeffrey Lai and William Gilpin},
  title = {{Transformers for dynamical systems learn transfer operators in-context}},
  year = {2026},
  eprint = {2602.18679},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.18679},
}
Figure