Learning How to Infer Partial MDPs for In-Context Adaptation and Exploration

Chentian Jiang, Nan Rosemary Ke, Hado van Hasselt

TL;DR

Posterior sampling offers a principled way to balance exploration and exploitation in reinforcement learning, but performing exact Bayesian inference and dynamic programming on full environment models is often computationally intractable. This paper shows that a transformer can be trained to perform in-context approximate Bayesian inference over compact partial MDPs (small abstract graphs). At test time, running posterior sampling over these cheap partial models enables an agent to explore effectively and adapt to unseen tasks without any gradient updates, achieving roughly 90% of optimal reward.

What Problem Does This Paper Address?

In in-context meta-reinforcement learning, an agent must adapt to unseen tasks strictly through real-time context (the ongoing history of states, actions, and rewards) while keeping its network weights frozen.

A natural approach is posterior sampling (an extension of Thompson sampling to MDPs), where the agent maintains a distribution over possible environment models, samples a candidate model, plans an optimal policy for it, and uses the resulting transitions to update its posterior beliefs. However, standard posterior sampling has two major hurdles in practice:

  1. Intractable Bayesian Inference: Calculating exact posteriors requires explicit prior distributions and exact Bayesian updates, which are rarely available or tractable in complex environments.
  2. Expensive Planning: Running dynamic programming (e.g., value iteration) over large, fine-grained state-action spaces at every update is prohibitively slow.

Methods

The authors tackle these challenges by replacing the exact inference engine with a transformer and replacing full environment models with partial MDPs:

Context (History of s, a) ──> [ Frozen Transformer ] ──> Posterior over Graph Edges
                                                               │
                                                       Sample concrete graph
                                                               │
Action in Full Env <── Map Action <── [ Value Iteration ] <────┘
  • Partial MDPs as Small Graphs: Rather than modeling the full environment dynamics, the agent maintains an abstract model over a compressed state space $\mathcal{V}$ (a small graph). In this model, vertices represent core state properties, directed edges denote transitions under available actions, and rewards reside on specific goal vertices. Unnecessary variables (such as resource depletion or low-reward side goals) are deliberately excluded.
  • Transformer-Based Amortized Inference: An autoregressive transformer encoder $f_\theta$ consumes the sequence of state-action transitions $C_{1:t}$ and directly outputs Bernoulli probabilities for the existence of each edge $\mathbf{e}$ in the graph, as well as a categorical distribution over vertex assignments $v_t$ for state $s_t$.
  • Offline Supervised Meta-Training: The transformer is trained offline on data collected by a random policy across training tasks. Supervised cross-entropy losses encourage the model to infer ground-truth graph edges $e_k^*$ and state-to-vertex mappings $v_t^*$.
  • Online Posterior Sampling (Algorithm 1): At test time, network weights are frozen. At every time step $t$, the agent:
  • Queries the transformer with the current context $C_{1:t}$ to get edge probabilities.
  • Samples a deterministic partial model graph ($\mathbf{e} \sim \hat{p}_\theta$).
  • Solves it quickly via value iteration to find policy $\pi$.
  • Maps and executes action $a_t$ in the real environment and appends $(a_t, s_{t+1})$ to the context.

Datasets

The authors evaluate on a simplified, symbolic variant of the Symbolic Alchemy benchmark (Wang et al., 2021):

  • Environment Setup: An agent modifies a stone across 3 discrete features (color, size, shape) by dipping it into 6 possible chemical potions to reach a maximum-reward target stone (+15 reward), before placing it in a cauldron. Potions can only be used once per trial, but the partial model deliberately ignores potion depletion.
  • Task Distribution: Each task is parameterized by a graph ("cube") with 8 vertices and 12 possible edges defining how potions transform stone features. Out of 109 possible Alchemy cubes:
  • 88 cubes are used for offline training (500 episodes per cube, collected via a random policy).
  • 11 cubes are reserved for validation/hyperparameter tuning.
  • 10 held-out cubes are used for zero-shot testing (evaluated across 20 random stone sequences per cube = 200 test episodes).

Key Insights and Ideas

  • Incomplete Models Are Sufficient for High Performance: The partial models omit key dynamics (such as potions becoming empty after use). Despite this model mismatch, dynamic programming on the small graph finds the shortest path to the highest reward, which typically uses each required potion at most once.
  • Sampling Drives Productive Exploration: In an ablation that removes sampling and uses expected transition probabilities, the agent becomes overly cautious, visits fewer unique abstract state-actions, and adapts its model more slowly. Sampling candidate graphs injects targeted exploration that quickly disambiguates the underlying environment.
  • Supervision Unlocks Random Offline Data: Unlike many meta-RL methods that require expert demonstrations or reinforcement learning rollouts, the transformer successfully learns Bayesian inference mechanics purely from naively collected random walk data paired with partial-graph ground truth.

Key Results

  • Fast Model Convergence: On held-out tasks, the transformer’s Mean Absolute Error (MAE) on edge predictions drops close to zero within 200 environment steps (Figure 3), closely matching an Exact Posterior Sampling (Exact PS) oracle that uses a handcrafted prior and exact Bayesian updating over the known 109-cube space.
  • Near-Optimal Reward Adaptation: The agent adapts in-context to achieve approximately 90% of the optimal trial reward within 100 time steps (10 trials), nearing the ceiling of the exact posterior sampling oracle and true partial model (Figure 5).
  • Balanced Exploration: The method visits nearly the same number of unique state-actions in partial model space as the Exact PS oracle, effectively avoiding both under-exploration (seen in the deterministic ablation) and excessive exploration (seen in random baselines).

Limitations and Future Work

  • Reliance on Ground-Truth Graph Supervision: The framework currently requires ground-truth graph structures ($e_k^*$) and state-vertex labels ($v_t^*$) during offline training. In real-world environments, these supervision signals are rarely available.
  • Fixed, Simplified Model Structures: Experiments were limited to a uniform 8-node cube topology with deterministic transitions and fixed reward locations.
  • Future Directions: The authors suggest integrating value-equivalence methods (e.g., MuZero / Value Prediction Networks) to learn abstract partial model representations directly from task reward signals without needing explicit graph labels.

Summary updated

BibTeX
@inproceedings{jiang2023learning,
  author = {Chentian Jiang and Nan Rosemary Ke and Hado van Hasselt},
  title = {{Learning How to Infer Partial MDPs for In-Context Adaptation and Exploration}},
  booktitle = {RRL @ ICLR},
  year = {2023},
  url = {https://openreview.net/forum?id=TdKW3Evujf},
}
Figure