Chapter 2: The Offline RL Problem
"The value function is an optimist. Given the chance, it will assign infinite value to actions it has never seen – and that is precisely the problem."
From BC to RL: What Changes
Behavioral cloning ignores rewards. It copies what the expert did, not what the expert was trying to achieve.
The natural next step: use the reward signal. If we have a dataset of transitions $(s, a, r, s')$, we can try to learn a policy that maximizes cumulative reward – not just imitates observed behavior. This is the promise of offline RL.
The tool that makes online RL work is Q-learning: learn a value function $Q(s, a)$ that estimates the expected future reward of taking action $a$ in state $s$, then act greedily with respect to it.
The question: can we apply Q-learning to a fixed offline dataset? The answer is yes – but with a catastrophic failure mode that requires careful handling.
Q-Learning: A Brief Recap
The Q-function satisfies the Bellman optimality equation:
We learn $Q_\theta$ by minimizing the TD error (Temporal Difference):
where $Q_{\bar{\theta}}$ is a target network – a periodically updated copy of $Q_\theta$ used to stabilize training.
In online RL, the agent collects new transitions by acting in the environment. When $Q_\theta$ becomes inaccurate somewhere, the agent will visit those states, get real rewards, and correct the estimate.
In offline RL, the dataset $\mathcal{D}$ is fixed. There is no feedback loop.
The Extrapolation Error Problem
Here is the key issue. During the $\max_{a'}$ step in the Bellman backup:
the optimizer searches over all possible actions $a'$ – including actions that never appear in the dataset $\mathcal{D}$.
For an action $a' \notin \mathcal{D}$, the Q-function has no training signal. Its value at $(s', a')$ is determined entirely by generalization from nearby points – which, for neural networks, can be arbitrarily optimistic.
When the Bellman backup picks this overestimated $Q(s', a')$ as the target, it propagates the overestimation backward through the chain:
This is bootstrapping error: errors propagate and amplify through the TD update chain.
A Concrete Example
Suppose our dataset contains transitions from a chemical process. The operator always kept temperature between 380–420K. The Q-function is trained on these states.
At state $s'$ near the boundary (say, 419K), the $\max_{a'}$ step might find that the Q-function predicts high reward for an OOD action such as increase heating to 450K – an action never taken by the operator. There's no training data to contradict this. The Q-function has generalized optimistically into that region.
The Bellman update then uses this value as a target, inflating $Q(s, 419K, \text{heat})$. This propagates backward, inflating values at earlier states. The resulting policy will confidently drive the process into dangerous territory – and the Q-function will predict high rewards all the way there.
This is not a corner case. It is the default behavior of Q-learning on offline data.
Formal Statement: The Performance Gap
Let $\hat{\pi}$ be the greedy policy with respect to a learned Q-function:
Define the estimated performance as the return the Q-function promises at the start of an episode, $\hat{J}(\hat{\pi}) = \mathbb{E}_{s_0 \sim \rho_0}\bigl[Q_\theta(s_0, \hat{\pi}(s_0))\bigr]$, and the true performance $J(\hat{\pi})$ – what the policy actually achieves in the environment.
The gap between them is given exactly by a standard telescoping identity (a form of the simulation lemma):
Here $d^{\hat{\pi}}$ is the normalized discounted state-action occupancy of $\hat{\pi}$, and $\mathcal{B}^{\hat{\pi}} Q(s,a) = r(s,a) + \gamma\, \mathbb{E}_{s'}\bigl[Q(s', \hat{\pi}(s'))\bigr]$. For the greedy policy $\mathcal{B}^{\hat{\pi}} Q_\theta$ coincides with the optimality backup $\mathcal{B}^{\ast} Q_\theta$, so the right side is simply the Bellman error of the learned Q-function, averaged over the states and actions that the learned policy visits.
This is the right way to frame the problem. The left side is what we fear: the gap between the promised and the real return. The right side shows what drives it: Bellman error measured under $d^{\hat{\pi}}$, not under the data distribution.
This is what makes OOD overestimation dangerous. TD training drives the Bellman error down only on pairs $(s, a)$ that appear in $\mathcal{D}$. On actions the data never contains nothing constrains it, and those are exactly the actions the greedy policy seeks out, because that is where $Q_\theta$ happens to be highest. Every positive residual along the policy's own path adds to the promised return, so real performance can be arbitrarily worse than estimated.
The crucial asymmetry: the error that matters is measured under $d^{\hat{\pi}}$, while training controls it only under $d^{\pi_{\beta}}$. A policy that stays near the behavior policy keeps the two distributions close. The greedy policy actively pushes them apart.
Distribution Shift: The Offline RL Version
In Chapter 1, we saw distribution shift in BC: the policy visits different states than the expert, causing compounding errors in action prediction.
In offline Q-learning, the distribution shift is in action space:
- Training distribution: $(s, a) \sim d^{{\pi_{\beta}}}(s) \cdot \pi_{\beta}(a \mid s)$ – state-action pairs from the dataset
- Evaluation distribution: $(s, a) \sim d^{{\hat{\pi}}}(s) \cdot \hat{\pi}(a \mid s)$ – state-action pairs under the greedy policy
The greedy policy will select actions outside the training distribution whenever the Q-function is overoptimistic there – which is exactly when no corrective training signal exists.
Offline Q-learning also combines all three ingredients of what Sutton and Barto call the "deadly triad": function approximation, bootstrapping and off-policy learning. The triad explains why errors can grow without bound once they appear; the action-space distribution shift above explains where those errors come from.
Empirical Demonstration
📄 Full code:
extrapolation_error.py
import torch
import torch.nn as nn
import numpy as np
class QNetwork(nn.Module):
def __init__(self, state_dim, action_dim, hidden=128):
super().__init__()
self.net = nn.Sequential(
nn.Linear(state_dim + action_dim, hidden), nn.ReLU(),
nn.Linear(hidden, hidden), nn.ReLU(),
nn.Linear(hidden, 1),
)
def forward(self, s, a):
return self.net(torch.cat([s, a], dim=-1)).squeeze(-1)
def measure_ood_overestimation(Q, dataset_actions, all_actions, state):
"""
Compare Q-values for in-distribution vs OOD actions at a fixed state.
"""
s = state.unsqueeze(0).expand(len(all_actions), -1)
with torch.no_grad():
q_all = Q(s, all_actions)
q_in_dist = Q(
state.unsqueeze(0).expand(len(dataset_actions), -1),
dataset_actions
)
print(f"In-distribution actions | Q mean: {q_in_dist.mean():.3f}, max: {q_in_dist.max():.3f}")
print(f"All actions (incl. OOD) | Q mean: {q_all.mean():.3f}, max: {q_all.max():.3f}")
gap = (q_all.max() - q_in_dist.max()).item()
print(f"OOD − ID max Q gap : {gap:+.3f} (positive ⇒ OOD overestimation)")
return gap
Running this:
# Dataset: actions restricted to [-0.5, 0.5]
dataset = build_dataset(n=10_000)
# Train Q-network with standard TD – max_{a'} searches over the FULL space [-2, 2]
Q = train_q_network(dataset, epochs=3000)
# Compare Q-values at a representative state
eval_state = torch.zeros(STATE_DIM)
in_dist_actions = torch.clamp(torch.randn(2_000, ACTION_DIM) * 0.2, -0.5, 0.5)
all_actions = torch.rand(2_000, ACTION_DIM) * 4 - 2 # full range
gap = measure_ood_overestimation(Q, in_dist_actions, all_actions, eval_state)
Output after 3000 TD steps of vanilla Q-learning on a dataset where actions are restricted to [-0.5, 0.5] but the action space is [-2, 2]:
In-distribution actions | Q mean: 2120.517, max: 2325.024
All actions (incl. OOD) | Q mean: 2300.042, max: 3354.532
OOD − ID max Q gap : +1029.508 (positive ⇒ OOD overestimation)
The true optimal value at this state is about $-3.3$ for every action in the range. The learned Q-function is wrong by three orders of magnitude, and wrong in a telling direction: its highest values lie on actions far outside the data (a maximum of about $+3355$, against $+2325$ inside the data), and bootstrapping has inflated even the in-distribution values far above the truth. The greedy policy will select the OOD actions confidently.
The mechanism is easiest to see on a one-dimensional slice of the action space. The figure below, produced by code/chapter2_4_figures.py on the same environment, tracks $Q(s=0, a)$ during training (a separate run: magnitudes vary with the seed, the pattern does not). After 1000 TD steps the network is still pessimistic and roughly the right shape, peaking at the dataset actions. By 2000 steps the optimism injected through $\max_{a'}$ over unseen actions has lifted the whole curve; by 3000 steps the edges of the action space, where there is no data at all, are rated highest.

The Core Challenge
Everything in offline RL comes down to this tension:
| Goal | Constraint |
|---|---|
| Maximize reward → exploit Q-function | Q-function is unreliable for OOD actions |
| Stay close to behavior policy | Behavior policy may be suboptimal |
- Too conservative → policy = BC (no improvement over behavior).
- Too aggressive → policy exploits Q-function errors (catastrophic failure).
The solution space splits into two families:
Policy-constraint methods – restrict the learned policy to stay close to $\pi_{\beta}$:
Examples: TD3+BC, BEAR, BCQ.
Value-pessimism methods – instead of constraining the policy, make Q-values pessimistic for OOD actions:
The intuition: Q-values are pushed down on actions from a broad proposal $\mu$ (uniform, or the current policy) and pushed back up on the logged actions, so only actions the data do not support lose value; without the second term every Q-value would just shift down together. The greedy policy then prefers in-distribution actions.
This is the approach of CQL (Chapter 4). IQL (Chapter 5) reaches a similar effect differently: it never evaluates an action outside the data, using expectile regression instead of an explicit penalty.
The Offline RL Algorithm Landscape
Beyond value-pessimism, two other families are widely used. Chapters 4–8 cover them in depth – value pessimism (Chapters 4–5), policy constraints (Chapter 6), sequence models (Chapter 7) and model-based methods (Chapter 8); the map below places them side by side.
Policy-constraint and Actor-Critic methods keep the learned policy close to the behavior policy, either by explicit constraints or by regularizing the actor toward the data. TD3+BC (Fujimoto & Gu, 2021) adds a behavioral cloning term to the actor loss: $\pi$ maximizes $\lambda Q(s, \pi(s)) - (\pi(s) - a)^{2}$ (with $Q$ scaled by mean $\lvert Q \rvert$ over the batch) so it stays near the data while improving on it. AWAC (Advantage-Weighted Actor-Critic) and AWR (Advantage-Weighted Regression) fit the policy with importance weights derived from the advantage; the actor is fitted only on dataset pairs $(s, a)$, although AWAC's critic still evaluates the current policy and therefore queries Q at its actions; IQL (Chapter 5) removes those queries as well. BEAR and BCQ restrict the policy support (e.g. to actions close to the dataset or generated by a conditional VAE). All of these are actor-critic in the sense that they train both a critic (Q or V) and an actor (policy), but the actor is constrained or regularized rather than greedy over an unconstrained Q.
Decision Transformers (DT) (Chen et al., 2021) take a different view: treat offline RL as sequence modeling. The model is given a trajectory prefix (states, actions, returns-to-go or rewards) and predicts the next action autoregressively. There is no Bellman backup and no explicit Q-function; the “policy” is implicit in the conditional distribution over actions given past context and desired return. Offline DT is trained by supervised learning on $(s, a, R)$ chunks from the dataset, often with return-conditioning so that at test time you can ask for “high return” behavior. This avoids extrapolation error by construction (no $\max_{a'}$ over OOD actions) but shifts the challenge to generalization of the sequence model and the choice of conditioning. Variants include Q-learning DT (e.g. QDT) that combine return-conditioning with TD learning for better credit assignment.
For practitioners: value-pessimism (CQL, IQL) and model-based methods (Chapter 8) are a strong default for continuous control and process data; policy-constraint (e.g. TD3+BC) and DT are worth trying when you have long horizons, multi-task data, or a preference for sequence-model tooling. References for these families are listed at the end of this chapter.
Why Not Just Use BC?
A reasonable question at this point: if offline Q-learning is so dangerous, why not just use BC?
The answer depends on the quality and coverage of the behavior policy.
BC is sufficient when: - The behavior policy is near-optimal - The task horizon is short - The dataset covers the states you'll encounter
BC is insufficient when: - The behavior policy is suboptimal (real operators make mistakes) - You want to interpolate between good parts of different trajectories - The task requires reasoning about long-term consequences (long horizons, where errors compound) - You have reward information and want to exploit it
In industrial settings, all four conditions for BC insufficiency typically hold. Operators are not optimal; different shifts make different decisions; a 30-minute prediction horizon requires long-term planning; and the reward function (filler%, temperature stability, energy use) is well-defined.
This is the motivation for the methods in Chapters 3–9.
Summary
| Issue | Description |
|---|---|
| Extrapolation error | Q-values overestimated for unobserved actions |
| Bootstrapping amplification | TD updates propagate errors backward through time |
| Distribution shift | Greedy policy visits states/actions not in dataset |
| Deadly triad | Function approx + bootstrapping + off-policy = unstable |
The two main remedies: policy constraints (stay near $\pi_{\beta}$) and value pessimism (push OOD Q-values down). CQL implements the second approach with an elegant regularization objective – which is where we go next. This chapter also mapped the broader landscape – policy-constraint and actor-critic methods (TD3+BC, AWAC, BEAR, BCQ) and Decision Transformers – which Chapters 6 and 7 develop next to value pessimism (Chapters 4–5) and model-based methods (Chapter 8).
References
- Levine, S. et al. (2020). Offline Reinforcement Learning: Tutorial, Review, and Perspectives. arXiv:2005.01643.
- Kumar, A. et al. (2019). Stabilizing Off-Policy Q-Learning via Bootstrapping Error Reduction (BEAR). NeurIPS. arXiv:1906.00949.
- Fujimoto, S. et al. (2019). Off-Policy Deep Reinforcement Learning without Exploration (BCQ). ICML. arXiv:1902.08754.
- Kumar, A. et al. (2020). Conservative Q-Learning for Offline Reinforcement Learning (CQL). NeurIPS. arXiv:2006.04779.
- Fujimoto, S. & Gu, S.S. (2021). A Minimalist Approach to Offline Reinforcement Learning (TD3+BC). NeurIPS. arXiv:2106.06860.
- Nair, A. et al. (2020). Accelerating Online Reinforcement Learning with Offline Datasets (AWAC). arXiv:2006.09359.
- Chen, L. et al. (2021). Decision Transformer: Reinforcement Learning via Sequence Modeling. NeurIPS. arXiv:2106.01345.
- Sutton, R. S., & Barto, A. G. (2018). Reinforcement Learning: An Introduction (2nd ed.), Ch. 11. MIT Press. (deadly triad)