Search

Search papers and lessons

V-trace

Level 4 · 13 min read

V-trace learns a value function from trajectories that an older copy of the policy generated, by truncating importance-sampling weights so that the learned values stay stable when the copies drift apart.

On this page

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

TL;DR

In a large reinforcement learning system, many actors play the game in parallel and send their experience to one learner. By the time the learner uses that experience, its own policy has moved on, so the data is off-policy: it was generated by a different policy than the one being improved. V-trace is a target for the value function that corrects for this lag by weighting each step with a truncated importance-sampling ratio, so the learned values stay stable even when the lag is large.

Builds on: Importance Sampling, Actor-Critic Methods, Temporal-Difference Learning, Value Function · Leads to: the IMPALA paper

Where it's used

Large distributed agents. The IMPALA architecture runs many actors and a central learner. The paper reports a throughput of 250,000 frames per second and says this is over 30 times faster than a single-machine A3C agent. At that speed the learner trains on trajectories that lag behind its current policy, and V-trace is the correction that keeps the value estimates usable.

Training one agent on many tasks. The same paper trains one agent on DMLab-30, a set of 30 tasks in a 3D environment, and on the 57 Atari games. Multi-task training needs a single learning rule that works for every task, and V-trace is the off-policy correction the paper uses for all of them.

Replay buffers. Reusing old experience from a replay buffer makes the data more off-policy the older it gets. The paper's replay experiments draw half of each batch uniformly at random from a buffer, and V-trace was the only variant that consistently benefited from adding replay.

How it works

Take a short trajectory of two steps. The actor took actions with an old policy μ\mu, and the learner now has a newer policy π\pi. We will compute the V-trace target for the value of the first state. Use a discount γ=0.5\gamma = 0.5, and truncation level 1 for both weights, which is the setting the paper found best in its experiments.

The trajectory has three states x0,x1,x2x_0, x_1, x_2, rewards r0=1r_0 = 1 and r1=0r_1 = 0, and current value estimates V(x0)=0.5V(x_0) = 0.5, V(x1)=1.0V(x_1) = 1.0, V(x2)=0V(x_2) = 0. For each step the learner has the probability the new policy gives the taken action, divided by the probability the old policy gave it: at step 0 the ratio is 2.02.0, and at step 1 it is 0.50.5.

  1. Compute the importance ratios. At step 0, π/μ=2.0\pi / \mu = 2.0. At step 1, π/μ=0.5\pi / \mu = 0.5. Check: a ratio above 1 means the new policy likes the action more than the old one did.

  2. Truncate the ratios. Cap each at the truncation level 1. This gives ρ0=min⁡(1,2.0)=1\rho_0 = \min(1, 2.0) = 1 and ρ1=min⁡(1,0.5)=0.5\rho_1 = \min(1, 0.5) = 0.5. The same capped values serve as c0=1c_0 = 1 and c1=0.5c_1 = 0.5 for the trace. Check: the capped ratio is never larger than the uncapped one, and step 0 has been cut from 2.0 to 1.

  3. Compute the temporal differences. Each step's error is δt=ρt (rt+γV(xt+1)−V(xt))\delta_t = \rho_t\,(r_t + \gamma V(x_{t+1}) - V(x_t)). For step 0, δ0=1 (1+0.5⋅1.0−0.5)=1.0\delta_0 = 1\,(1 + 0.5 \cdot 1.0 - 0.5) = 1.0. For step 1, δ1=0.5 (0+0.5⋅0−1.0)=−0.5\delta_1 = 0.5\,(0 + 0.5 \cdot 0 - 1.0) = -0.5. Check: the bracket for step 1 is 0+0−1.0=−1.00 + 0 - 1.0 = -1.0, and 0.5⋅(−1.0)=−0.50.5 \cdot (-1.0) = -0.5.

  4. Work backwards from the end. The last target is just the current estimate, v2=V(x2)=0v_2 = V(x_2) = 0. Because v2−V(x2)=0v_2 - V(x_2) = 0, the term that carries the later target back in step 5 vanishes here. Start at step 1: v1=V(x1)+δ1=1.0−0.5=0.5v_1 = V(x_1) + \delta_1 = 1.0 - 0.5 = 0.5. Check: v1v_1 is the value of x1x_1 after one correction.

  5. Carry the result back to the first state. v0=V(x0)+δ0+γ c0 (v1−V(x1))=0.5+1.0+0.5⋅1⋅(0.5−1.0)=1.25v_0 = V(x_0) + \delta_0 + \gamma\, c_0\,(v_1 - V(x_1)) = 0.5 + 1.0 + 0.5 \cdot 1 \cdot (0.5 - 1.0) = 1.25. Check: the same number comes from the sum form, V(x0)+δ0+γ c0 δ1=0.5+1.0+0.5⋅1⋅(−0.5)=1.25V(x_0) + \delta_0 + \gamma\, c_0\, \delta_1 = 0.5 + 1.0 + 0.5 \cdot 1 \cdot (-0.5) = 1.25.

  6. Read the result. The learner moves V(x0)V(x_0) from 0.50.5 toward the target 1.251.25. The truncation kept the step-0 ratio from doubling the update, and the step-1 ratio was small enough to reduce the influence of the later error.

The backward form in step 5 is the practical one: a learner can compute all targets in one pass over a batch of trajectories.

flowchart RL
  A["Actor data: states, actions, rewards, old policy mu"] --> B["Ratio pi over mu for each step"]
  B --> C["Truncate: rho and c capped at the levels"]
  C --> D["Temporal differences delta_t"]
  D --> E["Work backwards: v_s = V(x_s) + delta_s + gamma c_s (v_s+1 - V(x_s+1))"]
  E --> F["Regress V toward v_s; update policy with rho"]

The math

The definitions follow the paper's notation. A trajectory (xt,at,rt)(x_t, a_t, r_t) is generated by a behaviour policy μ\mu, and the learner evaluates a target policy π\pi.

Definition

Definition: V-trace target

For the nn-step V-trace target of V(xs)V(x_s),

vs=V(xs)+∑t=ss+n−1γt−s(∏i=st−1ci) δtVv_s = V(x_s) + \sum_{t=s}^{s+n-1} \gamma^{t-s}\Bigl(\prod_{i=s}^{t-1} c_i\Bigr)\,\delta_t V

where the temporal difference is

δtV=ρt(rt+γV(xt+1)−V(xt))\delta_t V = \rho_t\bigl(r_t + \gamma V(x_{t+1}) - V(x_t)\bigr)

and the truncated importance weights are

ρt=min⁡(ρˉ,π(at∣xt)μ(at∣xt)),ci=min⁡(cˉ,π(ai∣xi)μ(ai∣xi))\rho_t = \min\Bigl(\bar{\rho}, \frac{\pi(a_t \mid x_t)}{\mu(a_t \mid x_t)}\Bigr), \qquad c_i = \min\Bigl(\bar{c}, \frac{\pi(a_i \mid x_i)}{\mu(a_i \mid x_i)}\Bigr)

The empty product is 1 when s=ts = t. The levels satisfy ρˉ≥cˉ\bar{\rho} \geq \bar{c}.

Step 1 in symbols: the ratios and their truncation

The raw ratio at step tt is π(at∣xt)/μ(at∣xt)\pi(a_t \mid x_t) / \mu(a_t \mid x_t). The truncation caps it at ρˉ\bar{\rho} for ρt\rho_t and at cˉ\bar{c} for ctc_t. In the walkthrough, ρˉ=cˉ=1\bar{\rho} = \bar{c} = 1, so ρ0=1\rho_0 = 1 and ρ1=0.5\rho_1 = 0.5.

Step 2 in symbols: the temporal differences

δ0V=ρ0(r0+γV(x1)−V(x0))=1 (1+0.5⋅1.0−0.5)=1.0\delta_0 V = \rho_0\bigl(r_0 + \gamma V(x_1) - V(x_0)\bigr) = 1\,(1 + 0.5 \cdot 1.0 - 0.5) = 1.0

The same formula with t=1t = 1 gives δ1V=−0.5\delta_1 V = -0.5.

Step 3 in symbols: the backward recursion

The paper notes that the targets can be computed recursively:

vs=V(xs)+δsV+γ cs(vs+1−V(xs+1))v_s = V(x_s) + \delta_s V + \gamma\, c_s\bigl(v_{s+1} - V(x_{s+1})\bigr)

This is the form used in steps 4 and 5. Starting from the last state and moving back, each target needs only the next target and the local quantities at step ss.

Step 4 in symbols: what the target converges to

When the value function is represented exactly, the fixed point of the update is the value function VπρˉV^{\pi_{\bar{\rho}}} of a mixed policy

πρˉ(a∣x)=min⁡(ρˉ μ(a∣x), π(a∣x))∑bmin⁡(ρˉ μ(b∣x), π(b∣x))\pi_{\bar{\rho}}(a \mid x) = \frac{\min\bigl(\bar{\rho}\,\mu(a \mid x),\, \pi(a \mid x)\bigr)}{\sum_{b} \min\bigl(\bar{\rho}\,\mu(b \mid x),\, \pi(b \mid x)\bigr)}

This policy lies between the behaviour policy and the target policy. When ρˉ\bar{\rho} is infinite, it is π\pi itself, and as ρˉ\bar{\rho} approaches zero it is μ\mu. The paper also shows that cˉ\bar{c} does not change this fixed point. It only changes how fast the online algorithm approaches it.

Step 5 in symbols: the policy update

The policy is updated in the direction

ρs ∇ωlog⁡πω(as∣xs)(rs+γvs+1−Vθ(xs))\rho_s\,\nabla_\omega \log \pi_\omega(a_s \mid x_s)\bigl(r_s + \gamma v_{s+1} - V_\theta(x_s)\bigr)

so the same truncated ratio that controls the value target also weights the policy gradient.

Worked examples

Example
Example 1: one step, by hand

Take a single step with reward r=1r = 1, V(x0)=0V(x_0) = 0, V(x1)=2V(x_1) = 2, γ=0.9\gamma = 0.9, and ratio π/μ=0.5\pi / \mu = 0.5. Truncation level 1.

  1. Truncate: ρ0=min⁡(1,0.5)=0.5\rho_0 = \min(1, 0.5) = 0.5.
  2. Temporal difference: δ0=0.5 (1+0.9⋅2−0)=0.5⋅2.8=1.4\delta_0 = 0.5\,(1 + 0.9 \cdot 2 - 0) = 0.5 \cdot 2.8 = 1.4.
  3. The target for n=1n = 1 is v0=V(x0)+δ0=0+1.4=1.4v_0 = V(x_0) + \delta_0 = 0 + 1.4 = 1.4.
  4. Check: the target is the reward plus the discounted next value, 1+0.9⋅2=2.81 + 0.9 \cdot 2 = 2.8, scaled by the ratio 0.50.5 to give 1.41.4.

Interpretation: with a single step, V-trace is the ordinary one-step target, shrunk by how much the learner's policy disagrees with the one that acted.

Example
Example 2: the two-step trajectory

This is the walkthrough case: γ=0.5\gamma = 0.5, ρ0=c0=1\rho_0 = c_0 = 1, ρ1=c1=0.5\rho_1 = c_1 = 0.5, V(x0)=0.5V(x_0) = 0.5, V(x1)=1.0V(x_1) = 1.0, V(x2)=0V(x_2) = 0, r0=1r_0 = 1, r1=0r_1 = 0.

  1. δ0=1 (1+0.5⋅1.0−0.5)=1.0\delta_0 = 1\,(1 + 0.5 \cdot 1.0 - 0.5) = 1.0.
  2. δ1=0.5 (0+0.5⋅0−1.0)=−0.5\delta_1 = 0.5\,(0 + 0.5 \cdot 0 - 1.0) = -0.5.
  3. Backward: v1=V(x1)+δ1=1.0−0.5=0.5v_1 = V(x_1) + \delta_1 = 1.0 - 0.5 = 0.5.
  4. v0=V(x0)+δ0+γc0(v1−V(x1))=0.5+1.0+0.5⋅1⋅(−0.5)=1.25v_0 = V(x_0) + \delta_0 + \gamma c_0 (v_1 - V(x_1)) = 0.5 + 1.0 + 0.5 \cdot 1 \cdot (-0.5) = 1.25.
  5. Check the sum form: 0.5+1.0+0.5⋅1⋅(−0.5)=1.250.5 + 1.0 + 0.5 \cdot 1 \cdot (-0.5) = 1.25.

Interpretation: the uncorrected one-step estimate would have been r0+γV(x1)=1.5r_0 + \gamma V(x_1) = 1.5. The V-trace target is lower because the second step, where the new policy disagrees with the old one, contributes a negative correction.

Example
Example 3: a three-step trajectory from a lagging actor

This is an illustrative trajectory with made-up numbers. The learner's policy has moved far enough from the actor's that the ratios vary a lot. Use γ=0.9\gamma = 0.9 and truncation level 1. The rewards are r0=0r_0 = 0, r1=1r_1 = 1, r2=0r_2 = 0. The values are V(x0)=0.5V(x_0) = 0.5, V(x1)=0.8V(x_1) = 0.8, V(x2)=1.0V(x_2) = 1.0, V(x3)=0.2V(x_3) = 0.2. The ratios are 1.81.8, 0.40.4 and 1.21.2.

  1. Truncate: ρ=(1,0.4,1)\rho = (1, 0.4, 1) and c=(1,0.4,1)c = (1, 0.4, 1).
  2. δ0=1 (0+0.9⋅0.8−0.5)=0.72−0.5=0.22\delta_0 = 1\,(0 + 0.9 \cdot 0.8 - 0.5) = 0.72 - 0.5 = 0.22.
  3. δ1=0.4 (1+0.9⋅1.0−0.8)=0.4⋅1.1=0.44\delta_1 = 0.4\,(1 + 0.9 \cdot 1.0 - 0.8) = 0.4 \cdot 1.1 = 0.44.
  4. δ2=1 (0+0.9⋅0.2−1.0)=0.18−1.0=−0.82\delta_2 = 1\,(0 + 0.9 \cdot 0.2 - 1.0) = 0.18 - 1.0 = -0.82.
  5. Backward from the end. v2=V(x2)+δ2=1.0−0.82=0.18v_2 = V(x_2) + \delta_2 = 1.0 - 0.82 = 0.18.
  6. v1=V(x1)+δ1+γc1(v2−V(x2))=0.8+0.44+0.9⋅0.4⋅(0.18−1.0)=1.24−0.2952=0.9448v_1 = V(x_1) + \delta_1 + \gamma c_1 (v_2 - V(x_2)) = 0.8 + 0.44 + 0.9 \cdot 0.4 \cdot (0.18 - 1.0) = 1.24 - 0.2952 = 0.9448.
  7. v0=V(x0)+δ0+γc0(v1−V(x1))=0.5+0.22+0.9⋅1⋅0.1448=0.85032v_0 = V(x_0) + \delta_0 + \gamma c_0 (v_1 - V(x_1)) = 0.5 + 0.22 + 0.9 \cdot 1 \cdot 0.1448 = 0.85032.
  8. Check with the sum form: 0.5+0.22+0.9⋅1⋅0.44+0.81⋅1⋅0.4⋅(−0.82)=0.5+0.22+0.396−0.26568=0.850320.5 + 0.22 + 0.9 \cdot 1 \cdot 0.44 + 0.81 \cdot 1 \cdot 0.4 \cdot (-0.82) = 0.5 + 0.22 + 0.396 - 0.26568 = 0.85032.

Interpretation: the step-1 ratio of 0.40.4 cuts that step's influence on the target, so the large negative error at step 2 is discounted twice, once by γ\gamma and once by the small cc product.

Try it. Keep everything in Example 3 the same, except that the ratio at step 1 is 1.01.0 instead of 0.40.4 (so ρ1=c1=1\rho_1 = c_1 = 1). What is v0v_0?

Answer: δ1=1.0 (1+0.9⋅1.0−0.8)=1.1\delta_1 = 1.0\,(1 + 0.9 \cdot 1.0 - 0.8) = 1.1. Then v1=0.8+1.1+0.9⋅1⋅(−0.82)=1.162v_1 = 0.8 + 1.1 + 0.9 \cdot 1 \cdot (-0.82) = 1.162, and v0=0.5+0.22+0.9⋅(1.162−0.8)=1.0458v_0 = 0.5 + 0.22 + 0.9 \cdot (1.162 - 0.8) = 1.0458. The sum form agrees: 0.5+0.22+0.99−0.6642=1.04580.5 + 0.22 + 0.99 - 0.6642 = 1.0458, about 1.05.

Common mistakes and tradeoffs

It is tempting to think truncation only reduces variance. In fact the two levels do different jobs. The paper shows that ρˉ\bar{\rho} changes which policy the target evaluates, so a finite ρˉ\bar{\rho} introduces bias, while cˉ\bar{c} does not change the fixed point and only controls how fast the update converges.

It is tempting to think clipping the ratio at 1 is always correct. In fact the paper tried truncation levels 1, 10 and 100 on five DeepMind Lab tasks and found 1 worked best there. That is an empirical finding about those tasks, not a rule.

It is tempting to think V-trace is the same as Retrace. In fact Retrace, which the paper compares against, corrects Q-values and needs a learned action-value function. V-trace is built on the state-value function, which is what a typical actor-critic learns.

It is tempting to think a large ratio is always a good signal. In fact the ratio is truncated precisely because large ratios make the variance of the update explode, especially through the products of the cc weights over long trajectories.

When to use it. Use V-trace when data comes from behaviour that lags the learner, as in distributed actors, replay buffers, or any setting where the policy used to collect data is noticeably different from the current one.

When not to use it. When data is on-policy, the ratios are all 1 and V-trace reduces to the ordinary nn-step Bellman target. There is no need for the correction in that case.

Alternatives. Retrace corrects action-value estimates. Plain one-step importance sampling multiplies each advantage by its weight but has no traces, and with experience replay, which increases the lag, the paper found the gap to V-trace widened on four of five DeepMind Lab tasks.

History

Off-policy learning, where the data comes from a different policy than the one being improved, was studied well before deep reinforcement learning. The IMPALA paper cites earlier off-policy work by Precup and co-authors, published in 2000 and 2001.

The closest precursor is Retrace, introduced by Munos and co-authors in 2016 as an off-policy correction for multi-step reinforcement learning. It works with action values, and many actor-critic methods learn state values instead.

The IMPALA paper, published in 2018, combined a scalable actor-learner architecture with V-trace. It used the correction to train one agent on many tasks at once, and its ablation showed that the advantage over the simpler 1-step correction widened when experience replay increased the policy lag.

Recap

  • Distributed actors generate data with an old policy, so the learner's data is off-policy.
  • Each step is weighted by the ratio of the learner's policy to the actor's policy, truncated at a level so that the weight cannot explode.
  • The truncated temporal differences are summed backwards with discounting and the trace weights cc, giving a target for the value function.
  • The level ρˉ\bar{\rho} decides which policy the value function converges to, and cˉ\bar{c} decides how fast it converges.
  • The same truncated ratio also weights the policy gradient, so both learners use one correction.

Read next: IMPALA: Scalable Distributed Deep-RL with Importance Weighted Actor-Learner for the full architecture and the multi-task results.

Check yourself

QuestionIn one sentence, why does V-trace truncate the importance ratios?Show answer

Because the raw ratio π/μ\pi / \mu can be arbitrarily large when the learner's policy has moved far from the actor's, and an untruncated product of ratios along a trajectory makes the variance of the target explode. Truncation caps the weights so the targets stay stable.

QuestionA trajectory has one step with reward r=2r = 2, V(x0)=1V(x_0) = 1, V(x1)=3V(x_1) = 3, γ=0.5\gamma = 0.5, and ratio π/μ=0.4\pi / \mu = 0.4 with truncation level 1. What is the one-step V-trace target v0v_0?Show answer

Truncate: ρ0=0.4\rho_0 = 0.4. Then δ0=0.4 (2+0.5⋅3−1)=0.4⋅2.5=1.0\delta_0 = 0.4\,(2 + 0.5 \cdot 3 - 1) = 0.4 \cdot 2.5 = 1.0, and v0=V(x0)+δ0=1+1.0=2.0v_0 = V(x_0) + \delta_0 = 1 + 1.0 = 2.0.

QuestionThe paper says the bar-rho truncation changes the value function the learner converges to, but the bar-c truncation does not. Why would these two levels play such different roles?Show answer

The weight ρt\rho_t appears in the temporal difference δtV\delta_t V, and that term defines the fixed point of the update, so capping it changes the policy being evaluated. The weight cic_i appears only in the trace, which multiplies the corrections across time. The fixed point depends only on ρ\rho, so cc affects the contraction rate, which is the speed of convergence.

QuestionA team trains a single agent on many environments with replay buffers that hold old experience. Their value estimates drift and training becomes unstable. What should they check first?Show answer

They should check the truncation levels and the size of the importance ratios on the replayed data. Old experience is more off-policy, so ratios grow and the truncation becomes important. If the ratios are large and untruncated, or the levels are set very high, the variance can destabilise learning. Lowering the levels or checking the ratio distribution are the first steps.

Sources