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 , and the learner now has a newer policy . We will compute the V-trace target for the value of the first state. Use a discount , and truncation level 1 for both weights, which is the setting the paper found best in its experiments.
The trajectory has three states , rewards and , and current value estimates , , . 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 , and at step 1 it is .
-
Compute the importance ratios. At step 0, . At step 1, . Check: a ratio above 1 means the new policy likes the action more than the old one did.
-
Truncate the ratios. Cap each at the truncation level 1. This gives and . The same capped values serve as and 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.
-
Compute the temporal differences. Each step's error is . For step 0, . For step 1, . Check: the bracket for step 1 is , and .
-
Work backwards from the end. The last target is just the current estimate, . Because , the term that carries the later target back in step 5 vanishes here. Start at step 1: . Check: is the value of after one correction.
-
Carry the result back to the first state. . Check: the same number comes from the sum form, .
-
Read the result. The learner moves from toward the target . 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 is generated by a behaviour policy , and the learner evaluates a target policy .
Definition
For the -step V-trace target of ,
where the temporal difference is
and the truncated importance weights are
The empty product is 1 when . The levels satisfy .
Step 1 in symbols: the ratios and their truncation
The raw ratio at step is . The truncation caps it at for and at for . In the walkthrough, , so and .
Step 2 in symbols: the temporal differences
The same formula with gives .
Step 3 in symbols: the backward recursion
The paper notes that the targets can be computed recursively:
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 .
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 of a mixed policy
This policy lies between the behaviour policy and the target policy. When is infinite, it is itself, and as approaches zero it is . The paper also shows that 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
so the same truncated ratio that controls the value target also weights the policy gradient.
Worked examples
Take a single step with reward , , , , and ratio . Truncation level 1.
- Truncate: .
- Temporal difference: .
- The target for is .
- Check: the target is the reward plus the discounted next value, , scaled by the ratio to give .
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.
This is the walkthrough case: , , , , , , , .
- .
- .
- Backward: .
- .
- Check the sum form: .
Interpretation: the uncorrected one-step estimate would have been . The V-trace target is lower because the second step, where the new policy disagrees with the old one, contributes a negative correction.
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 and truncation level 1. The rewards are , , . The values are , , , . The ratios are , and .
- Truncate: and .
- .
- .
- .
- Backward from the end. .
- .
- .
- Check with the sum form: .
Interpretation: the step-1 ratio of cuts that step's influence on the target, so the large negative error at step 2 is discounted twice, once by and once by the small product.
Try it. Keep everything in Example 3 the same, except that the ratio at step 1 is instead of (so ). What is ?
Answer: . Then , and . The sum form agrees: , 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 changes which policy the target evaluates, so a finite introduces bias, while 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 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 -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 , giving a target for the value function.
- The level decides which policy the value function converges to, and 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 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 , , , , and ratio with truncation level 1. What is the one-step V-trace target ?Show answer
Truncate: . Then , and .
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 appears in the temporal difference , and that term defines the fixed point of the update, so capping it changes the policy being evaluated. The weight appears only in the trace, which multiplies the corrections across time. The fixed point depends only on , so 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
- Espeholt et al., IMPALA: Scalable Distributed Deep-RL with Importance Weighted Actor-Learner Architectures, 2018.
- Wikipedia, Importance sampling.