Off-Policy Traces: Tree Backup & Retrace
Cutting traces safely: learning off-policy without exploding variance.
Learning about one policy from another's actions is easy for one step and hard for many. Every multi-step off-policy method must decide, at each later action of the behavior, how far to keep trusting the trajectory. Importance ratios keep everything unbiased and let the variance explode; tree backup trusts in proportion to the target policy and cuts too much; Watkins's Q(λ) stops at the first exploratory action. Retrace(λ) found a cut that is safe for every behavior and efficient when the two policies agree, and V-trace, its cousin inside IMPALA, deliberately moves the fixed point to keep the variance bounded. This lesson derives the family, proves its contraction, and states what is known about control.
What you’ll learn
- Write the importance-sampled multi-step correction for action values, and derive when its variance is infinite, with an exact threshold for ε-greedy behavior.
- State the general trace-coefficient operator and prove that it is a -contraction around whenever , with its exact contraction coefficient.
- Compare importance sampling, , tree backup, Retrace, and Watkins's and Peng's Q(λ) by safety and efficiency, and state Retrace's convergence theorem for control.
- Derive V-trace's fixed point and explain the different roles of its two truncation levels.
Importance-sampled traces and their variance
Notation: a behavior policy generates the data, the target policy is , , and . (Munos et al., whose framework this lesson follows, write for the behavior.) Every multi-step off-policy method for action values in this lesson moves by a correction of the form
a sum of expected TD errors weighted by products of trace coefficients . The first action needs no correction: it defines which entry is updated. Every later one does, and the choice of chooses the algorithm.
The unbiased choice is , the per-decision importance sampling of Precup, Sutton and Singh (2000): each ratio reweights the behavior's action to the target's, so in expectation the correction is the one an on-policy trajectory of would give. The cost is in the products. Suppose the ratios at successive steps are independent with and . Then the weight of the term steps ahead has second moment
and over long trajectories the correction has finite variance only if .
Let be greedy and ε-greedy over actions, and write for the probability that takes the greedy action, the same in every state. The ratio is on the greedy action and 0 otherwise, so the ratios are independent across steps, with
The second moments of the weights then form a geometric series with ratio , which converges only if
With and four actions, and the threshold is . A typical with is past it: the importance-sampled correction has infinite variance, although every single ratio is at most .
One operator, many traces
| Algorithm | Trace coefficient | Variance | Converges for any ? | Uses long traces near on-policy? |
|---|---|---|---|---|
| Per-decision importance sampling (Precup, Sutton & Singh, 2000) | can be infinite | yes | yes | |
| (Harutyunyan, Bellemare, Stepleton & Munos, 2016) | low | no: needs near | yes | |
| Tree backup, TB() (Precup, Sutton & Singh, 2000) | low | yes | no: shrinks traces even when | |
| Retrace() (Munos, Stepleton, Harutyunyan & Bellemare, 2016) | low: | yes | yes |
Let , and let act on functions of pairs by : one step of the behavior, discounted and weighted by the trace. Then , and since each expected TD error has conditional mean ,
Let . Because , , where . Collect terms:
Both factors are entrywise nonnegative: , and the entries of are , which are nonnegative precisely when . Each entry of is therefore a weighted sum of entries of with nonnegative weights. Since , the weights in each row add up to the corresponding entry of :
The weights are exactly , and gives . Two extremes: with , and is the one-step expected SARSA backup; on-policy with , , and in one application.
Which choice of trace coefficient can fail to make a contraction around for some behavior policy?
- Tree backup,
- ,
- Retrace,
- Per-decision importance sampling,
Show the answer
B. ,
The proof needs for every action. A constant violates it for actions the behavior takes much more often than the target would, where ; some weights in turn negative and the argument fails. Harutyunyan et al. (2016) proved that still contracts around when , with , so only for nearly on-policy data.
Control: Watkins’s Q(λ), Peng’s Q(λ) and Retrace
For control the target policy changes with . If is greedy, then is for the greedy action and 0 for the others, so Retrace's coefficient is on greedy actions and 0 on exploratory ones; tree backup's is the same. Both become Watkins's Q(λ) (Watkins, 1989), which keeps the trace while the behavior acts greedily and cuts it to zero at the first exploratory action. That is safe, and with frequent exploration it is short-sighted: under ε-greedy behavior with and four actions, each step is exploratory with probability , so a trace survives on average about steps. Retrace with increasingly greedy target policies, ε-greedy ones whose shrinks for instance, cuts less while still converging to .
Two consequences stand out. The behavior never has to become greedy: no GLIE assumption, which Munos et al. believed made this the first convergence result to for a λ-return algorithm without it. And taking the targets greedy gives Watkins's Q(λ), whose convergence had been open since 1989; the result covers its tabular, episodic version with updates made after each trajectory.
Peng's Q(λ) (Peng & Williams, 1996) makes the opposite choice: it never cuts. Its return bootstraps a fraction from at every step and carries the rest along the behavior's actual trajectory, . With a fixed exploratory behavior its fixed point is in general neither nor , so it is not safe in Munos et al.'s sense. Yet it uses every reward, and Kozuno et al. (2021) proved that it converges to an optimal policy if the behavior policy slowly tracks a greedy policy, in a way similar to conservative policy iteration, which had been conjectured but not proven; in their continuous-control experiments it often outperformed conservative algorithms. Non-conservative multi-step targets are common in deep RL for the same reason: n-step returns with no correction at all are part of Rainbow.
uses the uncorrected trace , and contracts around when , where . With and policies that differ by at most , how large may be?
Show the answer
0.1
. Even small disagreements between the policies allow only short uncorrected traces at long horizons, which is why corrections such as Retrace's matter.
V-trace: truncation that moves the fixed point
In IMPALA (Espeholt et al., 2018), many actors generate experience with slightly out-of-date copies of the policy, and a central learner corrects for the lag with V-trace, a state-value target built from truncated ratios. With ,
Unlike Retrace, V-trace also truncates the ratio on the TD error itself. That changes what it converges to.
Take one step (). A fixed point must make the expected correction vanish in every state; write :
Move inside the minimum, , and normalize the weights into a policy:
This is the Bellman equation of , so the fixed point is : the value of a policy between and . It equals when is at least every ratio (nothing is truncated) and approaches the value of restricted to 's support as . For -step V-trace with , Espeholt et al. show a contraction with the same fixed point: affects only how fast it is reached.
So V-trace makes a deliberate trade: bounded ratios, and therefore bounded variance under policy lag, in exchange for evaluating a slightly different policy than . When actors lag only a little, stays near 1, little is truncated, and the bias is small. Distributed Actor–Critic: A3C & IMPALA shows how the V-trace targets drive the actor and critic updates.
Key takeaways
- Multi-step off-policy corrections are sums of expected TD errors weighted by products of trace coefficients ; the choice of is the choice of algorithm.
- Importance-sampled traces () are unbiased, but their variance is finite only if : with a greedy target and ε-greedy behavior, only if .
- Any makes a contraction around with modulus ; Retrace's is safe, low-variance and keeps full traces on-policy.
- With greedy targets, Retrace and tree backup become Watkins's Q(λ); Retrace with increasingly greedy targets converges to for arbitrary behavior, which also proves Watkins's Q(λ) convergent. Peng's Q(λ) never cuts, is biased for fixed behavior, and converges when the behavior slowly tracks the greedy policy.
- V-trace truncates the ratio on each TD error too, which moves its fixed point to with : bounded variance under policy lag, at the price of a small bias.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
The behavior is ε-greedy with over four actions and the target policy is greedy. For which values of does the importance-sampled multi-step correction have finite variance over long trajectories?
- For every
- Only for
- For
- For no value of
Show the answer
C. For
The ratio is with probability and 0 otherwise, so , and the squared weights grow like . They are summable only if .
For a safe trace choice, the contraction coefficient is . What does it equal when the traces are cut at once (), and when the data are on-policy with ?
- and 0: a one-step backup, and a single application landing exactly on
- 0 and
- in both cases
- 1 and 0
Show the answer
A. and 0: a one-step backup, and a single application landing exactly on
With only the term survives, and : the one-step expected SARSA backup. With and , and : the full on-policy return gives in one application. Longer surviving traces mean faster contraction, which is why cutting them has a cost.
V-trace is run with on data from a behavior that lags behind the target . What does it converge to?
- , because truncation only reduces variance
- , the behavior's value
- , the value of the policy proportional to , which lies between and
- It does not converge, because truncated ratios are biased
Show the answer
C. , the value of the policy proportional to , which lies between and
Truncating the ratio on the TD error reweights actions by , and the expected correction vanishes at the value of the normalized policy . With it is proportional to . The truncation of the trace coefficients changes only the speed.
On perfectly on-policy data (, a stochastic policy), how do the traces of tree backup and Retrace compare?
- Both keep
- Both cut to
- Retrace cuts more than tree backup
- Retrace keeps , while tree backup still multiplies by at every step
Show the answer
D. Retrace keeps , while tree backup still multiplies by at every step
On-policy, and Retrace's : no needless cutting. Tree backup's shrinks the trace whatever the behavior did, so it gives up multi-step information even when there is nothing to correct.
Further reading
- D. Precup, R. S. Sutton & S. Singh, "Eligibility traces for off-policy policy evaluation," Proceedings of the 17th International Conference on Machine Learning, 759–766 (2000).
- R. Munos, T. Stepleton, A. Harutyunyan & M. G. Bellemare, "Safe and efficient off-policy reinforcement learning," Advances in Neural Information Processing Systems 29 (2016).
- A. Harutyunyan, M. G. Bellemare, T. Stepleton & R. Munos, "Q(λ) with off-policy corrections," Algorithmic Learning Theory (ALT) (2016).
- L. Espeholt et al., "IMPALA: Scalable distributed deep-RL with importance weighted actor-learner architectures," Proceedings of the 35th International Conference on Machine Learning (2018).
- T. Kozuno, Y. Tang, M. Rowland, R. Munos, S. Kapturowski, W. Dabney, M. Valko & D. Abel, "Revisiting Peng's Q(λ) for modern reinforcement learning," Proceedings of the 38th International Conference on Machine Learning, 5794–5804 (2021).