Simple Algorithm
Reinforcement Learning · Fixed Point · 26 min

Distributed Actor–Critic: A3C & IMPALA

Parallel actors, policy lag and V-trace corrections.

IMPALA's learner trains on experience generated by policies several updates out of date, at a reported 250,000 environment frames per second. That works because of a correction, V-trace, whose fixed point is not the value of the current policy but of a policy between it and the one that acted. This lesson follows distributed actor–critic from A3C's lock-free threads to decoupled actors and learners, proves that V-trace contracts and identifies its fixed point, and surveys how such systems scale.

What you’ll learn

  • Compare A3C's asynchronous updates, A2C's synchronous ones and IMPALA's decoupled actors and learner, and explain policy lag.
  • Write the V-trace target and policy-gradient update, and explain the roles of the truncation levels ρˉ\bar\rho and cˉ\bar c.
  • Prove that the one-step V-trace operator is a contraction with fixed point VπρˉV^{\pi_{\bar\rho}}, and state the general theorem.
  • Describe SEED RL, population-based training and PPO at scale, quoting throughput only as reported.

Asynchronous, synchronous, decoupled

A3C (Mnih et al., 2016) runs many actor-learner threads, each with its own environment and its own copy of the parameters. A thread acts for a few steps, computes an nn-step advantage gradient on its segment, and applies it to the shared parameters without locks, in the style of Hogwild! (Recht, Ré, Wright & Niu, 2011). Two kinds of staleness follow. A thread's gradient was computed at parameters that other threads have since changed, so it is applied at a different point from the one where it was computed; and its actions came from a slightly older policy than the one being updated. With short segments and a handful of threads on one machine both effects stay small, and asynchrony delivers its real benefit: cheap, decorrelated data.

A2C removes the asynchrony: actors step in lockstep and the learner makes one synchronous update from the batch. OpenAI's 2017 report on its baselines found no evidence that asynchrony's noise improves performance, and the batched update uses accelerators better. But it scales poorly, since every update waits for the slowest actor and the learner idles while actors act.

Decoupling removes the waiting. In IMPALA (Espeholt et al., 2018) actors never compute gradients. Each runs a copy of the policy, sends whole trajectories to a central learner, and fetches fresh parameters from time to time; the learner trains on batches of trajectories from many actors at once. Acting and learning proceed at their own speeds. The price is policy lag: the behavior policy bb that generated a trajectory can be several updates behind the learner's policy π\pi, so the data are off-policy, and an on-policy actor–critic update on them is biased.

ArchitectureWho computes gradientsDataMain cost
A3Cevery actor thread, applied asynchronouslyslightly off-policystale gradients; limited to one machine's threads
A2Cone learner, synchronous batcheson-policywaits for the slowest actor
IMPALAa central learner; actors only actoff-policy by the policy lagneeds an off-policy correction: V-trace
Check your understanding

IMPALA's actors run copies of the same network as the learner. Why are the learner's data off-policy anyway?

  1. Because actors explore with ε-greedy actions
  2. Because actors fetch parameters only from time to time, so a trajectory was generated by a policy that is several learner updates old
  3. Because rewards arrive with a delay
  4. Because actors use a different network architecture
Show the answer

B. Because actors fetch parameters only from time to time, so a trajectory was generated by a policy that is several learner updates old

Between an actor's parameter fetch and the moment the learner uses its trajectory, the learner keeps updating. That gap, the policy lag, grows with the number of actors and with network and queueing delays, and the behavior policy bb differs from the current π\pi by that many updates.

V-trace

Importance sampling could correct the lag, but products of ratios over nn steps have exploding variance (Off-Policy Monte Carlo & Importance Sampling). V-trace truncates them. Espeholt et al. write μ\mu for the behavior policy and rtr_t for the reward after action ata_t; here they are bb, since μ\mu is our start distribution, and Rt+1R_{t+1}. From the importance ratio π(At∣St)/b(At∣St)\pi(A_t\mid S_t)/b(A_t\mid S_t) define two truncated versions:

ρt=min⁡(ρˉ, π(At∣St)b(At∣St)),ct=min⁡(cˉ, π(At∣St)b(At∣St)),ρˉ≥cˉ\rho_t=\min\Big(\bar\rho,\ \frac{\pi(A_t\mid S_t)}{b(A_t\mid S_t)}\Big),\qquad c_t=\min\Big(\bar c,\ \frac{\pi(A_t\mid S_t)}{b(A_t\mid S_t)}\Big),\qquad\bar\rho\ge\bar c

Three properties.

  • On-policy, it is the nn-step return. If π=b\pi=b and cˉ≥1\bar c\ge1, every ρt\rho_t and ctc_t equals 1 and vsv_s telescopes to ∑t=ss+n−1γt−sRt+1+γnV(Ss+n)\sum_{t=s}^{s+n-1}\gamma^{t-s}R_{t+1}+\gamma^nV(S_{s+n}). One algorithm handles both on- and off-policy data.
  • ρˉ\bar\rho decides what is learned, cˉ\bar c how fast. The weights ρt\rho_t on the TD errors determine the fixed point, as the theorem below shows. The traces cic_i only control how far corrections propagate back, which affects the contraction speed and the variance but not the fixed point. Truncating them keeps the products of ratios bounded.
  • Relation to Retrace. Retrace (Munos, Stepleton, Harutyunyan & Bellemare, 2016) cuts traces at λmin⁡(1,π/b)\lambda\min(1,\pi/b) for action values and keeps QπQ^\pi as its fixed point (Off-Policy Traces: Tree Backup & Retrace). V-trace works with state values and pays for that simplicity with a fixed point that differs from VπV^\pi whenever ρˉ\bar\rho truncates.

Where V-trace converges, and how fast

Treat the expected V-trace update as an operator on value functions. The one-step case already shows both the contraction and the fixed point.

DerivationOne-step V-trace: contraction and fixed point
  1. (RV)(s)=V(s)+Eb[ρ0(R1+γV(S1)−V(s)) ∣ S0=s](\mathcal RV)(s)=V(s)+\E_b\big[\rho_0\big(R_1+\gamma V(S_1)-V(s)\big)\,\big|\,S_0=s\big]

    With S0=sS_0=s and A0∼b(⋅∣s)A_0\sim b(\cdot\mid s), define

  2. (RV1−RV2)(s)=(1−κ(s)) (V1−V2)(s)+γ Eb[ρ0 (V1−V2)(S1) ∣ S0=s](\mathcal RV_1-\mathcal RV_2)(s)=\big(1-\kappa(s)\big)\,(V_1-V_2)(s)+\gamma\,\E_b\big[\rho_0\,(V_1-V_2)(S_1)\,\big|\,S_0=s\big]

    For two value functions the rewards cancel. Write κ(s)=Eb[ρ0∣S0=s]=∑amin⁡(ρˉ b(a∣s),π(a∣s))\kappa(s)=\E_b[\rho_0\mid S_0=s]=\sum_a\min\big(\bar\rho\,b(a\mid s),\pi(a\mid s)\big), which is at most ∑aπ(a∣s)=1\sum_a\pi(a\mid s)=1:

  3. ∥RV1−RV2∥∞≤(1−(1−γ)β) ∥V1−V2∥∞\norm{\mathcal RV_1-\mathcal RV_2}_\infty\le\big(1-(1-\gamma)\beta\big)\,\norm{V_1-V_2}_\infty

    Both coefficients are nonnegative, and they add up to 1−(1−γ)κ(s)1-(1-\gamma)\kappa(s). So if κ(s)≥β>0\kappa(s)\ge\beta>0 in every state:

  4. Eb[ρ0 δ0∣S0=s]=κ(s)∑aπρˉ(a∣s)[r(s,a)+γ∑s′P(s′∣s,a)V(s′)−V(s)],πρˉ(a∣s)=min⁡(ρˉ b(a∣s), π(a∣s))κ(s)\E_b\big[\rho_0\,\delta_0\mid S_0=s\big]=\kappa(s)\sum_a\pi_{\bar\rho}(a\mid s)\Big[r(s,a)+\gamma\textstyle\sum_{s'}P(s'\mid s,a)V(s')-V(s)\Big],\qquad\pi_{\bar\rho}(a\mid s)=\dfrac{\min\big(\bar\rho\,b(a\mid s),\ \pi(a\mid s)\big)}{\kappa(s)}

    The fixed point. RV=V\mathcal RV=V exactly when the expected weighted TD error vanishes in every state. Since b(a∣s) ρ0=min⁡(ρˉ b(a∣s),π(a∣s))b(a\mid s)\,\rho_0=\min\big(\bar\rho\,b(a\mid s),\pi(a\mid s)\big) for A0=aA_0=a, that expectation is κ(s)\kappa(s) times a Bellman residual for a new policy:

  5. So the fixed point satisfies the Bellman equation of πρˉ\pi_{\bar\rho}: it is VπρˉV^{\pi_{\bar\rho}}, the value of a policy between bb and π\pi. ■\blacksquare

Predict before you look

Two actions, behavior policy b=(0.5,0.5)b=(0.5,0.5), target policy π=(0.9,0.1)\pi=(0.9,0.1) and ρˉ=1\bar\rho=1. What probability does πρˉ\pi_{\bar\rho} give the first action?

Show the answer

0.83

min⁡(ρˉ b,π)=(0.5, 0.1)\min(\bar\rho\,b,\pi)=(0.5,\,0.1), which normalizes to (56,16)≈(0.83,0.17)(\tfrac56,\tfrac16)\approx(0.83,0.17): between b=(0.5,0.5)b=(0.5,0.5) and π=(0.9,0.1)\pi=(0.9,0.1). Here κ=0.6\kappa=0.6, so the one-step contraction modulus is at most 1−0.6 (1−γ)1-0.6\,(1-\gamma), slower than the usual γ\gamma.

What ρˉ\bar\rho buys. As ρˉ→∞\bar\rho\to\infty, πρˉ→π\pi_{\bar\rho}\to\pi: the target is unbiased for VπV^\pi, but the weights are raw importance ratios and the variance can explode. As ρˉ→0\bar\rho\to0, πρˉ\pi_{\bar\rho} tends to bb and the critic learns the behavior policy's value. In IMPALA's analysis experiments the ratios were clipped at ρˉ=cˉ=1\bar\rho=\bar c=1, and among ρˉ∈{1,10,100}\bar\rho\in\{1,10,100\} the value 1 worked best. With small policy lag, π\pi and bb are close, πρˉ\pi_{\bar\rho} is close to both, and the bias is small.

Scaling further

Central inference. SEED RL (Espeholt, Marinier, Stanczyk, Wang & Michalski, 2020) moves the policy network off the actors too. Actors only step environments and send observations; a central learner on accelerators runs inference for all of them in large batches and trains on the resulting trajectories, with V-trace for actor–critic learning (and R2D2 for value-based learning). The paper reports training at millions of frames per second, and cost reductions of 40% to 80% for the experiments it considered.

Population-based training (Jaderberg et al., 2017) runs a population of agents in parallel, each with its own hyperparameters. Periodically, weak members copy the weights of stronger ones (exploit) and perturb their hyperparameters (explore). The result is a hyperparameter schedule found within a single training run, at the price of a whole population's compute. The original paper applied it to deep RL agents as well as to supervised learning and GANs.

PPO at scale. OpenAI Five (Berner et al., 2019) trained a PPO agent for Dota 2 continually for about ten months, learning from batches of roughly two million frames about every two seconds, and on April 13, 2019 it beat OG, the reigning world champions. Its architecture has IMPALA's shape: many rollout workers feeding central optimizers on GPUs. Large distributed PPO runs are also the backbone of RLHF pipelines for language models (RL from Human Feedback).

Key takeaways

  • A3C applies asynchronous, slightly stale gradients from many threads; A2C synchronizes; IMPALA decouples acting from learning, so its data are off-policy by the policy lag.
  • V-trace weights TD errors by truncated ratios ρt=min⁡(ρˉ,π/b)\rho_t=\min(\bar\rho,\pi/b) and traces by ci=min⁡(cˉ,π/b)c_i=\min(\bar c,\pi/b); on-policy it reduces to the nn-step return.
  • The V-trace operator contracts with modulus at most 1−(1−γ)β1-(1-\gamma)\beta and converges to VπρˉV^{\pi_{\bar\rho}} with πρˉ∝min⁡(ρˉ b,π)\pi_{\bar\rho}\propto\min(\bar\rho\,b,\pi): ρˉ\bar\rho sets what is learned, cˉ\bar c how fast.
  • Scaling continued with central inference (SEED RL), population-based hyperparameter schedules and very large PPO runs such as OpenAI Five; reported throughput gains trade against policy lag and sample efficiency.

Check yourself

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

Question 1

In V-trace, what happens to the fixed point as ρˉ→∞\bar\rho\to\infty, and at what cost?

  1. It becomes the behavior policy's value VbV^b, and the variance falls
  2. It becomes the target policy's value VπV^\pi, but the unbounded ratios can make the variance explode
  3. It stays the same for every ρˉ\bar\rho
  4. The operator stops being a contraction
Show the answer

B. It becomes the target policy's value VπV^\pi, but the unbounded ratios can make the variance explode

πρˉ∝min⁡(ρˉ b,π)\pi_{\bar\rho}\propto\min(\bar\rho\,b,\pi) tends to π\pi as ρˉ\bar\rho grows, so the target becomes unbiased for VπV^\pi. The weights ρt\rho_t are then plain importance ratios, which can be huge when bb rarely takes actions that π\pi likes. As ρˉ→0\bar\rho\to0 the fixed point tends to VbV^b instead.

Question 2

What does the trace truncation level cˉ\bar c affect?

  1. The fixed point of the V-trace operator
  2. The weight of the entropy bonus
  3. The speed of contraction and the variance, but not the fixed point, which depends on ρˉ\bar\rho alone
  4. Nothing at all
Show the answer

C. The speed of contraction and the variance, but not the fixed point, which depends on ρˉ\bar\rho alone

The traces cic_i multiply TD errors further along the segment, so they decide how far a correction propagates back in one update. The expected TD errors that define the fixed point carry the weights ρt\rho_t only.

Question 3

What is stale about an A3C thread's gradient when it is applied to the shared parameters?

  1. It was computed at parameters that other threads have since changed, from actions of a slightly older policy
  2. It ignores the critic
  3. It is computed from replayed experience
  4. Nothing: lock-free updates make every gradient current
Show the answer

A. It was computed at parameters that other threads have since changed, from actions of a slightly older policy

Without locks, other threads write to the parameters while a thread acts and computes its gradient, so the gradient is applied at a different point from where it was computed, and the segment's actions came from the policy as it was when the thread last copied the parameters. Short segments keep both effects small.

Question 4

If the data are on-policy (π=b\pi=b) and ρˉ≥cˉ≥1\bar\rho\ge\bar c\ge1, what is the V-trace target vsv_s for a segment of nn steps?

  1. Zero
  2. The one-step TD target
  3. The Monte Carlo return to the end of the episode
  4. The nn-step return ∑t=ss+n−1γt−sRt+1+γnV(Ss+n)\sum_{t=s}^{s+n-1}\gamma^{t-s}R_{t+1}+\gamma^nV(S_{s+n})
Show the answer

D. The nn-step return ∑t=ss+n−1γt−sRt+1+γnV(Ss+n)\sum_{t=s}^{s+n-1}\gamma^{t-s}R_{t+1}+\gamma^nV(S_{s+n})

All ratios equal 1, so every ρt\rho_t and ctc_t is 1, and the sum of discounted TD errors telescopes to the nn-step return. This is why one algorithm can run on fresh and stale data alike.

Further reading

  • V. Mnih, A. P. Badia, M. Mirza, A. Graves, T. Lillicrap, T. Harley, D. Silver & K. Kavukcuoglu, "Asynchronous methods for deep reinforcement learning," ICML (2016).
  • L. Espeholt, H. Soyer, R. Munos, K. Simonyan, V. Mnih, T. Ward, Y. Doron, V. Firoiu, T. Harley, I. Dunning, S. Legg & K. Kavukcuoglu, "IMPALA: Scalable distributed deep-RL with importance weighted actor-learner architectures," ICML (2018).
  • L. Espeholt, R. Marinier, P. Stanczyk, K. Wang & M. Michalski, "SEED RL: Scalable and efficient deep-RL with accelerated central inference," ICLR (2020).
  • M. Jaderberg et al., "Population based training of neural networks," arXiv:1711.09846 (2017).
  • C. Berner et al. (OpenAI), "Dota 2 with large scale deep reinforcement learning," arXiv:1912.06680 (2019).