Supervised Pretraining Can Learn In-Context Reinforcement Learning

Jonathan Lee, Annie Xie, Aldo Pacchiano, Yash Chandak, Chelsea Finn, Ofir Nachum, Emma Brunskill

Introduction

Reinforcement Learning (RL) has traditionally been viewed as a distinct paradigm from supervised learning, characterized by the fundamental challenge of the exploration-exploitation trade-off. While Large Language Models (LLMs) have demonstrated remarkable in-context learning (ICL) capabilities—solving new tasks at inference time without weight updates—this success has largely been confined to static supervised domains like translation or reasoning.

Applying in-context learning to RL is significantly more complex because the "context" is not a static prompt, but a dynamic history of interactions within an environment where the underlying rules are unknown. Researchers from Stanford, Microsoft, and Google DeepMind have recently challenged the necessity of complex meta-RL algorithms with the Decision-Pretrained Transformer (DPT). Their work demonstrates that a standard Transformer, trained via simple supervised learning to predict optimal actions, can naturally emerge as a sophisticated RL algorithm capable of in-context exploration and exploitation.

The Decision-Pretrained Transformer (DPT)

Unlike previous approaches such as Algorithm Distillation, which attempt to train Transformers to mimic the trajectories of existing RL algorithms, DPT asks a more fundamental question: Can we simply train a model to predict the best action given a history of interactions, and will the ability to "do RL" emerge as a byproduct?

Methodology

The training process for DPT is elegantly straightforward:

  1. Data Collection: The researchers generate a massive dataset consisting of diverse "tasks" (e.g., various bandit configurations or navigation maps). For each task, they compile a history of interactions—sequences of states, actions, and rewards—and identify the optimal action for a specific query state.
  2. Supervised Pretraining: A causal Transformer (specifically a GPT-2 architecture) is trained to predict that optimal action given the interaction history.
  3. In-Context Deployment: At test time, the model's weights remain frozen. When placed in a novel environment, the model treats its growing history of successes and failures as a prompt. This allows it to infer the environment's rules and converge on the goal without further training.

Crucially, DPT does not explicitly copy a specific RL algorithm; it learns to predict what an expert agent would do if that agent possessed the same historical information.

Theoretical Foundation: The Bayesian Connection

A key contribution of this research is the mathematical proof that DPT acts as an efficient implementation of Bayesian Posterior Sampling. By training on a wide distribution of tasks, the Transformer learns an implicit "prior." During the forward pass at inference time, the model uses the provided context to perform a "posterior update," effectively narrowing down the possible task parameters and selecting actions that balance the need to gather information with the need to maximize reward.

Experimental Evaluation

The authors evaluated DPT across three distinct environments designed to test different facets of RL:

  • Multi-Armed Bandits: These classic problems require the agent to find the best "slot machine" among several options. In linear bandit tasks, where rewards follow a hidden mathematical structure, DPT was tested on its ability to exploit latent patterns.
  • Dark Room: A 2D grid-world where an agent must locate a hidden goal in total darkness. The agent only receives a reward upon reaching the exact coordinates of the goal, testing its systematic exploration capabilities.
  • Miniworld: A 3D visual navigation task. The agent must find a specific colored box based on first-person RGB image observations, testing the model's ability to handle high-dimensional visual inputs.

Key Findings

Emergent Exploration and Stitching

Even though DPT was never explicitly programmed to explore, it naturally exhibits exploratory behavior. When the context is empty, it tries different actions; as it gathers data, it narrows its focus to the most rewarding strategies. Furthermore, DPT demonstrates "stitching"—the ability to combine segments of different unsuccessful trajectories to infer a brand-new, optimal path to a goal it has never successfully reached before.

Performance Benchmarks

In bandit tasks, DPT matched the performance of gold-standard algorithms like Thompson Sampling and Upper Confidence Bound (UCB). Notably, when hidden linear structures were present, DPT automatically outperformed these standard algorithms by discovering and exploiting that structure. In the Dark Room and Miniworld tasks, DPT reached goals faster than existing meta-RL methods like RL² and Algorithm Distillation.

Zero-Shot Adaptation

DPT showed remarkable robustness to changes in the environment. When the action space was randomly permuted (e.g., changing which directional key moves the agent forward), DPT was able to re-learn the control scheme within a single episode simply by observing the outcomes of its initial moves.

Limitations and Future Directions

The primary constraint of DPT is its reliance on optimal action labels during the pretraining phase. In many real-world scenarios, the "optimal" action is unknown. While the researchers demonstrated that using "good enough" data (such as that from a trained PPO agent) still yields functional models, there is a performance trade-off.

Future research will focus on scaling DPT to more complex, high-dimensional environments and investigating methods to provide training signals in domains where human or algorithmic experts are unavailable. This work suggests that supervised pretraining on decision-making data could be a vital path toward creating foundation models capable of truly autonomous, adaptive behavior.

Summary updated

BibTeX
@inproceedings{lee2023supervised,
  author = {Jonathan Lee and Annie Xie and Aldo Pacchiano and Yash Chandak and Chelsea Finn and Ofir Nachum and Emma Brunskill},
  title = {{Supervised Pretraining Can Learn In-Context Reinforcement Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=dCYBAGQXLo},
}
Figure