Search

Search papers and lessons

Dota 2 with Large Scale Deep Reinforcement Learning

OpenAI, Christopher Berner, Greg Brockman et al. · 2019

OpenAI Five (2019) trained one large LSTM policy by self-play reinforcement learning for ten months, and it beat the Dota 2 world champions in a best-of-three match.

On this page

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

TL;DR

OpenAI Five is a reinforcement-learning agent that plays Dota 2, a five-versus-five team game with long matches, hidden information and a huge number of possible actions. It learns by playing against copies of itself, using a large recurrent network trained with a standard policy-gradient method on very large batches of experience. Trained for ten months, it defeated the reigning world champions, Team OG, two games to none in April 2019, and it won 99.4 percent of its games against human players in a public arena. The paper's main message is that existing reinforcement-learning methods work at this scale when the training system is engineered carefully, and that long training can be kept alive while the game and the model keep changing.

Builds on: Proximal Policy Optimization (PPO), Generalized Advantage Estimation (GAE), Long Short-Term Memory, Self-Play · Leads to: later large-scale game-playing agents, such as AlphaStar, which the paper discusses as concurrent work in section 5

Why it mattered

Chess and Go were the classic milestones for game AI. Dota 2 adds the features of the real world that those games lack: continuous time, partial observation, teamwork, and rules that change with each game patch. The paper's authors say these challenges will matter more as AI systems tackle harder tasks.

The result showed that a reinforcement-learning system could reach the top of a major esport, where the best human teams train for years. The training recipe, self-play with a shared policy and a distributed rollout system, is the part another team can reuse. The paper's technique for keeping one model training through many changes to the environment, called surgery, is a practical contribution for any long project where the environment itself evolves.

The problem

Dota 2 is hard for four reasons. Section 2 of the paper lists the first three, and the introduction and section 3.3 describe the fourth.

  • Long horizons. The game runs at 30 frames per second for about 45 minutes. OpenAI Five chooses an action every fourth frame, so an episode has roughly 20,000 decisions. Chess lasts about 80 moves and Go about 150.
  • Partial observation. Each team sees only the area near its units and buildings. The agent has to infer what the opponent is doing from incomplete information.
  • Huge action and observation spaces. The agent receives about 16,000 values per step, and it chooses among 8,000 to 80,000 actions depending on the hero. Chess has a branching factor of about 35, and Go about 250.
  • Changing rules. The game is patched regularly. A model trained on one version can break when a hero or item changes, so the team needed a way to keep training without starting again.

The authors simplified the first and third problems in two ways: the agent could play 17 of the 117 heroes, and it could not use the items that let a player control several units at once. The agent also read a structured list of game values rather than pixels.

How it works

The system has four kinds of machine. A rollout is one game played out with the current policy, which produces a trace of observations, actions and rewards. Rollout machines run the game engine on CPUs. Forward-pass GPUs compute the agent's actions for those games. Optimizer GPUs compute gradient updates from the collected experience. A controller stores parameter versions and training metadata. Each rollout sends its experience to the optimizers, and the optimizers publish new parameters that the forward-pass GPUs pick up.

flowchart LR
  R["Rollouts: run Dota 2 on CPUs"] -->|observations| F["Forward-pass GPUs: sample actions"]
  F -->|actions| R
  R -->|experience batches| O["Optimizer GPUs: gradient step"]
  O -->|new parameter version| C["Controller: stores versions"]
  C -->|latest parameters| F

Here is one trace of the loop, with round numbers to show the order of events.

  1. Observe. The game engine produces a snapshot of what one hero could see. The agent's network reads it as a vector of numbers.
  2. Act. The LSTM updates its memory and outputs a probability for each action. The agent samples one action, say "move to point X", and sends it to the game. Check: the action is drawn from the output distribution, not picked by maximum, so the agent keeps trying alternatives.
  3. Wait for four frames. The game advances four frames, one timestep at 30 frames per second divided by 4, which is 7.5 timesteps per second of game time. Check: 45 minutes times 60 seconds times 7.5 gives 20,250 steps, close to the paper's 20,000.
  4. Record. Each step stores the observation, the action, the reward and the value estimate. The reward mixes the win signal with smaller signals such as deaths and resources, and each hero's reward has the average of the enemies' rewards subtracted, so that the rewards of the two teams cancel out in a zero-sum game.
  5. Ship the data. Rollouts send their experience every 256 steps, which is 34 seconds of game play. Check: 256 divided by 7.5 is about 34, as the paper states.
  6. Learn. Optimizers sample minibatches of 16-step sequences from their buffers and compute the policy-gradient update. The gradients from all optimizer GPUs are averaged before the parameters change. Check: the averaging is what makes the effective batch size the per-GPU batch times the number of GPUs.
  7. Publish and repeat. Every 32 gradient steps the optimizers publish a new parameter version. Forward-pass GPUs pull it, and the cycle starts again. Most games are played against the latest policy, 80 percent, and the rest against older policies, 20 percent, so the agent does not forget earlier strategies.

The same network controls all five heroes on a team. Each copy has its own hidden state and receives an extra input that says which hero it controls. The observations are almost identical for the five copies because team members see the same information.

The math

Policy and value

The policy πθ(a∣o)\pi_\theta(a \mid o) gives a probability for each action aa given the observation history oo, with parameters θ\theta. The network has about 159 million parameters, and a single LSTM with 4096 units accounts for 84 percent of them. A second output head estimates the value V(o)V(o), the expected future reward from the current state.

The policy update

The policy is trained with Proximal Policy Optimization. Write rt(θ)r_t(\theta) for the ratio of the new action probability to the old one at step tt, and A^t\hat{A}_t for the estimated advantage, which says how much better the action was than average. PPO maximises

LCLIP(θ)=Et[min⁡(rt(θ) A^t,  clip(rt(θ),1−ϵ,1+ϵ) A^t)],L^{\mathrm{CLIP}}(\theta) = \mathbb{E}_t\left[ \min\left( r_t(\theta)\, \hat{A}_t, \; \mathrm{clip}\bigl(r_t(\theta), 1-\epsilon, 1+\epsilon\bigr)\, \hat{A}_t \right) \right],

where ϵ\epsilon is a small constant. The clip stops one batch from moving a probability too far, which is what allows large batches to be used safely.

Advantage estimation

Generalized Advantage Estimation builds the advantage from one-step errors δt=rt+γV(ot+1)−V(ot)\delta_t = r_t + \gamma V(o_{t+1}) - V(o_t), where γ\gamma is the discount factor. It weights them with λ\lambda:

A^t=∑l≥0(γλ)l δt+l.\hat{A}_t = \sum_{l \ge 0} (\gamma \lambda)^l \, \delta_{t+l}.

The paper uses λ=0.95\lambda = 0.95. Since 1/λ=201/\lambda = 20, the advantage averages over roughly twenty steps, and the paper notes that cutting the window to 256 steps costs little. Smaller λ\lambda trades more bias for less variance.

Batch size in the learning step

Each optimizer GPU uses 120 samples of 16 timesteps, which is 120×16=1,920120 \times 16 = 1{,}920 timesteps. At the peak of 1,536 GPUs the total is

1,920×1,536=2,949,1201{,}920 \times 1{,}536 = 2{,}949{,}120

timesteps per update, each with five hero replicas. The paper's batch sizes are 50 to 150 times those of AlphaGo.

Gradient clipping

Adam Optimizer scales each gradient by the running estimate of its second moment, vv. The paper also clips each parameter's gradient to lie within ±5v\pm 5\sqrt{v}, so that a single unusual batch cannot produce a very large step.

Surgery

When the environment changes, the paper keeps the old function where it can. If the new model π^θ^\hat{\pi}_{\hat{\theta}} should behave exactly like the old model πθ\pi_\theta on every observation, the requirement is

∀o    π^θ^(o)=πθ(o).\forall o \;\; \hat{\pi}_{\hat{\theta}}(o) = \pi_\theta(o).

This is a function-preserving transformation, the idea behind Net2Net: change a network's shape without changing the function it computes. When a change makes exact preservation impossible, the tools preserve it approximately. The paper performed over twenty surgeries in ten months.

Results

The main results come from play against people and from a comparison with a training run that never changed the environment.

Human matches. On April 13, 2019, OpenAI Five beat OG two games to none. In the public arena from April 18 to 21, the agent played 7,257 games against 3,193 teams and won 99.4 percent. The paper notes that many human players abandoned losing games, and that abandoned games count as wins for the agent. Of the wins, 3,140 out of 7,215 were abandoned games, and 29 teams beat the agent in total for 42 games lost. The win rate is therefore partly a measure of human behaviour, and the paper says so.

Reaction time. The agent reacts to a game event in 217 milliseconds on average, and the paper cites typical human visual reaction times near 250 milliseconds. Its reaction time does not change with game state, which is a fact about the machine rather than about skill.

TrueSkill during training. The paper rates each checkpoint against a pool of fixed reference agents with TrueSkill, a Bayesian rating system that works like a skill score (similar in spirit to Elo). A difference of about 8.3 TrueSkill points corresponds to an 80 percent win rate between two agents. The rating rose steeply early on, and the authors attribute part of an inflection near 600 PFLOPs/s-days to a new action (buyback) and a game version upgrade.

Rerun. To test whether surgery wasted compute, the team trained a second agent from scratch on the final environment. It took 2 months and 150±5150 \pm 5 PFlops/s-days of compute, against 770±50770 \pm 50 for the whole project. Rerun reached a 98 percent win rate against the final OpenAI Five. The paper estimates that restarting after each of the twenty surgeries would have taken 40 months instead of 10.

Limits. The paper is candid about several of them.

  • Surgery did not give the same final quality as training from scratch. The continued model plateaued at a weaker level, and the authors leave this as future work.
  • The agent played 17 of 117 heroes and could not use the multi-unit items. The paper treats the hero pool as an experimental variable, not a settled result.
  • Several parts of the game were scripted rather than learned, including item purchase order and the courier. The authors believe the agent could do better without this, but they did not test it before reaching superhuman play.
  • The agent saw semantic game data rather than pixels, which removes the vision problem. It also sees all of its observations at every step, while a human has to click through menus to find the same information. The paper says this does not bias the comparison significantly, but it is an assumption.
  • Many design choices were set on the basis of early experiments and were never fully ablated, and the paper says so.

Reading guide

Read the paper in this order. Each section lists the lessons it depends on.

Check yourself

QuestionRecall: what does the paper mean by surgery, and what does the equation for exact preservation say?Show answer

Surgery is a set of tools for moving a trained model to a changed environment without starting over. When the observation and action spaces are unchanged, the new model should satisfy π^θ^(o)=πθ(o)\hat{\pi}_{\hat{\theta}}(o) = \pi_\theta(o) for every observation oo, so it behaves exactly like the old one at the moment of transfer and training can continue from there.

QuestionCompute: each optimizer GPU uses 120 samples of 16 timesteps. How many timesteps does one update use at the peak of 1,536 GPUs, and how does that compare with the single-GPU batch?Show answer

One GPU uses 120×16=1,920120 \times 16 = 1{,}920 timesteps. Across 1,536 GPUs the update uses 1,920×1,536=2,949,1201{,}920 \times 1{,}536 = 2{,}949{,}120 timesteps, which is 1,536 times the single-GPU batch. The averaging across GPUs is what makes the update look like one very large batch.

QuestionWhy: why does the advantage estimate use λ=0.95\lambda = 0.95 and not λ=0\lambda = 0 or λ=1\lambda = 1?Show answer

The advantage is a weighted sum of one-step errors. With λ=0\lambda = 0 it uses only the one-step error, which has low variance but relies heavily on the value estimate, so it is biased when that estimate is wrong. With λ=1\lambda = 1 it becomes a full Monte Carlo return, which is unbiased but has high variance over a long episode. A value near 0.95 averages over about twenty steps, a middle ground that the paper uses for a game of about 20,000 steps.

QuestionApplied: a team wants to reuse the OpenAI Five method for a robot whose sensors are noisy and whose opponent is a fixed program, not another learner. Which parts of the paper transfer directly, and which need changing?Show answer

The PPO update, the GAE advantage and the distributed rollout and optimizer split transfer, since they do not depend on the game. Self-play and the 80 and 20 percent opponent mix do not apply, because the opponent is fixed and there is no pool of older selves to draw from. The team would need domain randomization of the sensor noise, a reward that reflects the real task, and a check that the human-match style win rate is measured against the real opponent. The paper's throughput comes from running many copies of the game in parallel on CPUs, which a single physical robot cannot do, so the team would need a different data source.

Sources

Read the full paper

OpenAI, Christopher Berner, Greg Brockman et al., 2019. arXiv:1912.06680