Pretrain on a log, then let the robot practise. The moment practice starts, a conservative critic often loses what it learned: success falls before it climbs. A half-offline, half-online batch from scratch is hard to beat.
Learn how to move a policy from a fixed log to live practice without the dip, and how flow actors help.
Press Replay training. Watch success at the yellow line where practice starts. Then pick WSRL warm-up or RLPD, and drag the pessimism α. Then we build each piece: constraints, the CQL bound, the dip, RLPD, flow actors and model-based offline RL.
You need offline RL with CQL and IQL (Offline RL) and actor-critic. We build the rest from zero.
A supplement to UC Berkeley CS 185/285, Deep Reinforcement Learning, Sergey Levine (Spring 2026). It follows Lecture 17 (PDF) and Lecture 18 (PDF) on offline RL. The words, toys and numbers here are our own.
Illustrative model, not a trained agent: each curve follows simple rules that encode the course's account (Lecture 18, pp 24 to 26). The critic gap relaxes toward the truth after the switch, and the actor loses ground while the gap moves fast. Steps in thousands; online starts at 50k, as in the course's CQL plot.
Chapter 0
See why the offline phase and the online phase want opposite things
A robot must drive round a rock to its charger. You hold a log of past trips. Most trips take the long left route; a few take the short gap on the right. You may train on the log, then let the robot practise for a short budget.
Offline-to-online RL is that recipe: pretrain a policy and a critic on a fixed log, then fine-tune both with new interaction. The policy that wrote the log is the behaviour policy πβ. The two phases pull in opposite directions.
| Part | Offline phase wants | Online phase wants |
|---|---|---|
| Policy | stay close to πβ | improve as much as it can |
| Values | conservative: Q̂ ≤ Q | optimistic: Q̂ ≥ Q, to explore |
| Updates | many steps on the same data | learn fast from new data |
The Offline RL lesson builds three offline fixes. Constrain the policy (AWR, AWAC), be pessimistic (CQL), or never query an unseen action (IQL). This lesson adds the switch.
From one state the log holds two actions. One leads to a return of −10, the other to +10. IQL fits V(s) with an expectile loss. It is a squared loss with weight τ when V sits below Q, and 1 − τ above. Set the derivative to zero over the two points:
V equals ten times, two tau minus one.
The loss at the bad action pulls V down with weight 1 − tau. The loss at the good action pulls V up with weight tau. They balance where (1 − tau)(V + 10) = tau(10 − V).
Tau 0.5 gives V = 0, the mean. Tau 0.7 gives V = 4. Tau 0.9 gives V = 8. A value of 9.7 needs tau 0.985.
The hero shows the cost of the switch. Each chapter below explains one part of it.
Chapter 1
Tell forward KL from reverse KL by the term you add, and see what each lets the policy drop
A policy constraint keeps the learned policy πθ near πβ. The KL divergence D(p‖q) is the average of log p − log q under p. Its direction decides what the policy may drop.
| Direction | Average under | Infinite when | Effect |
|---|---|---|---|
| Forward D(πβ‖πθ) | logged actions | πθ = 0 on a logged action | covers every mode |
| Reverse D(πθ‖πβ) | the policy's actions | πθ > 0 where πβ = 0 | picks one mode |
With numbers: πβ = (0.7, 0.3, 0) over left, right and through the rock. The policy (0, 1, 0) has forward KL ∞ and reverse KL ln(1/0.3) = 1.20. The policy (0.35, 0.35, 0.3) has forward KL 0.44 and reverse KL ∞.
The forward KL is −Eπβ[log πθ] plus a constant: a cloning term on logged actions. The course calls an actor loss with this term [method]+BC, as in TD3+BC.
J of theta equals the sum over i of the average Q under pi-theta, plus lambda times log pi-theta of a-i given s-i.
Raise Q of the policy's actions and the chance of each logged action a-i. For a Gaussian with fixed spread, the second term is minus a squared distance to a-i.
With made-up numbers: spread 0.1, logged action 0.45, policy mean 0.60. log πθ = −0.15²/(2 × 0.1²) = −1.125 plus a constant. At lambda 1 the policy pays 1.125.
The reverse KL adds λ log πβ to Q plus an entropy bonus, so it needs an estimate of πβ. Its best policy:
Pi-star of a given s equals one over Z of s, times pi-beta of a given s, times e to the A over lambda.
Multiply each pi-beta chance by e to the A over lambda, then divide by the total. An action pi-beta never takes stays at zero.
With made-up numbers: pi-beta (0.7, 0.3), Q (3, 8), so V = 4.5 and A = (−1.5, 3.5). At lambda 2 the weights are 0.47 and 5.75, and pi-star = (0.16, 0.84).
Teal is the log's πβ. Warm is the learned Q̂, with a false peak where the log is empty. Pick a constraint and drag λ; the best Gaussian appears.
Illustrative toy: one state, one action on a line. πβ = 0.7 N(−0.5, 0.2²) + 0.3 N(0.5, 0.1²). The policy is a Gaussian found by grid search over mean and spread.
The ideal is a support constraint: pay only for actions πβ never takes. It is hard to compute, so methods use a KL.
The failure. Under a forward KL a Gaussian covers both modes, and its mean lands on the rock. Measure the share of policy actions where πβ is tiny. Fix: a reverse KL, or a policy that holds two modes.
Chapter 2
Solve the CQL loss for one table entry and find the penalty that keeps Q̂ low on average
Offline, the argmax of a learned Q finds where Q̂ is most wrong. Conservative Q-learning (CQL) pushes Q̂ down on actions from a distribution μ and up on logged actions.
L-CQL equals alpha times, the average Q under mu minus the average Q on the data, plus one half the average squared Bellman error.
Fit Q to its Bellman target. Then lower Q on actions from mu and raise it on logged actions, both scaled by alpha.
With made-up numbers: alpha 1, average Q under mu 6, average Q on data 5, Bellman error 0.4. L = 1 × (6 − 5) + 0.5 × 0.16 = 1.08.
Now solve it for one entry Q(s, a). Logged pairs appear with chance πβ(a|s). Set the derivative to zero: αμ − απβ + πβ(Q − BπQ̂) = 0. Divide by πβ:
Q-hat equals the Bellman target minus alpha times, mu over pi-beta minus one.
CQL lowers an action that mu favours more than the log does, and raises the rest. Averaged under pi with mu = pi, the push is alpha times the chi-squared Σ(π − πβ)²/πβ, never negative.
With made-up numbers: one step, so the target is the reward, (3, 8, 6). Pi-beta (0.6, 0.3, 0.1), pi = mu = (0.1, 0.6, 0.3), alpha 1. Q-hat = (3.83, 7, 4). Under pi, Q-hat averages 5.78 and Q averages 6.90: below, by exactly the chi-squared 1.12.
The first entry ends above its truth, 3.83 > 3. So CQL keeps the policy's average low in every logged state, not every entry. Without the push-up term the bound holds entry by entry, at a larger α.
Teal bars show the logged estimates, warm bars CQL's values, blue lines the truth. The fourth action has one lucky entry: estimate 9, truth 2. Drag α and watch the greedy pick.
Illustrative one-step toy. πβ = (0.45, 0.30, 0.20, 0.05). μ is the softmax of Q̂, solved to a fixed point.
Which μ? Add its entropy and maximise. The best μ is proportional to exp Q, and the maximum is a log-sum-exp, a soft maximum.
The max over mu of, the average Q plus the entropy, equals log of the sum of e to the Q.
Exponentiate each Q, add, take the log. Continuous actions need a sampled estimate.
Q = (3, 8, 6) gives log-sum-exp 8.13. There mu = (0.006, 0.876, 0.118), the average Q is 7.73 and the entropy 0.40: 7.73 + 0.40 = 8.13.
The failure. A large α drags every value far below the truth. Measure mean Q̂ against the policy's Monte Carlo returns. Chapter 3 shows the bill.
Chapter 3
See how an underestimated favourite loses to a worse action that was just tried
The course trains CQL offline, then starts online training at 50,000 steps. Success falls sharply, then recovers. The average Q-value fell during offline training, which the course marks "underestimating too much". The recovery period is time "wasted recovering offline performance".
Here is one way the dip happens. After CQL, the policy's favourite action a* has a value estimate below its truth. A neighbour a′ is worse, and the log barely covers it, so CQL pushed it lower still. Online, the robot tries a′. Its estimate jumps to its true value, which beats the low estimate of a*. The greedy policy switches to the worse action.
Blue outlines are true values; warm bars are estimates. The ring marks the greedy action. Drag the pessimism gap, then step the episodes.
Illustrative toy. One try sets an estimate to its true value. Episodes 1, 3 and 5 explore a neighbour; the rest act greedily. Less-logged actions carry a gap one larger.
With made-up numbers: a* is worth 8, and CQL estimates 5. The neighbour a′ is worth 6, estimated at 2. One try sets a′ to 6. Now 6 > 5, so the policy plays a′ and earns 6, not 8, until it tries a* again.
| Fix | What it does | Why it helps |
|---|---|---|
| Keep offline data | put some logged data in the online replay buffer | the sampled data shifts less at the switch |
| WSRL warm-up | freeze the policy for N steps; fill the buffer with its own rollouts | the critic recalibrates on the policy's actions before the actor moves |
The failure. Symptom: success falls in the first few thousand online steps while mean Q̂ climbs fast. Measure both on one plot, with the switch marked. Fix: lower α before the switch, warm up the critic, or keep logged data in the batch. The course says every offline method has its own version of this, and it is hard to remove fully.
Chapter 4
Skip pretraining, sample every batch half from the log, and give new data a loud voice
RLPD (Ball, Smith, Kostrikov and Levine) is a recipe the course calls "embarrassingly effective":
The course calls it "deeply unsatisfying", and hard to beat with any proper offline-to-online method. No pretrained critic means no miscalibrated critic, so there is nothing to lose at the switch.
Why half and half, not one pool? Call the log size Noff, the online buffer size Non, and the batch size B.
p-on over p-off equals, B over two divided by N-on, over B over two divided by N-off, which is N-off over N-on.
Each half of the batch splits its draws over its own buffer. The small online buffer splits its half among few transitions, so each one comes up often.
With made-up numbers: N-off 1,000,000, N-on 10,000, B 256. Each online transition gets 128/10,000 = 0.0128 draws per batch, each logged one 0.000128: 100 times fewer. One pooled buffer would give the online data only 2.5 slots per batch.
Teal tiles come from the log, yellow tiles from practice. Drag the online steps and compare the two ways to sample.
Illustrative sizes: a log of 1,000,000 transitions and one transition per online step.
Two more choices travel with RLPD. The course project adds LayerNorm between each linear layer and its activation in the critic, citing RLPD. The RLPD code runs 20 critic updates per environment step, a high update-to-data ratio, in its published commands.
The failure. Pool the log and the new data in one buffer, and the new data drowns: 1% of each batch at 10,000 steps. Symptom: online learning crawls. Measure the online share of each batch. Fix: sample the two buffers separately.
Chapter 5
Clone the log with a flow model, then improve it three ways without asking about unseen actions
The course notes that diffusion and flow actors tend to make offline-to-online RL work better, for reasons not yet settled. Such a model turns noise z into an action and can hold both routes. RL on it is hard: the gradient needs log π, or backpropagation through every denoising step. So these methods clone the log with the flow model and do the RL elsewhere.
IDQL trains Q̂ with IQL and a flow policy by cloning. At test time it samples N actions and keeps the best.
a-star is the argmax over k of Q-hat of s and a-k, with a-one to a-N sampled from pi-BC.
Draw N actions from the clone. Score each with Q-hat. Act with the best. The critic only ranks actions the log could produce.
The log goes left 0.7 and right 0.3. Some sample takes the gap with chance 1 − 0.7N: 0.30 at N = 1, 0.76 at N = 4, 0.94 at N = 8.
FQL (flow Q-learning) adds a one-step actor μω(s, z), a plain network fed the noise z. It raises Q̂ while copying the flow model's action for the same z.
L of omega is the average over s and z of: minus Q-hat at mu-omega, plus alpha times the squared distance from mu-omega to mu-flow.
For each z, move the actor's action uphill on Q-hat. Pay alpha per squared unit of distance from the flow model's action.
With made-up numbers: if Q-hat rises with slope 2 near the flow action, the actor settles 2/(2α) away. At alpha 10 that is 0.1.
Teal is the clone's density. Warm is Q̂, with a false peak at the right edge. IDQL: drag N. FQL: drag α; each arrow moves one z from the flow action to the actor's action.
Illustrative toy on the log of Chapter 1. The flow map is the exact 1-D transport from N(0, 1) to the log. Averages use 41 noise quantiles (FQL) or 4,000 draws (IDQL).
DSRL runs online RL, such as SAC, on the noise input of a frozen diffusion policy. Every noise gives an in-distribution action, so logged data stays safe. The RL for VLAs lesson lets you steer one.
The failure. FQL with a small α lets z jump to the false peak. Measure the distance from μω to μflow. Fix: raise α; the course project tunes it per task.
Chapter 6
Subtract the model's doubt from its reward, or push down Q on states the model invents
A learned dynamics model answers "what if" questions. Offline, the policy steers the model's rollouts to states the log never saw. There the model guesses, and the policy finds states where the guess is too good. This is the false peak of Chapter 1, now in state space. The model-based RL lesson builds the model and its ensemble.
MOPO punishes the policy for that. Call the model's doubt at (s, a) the uncertainty u(s, a), for example the spread of an ensemble's predictions.
r-tilde of s and a equals r of s and a, minus lambda times u of s and a.
Wherever the ensemble disagrees, cut the reward by lambda times the disagreement. Then run any model-based RL method on the cut reward.
With made-up numbers: an unseen state promises 1.2 with u = 0.5; a logged state promises 0.9 with u = 0.05. At lambda 1: 0.7 against 0.85, so the logged state wins.
Teal shades the logged states. Warm lines are five models; blue is the truth. Drag λ and watch where the planner goes.
Illustrative toy: one state variable, logged from 2 to 6. u is the standard deviation of five model predictions.
MOReL, from the same year, is a related method the course cites. COMBO takes CQL's idea instead: push Q down on state-action pairs from model rollouts, and up on logged pairs.
Beta times, the average Q on model pairs minus the average Q on logged pairs, plus one half the squared Bellman error.
Fit Q on real and model data. Lower Q on what the model invents, raise it on what the log holds. A model state that looks unlike real data is easy for Q to mark down.
With made-up numbers: beta 0.5, model pairs average 7, logged pairs 5, Bellman error 0.2. Loss = 0.5 × 2 + 0.5 × 0.04 = 1.02.
The failure. If λ is too small the planner rides the models' false rise; too large and it stays at the most-logged state. Measure the true return of the plan on held-out real rollouts. Fix: tune λ against those.
Chapter 7
Keep the terms, the numbers, the checks and the code in one place
Offline, every method keeps the critic away from actions the log cannot vouch for. Online, the critic must recalibrate, and the policy pays while it does. The fixes avoid a pretrained critic (RLPD), recalibrate it first (WSRL), or tie the actor to a cloned flow model (IDQL, FQL, DSRL).
| Term or result | Value | Where |
|---|---|---|
| IQL two-point toy | V = 10(2τ − 1): 4 at τ 0.7, 8 at 0.9; 9.7 needs 0.985 | Ch 0 |
| Forward KL | a BC log-likelihood term; covers modes; (0,1,0) vs (0.7,0.3,0) is ∞ | Ch 1 |
| Reverse KL | adds λ log πβ + entropy; same pair gives 1.20 | Ch 1 |
| Closed form | π* ∝ πβ exp(A/λ): (0.7, 0.3) → (0.16, 0.84) at λ 2 | Ch 1 |
| CQL fixed point | Q̂ = BπQ̂ − α(μ/πβ − 1); average gap αχ² = 1.12 | Ch 2 |
| Log-sum-exp | (3, 8, 6) → 8.13 = 7.73 + entropy 0.40 | Ch 2 |
| The dip | switch when a tried neighbour's true value beats the favourite's estimate | Ch 3 |
| RLPD weight | online/offline draw ratio Noff/Non: 100 at 10,000 steps | Ch 4 |
| IDQL coverage | 1 − 0.7N: 0.76 at N = 4 | Ch 5 |
| MOPO | r − λu: 1.2 − 0.5 = 0.7 < 0.85 | Ch 6 |
pythonimport numpy as np def rlpd_batch(off, on, B, rng): # half from the log, half from practice (RLPD step 3) i = rng.integers(0, len(off), B // 2) j = rng.integers(0, len(on), B - B // 2) return np.concatenate([off[i], on[j]]) def cql_penalty(q_all, q_data, alpha): # q_all: [B, n_actions] Q of every action; q_data: [B] Q of logged actions m = q_all.max(1, keepdims=True) lse = (m + np.log(np.exp(q_all - m).sum(1, keepdims=True)))[:, 0] return alpha * (lse - q_data).mean() # push down soft max, push up data def idql_act(s, sample_bc, q, N=16): acts = sample_bc(s, N) # [N, act_dim] from the cloned flow model return acts[np.argmax(q(s, acts))] def fql_actor_loss(s, z, actor, flow, q, alpha): a = actor(s, z) # one pass, no denoising loop return (-q(s, a) + alpha * ((a - flow(s, z)) ** 2).sum(-1)).mean() def mopo_reward(r_models): # r_models: [K, B] reward predictions of K ensemble members return lambda lam: r_models.mean(0) - lam * r_models.std(0)
Now press Present or Teach and derive from memory: the CQL fixed point, the log-sum-exp and RLPD's draw ratio. Then go back to the hero, set α to 3, and predict the dip before you replay.
This supplement follows UC Berkeley CS 185/285, Deep Reinforcement Learning, Sergey Levine (Spring 2026). See the course page, Lecture 17 on offline RL and Lecture 18 on offline RL algorithms. It also uses the course's Section 9 notes and the offline-to-online project handout.
The methods: CQL (Kumar et al. 2020), IQL (Kostrikov et al. 2021) and RLPD (Ball et al. 2023). Also IDQL (Hansen-Estruch et al. 2023), FQL (Park, Li and Levine 2025), DSRL (Wagenmaker et al. 2025) and WSRL (Zhou et al. 2025). Also MOPO (Yu et al. 2020), MOReL (Kidambi et al. 2020) and COMBO (Yu et al. 2021). The words, toys and numbers here are our own.