Offline-to-Online RL and Flow Actors (UC Berkeley CS 285)

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.

Switch from the log to practice

1.5

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

Pretrain on the Log, Then Practise

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.

PartOffline phase wantsOnline phase wants
Policystay close to πβimprove as much as it can
Valuesconservative: Q̂ ≤ Qoptimistic: Q̂ ≥ Q, to explore
Updatesmany steps on the same datalearn 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.

IQL's toy, recomputed

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:

Say it aloud

V equals ten times, two tau minus one.

V
V the expectile value of the state.
10
ten the size of each logged return, −10 and +10.
τ
tau the tilt, from 0.5 to just under 1.
In plain words

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).

With numbers

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.

  1. Read the constraint off the objective: forward KL, reverse KL, the support.
  2. CQL's bound, derived: why pushing down and up gives Q̂ ≤ Q on average.
  3. The dip at the switch: an underestimated critic meets new tries.
  4. RLPD: half offline, half online, from scratch.
  5. Flow actors: sample and rank, distil, or steer the noise.
  6. Model-based offline RL: punish the model where it is unsure.
  7. The field guide: terms, numbers, code and the credit.
Which wish belongs to the online phase, not the offline phase?

Chapter 1

Read the Constraint off the Objective

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.

DirectionAverage underInfinite whenEffect
Forward D(πβ‖πθ)logged actionsπθ = 0 on a logged actioncovers every mode
Reverse D(πθ‖πβ)the policy's actionsπθ > 0 where πβ = 0picks 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.

Say it aloud

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.

J(θ)
J of theta the actor's objective, which it raises.
Σi
the sum over i one term per logged pair (si, ai).
Ea~πθ[Q]
the average Q under pi-theta how good the policy's own actions look to the critic.
λ
lambda the price of moving away from the log.
log πθ(ai|si)
log pi-theta of a-i given s-i how likely the policy finds the logged action.
In plain words

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 numbers

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:

Say it aloud

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.

π*(a|s)
pi-star the best policy under a reverse-KL limit.
1/Z(s)
one over Z of s the number that makes the chances add to 1.
πβ(a|s)
pi-beta the behaviour policy's chance of action a.
exp(A/λ)
e to the A over lambda a weight that grows with the advantage A, how much better a is than average.
In plain words

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 numbers

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).

Fit a policy under each constraint

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.

1.00

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.

An actor loss is −Q(s, π(s)) plus α times the squared distance from π(s) to the logged action. Which constraint is it?

Chapter 2

CQL's Bound, Derived

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.

Say it aloud

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.

LCQL
L-CQL the critic's loss, which it lowers.
α
alpha the strength of pessimism.
Ea~μ[Q]
the average Q under mu the push down, on actions the policy asks about.
ED[Q]
the average Q on the data the push up, on logged pairs.
½ ED[( )²]
one half the squared Bellman error the usual fit to the target BπQ̂ = r + γ Eπ[Q̂(s′, a′)].
In plain words

Fit Q to its Bellman target. Then lower Q on actions from mu and raise it on logged actions, both scaled by alpha.

With numbers

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 πβ:

Say it aloud

Q-hat equals the Bellman target minus alpha times, mu over pi-beta minus one.

Q̂(s,a)
Q-hat where the critic settles for this entry.
BπQ̂
the Bellman target what plain fitting would give.
α
alpha the strength of pessimism.
μ/πβ − 1
mu over pi-beta minus one how much more the policy asks about a than the log holds it.
In plain words

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 numbers

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 α.

Push down, push up

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.

0.00

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.

Say it aloud

The max over mu of, the average Q plus the entropy, equals log of the sum of e to the Q.

maxμ
the max over mu the push-down distribution that makes it largest.
Eμ[Q]
the average Q under mu
H(μ)
the entropy of mu its spread.
log Σ exp Q
log-sum-exp of Q a soft maximum.
In plain words

Exponentiate each Q, add, take the log. Continuous actions need a sampled estimate.

With numbers

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.

With the push-up term, what does CQL guarantee?

Chapter 3

The Dip at the Switch

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.

Step through eight online episodes

Blue outlines are true values; warm bars are estimates. The ring marks the greedy action. Drag the pessimism gap, then step the episodes.

3.0
0

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.

Two fixes from the course project

FixWhat it doesWhy it helps
Keep offline dataput some logged data in the online replay bufferthe sampled data shifts less at the switch
WSRL warm-upfreeze the policy for N steps; fill the buffer with its own rolloutsthe 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.

In the toy, a* is worth 8 and estimated at 7. A tried neighbour is worth 6. Does the policy switch?

Chapter 4

RLPD: Half Offline, Half Online

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":

  1. Make two buffers: one for online data and one for the log.
  2. Start the critic and actor from scratch. No pretraining.
  3. Run online RL. Draw half of every batch from the log and half from the online buffer.

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.

Say it aloud

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.

pon/poff
p-on over p-off how much more often a batch holds one given online transition than one given logged transition.
B/2 ÷ Non
B over two, divided by N-on the draws per batch for each online transition.
B/2 ÷ Noff
B over two, divided by N-off the same for each logged transition.
Noff/Non
N-off over N-on the size ratio of the two buffers.
In plain words

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 numbers

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.

Fill one batch of 256

Teal tiles come from the log, yellow tiles from practice. Drag the online steps and compare the two ways to sample.

10,000

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.

Log of 500,000 transitions, online buffer of 5,000, RLPD batches. How much more often is one online transition drawn than one logged transition?

Chapter 5

Flow Actors: Sample, Distil, Steer

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.

Say it aloud

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.

a*
a-star the action IDQL takes.
argmaxk
the one that makes it largest over the N samples only.
Q̂(s, ak)
Q-hat of s and a-k the IQL critic's score.
ak ~ πBC
drawn from pi-BC the flow model cloned from the log.
In plain words

Draw N actions from the clone. Score each with Q-hat. Act with the best. The critic only ranks actions the log could produce.

With numbers

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.

Say it aloud

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.

L(ω)
L of omega the one-step actor's loss.
Es,z
the average over s and z logged states and fresh noise.
−Q̂(s, μω)
minus Q-hat lowering this raises the critic's score.
α
alpha how tightly the actor copies the flow model.
‖μω − μflow‖²
the squared distance from the actor's action to the flow model's action for the same z.
In plain words

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 numbers

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.

Improve a cloned flow policy

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.

4

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.

Why is the FQL actor cheap at test time?

Chapter 6

Model-Based Offline RL: Penalise the Unsure

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.

Say it aloud

r-tilde of s and a equals r of s and a, minus lambda times u of s and a.

r̃
r-tilde the penalised reward used in model rollouts.
r
r the model's predicted reward.
λ
lambda the price of doubt.
u
u the uncertainty: how much the ensemble members disagree.
In plain words

Wherever the ensemble disagrees, cut the reward by lambda times the disagreement. Then run any model-based RL method on the cut reward.

With numbers

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.

Price the model's doubt

Teal shades the logged states. Warm lines are five models; blue is the truth. Drag λ and watch where the planner goes.

0.00

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.

Say it aloud

Beta times, the average Q on model pairs minus the average Q on logged pairs, plus one half the squared Bellman error.

β
beta the strength of the push.
Eρ[Q]
the average Q on model pairs pairs ρ from model rollouts, pushed down.
ED[Q]
the average Q on logged pairs pushed up.
½ Edf[( )²]
one half the Bellman error on a mix df of logged and model data.
In plain words

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 numbers

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.

What does MOPO change in model-based RL?

Chapter 7

The Field Guide

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 resultValueWhere
IQL two-point toyV = 10(2τ − 1): 4 at τ 0.7, 8 at 0.9; 9.7 needs 0.985Ch 0
Forward KLa BC log-likelihood term; covers modes; (0,1,0) vs (0.7,0.3,0) is ∞Ch 1
Reverse KLadds λ log πβ + entropy; same pair gives 1.20Ch 1
Closed formπ* ∝ πβ exp(A/λ): (0.7, 0.3) → (0.16, 0.84) at λ 2Ch 1
CQL fixed pointQ̂ = BπQ̂ − α(μ/πβ − 1); average gap αχ² = 1.12Ch 2
Log-sum-exp(3, 8, 6) → 8.13 = 7.73 + entropy 0.40Ch 2
The dipswitch when a tried neighbour's true value beats the favourite's estimateCh 3
RLPD weightonline/offline draw ratio Noff/Non: 100 at 10,000 stepsCh 4
IDQL coverage1 − 0.7N: 0.76 at N = 4Ch 5
MOPOr − λu: 1.2 − 0.5 = 0.7 < 0.85Ch 6

Checks at the switch

The core in code

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)

Keep going

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.

Credit and source

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.

Offline-to-Online RL and Flow Actors (UC Berkeley CS 285)
The course page · Lecture 18 slides · RLPD paper · FQL paper · Back to Gleams