Evaluation lab · San Francisco · London · Zürich
Reinforced Labs Request a briefing
Reinforcement learning

Offline reinforcement learning: learning from logged data without falling off the cliff

Offline RL learns a policy from a fixed log of past decisions, with no chance to try anything new. A seeded toy shows how the max in Q-learning turns gaps in the data into confident, catastrophic choices, and how behaviour regularisation, CQL and IQL keep the policy where the data can vouch for it.

Part of Reinforcement learning. New to the topic? Start with What is reinforcement learning? A guide from gridworlds to language models.

Offline reinforcement learning (also called batch RL) learns a decision-making policy entirely from a fixed dataset of logged interactions, with no further trial and error in the environment. The central difficulty is distribution shift: a learned value function is only trustworthy for actions that appear in the data, and the maximisation at the heart of RL actively seeks out the actions where it is wrong.

This guide explains why that happens, using a toy problem small enough to solve exactly and an interactive figure you can break yourself. It then walks through the three families of fixes (behaviour regularisation, conservatism and in-sample learning), how to evaluate an offline policy before deploying it, and why the same ideas show up in preference-based training of language models. Every number below comes from a seeded numpy simulation that we ran; the figure runs the same code in your browser.

A concrete example: the cliff the data never saw#

Imagine a controller with one knob, an action between and . The best setting is , which earns a reward of 1 per step. Push the knob past and you fall off a cliff: the reward drops linearly, to about at the extremes. The task repeats forever with discount factor , so the best achievable value is .

You do not get to experiment. You get a log of 200 past decisions made by a cautious operator who kept the knob between and , with the reward observed each time (plus a little noise). The operator never tried the good setting and never went near the cliff. You fit a smooth model of , the long-run value of each knob setting, to this log with fitted Q iteration (the batch version of Q-learning), then pick the setting with the highest .

What happens, for the dataset with seed 1: the fitted model is accurate inside the logged range, but a cubic curve has to do something outside it, and here it bends upwards at . The greedy policy picks , the critic reports a value of 20.3, twice the true optimum, and the policy actually earns . It drove off the cliff with full confidence. Across 50 random datasets of the same shape, naive fitted Q iteration chose an action outside the logged range every single time, landed in the cliff zone in 49 of them and ended up with a negative value in 47, while its median value estimate was 19.2. The operator it was supposed to improve on earned 1.7.

Nothing went wrong with the regression; it went wrong with the max.

Offline RL vs online RL, off-policy RL and imitation learning#

In ordinary reinforcement learning the agent acts, sees what happens and corrects itself. If its value function overrates an action, it tries the action, gets a low reward and the error disappears. Offline RL removes that feedback loop. Levine, Kumar, Tucker and Fu's tutorial frames this as the main reason offline RL is hard and the main reason it is worth doing: in robotics, healthcare, recommendation and dialogue, exploration is expensive or unsafe, but logs are plentiful [1].

SettingWhere data comes fromUses reward?Can it beat the data?Main risk
Online on-policy RLThe current policy, freshly collectedYesYesSample cost, unsafe exploration
Online off-policy RL (DQN, SAC)A replay buffer of past policies, constantly refreshedYesYesInstability, but errors get corrected by new data
Offline RLA fixed log from some behaviour policyYesYes, within what the data supportsExtrapolation error on unseen actions
Imitation learning (behaviour cloning)DemonstrationsNoNo, it copies the demonstratorCopies mistakes; compounding errors

The difference between off-policy and offline is subtler than it looks. Off-policy algorithms can in principle learn from any data, but Fujimoto, Meger and Precup showed that standard off-policy deep RL agents fail when trained purely on a fixed batch, even a batch generated by an expert, because nothing ever corrects their value estimates for actions the batch does not contain. They named the effect extrapolation error [2]. Behaviour cloning, at the other end, is perfectly stable offline but cannot use the reward to do better than the data. Offline RL sits between them: it uses rewards to improve on the behaviour policy while staying close enough to the data that its value estimates mean something. If you only have demonstrations and no rewards, the relevant tools are imitation and inverse reinforcement learning instead.

Why distribution shift breaks Q-learning#

Fitted Q iteration repeats one regression. Given the current estimate , compute a target for every logged transition and fit to those targets:

Here is the -th logged transition, is the discount factor and the maximum runs over every action available in the next state . This is the sample version of the Bellman optimality equation, and it is exactly the update Ernst, Geurts and Wehenkel studied as batch-mode RL two decades ago [11].

The regression only ever sees at logged pairs . The target, though, asks for at the maximising action , which can be any action at all. Two things then compound. First, selection: if the estimates at unseen actions are noisy, the maximum picks out the ones with the most positive error, because the expected maximum of noisy estimates exceeds the maximum of their expectations. Second, bootstrapping: the inflated value becomes part of the next target, so the error is passed back through every state that can reach it. In our one-state example the fixed point of fitted Q iteration is , so a reward overestimate of 2.03 at becomes a value overestimate of 20.3 once multiplied by .

Online, the next rollout punishes this optimism. Offline, there is no next rollout. Kumar et al. call the same mechanism bootstrapping error and show that it accumulates through the backups rather than averaging out [3].

See it happen: dataset coverage vs extrapolation error#

Setup. True reward ; behaviour actions uniform on , clipped to ; 200 transitions with reward noise SD 0.1; critic linear in the first three Legendre polynomials plus an intercept; . The coverage half-width controls how much of the action space the log covers. We compare five learners (formulas in the next section): naive fitted Q iteration, a support-constrained maximum in the spirit of BCQ (only actions within 0.05 of a logged action are eligible), a CQL-style penalty (), an IQL-style expectile learner (, advantage weighting ), and behaviour cloning. For each we record what its own critic claims the policy is worth and what the policy really earns. Seeds 1 to 50 for every coverage level; this is a simulation, not a benchmark.

-1012-1.0-0.50.00.51.0Reward per step: truth vs what each critic believestrue r(a)naive criticCQL criticaction a (shaded: actions in the dataset; triangles: actions chosen)Policy value: estimated (outline) vs actual (solid)-505101520optimal 10Naive FQICQL-styleIQL-styleSupport maxBC
±0.30 α = 0.10 seed 1

Figure 1. Simulation. Top: logged rewards (dots), the true reward curve, and the per-step reward that the naive and CQL-style critics believe in (each critic's ). Triangles mark the action each method chooses. Bottom: each method's own value estimate (outline) against the value its policy actually earns (solid); the optimum is 10. Slide coverage up and watch the naive critic's estimate collapse back to reality once the data reaches the cliff edges. The static version shows coverage ±0.3, seed 1.

The full sweep, averaged over 50 datasets per coverage level:

-505100.20.40.60.81.01.2coverage half-width w (behaviour actions in [-0.2 - w, -0.2 + w])Naive FQICQL-styleIQL-styleSupport maxBCbest action in dataActual value of the learned policy (mean of 50 seeds; optimum 10)
Figure 2. Simulation, 50 seeds per point. Actual value of each learned policy against coverage. The dashed line is the best action the log contains. Naive fitted Q iteration is the worst method whenever the data stops short of the cliff edges, and the best (with CQL) once it does not.
Coverage Naive FQI: claims / earnsSupport maxCQL-styleIQL-styleBCBest logged action
0.1514.4 / 3.501.111.761.222.66
0.319.2 / 6.541.784.331.685.48
0.631.1 / 9.916.389.692.909.99
0.818.2 / 7.059.648.852.7410.0
1.08.1 / 9.839.839.978.563.0410.0

Four things are worth noticing. The naive critic's claimed value is worst exactly when its policy is worst: overestimation and failure are the same event, so you cannot use the critic to catch it. With full coverage () the naive method is excellent; offline RL is not hard because of the data size but because of the data's support. The support-constrained learner can slightly beat the best logged action at low coverage because it may step 0.05 beyond the data, and it underperforms at because the cubic critic is misspecified inside the support, a reminder that staying in-distribution does not fix a bad function class. And behaviour cloning is safe but stuck at the operator's level, around 2 to 3, because the operator was mediocre.

How offline RL algorithms fix it#

Every serious offline RL method is a way of keeping the maximisation away from actions the data cannot vouch for. They differ in where the constraint lives.

Behaviour regularisation and policy constraints#

The most direct fix constrains the policy. BCQ trains a generative model of the behaviour policy and only lets the learned policy choose among (slightly perturbed) actions that the model considers likely, so the maximisation in the target never reaches far outside the data [2]. BEAR relaxes this from matching the behaviour distribution to staying within its support, using a kernel distance between action samples [3]. Wu, Tucker and Nachum's behaviour-regularised actor-critic framework compared many of these variants and found that much of the added machinery was unnecessary for good performance [4]. TD3+BC took that to its conclusion. It adds one behaviour cloning term to an ordinary actor update:

Here is the deterministic policy's action, is the logged action in the same state, and normalises the value term by the average magnitude of so a single (2.5 in the paper) works across tasks. The policy is pulled towards higher value but pays a squared penalty for straying from what was logged. With this and state normalisation, Fujimoto and Gu matched the state of the art of the time while more than halving run time [7]. Policy constraints are easy to reason about, but their quality is capped by how well you can estimate the behaviour policy, and in high-dimensional action spaces that estimate is itself a hard problem. Our support-max learner is the idealised version with a perfect support estimate, which is why it looks so good in one dimension.

Conservatism: Conservative Q-Learning#

CQL moves the constraint from the policy to the critic. It adds a penalty that pushes down on actions the current policy (or a soft maximum over all actions) favours, and up on actions in the data [5]:

The log-sum-exp term is a soft version of , the second term inside the bracket is the average on logged actions, is the usual Bellman target and sets the strength. Intuitively: any action whose value is propped up only by extrapolation gets dragged down, while logged actions are anchored by real rewards. Kumar et al. prove that with an appropriate , the learned lower-bounds the true value of the policy in expectation, so policy improvement on it is pessimistic rather than optimistic [5]. You can see the shape in Figure 1: the CQL critic is roughly correct inside the data and falls off steeply outside it.

The price is a hyperparameter that matters a great deal. In our toy, at coverage 0.6:

CQL Mean actual value, Datasets (of 50) that chose the cliff at
0.032.944.58159.96
0.11.786.3859.97
0.31.395.6109.73
1.01.203.3009.01

Too little conservatism lets some datasets through to the cliff; too much and the policy hugs the behaviour mean and gives back most of the possible improvement. The value lower bound is a statement about tabular or well-specified critics; with our misspecified cubic critic the CQL estimates were still somewhat optimistic about the actions it chose (3.7 claimed against 2.0 earned for seed 1 at ), just far less so than the naive critic.

In-sample learning: Implicit Q-Learning#

IQL avoids the problem at its root by never evaluating an action outside the dataset [6]. Instead of a maximum over actions, it estimates the value of the best actions in the data with an upper expectile:

is a state value, is the expectile level and is an asymmetric squared loss that penalises underestimates more than overestimates, so settles near the upper end of the values of logged actions; as it approaches the maximum over actions that appear in the data. The policy is then extracted by advantage-weighted regression: copy logged actions, weighted by . In the toy, IQL never chose the cliff at any coverage level and reached 9.7 at . Its cost shows at full coverage, where it earned 8.6 against CQL's 10.0: weighting logged actions only averages over good ones, it cannot put all its mass on the single best one unless is very large.

Other approaches#

Two more ideas are worth knowing. With a large and diverse enough dataset, plain off-policy methods can work: Agarwal, Schuurmans and Norouzi trained agents on the full replay logs of an Atari agent and found that recent off-policy algorithms trained only on the logs outperformed the agent that produced them [9]. This is our regime: when coverage is good, extrapolation error is small. Decision Transformer recasts offline RL as sequence modelling, predicting actions conditioned on a desired return [10]; it is simple and stable, but it learns from trajectory-level patterns and is less able to stitch together the good halves of different trajectories, which value-based methods do naturally.

How do you evaluate an offline RL policy?#

The awkward truth is that the reason you are doing offline RL (you cannot run the policy) is also the reason you cannot easily check it. Three practices help.

Do not trust the training critic. Figure 1 makes the point: the critic that produced the policy is the most biased judge of it. Use off-policy evaluation (OPE) with a separately fitted estimator, such as fitted Q evaluation of the fixed final policy, importance sampling when the behaviour policy's probabilities are logged, or doubly robust combinations of the two. Each has known failure modes, high variance for importance sampling over long horizons and the same support problem for model-based estimates.

Select hyperparameters offline, carefully. Many published results tune hyperparameters by running policies in the simulator, which quietly breaks the offline assumption. Paine et al. found that offline RL algorithms are sensitive to hyperparameter choices, that the choice of algorithm and Q estimator strongly affects how well offline selection works, and that with those factors controlled, policies can be ranked reliably from logged data alone [12]. Our CQL table above is a small instance of the first finding.

Use standard datasets for method comparisons. The D4RL suite provides fixed datasets with deliberately varied properties: narrow expert data, noisy data, mixtures and data that require stitching [8]. Results on one data regime rarely transfer to another. Report results with seeds and intervals, as in our guide to evaluating RL agents.

Where some online interaction is possible, a common pattern is offline pretraining followed by careful online fine-tuning; methods such as AWAC were designed for that hand-off [13].

Offline RL and language models#

Preference-based fine-tuning of language models has an offline flavour. A preference dataset is a fixed log: prompts, pairs of responses sampled from some earlier model, and a human or model judgment of which is better. Direct preference optimisation trains the policy on that fixed dataset without sampling new responses during training [14], which makes it closer to offline RL than to the online loop of classic RLHF. The same coverage question applies: the dataset only says something about responses that resemble the ones that were compared, and the KL term towards a reference model (see KL-regularised RL) plays a role similar to behaviour regularisation, keeping the policy near the region where the data is informative. When a reward model is trained offline and then optimised online, its errors on unfamiliar responses are what the policy finds, which is the overoptimisation pattern analysed in our research note on reward model overoptimization. And because the log is fixed, its label quality caps everything downstream, as discussed in our note on preference label noise. The wider picture is in reinforcement learning for LLMs.

In practice: a checklist#

QuestionWhat to do
Does the data cover good actions at all?Inspect action coverage per state cluster before choosing a method. If the best behaviour is absent, no offline algorithm can find it reliably; you need new data.
Narrow, expert-like data?Start with behaviour cloning as a baseline, then TD3+BC or IQL. Gains over BC will be modest.
Broad, mixed-quality data?Value-based methods (IQL, CQL) can stitch good segments and beat BC by a wide margin.
Safety-critical actions outside the data?Prefer explicit constraints (support constraints, action masks) over a soft penalty you must tune; combine with the methods in safe reinforcement learning.
Choosing hyperparametersUse off-policy evaluation with an estimator separate from the training critic; never select on the training critic's own value.
Before deploymentShadow mode or a small, monitored rollout; compare realised returns against the OPE estimate and stop if they diverge.

The core of the toy fits in a few lines. This reproduces the naive and support-constrained fixed points for one dataset:

import numpy as np

rng = np.random.default_rng(0)
gamma, grid = 0.9, np.linspace(-1, 1, 201)
r_true = lambda a: np.exp(-((a - 0.4) / 0.4) ** 2) - 3 * np.maximum(0, np.abs(a) - 0.75)
feats = lambda a: np.stack([np.ones_like(a), a, a**2, a**3], -1)

a = rng.uniform(-0.5, 0.1, 200)                      # the logged actions
r = r_true(a) + 0.1 * rng.standard_normal(200)        # the logged rewards
theta = np.linalg.lstsq(feats(a), r, rcond=None)[0]   # critic's reward model
r_hat = feats(grid) @ theta

# fixed point of fitted Q iteration in a one-state MDP: Q(a) = r_hat(a) + gamma * V
for name, allowed in [("naive", np.ones_like(grid, bool)),
                      ("in-support", np.abs(grid[:, None] - a).min(1) <= 0.05)]:
    k = np.flatnonzero(allowed)[r_hat[allowed].argmax()]
    print(f"{name:10s} action {grid[k]:+.2f}  claims {r_hat[k] / (1 - gamma):6.2f}"
          f"  earns {r_true(grid[k]) / (1 - gamma):6.2f}")

Failure modes#

Trusting the critic's value estimate. In the toy, the naive critic's estimate was highest exactly when its policy was worst. Overestimation is the failure, not a symptom you can monitor with the same model.

Confusing data volume with coverage. Doubling the log from the same cautious operator adds no information about the cliff. Coverage of the relevant actions matters more than size.

Over-conservatism. A large penalty or tight constraint is safe and useless: CQL with earned 3.3 at coverage 0.6, where 10 was available inside the data.

Misspecified critics inside the support. Constraining the policy to the data does not fix a function class that cannot fit the data, as the support-max learner's drop at shows.

Confounded logs. If the behaviour policy acted on information that is not in the logged state (a clinician who saw the patient, an operator who saw the weather), the data's action-outcome relationships are biased in ways no offline RL algorithm in this article corrects.

Tuning online and calling it offline. Hyperparameters selected by running policies in the environment produce optimistic results that will not hold when you truly cannot run them [12].

What the toy does not show#

Our example has one state, one continuous action and a four-parameter critic, so every failure is visible. Real offline RL has many states, neural critics that extrapolate less predictably than a cubic, and long horizons over which bootstrapping error compounds across the state space. The CQL and IQL learners here use the papers' objectives in their simplest form (a uniform grid for the log-sum-exp, a single expectile), not the full algorithms. Treat the toy as an illustration of mechanisms; for algorithm rankings, the D4RL literature is the place to look [8].

Frequently asked questions#

What is offline reinforcement learning?

Offline reinforcement learning, also called batch RL, learns a policy from a fixed dataset of logged transitions collected by some other behaviour policy, with no new interaction during learning. Unlike behaviour cloning it uses the logged rewards to try to do better than the behaviour policy, which is why it has to deal with value estimates for actions the data never tried.

What is the difference between offline RL and off-policy RL?

Off-policy algorithms can learn from data generated by other policies, but in normal use they keep collecting fresh data, which corrects their mistakes. Offline RL is the special case where the dataset is fixed. Standard off-policy agents trained on a fixed batch often fail, because nothing corrects their overestimates for actions missing from the data.

How is offline RL different from imitation learning?

Imitation learning, such as behaviour cloning, copies the demonstrated actions and ignores rewards, so it can at best match the demonstrator. Offline RL uses rewards to improve on the data, for example by stitching together the good parts of different trajectories. When the data is narrow and expert, the two perform similarly; when it is broad and mixed, offline RL can do much better.

What is distribution shift in offline RL?

It is the mismatch between the actions in the dataset and the actions the learned policy wants to take. The Bellman target uses the maximum of Q over all actions, so it queries Q where there is no data. Errors there are selected because they look good, then propagated through bootstrapping, a problem known as extrapolation error.

How does Conservative Q-Learning (CQL) work?

CQL adds a penalty to the critic's loss that lowers Q-values on actions favoured by a soft maximum and raises them on actions in the dataset. Values propped up only by extrapolation are pushed down, so the learned Q lower-bounds the policy's true value in expectation. The penalty weight alpha needs tuning: too small lets errors through, too large stops improvement.

What is Implicit Q-Learning (IQL)?

IQL never evaluates actions outside the dataset. It fits a state value V as an upper expectile of Q over logged actions, which approximates the value of the best logged actions, backs that up into Q, and extracts a policy by advantage-weighted behaviour cloning. It is stable and strong on mixed data but cannot fully concentrate on the single best action.

How do you evaluate an offline RL policy without running it?

Use off-policy evaluation with an estimator separate from the training critic, such as fitted Q evaluation, importance sampling when behaviour probabilities are logged, or doubly robust estimators. Select hyperparameters the same way rather than by simulator rollouts, and confirm with a monitored, limited deployment before trusting the estimate.

Sources#

  1. Sergey Levine, Aviral Kumar, George Tucker, Justin Fu. Offline Reinforcement Learning: Tutorial, Review, and Perspectives on Open Problems, 2020. arxiv.org
  2. Scott Fujimoto, David Meger, Doina Precup. Off-Policy Deep Reinforcement Learning without Exploration, 2018. arxiv.org
  3. Aviral Kumar, Justin Fu, George Tucker, Sergey Levine. Stabilizing Off-Policy Q-Learning via Bootstrapping Error Reduction, 2019. arxiv.org
  4. Yifan Wu, George Tucker, Ofir Nachum. Behavior Regularized Offline Reinforcement Learning, 2019. arxiv.org
  5. Aviral Kumar, Aurick Zhou, George Tucker, Sergey Levine. Conservative Q-Learning for Offline Reinforcement Learning, 2020. arxiv.org
  6. Ilya Kostrikov, Ashvin Nair, Sergey Levine. Offline Reinforcement Learning with Implicit Q-Learning, 2021. arxiv.org
  7. Scott Fujimoto, Shixiang Shane Gu. A Minimalist Approach to Offline Reinforcement Learning, 2021. arxiv.org
  8. Justin Fu, Aviral Kumar, Ofir Nachum, George Tucker, Sergey Levine. D4RL: Datasets for Deep Data-Driven Reinforcement Learning, 2020. arxiv.org
  9. Rishabh Agarwal, Dale Schuurmans, Mohammad Norouzi. An Optimistic Perspective on Offline Reinforcement Learning, 2019. arxiv.org
  10. Lili Chen, Kevin Lu, Aravind Rajeswaran, Kimin Lee, Aditya Grover, Michael Laskin, Pieter Abbeel, Aravind Srinivas, Igor Mordatch. Decision Transformer: Reinforcement Learning via Sequence Modeling, 2021. arxiv.org
  11. Damien Ernst, Pierre Geurts, Louis Wehenkel. Tree-Based Batch Mode Reinforcement Learning, 2005. jmlr.org
  12. Tom Le Paine, Cosmin Paduraru, Andrea Michi, Caglar Gulcehre, Konrad Zolna, Alexander Novikov, Ziyu Wang, Nando de Freitas. Hyperparameter Selection for Offline Reinforcement Learning, 2020. arxiv.org
  13. Ashvin Nair, Abhishek Gupta, Murtaza Dalal, Sergey Levine. AWAC: Accelerating Online Reinforcement Learning with Offline Datasets, 2020. arxiv.org
  14. Rafael Rafailov, Archit Sharma, Eric Mitchell, Stefano Ermon, Christopher D. Manning, Chelsea Finn. Direct Preference Optimization: Your Language Model is Secretly a Reward Model, 2023. arxiv.org

Know the number before you ship.

A 45-minute working session with an evaluation engineer. Bring one use case; leave with a threat model, a draft eval plan with sample sizes, and an honest read on where you stand.