Search

Search papers and lessons

Conservative Q-Learning for Offline Reinforcement Learning

Aviral Kumar, Aurick Zhou, George Tucker et al. · 2020

Kumar and colleagues add a penalty to Q-learning that pushes down the values of actions the dataset never took, so offline agents stop trusting their own over-optimistic guesses.

On this page

  • Colour = topic mix
  • Probability
  • Reinforcement learning
  • Discrete math
  • Calculus
  • Neural network basics
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

Conservative Q-learning (CQL) learns a control policy from a fixed log of past experience, with no new trials. It is ordinary Q-learning plus one extra term in the loss. The extra term pushes down the estimated value of actions the data never tried and pushes up the value of actions it did try, so the learned values act as a conservative lower bound rather than an optimistic guess.

Without that term, the learner trusts its own inflated values for actions it has never checked, and the policy it extracts performs badly when run for real. On the harder benchmark datasets the authors report clear gains over earlier offline methods.

Builds on: Deep Q-Network, Offline Reinforcement Learning · Leads to: later offline RL methods that penalise or constrain out-of-data actions

Why it mattered

Offline RL is the setting where a robot, a recommender or a clinic already has years of logged decisions and cannot safely explore. CQL became a common baseline for it because the recipe is simple: take a standard deep Q-learning or actor-critic implementation and add a regulariser. The change is small: it is added on top of soft actor-critic for continuous control and on top of QR-DQN for discrete control.

The benchmark it was tested on, the D4RL gym suite, became a standard way to compare offline methods. Later papers report on the same tasks against the same baselines, including CQL, so its numbers are part of the common scale the field uses.

The idea came from a 2020 arXiv posting by Kumar and colleagues. Earlier offline methods mostly kept the learned policy close to the behaviour policy with a constraint. CQL changes the value estimates instead, so the same penalty works with any value-based or actor-critic learner.

The problem

Q-learning learns a value for each state-action pair by bootstrapping: the target for one entry uses the best value of the next state. When the learner is online, a wrong high value is corrected because the agent tries that action and sees the true result. Offline, the agent cannot try anything. Actions absent from the dataset keep whatever value the network gives them, and the max in the Bellman target keeps selecting the largest of these unchecked numbers. The paper calls the result erroneously optimistic value estimates, driven by bootstrapping from out-of-distribution actions and by overfitting on a small dataset.

The goal is a learner whose value estimate for the policy it will run is never too high. In terms of the prerequisites: the learned QQ should lower-bound the true value VπV^\pi of the policy, which is defined through the Bellman equation over the MDP.

How it works

Here is one tiny instance. One state ss has two actions: a1a_1, which appears in the dataset, and a2a_2, which never does. The network currently says Q(s,a1)=1Q(s, a_1) = 1 and Q(s,a2)=3Q(s, a_2) = 3. The network has no evidence for a2a_2, so 33 is an unsupported guess.

  1. Take the dataset action a1a_1. Ordinary Q-learning fits Q(s,a1)Q(s, a_1) to its Bellman target and does nothing about a2a_2. A greedy policy would now choose a2a_2, because 3>13 > 1.
  2. Add a penalty that is large when the network gives high values to many actions at once. The penalty is the soft-maximum of all the Q-values in the state, log⁡∑aexp⁡Q(s,a)\log \sum_a \exp Q(s,a), minus the Q-value of the dataset action.
  3. Compute it. The soft-maximum is log⁡(e1+e3)=log⁡(22.80)≈3.13\log(e^1 + e^3) = \log(22.80) \approx 3.13. Subtract the dataset action's value Q(s,a1)=1Q(s,a_1) = 1 to get a penalty of about 2.132.13.
  4. Look at the gradient. The soft-maximum puts weight 0.880.88 on a2a_2 and 0.120.12 on a1a_1. Minimising the penalty pushes Q(s,a2)Q(s,a_2) down and pushes Q(s,a1)Q(s,a_1) up.
  5. Repeat the update. Over many steps Q(s,a2)Q(s,a_2) falls toward the level the data supports and Q(s,a1)Q(s,a_1) rises toward its real value. The greedy policy now prefers the action the data actually shows working.
flowchart LR
  D[Logged dataset of state, action, reward, next state] --> B[Bellman error on dataset transitions]
  D --> P[Penalty: push down Q on all actions, push up Q on dataset actions]
  B --> L[Total loss = alpha times penalty + Bellman error]
  P --> L
  L --> Q[Updated Q-function]
  Q --> PI[Policy: act greedily or by actor-critic]

The math

The paper's practical objective, CQL(H\mathcal{H}), is the Q-function loss used in Algorithm 1:

min⁡Q  α Es∼D ⁣[log⁡∑aexp⁡Q(s,a)−Ea∼π^β(a∣s)[Q(s,a)]]+12 E(s,a,s′)∼D ⁣[(Q(s,a)−B^∗Q^k(s,a))2]\min_{Q}\; \alpha\,\mathbb{E}_{s \sim \mathcal{D}}\!\left[\log \sum_{a} \exp Q(s,a) - \mathbb{E}_{a \sim \hat{\pi}_\beta(a \mid s)}\big[Q(s,a)\big]\right] + \frac{1}{2}\,\mathbb{E}_{(s,a,s') \sim \mathcal{D}}\!\left[\big(Q(s,a) - \hat{\mathcal{B}}^{*}\hat{Q}^{k}(s,a)\big)^{2}\right]

Here D\mathcal{D} is the dataset, π^β\hat{\pi}_\beta is the behaviour policy that generated the data (estimated from the data), α\alpha is the weight on the penalty, and B^∗Q^k\hat{\mathcal{B}}^{*}\hat{Q}^{k} is the Bellman target from the previous iterate. The first term is the penalty; the second is the usual squared Bellman error.

Step 2 in symbols: the penalty

The term log⁡∑aexp⁡Q(s,a)\log \sum_a \exp Q(s,a) is a smooth maximum over actions. Its gradient with respect to Q(s,a)Q(s,a) is the softmax weight exp⁡Q(s,a)∑a′exp⁡Q(s,a′)\frac{\exp Q(s,a)}{\sum_{a'} \exp Q(s,a')}, which is large for the highest-valued actions. The second term, Ea∼π^β[Q(s,a)]\mathbb{E}_{a \sim \hat{\pi}_\beta}[Q(s,a)], has gradient π^β(a∣s)\hat{\pi}_\beta(a \mid s), which is large only for actions the data contains. Minimising the difference lowers the high-valued actions and raises the logged ones.

In the tiny example the softmax weights were 0.880.88 on a2a_2 and 0.120.12 on a1a_1, and the data weight was 11 on a1a_1 and 00 on a2a_2. The net push on a2a_2 is down by 0.880.88, and on a1a_1 it is up by 1−0.12=0.881 - 0.12 = 0.88.

What the bound says

Under the usual regularity assumptions, the paper shows that the learned QQ satisfies Ea∼π[Q(s,a)]≤Vπ(s)\mathbb{E}_{a \sim \pi}[Q(s,a)] \le V^\pi(s) for the policy it will run. Only the expectation under the policy is bounded from above, not every single value. This matters: a bound on every action would also push down good actions that the data covers poorly, making the learner too pessimistic.

Variants

If the reference distribution in the penalty is a previous policy rather than uniform, the soft-maximum is replaced by an exponentially weighted average over that policy's actions. The paper calls this CQL(ρ\rho). It is one way to avoid estimating the log-sum-exp by sampling, which can be noisy when the action space is high-dimensional.

Results

The main table reports normalised return on D4RL gym tasks. CQL(H\mathcal{H}) is compared with plain SAC, behaviour cloning and earlier offline methods such as BEAR and BRAC. The pattern to look for: on datasets that mix good and mediocre behaviour, plain SAC trained on the same logged data does poorly, while CQL uses both parts of the data. On the single-policy datasets the margins over the strongest earlier baselines are smaller. Read the exact per-task numbers in the paper's table rather than trusting a summary ratio.

Limits, which the paper itself raises:

  • It is tempting to think that CQL makes Q-values small in general. In fact the penalty raises logged actions and lowers the rest. The aim is a correct ordering across covered actions and low values for unsupported ones, not a uniform shift down.
  • It is tempting to think a lower bound on every action is the goal. In fact only the expectation under the policy needs the bound, and a bound on each action would be too pessimistic.
  • For continuous actions the log-sum-exp is estimated by sampling and importance weights. With many action dimensions those weights are noisy, which is the motivation for the CQL(ρ\rho) variant.
  • Use CQL when the data is fixed, interaction is unsafe, and the data mixes behaviours. A simpler behaviour-constrained method may suffice when the data comes from one good controller. The weight α\alpha is a real choice: the paper tunes it automatically for continuous control with a Lagrangian rule and fixes it for discrete control.

Reading guide

Read these lessons first: Offline Reinforcement Learning, Deep Q-Network, Markov Decision Process and Bellman Equation. Then read the paper in this order.

After this paper, Soft Actor-Critic is the continuous-control base the paper modifies, and Behavior Cloning is the simplest offline baseline it is compared against.

Check yourself

QuestionIn the tiny example, Q(s,a_1) = 0 and Q(s,a_2) = 2, with alpha = 1 and the dataset containing only a_1. What is the penalty term?Show answer

The soft-maximum is log⁡(e0+e2)=log⁡(1+7.389)=log⁡8.389≈2.128\log(e^0 + e^2) = \log(1 + 7.389) = \log 8.389 \approx 2.128. Subtract the dataset action's value Q(s,a1)=0Q(s,a_1) = 0. The penalty is about 2.132.13.

QuestionWhy does the CQL penalty raise the value of the logged action when the Bellman term already fits it?Show answer

The Bellman term fits each logged transition to its own target, but it never compares the logged action with the unlogged ones. The penalty does: it subtracts the logged action's value, so lowering the soft-maximum over all actions also raises the logged action relative to them. The logged action is no longer outweighed by unsupported high values.

QuestionWhy does the paper bound only the expectation of Q under the policy, rather than every action's value?Show answer

The policy is evaluated through its expected value, so a bound on that expectation is enough for policy evaluation and improvement. A bound on every action would also push down good actions that the data covers poorly, making the learned values too pessimistic.

QuestionYou run CQL on a robot dataset in which every action comes from one good controller. Why might a simpler method do as well?Show answer

With one behaviour and little variety, there are few unsupported high-value actions to worry about. A method that stays close to the behaviour policy already performs well, so the extra penalty adds cost and tuning without much benefit. The penalty helps most when the data mixes behaviours and the learner could otherwise trust values for actions it never saw.

Sources

Read the full paper

Aviral Kumar, Aurick Zhou, George Tucker et al., 2020. arXiv:2006.04779