Skip to content
DAH

Monte Carlo tree search and AlphaZero

Planning by growing a search tree from simulated rollouts, guided by a learned policy and value network that is itself trained on the search results. It produced superhuman Go, chess and shogi from self-play.

On this page16 sections
Why other work relies on it

AlphaZero-style search-plus-learning is the template for game-playing agents (KataGo, Leela), for learned-model planners such as MuZero, and for search over language-model reasoning steps.

A program that thinks ahead by trying many imagined games and learns from its own matches.

  1. 1Imagine many games from here
  2. 2Focus on promising moves
  3. 3Network guesses moves and winner
  4. 4Search improves the guess
  5. 5Train network on search results

What it is for. In board games an agent can think ahead: imagine its moves, the opponent's replies, and so on. Go has about 250 legal moves in a typical position, so the full tree of possible games is far too large to search. Monte Carlo tree search (MCTS) searches only the promising parts, and AlphaZero adds a neural network that tells the search where to look.

MCTS. The search grows a tree from the current position. Each simulation (1) walks down the tree choosing moves by stored statistics, (2) adds a new position at the bottom, (3) evaluates it, and (4) sends the result back up, updating the average value QQ and the visit count NN of every move on the path. After many simulations the most-visited move is played. Early versions evaluated a position by playing random moves to the end of the game, a Monte Carlo estimate (an average over random trials).

Choosing where to look. Selection must balance exploiting moves that look good with exploring moves tried rarely. AlphaZero's PUCT rule picks a∗=arg⁡max⁡a[Q(s,a)+c P(s,a)∑bN(s,b)1+N(s,a)].a^*=\arg\max_a\Big[Q(s,a)+c\,P(s,a)\frac{\sqrt{\sum_b N(s,b)}}{1+N(s,a)}\Big]. The first term is the move's average result so far. The second is a bonus that is large when the network's prior PP favours the move and the move has few visits NN, and that shrinks as visits accumulate; cc sets the balance. It is the upper-confidence-bound idea from slot-machine (bandit) problems.

The self-play loop. One network takes a position and outputs move probabilities pp and a value vv, its estimate of who will win. The program plays itself; at each move MCTS guided by the network produces a sharper move distribution than the network alone. The network is then trained by gradient descent to predict the search's move distribution and the final result. Search acts as a teacher, the network learns to imitate it, and the improved network makes the next search stronger. AlphaGo Zero (2017) learned Go this way with no human games, and AlphaZero applied the same algorithm to chess and shogi.

Cost and efficiency. AlphaZero used thousands of TPUs. KataGo (Wu, 2019) reported a 50-fold reduction in computation, surpassing ELF OpenGo's final model after 19 days on about 27 V100 GPUs, mainly through general changes such as extra prediction targets. Gumbel AlphaZero (ICLR 2022) changes how moves are chosen at the root so that search still improves the policy with very few simulations; it is implemented in DeepMind's mctx library.

Limits. The method needs a simulator with known rules (or a learned model, see world models) and a clear win-or-loss signal.

Go deeper

The full technical text.

MCTS builds a game tree incrementally. Each iteration (a simulation) selects a path from the root using statistics stored in the tree, expands a leaf, evaluates it, and backs the result up the path. Kocsis and Szepesvári (2006) introduced UCT, which treats each node's choice as a bandit problem and picks children by an upper confidence bound, and Coulom (2006) introduced the term Monte Carlo tree search. Before neural networks, MCTS with random rollouts was the strongest approach to Go, though still below top professionals.

AlphaGo, AlphaGo Zero and AlphaZero

AlphaGo (Silver et al., Nature 2016) combined MCTS with a policy network trained on human games and a value network, and beat a professional player. AlphaGo Zero (Nature 2017) removed human data: a single network outputs move probabilities pp and a value vv, MCTS using them produces improved move distributions, and the network is trained to match the search's visit-count distribution and the game outcome. Search therefore acts as a policy improvement operator and the network distils its result, repeated in a self-play loop. AlphaZero (Silver et al., 2017; Science 2018) applied the same algorithm unchanged to chess and shogi.

Selection uses a PUCT rule, roughly

a∗=arg⁡max⁡a[Q(s,a)+c P(s,a)∑bN(s,b)1+N(s,a)],a^*=\arg\max_a\left[Q(s,a)+c\,P(s,a)\frac{\sqrt{\sum_b N(s,b)}}{1+N(s,a)}\right],

where QQ is the mean backed-up value, PP the network prior and NN visit counts.

Efficiency work

AlphaZero used thousands of TPUs. KataGo (Wu, 2019) reports a 50-fold computation reduction over comparable methods and surpassing the final ELF OpenGo model after 19 days on fewer than 30 GPUs, using non-domain-specific changes such as auxiliary targets and playout-cap randomisation. Gumbel AlphaZero/MuZero (Danihelka, Guez, Schrittwieser and Silver, ICLR 2022) replaces the root selection with sampling without replacement via the Gumbel-top-kk trick, which gives a policy-improvement guarantee even with few simulations; it is implemented in DeepMind's mctx library.

Limits

Search needs a simulator (or a learned model; see model-based RL) and a clear terminal reward. Branching factor and stochasticity raise cost. Using the same machinery for open-ended language reasoning is an active but unsettled area.

Practice

Reference code: DeepMind's JAX library mctx for batched search, OpenSpiel for game environments, and KataGo, the strongest open Go engine.

Words on this page (12)
Words on this page
reinforcement learning
Learning by trial and error: an agent acts, gets rewards, and adjusts its behaviour to collect more reward over time.
policy
The rule an agent uses to choose an action in each situation. In deep RL it is usually a neural network.
Monte Carlo tree search
A planning method that tries many simulated move sequences and focuses on the promising ones.
self-play
An agent improving by playing against copies of itself.
neural network
A function made of many adjustable numbers that is trained to produce useful outputs.
value network
A network that estimates how likely a position is to be a win.
upper confidence bound
A rule that picks options by their average result plus a bonus for being tried rarely.
branching factor
The number of moves available in a typical position; larger means harder search.
Monte Carlo method
Estimating a quantity by averaging the results of many random trials.
gradient descent
Repeatedly adjusting a model's parameters a small step against the slope of its error, so the error decreases.
Go
A two-player board game on a 19×19 grid with a very large number of possible positions.
TPU
Tensor Processing Unit: Google's chip specialised for neural-network arithmetic.
New to this? Read first (3)
New to this? Read first

Understanding map

map of the whole wiki →

What to read before Monte Carlo tree search and AlphaZero (left), and what builds on it: entries that depend on it and its open problems (right). Every box links to its page.

  1. Start with
  2. Step 2
  3. Step 3
  4. Then

Open problems & questions

Progress timeline

  1. Feb 27, 2019
    KataGo

    Open-source engine reports a 50x compute reduction over comparable methods (arXiv preprint).

    source
  2. Feb 27, 2019
    KataGo
    Related to: ELF OpenGo-level 19x19 Go from scratch at one tenth of KataGo's reported compute (about 51 V100-days)

    Reports surpassing ELF OpenGo's final model after 19 days on about 27 V100 GPUs, a 50x compute reduction.

    source
  3. Dec 5, 2017
    AlphaZero

    The same algorithm masters chess and shogi as well as Go (arXiv preprint; later in Science, 2018).

    source
  4. Oct 19, 2017
    AlphaGo Zero

    Self-play from scratch without human data (publication date approximate within October 2017).

    source
  5. Jan 27, 2016
    AlphaGo

    Nature publishes AlphaGo, combining policy and value networks with MCTS.

    source
  6. Sep 1, 2006
    UCT and MCTS

    Kocsis and Szepesvári publish UCT; Coulom names Monte Carlo tree search. Month approximate.

    source