Search

Search papers and lessons

MuZero

Level 5 · 10 min read

MuZero plans with a learned model that predicts only reward, policy and value, never the raw next observation, and it matches AlphaZero in board games without knowing the rules.

On this page

  • Colour = topic mix
  • Reinforcement learning
  • Probability
  • Linear algebra
  • Neural network basics
  • Stochastic processes
  • Learning basics
  • Sign in to see your progress

TL;DR

Tree search is very strong when the rules of the environment are known, as in chess or Go. Real problems rarely come with those rules, and learning a full simulator of pixels is expensive and wasteful. MuZero learns a compact model that predicts only the three things planning needs: the reward, the policy, and the value. It then runs a tree search inside that model, so it never has to reconstruct what the world looks like.

Where you'll see it: in the planning agents that learn their own environment model, for example in board games where the agent is never given the rules, and in Atari, where the paper reports results for 57 games.

Intuition

Plan in a space that only has to be useful

Think of a chess player who does not remember the board in full detail. What they remember is what matters for the next few moves: which pieces are under threat, how valuable each position feels, and which moves look promising. Their internal picture is a summary built for deciding, not a photograph of the board.

MuZero works the same way. It turns the observation (the Go board, or the last few Atari frames) into a hidden state. A second function takes a hidden state and a hypothetical action and produces the next hidden state and the reward for that step. A third function reads a hidden state and outputs a policy (which action looks good) and a value (how good the position is). Planning happens entirely on hidden states. The model is never asked to draw the next screen.

Why does this matter? A model trained to reproduce pixels spends its capacity on detail that does not change the decision, such as the exact texture of the background. Planning on pixels is also computationally impractical at scale. MuZero's hidden states are free to contain whatever helps prediction, and nothing forces them to be a faithful copy of the environment. The paper puts it this way: the agent can invent, internally, the rules or dynamics that lead to the most accurate planning.

flowchart LR
  O[Observations o_1 to o_t] --> H[Representation h]
  H --> S0[Hidden state s_0]
  S0 --> F[Prediction f: policy and value]
  S0 --> G[Dynamics g with action a_k]
  G --> SK[Hidden state s_k and reward r_k]
  SK --> F

Search as the teacher

A neural network that predicts policies and values is fast but imperfect. A search that looks ahead with the network's help is slower but more accurate. MuZero trains the network to match the search. The policy target is the search's visit distribution, and the value target is a discounted sum of observed rewards with the search's value at the end. Each time the search improves on the network, the network is pushed toward the improvement. This is the same policy-iteration loop that AlphaZero uses, extended to cases where the rules are not given.

The math

The model

The model has three learned functions, all parameterised by θ\theta. Let o1,…,oto_1, \dots, o_t be the observations so far and a1,…,aKa^1, \dots, a^K a hypothetical sequence of actions.

  • Representation hθh_\theta maps the observations to a root hidden state: s0=hθ(o1,…,ot)s^0 = h_\theta(o_1, \dots, o_t).
  • Dynamics gθg_\theta maps a hidden state and an action to a reward and the next hidden state: rk,sk=gθ(sk−1,ak)r^k, s^k = g_\theta(s^{k-1}, a^k).
  • Prediction fθf_\theta maps a hidden state to a policy and a value: pk,vk=fθ(sk)\mathbf{p}^k, v^k = f_\theta(s^k).

Here pk\mathbf{p}^k is a distribution over actions, vkv^k is a scalar estimate of future return, and rkr^k is an estimate of the immediate reward. The dynamics function is the only place where time moves forward inside the model. The paper's version is deterministic.

The targets

Each training position has three targets, taken from real experience:

  • The policy target πt+k\pi_{t+k} is the search distribution recorded at that step, proportional to visit counts at the root.
  • The reward target ut+ku_{t+k} is the reward the environment actually emitted.
  • The value target zt+kz_{t+k} is an nn-step return that bootstraps from the search value:
zt=ut+1+γut+2+⋯+γn−1ut+n+γnνt+nz_t = u_{t+1} + \gamma u_{t+2} + \dots + \gamma^{n-1} u_{t+n} + \gamma^{n} \nu_{t+n}

Here γ\gamma is the discount factor, uu is the observed reward, and νt+n\nu_{t+n} is the search value nn steps later. In board games, the discount is 1 and the only reward is the final outcome, +1+1, 00 or −1-1, and the target bootstraps to the end of the game. In Atari the paper uses n=10n = 10 and a discount of 0.9970.997.

The loss

Training unrolls the model for KK hypothetical steps from a sampled position. The loss sums three terms over every unrolled step, plus a weight penalty:

ℓt(θ)=∑k=0K[ℓr(ut+k,rk)+ℓv(zt+k,vk)+ℓp(πt+k,pk)]+c∥θ∥2\ell_t(\theta) = \sum_{k=0}^{K} \Big[ \ell^{r}(u_{t+k}, r^k) + \ell^{v}(z_{t+k}, v^k) + \ell^{p}(\pi_{t+k}, \mathbf{p}^k) \Big] + c \lVert \theta \rVert^2

The reward term is only meaningful for k≥1k \geq 1, since no reward is predicted at the root. The paper scales each head's loss by 1/K1/K so that the gradient size does not depend on how far it unrolls. The whole model, hh, gg and ff, is trained jointly by backpropagation through time.

Worked examples

Example
A value target with two-step bootstrapping

Take γ=0.9\gamma = 0.9, n=2n = 2, and suppose the environment gave rewards ut+1=1u_{t+1} = 1 and ut+2=0u_{t+2} = 0. The search at step t+2t+2 returned a value νt+2=5\nu_{t+2} = 5.

  1. Write the formula: zt=ut+1+γut+2+γ2νt+2z_t = u_{t+1} + \gamma u_{t+2} + \gamma^2 \nu_{t+2}.
  2. Substitute the reward: ut+1=1u_{t+1} = 1.
  3. Substitute the discounted second reward: γut+2=0.9×0=0\gamma u_{t+2} = 0.9 \times 0 = 0.
  4. Compute the discounted search value: γ2νt+2=0.81×5=4.05\gamma^2 \nu_{t+2} = 0.81 \times 5 = 4.05.
  5. Add the terms: zt=1+0+4.05=5.05z_t = 1 + 0 + 4.05 = 5.05.

The target mixes real rewards from the past with the network's own search estimate of the future. The value head is trained to output 5.055.05 at position tt, not 11 and not 55. The paper uses this form so that long episodes and intermediate rewards can be handled, which AlphaZero's terminal-outcome targets do not cover.

Example
The cost of one training sample

Take K=5K = 5. Sample one position from the replay buffer and unroll the model over the next five actions.

  1. Apply the representation function once: hθh_\theta gives s0s^0.
  2. Apply the dynamics function K=5K = 5 times: gθg_\theta gives s1,…,s5s^1, \dots, s^5, along with rewards r1,…,r5r^1, \dots, r^5.
  3. Apply the prediction function to each of s0,…,s5s^0, \dots, s^5. That is K+1=6K + 1 = 6 calls.

So one sample costs one encoder call, five dynamics calls and six prediction calls. Each dynamics call is cheap compared with the representation function, since it works on hidden states rather than raw observations. The count of calls is what matters here. This is the step that makes the model usable for planning: the search only ever calls gg and ff, never hh after the root.

Experimental results

The paper reports two broad results. In board games, MuZero matched the superhuman performance of AlphaZero on Go, chess and shogi, even though it was never given the rules. In Go it slightly exceeded AlphaZero. The board-game networks used 800 simulations per move. The paper says that for these games it followed the same UCB constants, Dirichlet exploration noise and simulation count as AlphaZero.

In Atari, the paper reports a new state of the art on the 57 games of the Arcade Learning Environment. The main agent used 50 simulations per move, and it beat the model-free R2D2 agent in 42 of 57 games. On the paper's Atari table, MuZero reaches a median of 2041.1% and a mean of 4999.2% of human score, compared with R2D2 at 1920.6% and 4024.9%. The table also lists 20 billion frames for MuZero against 37.5 billion for R2D2, so the comparison is not frame-matched. A second, sample-efficient variant called MuZero Reanalyze reaches a median of 731.1% with 200 million frames per game, against 431% for LASER and 231.1% for Rainbow in the same table.

The paper also studies how much planning matters. In Atari, performance rises with the number of simulations per move and plateaus at about 100 simulations, even though the network was trained at 50. With a single simulation, the agent still plays well by choosing moves from the policy network alone. In Ms. Pacman, the paper reports that training with only 6 simulations per move, fewer than the 8 available actions, still produced an effective policy.

Tradeoffs and failure modes

SituationWhat goes wrongBetter choice
The rules are known and cheap to simulateMuZero adds a model to learn with no gain[[alphazero
The environment is stochasticThe paper's dynamics are deterministic, so the model cannot represent randomnessA model that can represent stochastic transitions (the paper's model does not)
The model is wrong far from the dataSearch exploits model errors; the paper notes that planning helps less in Atari than in Go, perhaps because of model inaccuracyLimit search depth, or train on the real trajectories more often
Compute is tight at decision timeEach simulation makes network calls, and the paper's Atari gains flatten past about 100 simulationsFewer simulations, or the policy network alone
No reconstruction lossHidden states need not match the true state, so they are hard to inspectAccept that the model is a planner, not a simulator for humans

Because the hidden state is trained only to predict reward, policy and value, the model can learn to ignore details that do not matter for those quantities. The same freedom makes it hard to say what the state means.

History

The paper builds on AlphaZero, which had already shown that a network trained from search targets could master Go, chess and shogi. Before MuZero, the paper's own survey places two lines of model-based work. One predicts pixels or latent states that can reconstruct the observation. The other, which includes the predictron and value prediction networks, learns models that are trained only to predict value or reward. MuZero sits between them: it predicts value, reward and policy, and it does not reconstruct observations. The arXiv preprint dates from November 2019.

Check yourself

QuestionWhat are the three functions of MuZero's model, and what does each one output?Show answer

The representation function hθh_\theta maps the past observations to a root hidden state s0s^0. The dynamics function gθg_\theta maps a hidden state and an action to an immediate reward rkr^k and the next hidden state sks^k. The prediction function fθf_\theta maps a hidden state to a policy pk\mathbf{p}^k and a value vkv^k. Planning uses gg and ff on hidden states, and only the root uses hh.

QuestionWith γ=0.5\gamma = 0.5, n=3n = 3, rewards ut+1=2u_{t+1} = 2, ut+2=0u_{t+2} = 0, ut+3=4u_{t+3} = 4, and search value νt+3=10\nu_{t+3} = 10, what is ztz_t?Show answer

Apply zt=ut+1+γut+2+γ2ut+3+γ3νt+3z_t = u_{t+1} + \gamma u_{t+2} + \gamma^2 u_{t+3} + \gamma^3 \nu_{t+3}. The terms are 22, 0.5×0=00.5 \times 0 = 0, 0.25×4=10.25 \times 4 = 1, and 0.125×10=1.250.125 \times 10 = 1.25. The sum is 4.254.25.

QuestionWhy does MuZero train the hidden state without requiring it to reconstruct the observation?Show answer

Reconstruction would force the model to spend capacity on details that do not change the decision, such as background texture, and it would make planning in pixel space expensive. The model is trained only so that its predicted reward, policy and value match the observed reward, the search policy and the bootstrapped value target. Any hidden state that makes those predictions accurate is acceptable, so the model can use a more compact representation.

QuestionWhy might MuZero help less in Atari than in Go, according to the paper?Show answer

The paper suggests that greater model inaccuracy in visually complex Atari environments limits the benefit of search. Search amplifies whatever the model gets right, and it also amplifies errors. In Go, the model is more accurate, so longer searches keep improving play.

QuestionA training sample uses K=5K = 5 unroll steps. How many calls does it make to each of the three functions?Show answer

The representation function is called once. The dynamics function is called five times, for steps 11 through 55. The prediction function is called six times, once for each of s0s^0 through s5s^5.

Sources