Skip to content

Offline RL: learning from logged data (CQL, IQL)

optionalcorefundamentalpaperrubric 10/122020 · arXiv tutorial and review (taught here with CQL, arXiv 2006.04779, and IQL, arXiv 2110.06169) · ~60 min

Sergey Levine, Aviral Kumar, George Tucker, Justin Fu

Read first: Reinforcement Learning: An Introduction, Ch. 5–6 — Monte Carlo, Temporal-Difference Learning and Q-learning · Playing Atari with Deep Reinforcement Learning (DQN)

Status

TL;DR. In offline RL you get a fixed log of what an old policy did and what happened, and you must produce a better policy without ever acting. You already know the one-step version: learning a ranker from click logs. Two things break when you move from one decision to many. Importance weights multiply, so their variance can grow exponentially with the number of steps when policy mismatch persists. Q-learning’s max asks about actions nobody tried, and the network’s guess for those actions is pure extrapolation that nothing ever corrects. The tutorial by Levine, Kumar, Tucker and Fu (arXiv 2005.01643) frames both as distribution shift. Two methods that became standard baselines fix the second problem in opposite ways. CQL (Kumar et al., arXiv 2006.04779) pushes down values of actions the data does not support, so the learned value is a lower bound. IQL (Kostrikov, Nair and Levine, arXiv 2110.06169) never evaluates an unseen action at all.

Why it matters for you. DPO is offline policy optimisation from a fixed set of pairs. Async RL trains on data from a slightly older policy. Training a search agent from its own logs is offline RL. The vocabulary on this page explains why online RLHF tends to beat offline methods, and how far you can trust a policy trained on logs.

First read. Read the TL;DR, “Why offline RL is hard”, the IPS worked example, the CQL and IQL sections with their worked examples, and “The LLM connection”. Skip on a first read: the tutorial’s off-policy policy gradient and marginalised importance sampling (§3.2–3.4), linear value functions (§4.1), uncertainty-based methods (§4.4), model-based offline RL (§5), CQL’s Theorems 3.3–3.6 and appendices, and IQL’s online fine-tuning (§5.3).

Sources. This page synthesises three papers: the tutorial (arXiv 2005.01643), CQL (arXiv 2006.04779) and IQL (arXiv 2110.06169, code).

Symbols used throughout:

  • ss is a state (the query plus everything the agent has seen), aa an action (issue a query, show a document, answer), rr a reward, s′s' the next state, and γ\gamma the discount.
  • πβ(a∣s)\pi_\beta(a \mid s) is the behaviour policy, the one that generated the log. In IR this is the production ranker or the logging policy. π^β\hat\pi_\beta is its empirical estimate from counts in the data.
  • D={(s,a,r,s′)}\mathcal D = \{(s, a, r, s')\} is the fixed dataset, and π\pi is the new policy you want to learn or evaluate.
  • An out-of-distribution (OOD) action is one with πβ(a∣s)≈0\pi_\beta(a \mid s) \approx 0: a document the old ranker never showed for that query, or a tool call the old agent never made.
Offline RLCounterfactual / online LTR
behaviour policy πβ\pi_\betalogging ranker
πβ(a∣s)\pi_\beta(a \mid s)propensity of the logged action
off-policy evaluation (OPE) with importance samplingIPS, SNIPS and doubly robust estimators on click logs
OOD action (no support)a document never shown at that position: its clicks tell you nothing
online RL (fresh data from the current policy)online LTR and interleaving

The one real difference is the horizon. A click log is mostly a contextual bandit: one decision, one reward. The tutorial notes recommender evaluation is “typically formulated within a contextual bandit problem”, which removes sequential decision making but can introduce errors when actions have temporal dependence (§6.5). Agents and dialogue have many steps, and that is where the problems below appear.

1. No exploration. Without coverage or additional justified assumptions about the environment, the log alone cannot guarantee discovering high-reward regions it never visits. Structural generalisation may help, but that is an assumption, not evidence supplied by the missing data. The tutorial simply assumes the data covers them (§2.4).

2. Counterfactual queries and compounding error. To beat the logger you must act differently from it, so you ask “what if” questions about data you never saw. Even plain imitation suffers. If a cloned policy makes a mistake with probability ϵ\epsilon per step on states from the log, then over a horizon HH its expected number of mistakes is bounded by C+H2ϵC + H^2\epsilon (Theorem 2.1). With extra on-policy labels (DAgger) the bound becomes C+HϵC + H\epsilon (Theorem 2.2). The intuition: one mistake takes the policy to a state the log never contained, where it keeps making mistakes for the rest of the episode.

3. The max in the Bellman target trusts guesses. Recall the Q-learning target r+γmax⁡a′Q(s′,a′)r + \gamma \max_{a'} Q(s', a') from the DQN page. The network was trained only on logged actions, but the max looks at every action. For unlogged ones QQ is a guess, and the max picks exactly the guesses that are too high. Online, the agent would try those actions, see poor returns and fix them. Offline, nothing does, and errors are backed up into earlier states at every iteration (§4.2). The tutorial shows an “unlearning” effect: an offline actor-critic’s return first rises and then collapses as training continues, and more data does not prevent it (Fig. 2). This is the deadly triad of the MC, TD and Q-learning page (function approximation, bootstrapping, off-policy data) in its most extreme form, because the data distribution can never be corrected.

Note what is not a training problem. The Bellman backup only evaluates QQ at states from the log. During training, only the actions are out of distribution; states shift only at test time (§4.2; CQL §2).

Route 1: importance sampling, the IPS route

Section titled “Route 1: importance sampling, the IPS route”

Intuition. Reweight each logged episode by how much more (or less) likely the new policy is to produce it than the logger was. For a trajectory, the ratio is a product over steps:

J^(π)=1n∑i=1nwHi∑t=0Hγtrti,wti=∏t′=0tπ(at′i∣st′i)πβ(at′i∣st′i).\hat J(\pi) = \frac{1}{n}\sum_{i=1}^{n} w^i_H \sum_{t=0}^{H} \gamma^t r^i_t, \qquad w^i_t = \prod_{t'=0}^{t} \frac{\pi(a^i_{t'} \mid s^i_{t'})}{\pi_\beta(a^i_{t'} \mid s^i_{t'})}.

J^(π)\hat J(\pi) is the estimated expected return of π\pi and nn is the number of logged trajectories. The estimate is unbiased but can have very high variance because of the product (§3.1). Unbiasedness assumes the logged action probabilities are correct, trajectories are drawn from the stated logger, and every trajectory the target policy can produce has logging support. No weighting scheme reconstructs outcomes for an action with zero logging probability. Three standard refinements, all familiar from counterfactual LTR, are listed in the tutorial:

  • Per-decision IS: a reward at step tt cannot depend on later actions, so weight rtr_t by wtw_t instead of wHw_H.
  • Weighted (self-normalised) IS: divide by the sum of the weights. This is biased but has much lower variance, and it is still consistent.
  • Doubly robust: combine a model’s prediction with a propensity-weighted residual. In a one-step bandit, one sample contributes ∑a′π(a′∣s)q^(s,a′)+w [r−q^(s,a)]\sum_{a'}\pi(a'\mid s)\hat q(s,a') + w\,[r - \hat q(s,a)], where q^\hat q predicts mean reward, aa is the logged action and w=π(a∣s)/πβ(a∣s)w = \pi(a\mid s)/\pi_\beta(a\mid s). Sequential versions use the corresponding per-decision corrections. Under the usual support and estimation conditions, correctness of either the propensity model or the outcome model suffices.

Worked example (search-or-answer MDP, γ = 0.9). A cautious production agent searches in the question state with probability 0.1 and otherwise answers directly. Searching costs −0.1 and leads to the evidence state, where the answer is correct with probability 0.8, so a searching episode returns 0.8 or −0.1. You want the value of always search, which is −0.1+0.9×0.8=0.62-0.1 + 0.9 \times 0.8 = 0.62.

  • The weights are w=1/0.1=10w = 1/0.1 = 10 for searching episodes and 00 for direct answers.
  • The estimate is unbiased: E[wG]=0.1×10×0.62=0.62\mathbb E[wG] = 0.1 \times 10 \times 0.62 = 0.62.
  • The second moment is E[(wG)2]=0.1×100×(0.8×0.64+0.2×0.01)=5.14\mathbb E[(wG)^2] = 0.1 \times 100 \times (0.8 \times 0.64 + 0.2 \times 0.01) = 5.14, so the variance is 5.14−0.622≈4.765.14 - 0.62^2 \approx 4.76. The on-policy variance is only 0.514−0.384≈0.130.514 - 0.384 \approx 0.13.
  • With 1,000 logs, the IPS standard error is 4.76/1000≈0.069\sqrt{4.76/1000} \approx 0.069 against 0.0110.011 on-policy. The log is worth about 27 on-policy episodes.

The variance is driven by E[w2]=∑aπ2/πβ=1+χ2(π ∥ πβ)\mathbb E[w^2] = \sum_a \pi^2/\pi_\beta = 1 + \chi^2(\pi \,\|\, \pi_\beta), here 10. If a session contains three such decisions, each with the same conditional search probability 0.1, the weights multiply and E[w2]=103\mathbb E[w^2] = 10^3. (Arbitrary state-dependent ratios do not generally factor this neatly, but persistent mismatch compounds in the same way.) Hence the tutorial’s verdict: IS works when the new policy “only deviates by a limited amount from the behavior policy”, and the improvement it can reliably deliver is limited by the logger’s suboptimality, the size of the state and action spaces, and the horizon (§3.5). Keep χ2\chi^2 in mind: CQL’s penalty turns out to be the same quantity.

Route 2: keep the policy close to the logger

Section titled “Route 2: keep the policy close to the logger”

Intuition. If the new policy only takes actions the logger also takes, the Q-function is never asked about unseen actions. Policy-constraint methods maximise Q subject to a divergence DD from the behaviour policy (§4.3):

πk+1←arg⁡max⁡π Es∼D[Ea∼π(a∣s) Q^k+1(s,a)]s.t.D(π,πβ)≤ϵ.\pi_{k+1} \leftarrow \arg\max_{\pi}\ \mathbb E_{s\sim\mathcal D}\Big[\mathbb E_{a\sim\pi(a\mid s)}\,\hat Q_{k+1}(s,a)\Big] \quad\text{s.t.}\quad D(\pi, \pi_\beta) \le \epsilon .

With KL as DD, the constrained optimum has a closed form, and AWR and AWAC fit it by weighted behaviour cloning:

πˉk+1(a∣s)  ∝  πβ(a∣s) exp⁡ ⁣(1α Qk(s,a)).\bar\pi_{k+1}(a \mid s) \;\propto\; \pi_\beta(a \mid s)\,\exp\!\Big(\tfrac{1}{\alpha}\, Q_k(s,a)\Big).

In words: copy the logged actions, but weight each copy by exp⁡(Q/α)\exp(Q/\alpha), so good logged actions are imitated more. Here α\alpha is a temperature that plays the role of the Lagrange multiplier. Compare DPO’s optimal policy π∗∝πrefexp⁡(r/β)\pi^* \propto \pi_{\text{ref}} \exp(r/\beta) on the DPO page: it has exactly the same shape.

Weakness. Explicit constraints need an estimate of πβ\pi_\beta. When the log mixes several loggers, as most real logs do, a unimodal fit can average across modes and still let OOD actions through (§4.6). Constraints also cap how far you can improve on a weak logger.

Route 3: CQL — be pessimistic about what you have not seen

Section titled “Route 3: CQL — be pessimistic about what you have not seen”

Intuition. Instead of constraining the policy, change the critic: train QQ to fit the Bellman target on logged actions, and also push QQ down on actions the current policy likes and up on actions in the data. Over-optimistic OOD values then cannot survive. The CQL policy-evaluation objective (Eq. 2) is

Q^k+1←arg⁡min⁡Q α(Es∼D, a∼μ(a∣s)[Q(s,a)]−Es∼D, a∼π^β(a∣s)[Q(s,a)])+12 Es,a,s′∼D[(Q(s,a)−B^πQ^k(s,a))2].\hat Q^{k+1} \leftarrow \arg\min_{Q}\ \alpha\Big(\mathbb E_{s\sim\mathcal D,\,a\sim\mu(a\mid s)}\big[Q(s,a)\big] - \mathbb E_{s\sim\mathcal D,\,a\sim\hat\pi_\beta(a\mid s)}\big[Q(s,a)\big]\Big) + \tfrac12\,\mathbb E_{s,a,s'\sim\mathcal D}\Big[\big(Q(s,a) - \hat{\mathcal B}^{\pi}\hat Q^{k}(s,a)\big)^2\Big].

Here μ\mu is the distribution of actions where values are pushed down (set μ=π\mu = \pi for evaluation), α\alpha sets the strength of conservatism, and B^πQ^(s,a)=r+γ Ea′∼π[Q^(s′,a′)]\hat{\mathcal B}^\pi \hat Q(s,a) = r + \gamma\,\mathbb E_{a'\sim\pi}[\hat Q(s', a')] is the sampled Bellman backup. The practical variant CQL(H) (Eq. 4) chooses the push-down distribution adversarially with an entropy regulariser, which turns the first term into a log-sum-exp:

min⁡Q α Es∼D[log⁡∑aexp⁡Q(s,a)−Ea∼π^β(a∣s)[Q(s,a)]]+12 Es,a,s′∼D[(Q−B^πkQ^k)2].\min_{Q}\ \alpha\,\mathbb E_{s\sim\mathcal D}\Big[\log\sum_a \exp Q(s,a) - \mathbb E_{a\sim\hat\pi_\beta(a\mid s)}\big[Q(s,a)\big]\Big] + \tfrac12\,\mathbb E_{s,a,s'\sim\mathcal D}\Big[\big(Q - \hat{\mathcal B}^{\pi_k}\hat Q^{k}\big)^2\Big].

The log-sum-exp is a soft maximum, so it presses hardest on whichever action currently has the largest Q-value. A two-action gradient example is on the Aviral Kumar job-talk page.

Why it is a lower bound. In the tabular case, setting the derivative of Eq. 2 to zero for each (s,a)(s,a) gives the update (CQL App. C, Eq. 13)

Q^k+1(s,a)=B^πQ^k(s,a)−α(π(a∣s)π^β(a∣s)−1).\hat Q^{k+1}(s,a) = \hat{\mathcal B}^{\pi}\hat Q^{k}(s,a) - \alpha\Big(\frac{\pi(a\mid s)}{\hat\pi_\beta(a\mid s)} - 1\Big).

Average over a∼πa \sim \pi and the penalty on the state value becomes α∑aπ (π/π^β−1)=α d(s)\alpha \sum_a \pi\,(\pi/\hat\pi_\beta - 1) = \alpha\,d(s), where d(s)=χ2(π(⋅∣s) ∥ π^β(⋅∣s))≥0d(s) = \chi^2(\pi(\cdot\mid s) \,\|\, \hat\pi_\beta(\cdot\mid s)) \ge 0. So each value backup subtracts α d(s)\alpha\,d(s). With exact tabular backups, the converged value satisfies V^π=Vπ−α(I−γPπ)−1d\hat V^\pi = V^\pi - \alpha(I - \gamma P^\pi)^{-1} d. Here PπP^\pi is the state-transition matrix under π\pi: the inverse sums the discounted penalties at the current and future states. The value of π\pi is underestimated by an amount that grows with how far π\pi strays from the data. This is the same χ2\chi^2 that controlled the IS variance above. Individual Q-values are not lower-bounded: actions the data favours more than π\pi get pushed up (Theorem 3.2). Dropping the second, push-up term (Eq. 1) gives a pointwise lower bound, but a looser one. With finite data, the theorems need α\alpha large enough to outweigh a sampling-error term that shrinks like 1/∣D(s)∣1/\sqrt{|\mathcal D(s)|}. They are proved for tabular, linear and a subset of non-linear (NTK) approximators, not for general deep networks (§3.1, §7). The ratio derivation also assumes the target action distribution is supported by the behaviour distribution. A literal zero denominator is not covered by this calculation, and general neural-network extrapolation is not certified by the tabular argument.

Worked example. For this toy calculation, answering terminates, and searching leads to an evidence state with only one available action, answer. There is therefore no further policy/data mismatch after the question state, so the fixed-point correction here reduces to the one-step correction. (If the same divergence 9 recurred forever with γ = 0.9, the value correction would be 90α90\alpha, not 9α9\alpha.) Take the question state with π^β=(answer 0.9, search 0.1)\hat\pi_\beta = (\text{answer } 0.9,\ \text{search } 0.1), true values Q(answer)=0.3Q(\text{answer}) = 0.3 and Q(search)=0.62Q(\text{search}) = 0.62, and evaluate π\pi = always search, so χ2=1/0.1−1=9\chi^2 = 1/0.1 - 1 = 9:

αQ^\hat Q(answer) =0.3+α= 0.3 + \alphaQ^\hat Q(search) =0.62−9α= 0.62 - 9\alphagreedy choice
0.020.3200.440search (correct, value underestimated by 0.18)
0.0320.3320.332tie
0.050.3500.170answer (too conservative)

The rare but better action is penalised in proportion to how rare it is. Too little α\alpha and overestimation returns; too much and you are back to the logger. The paper tunes α\alpha automatically by dual gradient descent in continuous control (§4). It also proves a related gap-expanding property: the gap between in-data and OOD values is larger under CQL than under the true Q-function, so the policy is steered toward the data (Theorem 3.4).

Route 4: IQL — never ask about an unseen action

Section titled “Route 4: IQL — never ask about an unseen action”

Intuition. SARSA-style evaluation, r+γQ(s′,a′)r + \gamma Q(s', a') with the logged next action a′a', never touches OOD actions, but it learns the value of the logger, not of a better policy. IQL keeps that safety and recovers “the best logged action” with a statistic instead of a max. For each state, look at the distribution of Q(s,a)Q(s, a) over the actions in the log and estimate an upper expectile of it.

Expectiles. The τ-expectile mτm_\tau of a random variable XX minimises an asymmetric squared loss:

mτ=arg⁡min⁡m Ex∼X[L2τ(x−m)],L2τ(u)=∣τ−1(u<0)∣ u2.m_\tau = \arg\min_{m}\ \mathbb E_{x\sim X}\big[L_2^\tau(x - m)\big], \qquad L_2^\tau(u) = \big|\tau - \mathbb 1(u < 0)\big|\,u^2 .

At τ=0.5\tau = 0.5 this is ordinary MSE and mm is the mean. For τ>0.5\tau > 0.5, points above mm count more than points below, so mm moves up. As τ→1\tau \to 1, mτm_\tau tends to the supremum of the support (Lemma 1). An expectile is to the mean what a quantile is to the median; IQL found it worked somewhat better than quantile regression.

Worked example. At the question state the log contains “answer” (Q = 0.3) 90% of the time and “search” (Q = 0.62) 10% of the time. For two values a<ba < b with probability pp on bb, setting the derivative of (1−p)(1−τ)(a−m)2+pτ(b−m)2(1-p)(1-\tau)(a-m)^2 + p\tau(b-m)^2 to zero gives

mτ=a+(b−a) pτpτ+(1−p)(1−τ).m_\tau = a + (b - a)\,\frac{p\tau}{p\tau + (1-p)(1-\tau)} .
τ0.50.70.90.99→ 1
V(question)V(\text{question})0.332 (logger’s value)0.3660.4600.5930.62 (best logged action)

The algorithm. IQL trains three networks, each on dataset tuples only (Eqs. 5–7). These are three roles: value, Q and policy. The paper’s implementation actually uses two Q-functions and their target copies, taking their minimum for the V and actor updates, and clips the exponentiated advantages (at 100) for numerical stability.

LV(ψ)=E(s,a)∼D[L2τ(Qθ^(s,a)−Vψ(s))],LQ(θ)=E(s,a,s′)∼D[(r+γVψ(s′)−Qθ(s,a))2],L_V(\psi) = \mathbb E_{(s,a)\sim\mathcal D}\big[L_2^\tau\big(Q_{\hat\theta}(s,a) - V_\psi(s)\big)\big], \qquad L_Q(\theta) = \mathbb E_{(s,a,s')\sim\mathcal D}\big[\big(r + \gamma V_\psi(s') - Q_\theta(s,a)\big)^2\big], policy: maximise  E(s,a)∼D[exp⁡ ⁣(β (Qθ^(s,a)−Vψ(s))) log⁡πϕ(a∣s)].\text{policy: maximise}\ \ \mathbb E_{(s,a)\sim\mathcal D}\Big[\exp\!\big(\beta\,(Q_{\hat\theta}(s,a) - V_\psi(s))\big)\,\log\pi_\phi(a\mid s)\Big].

VψV_\psi is the state-value network, QθQ_\theta the Q-network, Qθ^Q_{\hat\theta} its slowly updated target copy, and β\beta an inverse temperature. Why a separate VV? An expectile taken directly over r+γQ(s′,a′)r + \gamma Q(s', a') would also reward lucky transitions into good states, not just good actions. VV takes the expectile over actions only, and QQ then averages over next states with plain MSE (§4.2). Policy extraction is the advantage-weighted cloning from Route 2, so the policy never affects value training. This is an implicit constraint: IQL avoids out-of-sample Q queries during training, but it does not prove that the deployed actor only emits logged actions. τ sweeps the method from SARSA (τ = 0.5) to Q-learning restricted to the data’s support (τ → 1) (Theorem 3).

Naive off-policy RL collapses offline; CQL does not (CQL Table 1, D4RL normalised return, 4 seeds). “SAC” is a standard off-policy actor-critic run on the fixed data; BC is behaviour cloning; BEAR is a policy-constraint method.

DatasetSACBCBEARCQL(H)
halfcheetah-medium−4.336.138.644.4
halfcheetah-expert−1.9107.0108.2104.8
hopper-mixed3.511.825.348.6
walker2d-medium-expert1.911.310.898.7
walker2d-random-expert0.80.71.991.1

On single-policy data CQL roughly matches the best prior method (and BC is hard to beat on expert data). On mixtures of policies, which is what real logs look like, it wins by large margins.

CQL’s values really are lower bounds (Table 4: predicted minus true policy value). On hopper-medium-expert, CQL(H) is −43.20, the pointwise variant (Eq. 1) −151.36, BEAR +65.93, and the minimum over a 2-network ensemble +3.71e6. Ensembles, a standard online fix for overestimation, do not rescue offline training.

Offline Atari with 1% of a DQN replay (Table 3): on Q*bert CQL reaches 14012.0 against 383.6 for QR-DQN and 343.4 for REM; on Breakout, 61.1 against 7.9 and 11.0.

Multi-step improvement matters when you must stitch trajectories (IQL Table 1, “-v2” locomotion and “-v0” AntMaze; IQL re-ran CQL on “-v2”, which scores higher than earlier reports):

The runtime column is the paper’s implementation-specific comparison, not a hardware-independent property of the algorithms. Its CQL time uses the authors’ faster JAX reimplementation, and its Onestep RL runtime uses comparable hyperparameters rather than exactly the configuration producing the reported scores.

Methodlocomotion total (9 datasets)antmaze-medium-playantmaze-large-playantmaze total (6)runtime
BC466.70.00.0100.210m
Onestep RL684.60.30.0125.3≈ 20m
CQL698.561.215.8303.680m
IQL (τ = 0.9 AntMaze, 0.7 locomotion)692.471.239.6378.020m

On locomotion, where the data already contains near-optimal trajectories, one improvement step is competitive on these datasets. On AntMaze, where the agent must combine pieces of suboptimal trajectories, one-step methods score close to zero, and IQL’s Fig. 3 shows that larger τ is what makes the difference.

DPO is offline policy optimisation. It learns from a fixed set of preference pairs, never samples from the policy during training, and its optimum π∗∝πrefexp⁡(r/β)\pi^* \propto \pi_{\text{ref}}\exp(r/\beta) is the KL-constrained solution from Route 2 (DPO). Two differences from the robotics setting are worth stating precisely:

  • The whole response is one action, so there is no bootstrapping and no deadly triad. The distribution-shift problem remains: responses that appear in no pair are unconstrained, which is how DPO can over-optimise (DPO page).
  • The anchor is πref\pi_{\text{ref}} (the SFT model), which is not necessarily the policy that generated the pairs. When pairs come from other models, the KL term keeps you near a model that did not produce your data.

Why online data tends to win in LLM RLHF. On TL;DR the RLOO paper reports a GPT-4 win rate of 77.9 for online RLOO with k = 4 against 66.6 for offline DPO (RLOO). That comparison changes the loss and the data loop at once. The DPO family page treats online versus offline as a separate axis, and cites OAIF, which labels fresh pairs from the current model and reports beating offline direct-alignment methods. The offline-RL reading: online samples let the reward model see and correct the policy’s own mistakes, which a fixed dataset never can (tutorial §4.2). This refreshes which outputs are scored, not the correctness of the scorer: a fixed reward model can still reward new mistakes or be exploited. Fresh rollouts address coverage mismatch, not reward-model misspecification. It is the LLM analogue of interleaving a new ranker instead of trusting IPS on old logs.

Async RL is online but off-policy. It continues collecting data, unlike offline RL, but learns from older policy versions. In async RLHF’s separate data-reuse experiment, N is the number of mini-batches generated by one policy before N successive updates, not a fixed delay of N updates for every sample. Online DPO still learns at N = 64. The actual asynchronous implementation (§3.5) instead uses a one-step-lagged producer–learner pipeline. AReaL bounds staleness by η and corrects with an importance weight πprox/πbehav\pi_{\text{prox}}/\pi_{\text{behav}}. This is close to the regime where the tutorial says IS works, a limited deviation from the behaviour policy. But bounding policy-version lag can reduce mismatch without itself bounding likelihood ratios, especially products over long responses. Measure ratio tails and effective sample size rather than assuming that a small version lag means ratios near 1. AReaL’s own ablation shows the limit: with unbounded staleness the decoupled objective scores 36.9 on AIME24, below 42.2 at η = 4. Missing old logits shows what goes wrong when the behaviour probabilities, the “propensities” of async RL, are not recorded.

Learning from logged agent traces and search logs. A click log with logged propensities is a contextual bandit, so IPS and doubly robust OPE apply directly (tutorial §6.5). A multi-step agent trace is full offline RL. Trajectory-product weights can become unusably noisy for long sessions or large policy mismatch. Diagnose overlap and effective sample size; depending on the setting, use per-decision or marginalised estimators, doubly robust evaluation, or in-sample/pessimistic value learning. Filtering logged trajectories by outcome and cloning them is the simplest offline method. DR Pixel reweights the steps of logged teacher trajectories by credit, which is close in spirit to advantage-weighted cloning. ArCHer learns an off-policy turn-level critic from a replay buffer. The lesson from this page: anything you learn about actions the logger never took is extrapolation, so either constrain the policy to the logger’s support or be pessimistic about the rest. For free-text actions, distinguish an explicit candidate restriction from a semantic-similarity heuristic. Similar wording does not establish logging support or justify an importance-sampling estimate.

No implementation is required. If useful, run the script below (standard-library Python, about 1 second) to check the three hand calculations: IPS against SNIPS against on-policy estimation, IQL’s expectile, and the CQL correction; skip it otherwise.

Show the script
import random, statistics as st
random.seed(0)
GAMMA, P_OK_Q, P_OK_E, COST = 0.9, 0.3, 0.8, -0.1
def episode(p_search):
"""Search-or-answer MDP. Returns (searched?, discounted return)."""
if random.random() < p_search: # search, then answer in E
return True, COST + GAMMA * (random.random() < P_OK_E)
return False, float(random.random() < P_OK_Q) # answer directly in Q
# Lab 1: IPS off-policy evaluation. Logger searches 10% of the time;
# target policy always searches (true value -0.1 + 0.9*0.8 = 0.62).
B, N, RUNS = 0.1, 1000, 2000
ips, snips, on = [], [], []
for _ in range(RUNS):
logs = [episode(B) for _ in range(N)]
w = [1 / B if s else 0.0 for s, _ in logs] # pi(a|s) / b(a|s)
wg = [wi * g for wi, (_, g) in zip(w, logs)]
ips.append(sum(wg) / N)
snips.append(sum(wg) / sum(w))
on.append(sum(episode(1.0)[1] for _ in range(N)) / N)
for name, xs in [("IPS", ips), ("SNIPS", snips), ("on-policy", on)]:
print(f"{name:9s} mean {st.mean(xs):.3f} std {st.pstdev(xs):.4f}")
# Lab 2a: IQL's V = tau-expectile of the in-data Q-values at state Q.
def expectile(xs, ps, tau, steps=20000, lr=0.05):
m = sum(x * p for x, p in zip(xs, ps))
for _ in range(steps):
m += lr * sum(p * 2 * (tau if x > m else 1 - tau) * (x - m) for x, p in zip(xs, ps))
return m
for tau in [0.5, 0.7, 0.9, 0.99]:
print(f"tau={tau}: V={expectile([0.3, 0.62], [0.9, 0.1], tau):.3f}")
# Lab 2b: CQL correction for this terminating toy; no downstream mismatch penalty. mu = pi = always search.
pi, pb, q = [0.0, 1.0], [0.9, 0.1], [0.3, 0.62] # (answer, search)
for alpha in [0.02, 0.032, 0.05]:
qh = [qi - alpha * (p / b - 1) for qi, p, b in zip(q, pi, pb)]
print(f"alpha={alpha}: Q_hat(answer)={qh[0]:.3f} Q_hat(search)={qh[1]:.3f}")

Expected output: IPS has mean 0.621 and standard deviation 0.0692, matching the predicted 0.069. SNIPS has 0.0361, because it reduces to averaging the roughly 100 searching episodes. On-policy has 0.0109. The expectiles are 0.332, 0.366, 0.460 and 0.593. Next steps: make the logger search with probability 0.01 and watch IPS degrade, or chain three decisions and check the 10310^3 blow-up of E[w2]\mathbb E[w^2].

  • Benchmarks evaluate online. D4RL scores come from running the policy in a simulator, and hyperparameters (α, τ, β, the checkpoint) are rarely selected strictly offline. CQL itself calls early stopping without validation an open problem (§7). In real deployments, selection needs OPE, which is least reliable exactly where the new policy departs from the data.
  • Guarantees are narrower than the slogans. CQL’s bounds need α large relative to sampling error and are not proved for deep networks. IQL’s Theorem 3 is a limit as τ → 1 with exact function fitting, while in practice τ is 0.7–0.9.
  • Coverage is assumed, not tested. The tutorial notes there are no known non-trivial sufficiency conditions on the dataset that guarantee recovering a near-optimal policy.
  • Pessimism can overshoot. On small datasets, CQL can assign too-low values to under-sampled but good actions (tutorial §4.6), as in the α = 0.05 row above.
  • LLM conclusions here are by analogy. The papers on this page are about control and Atari. The LLM claims rest on the site pages cited, and those confound loss and data loop unless an experiment separates them.
  • Compute an IPS estimate, its variance and its effective sample size for a toy logger, and explain why variance can grow exponentially with the number of decisions when mismatch persists.
  • Explain why the max in the Q-learning target fails offline but not online, and why training sees only action shift, not state shift.
  • Write CQL’s objective, derive the tabular fixed point, and distinguish the one-backup penalty α·χ² from its discounted accumulation at the fixed point, and show that some Q-values are overestimated.
  • Write IQL’s three losses, compute a two-point expectile by hand, and say what τ = 0.5 and τ → 1 correspond to.
  • Place DPO, online DPO, RLOO and async PPO on the offline-to-online spectrum, and design an experiment that separates the loss from the data loop.
  • Prerequisites: MC, TD and Q-learning (off-policy MC with importance sampling, the deadly triad) · DQN (the max-based target that offline training breaks).
  • Same trust-region idea, online: TRPO and PPO bound how far a policy moves from the one that collected the data. The tutorial cites the same KL-to-state-shift bound for offline constraints.
  • Offline preference optimisation: DPO (KL-constrained closed form, fixed pairs) · DPO family (online versus offline as its own axis) · RLOO (the online comparison point).
  • Online but off-policy RL: Async RLHF · AReaL · Missing old logits, which all deal with importance weights against a stale behaviour policy.
  • Off-policy critics for agents: ArCHer (a turn-level critic trained from replay) · DR Pixel (credit-reweighted cloning of logged trajectories) · Search-R1 (the fully online alternative for search agents).
  • The talk version: Aviral Kumar’s job talk presents CQL’s motivation and the case for offline RL. Course: CS285 covers offline RL in depth.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    A cautious production agent logs 1,000 episodes of the search-or-answer MDP (γ = 0.9). In the question state it searches with probability 0.1 (search costs −0.1, then the answer is correct with probability 0.8) and otherwise answers directly. You want the value of a new policy that always searches. Compute the IPS weights, show the IPS estimate is unbiased, compute its per-episode variance and standard error at n = 1,000, compare with 1,000 on-policy episodes, and say what happens to E[w²] if a session contained three such decisions in a row.

    What a strong answer covers
    • Weights: w = π/π_β = 1/0.1 = 10 for searching episodes and 0 for direct answers. E[w·G] = 0.1 × 10 × E[G | search] = −0.1 + 0.9 × 0.8 = 0.62, the true value of always searching.
    • E[(wG)²] = 0.1 × 100 × (0.8 × 0.8² + 0.2 × 0.1²) = 5.14, so the per-episode variance is 5.14 − 0.62² ≈ 4.76 and the standard error at n = 1,000 is √(4.76/1000) ≈ 0.069.
    • On-policy variance is 0.514 − 0.384 ≈ 0.13 (standard error ≈ 0.011), so 1,000 logged episodes are worth about 1000 × 0.13 / 4.76 ≈ 27 on-policy episodes.
    • E[w²] = Σ π²/π_β = 10 = 1 + χ²(π‖π_β). With three decisions that each have the same conditional search probability 0.1 the weights multiply, so E[w²] = 10³ = 1,000: the exponential blow-up the tutorial warns can happen when policy mismatch persists (§3.5).
    • Self-normalised IPS (weighted importance sampling) here is the mean return of the roughly 100 searching episodes, standard error ≈ √(0.13/100) ≈ 0.036. It is biased in general but has much lower variance, the same trade as SNIPS in counterfactual LTR.
  2. Derive / compute

    In the logged data, the question state is followed by "answer" 90% of the time (Q = 0.3) and by "search" 10% of the time (Q = 0.62). IQL fits V(s) by minimising the expectile loss |τ − 1(u < 0)|·u², with u = Q(s, a) − V(s), over dataset actions. Derive the minimiser for a general two-point distribution, evaluate it at τ = 0.5, 0.7, 0.9 and 0.99, and explain what τ → 1 approximates and why that differs from the max in Q-learning.

    What a strong answer covers
    • With values a < b and probability p on b, the loss is (1 − p)(1 − τ)(a − m)² + pτ(b − m)². Setting the derivative to zero gives m = a + (b − a)·pτ / (pτ + (1 − p)(1 − τ)).
    • With a = 0.3, b = 0.62 and p = 0.1: τ = 0.5 gives 0.332 (the plain mean, i.e. the logging policy's value, as in SARSA); τ = 0.7 gives ≈ 0.366; τ = 0.9 gives exactly 0.46 because pτ = (1 − p)(1 − τ) = 0.09; τ = 0.99 gives ≈ 0.593.
    • As τ → 1, m → 0.62, the best value among actions that appear in the data (IQL Lemma 1 and Theorem 3). This is a max restricted to the support of π_β.
    • Q-learning's max ranges over all actions, including ones never logged, whose Q-values are pure extrapolation. The expectile only ever evaluates Q at logged (s, a) pairs, so no out-of-distribution action is queried.
    • A rare good action needs τ close to 1 to dominate (at 10% frequency, τ = 0.9 only gets halfway). That is why τ is a hyperparameter (0.9 for AntMaze, 0.7 for locomotion) and why the paper notes larger τ is harder to optimise.
  3. Mechanism

    For CQL Eq. 2 with μ = π, derive the tabular Q update and distinguish its one-backup penalty from the converged value error in a recurrent MDP. Then take a terminating question state: answer gives expected reward 0.3; search costs −0.1 and leads to a forced answer that succeeds with probability 0.8; γ = 0.9. With logger probabilities (answer 0.9, search 0.1), target policy always search at the question state, and α = 0.02 or 0.05, compute both learned Q-values and explain why the guarantee is for V rather than each Q.

    What a strong answer covers
    • Setting the gradient to zero for each (s, a) gives Q̂_(k+1) = B^π Q̂_k − α(π(a|s)/π̂_β(a|s) − 1) (CQL Eq. 13). At convergence this is a recursion, not generally Q^π minus the local penalty. Actions that π prefers more than the data does are pushed down; actions the data prefers more than π are pushed up.
    • Averaging over a ∼ π gives a per-backup penalty α·d(s), with d(s) = χ²(π‖π̂_β) ≥ 0; with exact tabular backups V̂ = V^π − α(I − γP^π)⁻¹d (Theorem 3.2). Here d = 9 only at the question state and zero thereafter, so the toy's local correction is exact.
    • α = 0.02: Q̂(search) = 0.62 − 0.18 = 0.44 and Q̂(answer) = 0.3 + 0.02 = 0.32, so V̂ = 0.44 ≤ 0.62 and search still wins. α = 0.05: 0.17 against 0.35, so an over-conservative critic now prefers the logging policy's action. They tie at α = 0.032.
    • Q̂(answer) ends up above its true value (0.32 > 0.3), so the bound is not pointwise. Only the expectation under π is guaranteed, unlike Eq. 1, which lower-bounds every Q but is looser.
    • State the support and exact-fitting assumptions; finite-data bounds require α large enough to dominate a sampling-error term that shrinks like 1/√|D(s)|. These are not unconditional guarantees for neural critics.
  4. What if…

    IQL uses τ = 0.7 on locomotion and τ = 0.9 on AntMaze. Predict what happens if (a) each is changed to τ = 0.5, or (b) the separate V-network is removed and an upper-expectile loss is applied directly to r + γQ(s′, a′). Separate the evidence from IQL's τ ablation from the comparison with the separately configured Onestep RL algorithm, and explain why stochastic transitions matter.

    What a strong answer covers
    • (a) At τ = 0.5, exact in-sample evaluation recovers the logger's value before actor extraction, i.e. one improvement step. Onestep RL's locomotion total of 684.6 against IQL's 692.4 suggests one step is competitive on these datasets, but it is not a controlled τ-only ablation; Fig. 3 is the direct AntMaze τ experiment.
    • (a) AntMaze medium and large mazes require stitching parts of suboptimal trajectories, so values must propagate through several improvement steps. On the four medium and large mazes Onestep RL scores 0.3, 0.0, 0.0 and 0.0 against IQL's 71.2, 70.0, 39.6 and 47.5. Fig. 3 shows larger τ is crucial there, and the u-maze toy (Fig. 2) shows one-step values decaying too fast away from the goal.
    • (b) An expectile over r + γQ(s′, a′) mixes randomness in the action with randomness in the next state. A high τ then rewards a lucky transition rather than a good action, which is optimism about the dynamics.
    • (b) The separate V(s) takes the expectile over dataset actions only, and Q is then fitted with plain MSE, which averages over next states.
    • Neither ablation queries unseen actions. The trade-off is too little improvement in (a) against optimism about stochastic dynamics in (b).
  5. Critique

    A colleague reads the RLOO paper's TL;DR results (GPT-4 win rate: RLOO with k = 4 at 77.9, DPO at 66.6) and concludes that "the DPO loss is worse than REINFORCE". Critique this inference through the offline-RL lens of this page, and design the experiment that would separate the effect of the loss from the effect of on-policy data.

    What a strong answer covers
    • The comparison confounds two axes, the loss and the data loop. DPO trains on fixed pairs (offline); RLOO samples and scores fresh completions from the current policy (online). The DPO-family page treats these as separate axes.
    • Offline-RL explanation: DPO's policy can drift toward responses that appear in no pair, where its implicit reward is unconstrained and nothing corrects it. Online sampling lets the reward model score the policy's own outputs, the coverage correction the tutorial (§4.2) says happens naturally when a policy acts; it does not fix a misspecified reward model.
    • Experiment: hold the base policy, preference scorer, loss, optimizer budget and labelling budget fixed while varying data refresh (offline DPO, iterative DPO, online DPO). For a frozen-sample RLOO arm, distinguish naive reuse from an explicitly off-policy-corrected estimator with recorded behaviour probabilities; otherwise changing freshness also silently changes the estimator.
    • Measure gold-reward or judge win rate against KL to the reference, as the async RLHF paper does, on held-out prompts. Match the labelling budget across arms and use several seeds.
    • OAIF compares online and offline preference learning; Asynchronous RLHF's N = 64 result concerns 64 mini-batches per refresh, not a constant 64-step lag. Both motivate studying data freshness, but neither proves that the choice of loss is irrelevant.
  6. Design

    You have six months of logs from a production search agent: for each user query, the reformulations it issued, the results shown, clicks, a final satisfaction label, and the agent's logged action probabilities. You may run only one small online A/B test at the end. Design an offline pipeline to train and select a better reformulation policy: which estimator or algorithm you use for which part, how you handle actions the old agent never took, and how you choose what to A/B test.

    What a strong answer covers
    • Treat single-decision parts (for example, which reformulation to issue first) as a contextual bandit: IPS or doubly robust estimates using the logged propensities, with clipping or self-normalisation, and check the effective sample size of each candidate policy.
    • For multi-step sessions the products of ratios can blow up. Prefer in-sample value learning (an IQL-style expectile V with advantage-weighted extraction) or CQL-style pessimism over naive Q-learning with a max over all reformulations.
    • Unlogged actions have no support. A hard restriction to logged candidates can enforce an empirical-support constraint; advantage-weighted cloning and a KL penalty to an estimated logger are softer controls, since a parameterised generator can still emit unlogged actions (IQL avoids out-of-sample Q queries in training, not at deployment). Otherwise be pessimistic about them (CQL). Similar wording does not establish logging support.
    • Select models without interaction: off-policy evaluation (doubly robust or weighted IS) on held-out logs. Prefer candidates close to the logger with tight confidence bounds, remembering that OPE is least reliable exactly where a policy departs from the logs.
    • Reserve the single permitted A/B test for the preselected candidate and a prespecified safety or non-inferiority decision. Do not promise several online correction rounds within the stated budget; propose those only as a future extension.

Done with this page?

Status