Simple Algorithm
Reinforcement Learning · Bootstrapping · 24 min

The Deadly Triad

Function approximation, bootstrapping and off-policy data: why the three together can diverge.

In Baird's counterexample, in Sutton and Barto's seven-state version, every reward is zero and the features can represent the true values exactly, yet linear TD sends its weights to infinity, for every step size, even with exact expected updates. Nothing is wrong with the problem. The trouble is a combination of three ingredients that almost every deep RL agent uses. This lesson names them, works the smallest divergence by hand, shows why on-policy updates are safe and off-policy ones are not, and surveys how deep RL lives with the danger.

What you’ll learn

  • Define function approximation, bootstrapping and off-policy training, and explain why each pair of them is safe while all three together can diverge.
  • Compute, for a one-weight example, exactly how off-policy the data must be for semi-gradient TD to diverge.
  • Explain divergence and stability through the eigenvalues of the expected update matrix, and why the on-policy distribution guarantees stability.
  • Describe the mitigations used in practice (target networks, replay, multi-step returns, double Q-learning, gradient and emphatic TD) and what experiments show about divergence in deep RL.

Three ingredients, any two of which are safe

Sutton and Barto (2018, §11.3) describe the deadly triad: instability and divergence threaten whenever a method combines

  1. Function approximation: a parameterized v^(s,w)\hat v(s,\mathbf w) or q^(s,a,w)\hat q(s,a,\mathbf w) with far fewer weights than states, so that updating one state moves others;
  2. Bootstrapping: update targets that contain current estimates, as in TD, dynamic programming and Q-learning, rather than complete returns;
  3. Off-policy training: updates distributed differently from the state–action distribution of the policy being evaluated, as when Q-learning learns the greedy policy from ε\varepsilon-greedy data, or a replay buffer serves transitions from old policies.
IngredientsExampleBehavior
Approximation + bootstrappingLinear TD(0) evaluating the policy that generates the dataConverges to the TD fixed point (Tsitsiklis & Van Roy, 1997)
Approximation + off-policyGradient Monte Carlo with importance-sampling ratiosStochastic gradient descent on a fixed objective: stable, though the variance can be enormous
Bootstrapping + off-policyTabular Q-learningConverges to Q⋆Q^\star (Watkins & Dayan, 1992)
All threeOff-policy linear TD; Q-learning with linear or neural features; DQNCan diverge
"Can" matters: DQN combines all three and usually works. The triad is a danger with no general guarantee against it, not a certainty of failure. "Safe" in the first row means linear features: with a nonlinear approximator, TD can diverge even on-policy (Divergence: Baird’s Counterexample).

Giving up an ingredient is expensive. Approximation is unavoidable at scale. Bootstrapping lets an agent learn online, before an episode ends, from targets with far less variance than full returns. Off-policy learning is what lets an agent learn the greedy policy while exploring, reuse old experience from a replay buffer, learn from logged data or demonstrations, and learn many value functions in parallel from one stream of experience. The practical question is not how to avoid the triad but how to survive it.

The smallest divergence, worked by hand

Take two states with estimates tied by one weight: v^(A)=w\hat v(A)=w and v^(B)=2w\hat v(B)=2w (features 1 and 2). In AA, the action solid moves to BB and dashed returns to AA; from BB the episode ends. Every reward is 0, so the true values are 0 and w=0w=0 is exact. The target policy always takes solid. The behavior policy takes solid with probability qq and dashed otherwise, so updates use the importance ratio ρ=π(a∣A)/b(a∣A)\rho=\pi(a\mid A)/b(a\mid A), equal to 1/q1/q for solid and 00 for dashed.

DerivationWhen does off-policy semi-gradient TD(0) diverge here?
  1. Eb[ρ δ x∣A]=q⋅1q (0+γ⋅2w−w)⋅1+(1−q)⋅0=(2γ−1) w\E_b\big[\rho\,\delta\,x\mid A\big]=q\cdot\frac1q\,(0+\gamma\cdot2w-w)\cdot1+(1-q)\cdot0=(2\gamma-1)\,w

    At AA, the expected update per visit averages over the behavior's action. The ratio turns it into the target policy's update, the move toward the bootstrapped target γ⋅2w\gamma\cdot2w:

  2. δ x=(0−2w)⋅2=−4w\delta\,x=(0-2w)\cdot2=-4w

    At BB the episode ends, so the target is 0 and the feature is 2:

  3. E[Δw]=α w(2γ−1q−4)\E[\Delta w]=\alpha\,w\Big(\frac{2\gamma-1}{q}-4\Big)

    Each episode visits AA a geometric number of times with mean 1/q1/q, then BB once. The expected change of ww per episode is therefore

  4. divergence  ⟺  q<2γ−14,e.g. q<0.245 at γ=0.99\text{divergence}\iff q<\frac{2\gamma-1}{4},\qquad\text{e.g. }q<0.245\ \text{at}\ \gamma=0.99

    The weight grows geometrically, for every step size α>0\alpha>0, exactly when the bracket is positive. On-policy (q=1q=1) the bracket is 2γ−5<02\gamma-5<0 for every γ<1\gamma<1: always stable.

Predict before you look

With γ=0.9\gamma=0.9, below what probability qq of choosing solid does the weight diverge?

Show the answer

0.2

(2⋅0.9−1)/4=0.8/4=0.2(2\cdot0.9-1)/4=0.8/4=0.2. If the behavior takes solid less than 20% of the time, AA's update, which pushes ww up toward the inflated target 1.8w1.8w, happens more than five times per update of BB, which pulls ww down, and the push wins. Sutton and Barto's fragment (§11.2) is the limit q→0q\to0, where BB is never corrected and any γ>12\gamma>\tfrac12 diverges.

Baird’s counterexample

The fragment above needs a behavior that avoids BB. Baird's counterexample (Baird, 1995; here in Sutton & Barto's seven-state version) removes every such excuse. Six upper states have v^(si)=2wi+w8\hat v(s_i)=2w_i+w_8 and the seventh has v^(s7)=w7+2w8\hat v(s_7)=w_7+2w_8. From every state, dashed jumps to one of the six upper states at random and solid goes to s7s_7. The behavior policy takes dashed with probability 6/76/7, so its next state is uniform over all seven and every state is visited equally often. The target policy always takes solid. All rewards are 0 and γ=0.99\gamma=0.99, so every true value is 0, which w=0\mathbf w=\mathbf 0 represents exactly, and the feature vectors are linearly independent.

Because semi-gradient DP diverges, the problem cannot be noise, a step size that is too large, or bad luck: it is in the average update. For linear TD, that average is w←w+α(b−Aw)\mathbf w\leftarrow\mathbf w+\alpha(\mathbf b-\mathbf A\mathbf w), and everything depends on the matrix A\mathbf A.

Why on-policy updates are safe

With states updated according to a distribution dd (on the diagonal of D\mathbf D) and the target policy's transition matrix PπP_\pi, the expected semi-gradient update has key matrix

A=X⊤D (I−γPπ) X.\mathbf A=\mathbf X^\top\mathbf D\,(\mathbf I-\gamma P_\pi)\,\mathbf X.

If an eigenvalue λ\lambda of A\mathbf A has negative real part, then ∣1−αλ∣>1\abs{1-\alpha\lambda}>1 for every α>0\alpha>0, and the mean iteration w←(I−αA)w\mathbf w\leftarrow(\mathbf I-\alpha\mathbf A)\mathbf w diverges along that eigenvector, however small the step. If every eigenvalue has positive real part, small steps converge. A sufficient condition is that A\mathbf A be positive definite.

On-policy, dd is the stationary distribution of PπP_\pi, and then D(I−γPπ)\mathbf D(\mathbf I-\gamma P_\pi) has positive diagonal entries, nonpositive off-diagonal entries, positive row sums, and column sums d⊤(I−γPπ)=(1−γ) d⊤>0d^\top(\mathbf I-\gamma P_\pi)=(1-\gamma)\,d^\top>0. A matrix with that sign pattern and positive row and column sums is positive definite, and so is A\mathbf A for independent features (Sutton & Barto, §9.4). Off-policy, dd is the behavior's distribution, the column sums become d⊤−γd⊤Pπd^\top-\gamma d^\top P_\pi, and they can be negative wherever the target policy funnels more probability into a state than the behavior gives it. In Baird's problem the target policy sends all of its flow into s7s_7, which the behavior visits only 1/71/7 of the time: the column sum there is 17−0.99<0\tfrac17-0.99<0.

Check your understanding

In the one-weight example, take γ=0.99\gamma=0.99 and let the behavior choose solid with probability q=0.5q=0.5. What happens to the expected weight under off-policy semi-gradient TD(0)?

  1. It diverges for every step size, because the data are off-policy
  2. It converges to 0 for small enough step sizes, because (2γ−1)/q=1.96<4(2\gamma-1)/q=1.96<4
  3. It converges only if the initial weight is negative
  4. It oscillates forever without converging or diverging
Show the answer

B. It converges to 0 for small enough step sizes, because (2γ−1)/q=1.96<4(2\gamma-1)/q=1.96<4

The per-episode coefficient is (2⋅0.99−1)/0.5−4=1.96−4=−2.04<0(2\cdot0.99-1)/0.5-4=1.96-4=-2.04<0, so the mean iteration contracts for α<2/2.04≈0.98\alpha<2/2.04\approx0.98. Off-policy data make divergence possible; they diverge only when the mismatch is large enough, here when q<0.245q<0.245.

The repair suggested by this analysis is to correct the distribution of updates, not the targets. Sutton and Barto note that changing only the distribution of the DP sweeps in Baird's problem, from uniform to on-policy, guarantees convergence to a solution within the bound of their equation (9.14). Emphatic TD, in Stable Off-Policy Learning: Gradient TD & Emphatic TD, does this reweighting from off-policy data.

Living with the triad in deep RL

MitigationWhat it changesCaveat
Target networkBootstraps from a frozen copy, so each phase is a regression toward fixed targetsTurns TD into fitted Q-iteration, which can itself diverge (Tsitsiklis & Van Roy, 1996)
Experience replayDecorrelates updates and reuses dataOld transitions make training more off-policy; strong prioritization more so
Multi-step returnsPut weight γn\gamma^n instead of γ\gamma on the bootstrapped estimateOff-policy nn-step targets need corrections or tolerate some bias
Double Q-learningSelects and evaluates the max with different estimates, reducing overestimationReduces a feedback loop; does not remove the triad
Gradient TD, emphatic TDTrue gradient descent on the projected Bellman error, or reweighted updates with a positive definite key matrixProved for linear features; extra parameters or high variance
On-policy learningDrops the third ingredientGives up replay and learning from other policies' data

How dangerous is the triad in practice? van Hasselt et al. (2018) trained hundreds of DQN variants on Atari games, with rewards clipped so that no true action value can exceed 1/(1−γ)=1001/(1-\gamma)=100, and counted soft divergence, estimates beyond that bound. Bootstrapping from the online network (plain Q-learning) soft-diverged in 61% of runs, from a target network in 14%, with double Q-learning in 10%, and with "inverse" double Q-learning (the target network picks the action, but the online network being trained evaluates it) in 33%. No run ever produced unbounded values. Longer multi-step returns reduced soft divergence, stronger prioritization of replay increased it, and larger networks increased it except with double Q-learning. Soft divergence went with poor control performance, and values that grew explosively early in training often came back down to plausible magnitudes.

Key takeaways

  • The deadly triad is function approximation plus bootstrapping plus off-policy training; any two are safe, all three can diverge, and DQN-style agents use all three.
  • In a one-weight example, off-policy semi-gradient TD diverges exactly when the behavior takes the target action with probability below (2γ−1)/4(2\gamma-1)/4; on-policy it never does.
  • Baird's counterexample diverges for every step size, even with exact expected sweeps: the expected update matrix has eigenvalues with negative real part.
  • On-policy, the stationary distribution makes the key matrix positive definite; off-policy, the target policy can funnel more flow into a state than the behavior visits it.
  • In deep RL, target networks, double Q-learning and multi-step returns reduce soft divergence, prioritization increases it, and unbounded divergence was not observed (van Hasselt et al., 2018).

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Which of these agents has all three ingredients of the deadly triad?

  1. Semi-gradient SARSA with tile coding on mountain car, learning about the ε\varepsilon-greedy policy it follows
  2. Tabular Q-learning trained on a fixed log of a human's games
  3. A neural-network critic regressed on the complete returns of the policy that collected them
  4. Linear Q-learning trained on transitions from a replay buffer
Show the answer

D. Linear Q-learning trained on transitions from a replay buffer

Linear features approximate, the target r+γmax⁡a′q^(s′,a′)r+\gamma\max_{a'}\hat q(s',a') bootstraps, and the max makes it learn the greedy policy from replayed ε\varepsilon-greedy data, which is off-policy. The SARSA agent learns about the policy it follows, the tabular learner does not generalize, and the critic on complete returns does not bootstrap.

Question 2

Semi-gradient DP, which updates every state with exact expected targets, also diverges on Baird's counterexample. What does that establish?

  1. The divergence is caused by the variance of importance-sampling ratios
  2. The step size was too large
  3. The instability is in the expected update itself, so no reduction of noise or step size can fix it
  4. Dynamic programming cannot be combined with function approximation at all
Show the answer

C. The instability is in the expected update itself, so no reduction of noise or step size can fix it

With no sampling and no asynchrony, only the mean dynamics w←(I−αA)w\mathbf w\leftarrow(\mathbf I-\alpha\mathbf A)\mathbf w remain, and A\mathbf A has eigenvalues with negative real part, so every α>0\alpha>0 diverges. The cure must change A\mathbf A: the distribution of updates (on-policy, emphatic) or the update rule (gradient TD).

Question 3

In van Hasselt et al.'s (2018) study of DQN variants, which change was associated with more soft divergence?

  1. Using a target network
  2. Stronger prioritization of the replay distribution
  3. Longer multi-step returns
  4. Double Q-learning
Show the answer

B. Stronger prioritization of the replay distribution

Prioritized replay samples transitions far from the current policy's own distribution, a stronger off-policy mismatch, and soft divergence increased with it. Target networks, double Q-learning and longer multi-step returns all reduced it.

Question 4

In the one-weight example (features 1 and 2, the target policy always takes solid), which behavior makes semi-gradient TD diverge at γ=0.99\gamma=0.99?

  1. Taking solid with probability 0.5
  2. Taking solid with probability 0.3
  3. Taking solid with probability 0.2
  4. Taking solid with probability 1 (on-policy)
Show the answer

C. Taking solid with probability 0.2

Divergence needs q<(2γ−1)/4=0.98/4=0.245q<(2\gamma-1)/4=0.98/4=0.245. Only q=0.2q=0.2 is below the threshold; there AA's inflating update runs five times per correcting update of BB, and 0.98/0.2=4.9>40.98/0.2=4.9>4.

Go deeper

Further reading

  • R. S. Sutton & A. G. Barto, Reinforcement Learning: An Introduction, ch. 9 and 11 (MIT Press, 2nd ed., 2018).
  • L. Baird, "Residual algorithms: Reinforcement learning with function approximation", ICML (1995).
  • J. N. Tsitsiklis & B. Van Roy, "An analysis of temporal-difference learning with function approximation", IEEE Transactions on Automatic Control 42(5) (1997).
  • H. van Hasselt, Y. Doron, F. Strub, M. Hessel, N. Sonnerat & J. Modayil, "Deep reinforcement learning and the deadly triad", arXiv:1812.02648 (2018).