One for All: A Non-Linear Transformer can enable Cross-Domain Generalization for In-Context Reinforcement Learning

Bowen He, Juncheng Dong, Lin Lin, Xiang ChengNeurIPS 2026

TL;DR

How can a single, frozen Transformer adapt to completely different robotics environments on the fly without updating a single parameter? The authors prove that a non-linear Transformer’s forward pass implicitly executes kernel-based Temporal Difference (TD) learning. As long as the value landscapes of different domains share a common mathematical "smoothness," one set of weights can evaluate policies for them all.

What Problem Does This Paper Address?

Reinforcement Learning (RL) agents are notoriously narrow: train an agent to slide a puck, and it is usually helpless when asked to press a button. Recently, researchers discovered In-Context RL, where a Transformer takes a history of environment interactions (states, actions, rewards) as a prompt and adapts to new tasks at inference time—no gradient updates required.

Empirical studies have shown this works surprisingly well, even jumping across completely different domains. Yet why it works has remained largely a mystery. Prior theoretical work managed to explain this only in simplified settings—assuming linear environments and linear Transformers. Real-world tasks, however, are messy and non-linear. To isolate the core mechanics of how Transformers generalize across domains, the authors focus on policy evaluation (predicting how much future reward a given state holds for a fixed policy), which is the foundational subroutine of almost all modern RL algorithms.

Methods

Instead of training a massive black-box Transformer from scratch and hoping for the best, the authors mathematically construct the exact attention weights needed to run an RL algorithm inside the model's forward pass.

  1. Attention as a Kernel: Standard non-linear attention (specifically using an exponential activation, a close cousin of softmax) computes the exponentiated dot product between queries and keys. Mathematically, this acts as a kernel function $\kappa(x,y) = \exp(x^\top y / \delta)$, which implicitly maps states into a rich, infinite-dimensional function space known as a Reproducing Kernel Hilbert Space (RKHS)—essentially a mathematical playground of smooth, curved functions.
  2. Layers as TD Iterations: In classical RL, Temporal Difference (TD) learning updates value estimates step-by-step using observed rewards and next-state values. The authors design a two-head self-attention block where Head 1 evaluates current states and Head 2 evaluates next states against the prompt's historical states (which act as "kernel centers").
  3. Explicit Weight Construction: By stacking $L$ of these engineered layers, the forward pass executes $L$ exact steps of kernelized semi-gradient TD learning. In their experiments, the projection matrices ($K, Q, V$) are completely fixed by this mathematical blueprint; only a single scalar step-size parameter ($\alpha$, the effective learning rate of the internal TD algorithm) is learned during training.

Datasets

Rather than static datasets, the model is evaluated on interactive Markov Reward Processes (MRPs):

  • MetaWorld Benchmark: Five distinct robotic manipulation domains (Pick-Place-v3, Pick-Place-Wall-v3, Shelf-Place-v3, Plate-Slide-v3, and Button-Press-v3), each containing 50 task variations. By injecting three levels of action noise (low, medium, high) into near-optimal policies, the authors create 150 distinct MRPs per domain.
  • Synthetic 2D Environment: A newly introduced toy MRP with a 2D state space where the ground-truth value function is guaranteed to live inside the target RKHS, allowing clean 3D visualization of the model's predictions.
MetaWorld robotic manipulation domains used to test cross-domain generalization, ranging from picking and placing blocks to sliding plates and pressing buttons.

Key Insights and Ideas

  • The Transformer is a Functional Operator: Don't think of the Transformer as memorizing a value function. Think of its weights as hardcoding an optimization algorithm, while the context tokens supply the data points on the fly.
  • Shared RKHS = Cross-Domain Transfer: Why can a single model evaluate both puck-sliding and block-stacking? Because domain boundaries don't matter to kernel regression—only function geometry does. If the value functions of two wildly different physical tasks live in the same RKHS (meaning they vary at similar spatial scales), a single frozen Transformer can represent both.
  • Explaining Transfer Failure: Conversely, this framework predicts when transfer will break. Because the kernel's temperature parameter $\delta$ is baked into the attention mechanism, a model tuned for smooth, gentle value landscapes cannot suddenly pivot to sharp, spiky ones.

Key Results

  • Within-Domain Generalization: Across all five MetaWorld domains, a 30-layer constructed Transformer trained only on high-noise trajectories steadily converges in TD error when evaluated zero-shot on unseen medium- and low-noise trajectories. Meanwhile, a linear Transformer baseline fails to capture the non-linear value structures.
  • Cross-Domain Transfer: Models trained on a single domain successfully generalize zero-shot across Pick-Place, Pick-Place-Wall, Shelf-Place, and Plate-Slide. However, they fail to transfer to Button-Press—an outcome predicted by the theory, as hyperparameter analysis shows Button-Press requires a substantially different kernel bandwidth ($\delta$).
  • Precision in Synthetic Space: Using just 32 context transitions in the synthetic 2D environment, the 30-layer Transformer reconstructs the shape of the ground-truth value surface with a mean state-value error of 0.00034 (after accounting for a known constant offset).

Limitations and Future Work

  • Constant Value Offset: Due to using a dummy padding token for the query's unknown "next state," all value predictions carry a state-independent constant bias ($-\gamma v_\ell^{(\text{pad})}$). Fortunately, this cancels out in TD error calculations and in downstream policy-gradient advantage estimates, where only relative state values matter.
  • Fixed Kernel Bandwidth: Because the kernel temperature $\delta$ is static during inference, the model cannot adapt if a new domain requires a fundamentally different function space (as seen in Button-Press) or exhibits sharp discontinuities later in episodes.
  • Policy Evaluation Only: This work analyzes estimating state values for a fixed policy, not choosing actions. Extending this kernel-based view to full control (policy improvement) and designing architectures that dynamically adapt their kernel parameters in-context are prime targets for future research.

Summary updated

Abstract

A central challenge in reinforcement learning (RL) is to learn models that generalize beyond the tasks on which they are trained, a goal traditionally pursued through multi-task and meta RL. Recently, transformer architectures have emerged as a promising approach, enabling adaptation to new tasks via in-context learning without explicit parameter updates. From a functional perspective, a transformer can be viewed as a **functional operator** that maps a context to a task-specific function. It is thus fundamental to understand and design this operator to support stronger generalization in RL. In this work, we address this resulting question of generalization from a kernel-based perspective by establishing a connection between non-linear transformers and kernel-based temporal difference learning. By interpreting the transformer as performing regression in a **Reproducing Kernel Hilbert Space** (RKHS), we show that value functions from different domains can be represented using a shared set of weights, provided they lie within the same RKHS. Experiments on multiple MetaWorld domains support this interpretation, demonstrating convergence of the temporal-difference objective.
BibTeX
@inproceedings{he2026one,
  author = {Bowen He and Juncheng Dong and Lin Lin and Xiang Cheng},
  title = {{One for All: A Non-Linear Transformer can enable Cross-Domain Generalization for In-Context Reinforcement Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=ZZh6M076fq},
}
Figure