Skip to content
AI360Xpert
Beta

Implicit Q-Learning

Learn strong values from logged data only. You fit the top of what you saw with expectile regression and clone the good moves with weights.

IQL fits V at 5.0 between Q values 6.0 and 4.0 with tau 0.7, targets Q at 5.05, and weights the good action 403 times more
IQL fits V at 5.0 between Q values 6.0 and 4.0 with tau 0.7, targets Q at 5.05, and weights the good action 403 times more

Why Does This Exist?

Offline RL has one trap. Your data came from some old behavior policy, but your Bellman update wants to ask what would happen for a new action nobody tried. Neural nets answer with confident nonsense, and the policy chases that hallucination. That gap is distributional shift.

Earlier fixes wrestle the unseen actions directly. Batch constrained Q-learning learns a model of allowed actions. Conservative Q-learning pushes unseen values down. Both need extra sampling and tuning. Start with offline batch RL for the setup, then see this page as the in sample alternative.

This page teaches the method from Kostrikov and coauthors that never asks about unseen actions at all. You learn a value upper envelope from logged pairs only, back it into Q with plain regression, and extract the policy by weighted cloning.

The one idea you need first

A Bellman target for (s,a,r,s′)(s, a, r, s') is r+γV(s′)r + \gamma V(s'). Here rr is the logged reward, γ\gamma is the discount, V(s′)V(s') is the value of the next state. No max over actions appears, so you never need to invent an action at s′s'.

Think of It Like This

Picking the best logged bus route

Your city keeps logs of bus trips, with travel times for routes drivers actually drove. You cannot run test buses. You want the fastest reliable route per intersection.

You do not draw a straight line through a park and claim 30 seconds. You look only at logged roads. At each crossing you take a high percentile of logged times, say the 70th percentile good trip, not the average. Then you tell new drivers to copy the trips that beat that bar and ignore the slow ones.

Where the analogy stops: streets have hard curbs, so allowed versus forbidden is crisp. In control, allowed is a soft data cloud, so the percentile becomes a smooth expectile loss instead of a hard filter.

How It Actually Works

Three steps run together, all on dataset pairs (s,a,r,s′)(s, a, r, s') from D\mathcal{D}. Symbols: Vψ(s)V_\psi(s) is the state value net, Qθ(s,a)Q_\theta(s, a) is the action value net, τ\tau is the expectile level, β\beta is the policy temperature.

First, fit VV with asymmetric squared loss:

LV(ψ)=E(s,a)∼D[L2τ(Q(s,a)−Vψ(s))]L_V(\psi) = \mathbb{E}_{(s,a) \sim \mathcal{D}}[L_2^\tau(Q(s,a) - V_\psi(s))]

with L2τ(u)=τu2L_2^\tau(u) = \tau u^2 when u≥0u \ge 0 and (1−τ)u2(1-\tau) u^2 otherwise. When τ=0.5\tau = 0.5 you get the mean. When τ=0.7\tau = 0.7 or 0.90.9 you pull VV toward the good logged actions. As τ\tau nears 1, VV nears the best logged value.

Next, fit QQ with the state value as target:

LQ(θ)=E[(r+γVψ(s′)−Qθ(s,a))2]L_Q(\theta) = \mathbb{E}[(r + \gamma V_\psi(s') - Q_\theta(s,a))^2]

The target y=r+γV(s′)y = r + \gamma V(s') touches only the observed next state s′s'. No candidate action at s′s' is scored.

Finally, extract the policy with advantage A=Q−VA = Q - V:

Lπ(ϕ)=−E(s,a)∼D[exp⁡(βA(s,a))log⁡πϕ(a∣s)]L_\pi(\phi) = -\mathbb{E}_{(s,a) \sim \mathcal{D}}[\exp(\beta A(s,a)) \log \pi_\phi(a \mid s)]

Good moves get copied hard, bad moves get near zero weight. No backprop through Q is needed.

Worked example

One state ss has two logged actions. Target Q values are Q(s,a1)=6.0Q(s,a_1) = 6.0 and Q(s,a2)=4.0Q(s,a_2) = 4.0. Current V(s)=5.0V(s) = 5.0. Set τ=0.7\tau = 0.7, β=3.0\beta = 3.0, γ=0.9\gamma = 0.9.

Expectile gaps are u1=1.0u_1 = 1.0 and u2=−1.0u_2 = -1.0:

L20.7(1.0)=0.7×1.0=0.70L_2^{0.7}(1.0) = 0.7 \times 1.0 = 0.70 L20.7(−1.0)=0.3×1.0=0.30L_2^{0.7}(-1.0) = 0.3 \times 1.0 = 0.30

The upside error costs 2.33 times the downside, so VV drifts up toward 6.0.

Take transition (s,a1,r=1.0,s′)(s, a_1, r = 1.0, s') with V(s′)=4.5V(s') = 4.5:

y=1.0+0.9×4.5=5.05y = 1.0 + 0.9 \times 4.5 = 5.05

No action was invented at s′s'.

Advantages are A1=1.0A_1 = 1.0 and A2=−1.0A_2 = -1.0. Weights:

w1=exp⁡(3.0)≈20.0855w_1 = \exp(3.0) \approx 20.0855 w2=exp⁡(−3.0)≈0.0498w_2 = \exp(-3.0) \approx 0.0498

Ratio 20.0855/0.0498≈403.320.0855 / 0.0498 \approx 403.3. The actor copies a1a_1 about four hundred times harder than a2a_2, which is the filtering the diagram shows.

Code

This snippet mirrors the worked numbers with no dependencies.

"""Mirror the IQL worked numbers from the page."""
import math
tau = 0.7beta = 3.0gamma = 0.9
u_good = 6.0 - 5.0u_bad = 4.0 - 5.0loss_good = (tau if u_good >= 0 else 1 - tau) * u_good**2loss_bad = (tau if u_bad >= 0 else 1 - tau) * u_bad**2print(round(loss_good, 4), round(loss_bad, 4))# -> 0.7 0.3
print(round(1.0 + gamma * 4.5, 2))# -> 5.05
print(round(math.exp(beta * 1.0), 4), round(math.exp(beta * -1.0), 4))# -> 20.0855 0.0498

Watch Out For

Pushing tau to 1.0 on noisy logs

High τ\tau hugs the best logged return. On noisy data that best return is often a lucky outlier, so VV chases noise and targets wobble. The symptom is strong training curves on clean demos but shaky values on mixed logs.

Stay near τ=0.7\tau = 0.7, move to 0.90.9 only for expert heavy data, and watch the gap between VV and median QQ. If VV sits far above most logged QQ values, lower τ\tau before touching anything else.

Letting exp beta advantage explode

Large β\beta turns weights into spikes. One transition dominates the batch, gradients jump, and the policy collapses onto a few demos. The symptom is NaN loss or a policy that repeats one move.

Keep β\beta in [3.0,10.0][3.0, 10.0] and clip weights at 100.0100.0. If the top weight hits the clip often, lower β\beta instead of raising the clip.

The Quick Version

  • IQL trains offline with no queries to unseen actions.
  • Expectile loss with τ=0.7\tau = 0.7 fits VV toward good logged QQ values, here losses 0.700.70 versus 0.300.30.
  • Q targets use r+γV(s′)r + \gamma V(s'), here 5.055.05, with no max over actions.
  • Advantage weights exp⁡(βA)\exp(\beta A) copy winners, here 20.085520.0855 versus 0.04980.0498.
  • Tune τ\tau and β\beta carefully and clip weights, or noise and overflow undo the stability.