From Policy Evaluation to Off-Policy Control: Provable Emergence of In-Context Q-Learning
Organizations: Southern University of Science and Technology (SUSTech) · University of Electronic Science and Technology of China (UESTC)
Abstract
Transformers can implement reinforcement-learning algorithms in context, yet how off-policy control emerges within Transformers remains poorly understood. We study Q-learning, a foundational model-free control algorithm that combines off-policy bootstrapping with greedy policy improvement. We prove that a two-layer attention-only Transformer can implement a finite-temperature form of Q-learning, where the temperature controls the approximation to greedy action selection, recovering window Q-learning as . We train the structured Transformer on randomly generated MDP tasks using output-only supervision. Experiments show that the theoretically predicted parameter structure emerges during training, including the internal greedy action-selection mechanism, and that the trained Transformer achieves performance comparable to Q-learning on unseen tasks. Our theoretical analysis further shows that the equivalent realizations form a solution manifold and that, under suitable task-diversity conditions, the training iterates converge locally to this manifold at an exponential rate. For the random-task model analyzed here, the local worst-case number of gradient steps needed to reduce the distance to the manifold by a factor is , quantifying the increasing optimization cost as the learned update approaches window Q-learning.
Figures & tables
Appendix figures & tables24 assets
Supplementary material from the paper’s appendix.
Appendix
| Symbol | Meaning and default |
|---|---|
| State count , action count , Q-feature dimension . | |
| Q parameter ; distinct Transformer parameter vector . | |
| Teacher temperature. | |
| Q-update step , discount , behavior exploration , Adam learning rate. | |
| Independent contexts per optimizer update; number of optimizer updates. | |
| Transitions within one context, default ; not minibatch size . |
| Tasks ( ) | Soft error (%) | Hard error (%) | Greedy tr (%) | Greedy ctx (%) |
|---|---|---|---|---|
| 0.32 | ||||
| 5.12 | ||||
| 10.24 | ||||
| 20.48 | ||||
| 25.60 | ||||
| 37.76 |
| Tasks ( ) | Soft error (%) | Hard error (%) | Greedy tr (%) | Greedy ctx (%) |
|---|---|---|---|---|
| 0.32 | ||||
| 5.12 | ||||
| 10.24 | ||||
| 20.48 | ||||
| 25.60 | ||||
| 37.76 |
| Tasks ( ) | |||
|---|---|---|---|
| 0.32 | |||
| 5.12 | |||
| 10.24 | |||
| 20.48 | |||
| 25.60 | |||
| 37.76 |
| Method | Mean | 95% interval |
|---|---|---|
| Transformer | 0.479225 | |
| Soft window-Q | 0.480136 | |
| Hard window-Q | 0.465381 | |
| Online Q, constant | 0.449844 | |
| Online Q, visit count | 0.522897 | |
| Oracle | 0.529490 |
| Soft error (%) | Hard error (%) | Teacher bias (%) | Greedy (%) | |
|---|---|---|---|---|
| 1 | 10.0370 | 99.9985 | ||
| 0.8 | 7.1140 | 99.9974 | ||
| 0.5 | 3.2198 | 99.9962 | ||
| 0.2 | 0.6385 | 99.9990 | ||
| 0.1 | 0.1960 | 99.9707 |
| Soft error (%) | Hard error (%) | Greedy ( ) | ||
|---|---|---|---|---|
| 1 | 99.994 | 0.200113 | ||
| 2 | 99.995 | 0.200128 | ||
| 4 | 99.995 | 0.200161 | ||
| 8 | 99.999 | 0.200223 | ||
| 16 | 99.999 | 0.200299 | ||
| 32 | 100.000 | 0.200373 |
| Condition | Soft error (%) | Hard error (%) | Greedy (%) | |
|---|---|---|---|---|
| Constant Adam | 10,240,000 | |||
| Uniform cosine | 10,240,000 | |||
| Low-rate extension | 20,480,000 |
| 1 | 1 | 1.000000 | |||
|---|---|---|---|---|---|
| 0.8 | 1.25 | 1.250000 | |||
| 0.5 | 2 | 2.000002 | |||
| 0.2 | 5 | 4.992236 | |||
| 0.1 | 10 | 8.174396 |
| Transitions (M) | 95% interval half-width | ||||
|---|---|---|---|---|---|
| 1 | 20.48 | ||||
| 5 | 102.4 | ||||
| 10 | 204.8 | ||||
| 20 | 409.6 | ||||
| 40 | 819.2 | ||||
| 80 | 1638.4 |
| Dense matched (%) | Dense common 20 (%) | Tabular matched (%) | |
|---|---|---|---|
| 1 | |||
| 5 | |||
| 10 | |||
| 20 | |||
| 40 | |||
| 80 |
| Transformer [95% CI] | Hard Q (window) | Soft Q (window) | Oracle | Random | |
|---|---|---|---|---|---|
| 1 | 0.5036 [0.4835, 0.5237] | 0.4740 | 0.5036 | 0.5374 | 0.0033 |
| 0.8 | 0.5033 [0.4829, 0.5227] | 0.4740 | 0.5025 | 0.5374 | 0.0033 |
| 0.5 | 0.5003 [0.4804, 0.5198] | 0.4740 | 0.4996 | 0.5374 | 0.0033 |
| 0.2 | 0.4880 [0.4686, 0.5074] | 0.4740 | 0.4861 | 0.5374 | 0.0033 |
| 0.1 | 0.4833 [0.4644, 0.5022] | 0.4740 | 0.4795 | 0.5374 | 0.0033 |
In-Context RL
In-context reinforcement learning studies how agents adapt their policies from interaction histories without updating model parameters.
See all 42 papers