{'fraction_non_alphanumeric': 0.035595882045018325, 'fraction_numerical': 0.013610190193683477, 'mean_word_length': 4.5503597122302155, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Mastering Atari, Go, Chess and Shogi by Planning with a Learned Model

Constructing agents with planning capabilities has long been one of the main challenges in the pursuit of artificial intelligence. Tree-based planning methods have enjoyed huge success in challenging domains, such as chess and Go, where a perfect simulator is available. However, in real-world problems the dynamics governing the environment are often complex and unknown. In this work we present the MuZero algorithm which, by combining a tree-based search with a learned model, achieves superhuman performance in a range of challenging and visually complex domains, without any knowledge of their underlying dynamics. MuZero learns a model that, when applied iteratively, predicts the quantities most directly relevant to planning: the reward, the action-selection policy, and the value function. When evaluated on 57 different Atari games - the canonical video game environment for testing AI techniques, in which model-based planning approaches have historically struggled - our new algorithm achieved a new state of the art. When evaluated on Go, chess and shogi, without any knowledge of the game rules, MuZero matched the superhuman performance of the AlphaZero algorithm that was supplied with the game rules.


Introduction
Planning algorithms based on lookahead search have achieved remarkable successes in artificial intelligence. Human world champions have been defeated in classic games such as checkers [34], chess [5], Go [38] and poker [3,26], and planning algorithms have had real-world impact in applications from logistics [47] to chemical synthesis [37]. However, these planning algorithms all rely on knowledge of the environment's dynamics, such as the rules of the game or an accurate simulator, preventing their direct application to real-world domains like robotics, industrial control, or intelligent assistants.
Model-based reinforcement learning (RL) [42] aims to address this issue by first learning a model of the environment's dynamics, and then planning with respect to the learned model. Typically, these models have either focused on reconstructing the true environmental state [8,16,24], or the sequence of full observations [14,20]. However, prior work [4,14,20] remains far from the state of the art in visually rich domains, such as Atari 2600 games [2]. Instead, the most successful methods are based on model-free RL [9,21,18] -i.e. they estimate the optimal policy and/or value function directly from interactions with the environment. However, model-free algorithms are in turn far from the state of the art in domains that require precise and sophisticated lookahead, such as chess and Go.
In this paper, we introduce MuZero, a new approach to model-based RL that achieves state-of-the-art performance in Atari 2600, a visually complex set of domains, while maintaining superhuman performance in precision planning tasks such as chess, shogi and Go. MuZero builds upon AlphaZero's [39] powerful search and 1 arXiv:1911.08265v1 [cs.LG] 19 Nov 2019 search-based policy iteration algorithms, but incorporates a learned model into the training procedure. MuZero also extends AlphaZero to a broader set of environments including single agent domains and non-zero rewards at intermediate time-steps.
The main idea of the algorithm (summarized in Figure 1) is to predict those aspects of the future that are directly relevant for planning. The model receives the observation (e.g. an image of the Go board or the Atari screen) as an input and transforms it into a hidden state. The hidden state is then updated iteratively by a recurrent process that receives the previous hidden state and a hypothetical next action. At every one of these steps the model predicts the policy (e.g. the move to play), value function (e.g. the predicted winner), and immediate reward (e.g. the points scored by playing a move). The model is trained end-to-end, with the sole objective of accurately estimating these three important quantities, so as to match the improved estimates of policy and value generated by search as well as the observed reward. There is no direct constraint or requirement for the hidden state to capture all information necessary to reconstruct the original observation, drastically reducing the amount of information the model has to maintain and predict; nor is there any requirement for the hidden state to match the unknown, true state of the environment; nor any other constraints on the semantics of state. Instead, the hidden states are free to represent state in whatever way is relevant to predicting current and future values and policies. Intuitively, the agent can invent, internally, the rules or dynamics that lead to most accurate planning.

Prior Work
Reinforcement learning may be subdivided into two principal categories: model-based, and model-free [42]. Model-based RL constructs, as an intermediate step, a model of the environment. Classically, this model is represented by a Markov-decision process (MDP) [31] consisting of two components: a state transition model, predicting the next state, and a reward model, predicting the expected reward during that transition. The model is typically conditioned on the selected action, or a temporally abstract behavior such as an option [43]. Once a model has been constructed, it is straightforward to apply MDP planning algorithms, such as value iteration [31] or Monte-Carlo tree search (MCTS) [7], to compute the optimal value or optimal policy for the MDP. In large or partially observed environments, the algorithm must first construct the state representation that the model should predict. This tripartite separation between representation learning, model learning, and planning is potentially problematic since the agent is not able to optimize its representation or model for the purpose of effective planning, so that, for example modeling errors may compound during planning.
A common approach to model-based RL focuses on directly modeling the observation stream at the pixellevel. It has been hypothesized that deep, stochastic models may mitigate the problems of compounding error [14,20]. However, planning at pixel-level granularity is not computationally tractable in large scale problems. Other methods build a latent state-space model that is sufficient to reconstruct the observation stream at pixel level [48,49], or to predict its future latent states [13,11], which facilitates more efficient planning but still focuses the majority of the model capacity on potentially irrelevant detail. None of these prior methods has constructed a model that facilitates effective planning in visually complex domains such as Atari; results lag behind well-tuned, model-free methods, even in terms of data efficiency [45].
A quite different approach to model-based RL has recently been developed, focused end-to-end on predicting the value function [41]. The main idea of these methods is to construct an abstract MDP model such that planning in the abstract MDP is equivalent to planning in the real environment. This equivalence is achieved by ensuring value equivalence, i.e. that, starting from the same real state, the cumulative reward of a trajectory through the abstract MDP matches the cumulative reward of a trajectory in the real environment.
The predictron [41] first introduced value equivalent models for predicting value (without actions). Although the underlying model still takes the form of an MDP, there is no requirement for its transition model to match real states in the environment. Instead the MDP model is viewed as a hidden layer of a deep neural network. The unrolled MDP is trained such that the expected cumulative sum of rewards matches the expected value with respect to the real environment, e.g. by temporal-difference learning.
Value equivalent models were subsequently extended to optimising value (with actions). TreeQN [10] learns an abstract MDP model, such that a tree search over that model (represented by a tree-structured neural network) approximates the optimal value function. Value iteration networks [44] learn a local MDP model, such that value The model consists of three connected components for representation, dynamics and prediction. Given a previous hidden state s k−1 and a candidate action a k , the dynamics function g produces an immediate reward r k and a new hidden state s k . The policy p k and value function v k are computed from the hidden state s k by a prediction function f . The initial hidden state s 0 is obtained by passing the past observations (e.g. the Go board or Atari screen) into a representation function h. (B) How MuZero acts in the environment. A Monte-Carlo Tree Search is performed at each timestep t, as described in A. An action a t+1 is sampled from the search policy π t , which is proportional to the visit count for each action from the root node. The environment receives the action and generates a new observation o t+1 and reward u t+1 . At the end of the episode the trajectory data is stored into a replay buffer. (C) How MuZero trains its model. A trajectory is sampled from the replay buffer. For the initial step, the representation function h receives as input the past observations o 1 , ..., o t from the selected trajectory. The model is subsequently unrolled recurrently for K steps. At each step k, the dynamics function g receives as input the hidden state s k−1 from the previous step and the real action a t+k . The parameters of the representation, dynamics and prediction functions are jointly trained, end-to-end by backpropagation-through-time, to predict three quantities: the policy p k ≈ π t+k , value function v k ≈ z t+k , and reward r t+k ≈ u t+k , where z t+k is a sample return: either the final reward (board games) or n-step return (Atari). iteration over that model (represented by a convolutional neural network) approximates the optimal value function. Value prediction networks [28] are perhaps the closest precursor to MuZero: they learn an MDP model grounded in real actions; the unrolled MDP is trained such that the cumulative sum of rewards, conditioned on the actual sequence of actions generated by a simple lookahead search, matches the real environment. Unlike MuZero there is no policy prediction, and the search only utilizes value prediction.

MuZero Algorithm
We now describe the MuZero algorithm in more detail. Predictions are made at each time-step t, for each of k = 1...K steps, by a model µ θ , with parameters θ, conditioned on past observations o 1 , ..., o t and future actions a t+1 , ..., a t+k . The model predicts three future quantities: the policy p k t ≈ π(a t+k+1 |o 1 , ..., o t , a t+1 , ..., a t+k ), the value function v k t ≈ E [u t+k+1 + γu t+k+2 + ...|o 1 , ..., o t , a t+1 , ..., a t+k ], and the immediate reward r k t ≈ u t+k , where u . is the true, observed reward, π is the policy used to select real actions, and γ is the discount function of the environment.
Internally, at each time-step t (subscripts t suppressed for simplicity), the model is represented by the com-bination of a representation function, a dynamics function, and a prediction function. The dynamics function, r k , s k = g θ (s k−1 , a k ), is a recurrent process that computes, at each hypothetical step k, an immediate reward r k and an internal state s k . It mirrors the structure of an MDP model that computes the expected reward and state transition for a given state and action [31]. However, unlike traditional approaches to model-based RL [42], this internal state s k has no semantics of environment state attached to it -it is simply the hidden state of the overall model, and its sole purpose is to accurately predict relevant, future quantities: policies, values, and rewards. In this paper, the dynamics function is represented deterministically; the extension to stochastic transitions is left for future work. The policy and value functions are computed from the internal state s k by the prediction function, p k , v k = f θ (s k ), akin to the joint policy and value network of AlphaZero. The "root" state s 0 is initialized using a representation function that encodes past observations, s 0 = h θ (o 1 , ..., o t ); again this has no special semantics beyond its support for future predictions. Given such a model, it is possible to search over hypothetical future trajectories a 1 , ..., a k given past observations o 1 , ..., o t . For example, a naive search could simply select the k step action sequence that maximizes the value function. More generally, we may apply any MDP planning algorithm to the internal rewards and state space induced by the dynamics function. Specifically, we use an MCTS algorithm similar to AlphaZero's search, generalized to allow for single agent domains and intermediate rewards (see Methods). At each internal node, it makes use of the policy, value and reward estimates produced by the current model parameters θ. The MCTS algorithm outputs a recommended policy π t and estimated value ν t . An action a t+1 ∼ π t is then selected.
All parameters of the model are trained jointly to accurately match the policy, value, and reward, for every hypothetical step k, to corresponding target values observed after k actual time-steps have elapsed. Similarly to AlphaZero, the improved policy targets are generated by an MCTS search; the first objective is to minimise the error between predicted policy p k t and search policy π t+k . Also like AlphaZero, the improved value targets are generated by playing the game or MDP. However, unlike AlphaZero, we allow for long episodes with discounting and intermediate rewards by bootstrapping n steps into the future from the search value, z t = u t+1 + γu t+2 + ... + γ n−1 u t+n + γ n ν t+n . Final outcomes {lose, draw, win} in board games are treated as rewards u t ∈ {−1, 0, +1} occuring at the final step of the episode. Specifically, the second objective is to minimize the error between the predicted value v k t and the value target, z t+k 1 . The reward targets are simply the observed rewards; the third objective is therefore to minimize the error between the predicted reward r k t and the observed reward u t+k . Finally, an L2 regularization term is also added, leading to the overall loss: where l r , l v , and l p are loss functions for reward, value and policy respectively. Supplementary Figure S2 summarizes the equations governing how the MuZero algorithm plans, acts, and learns.

Results
We applied the MuZero algorithm to the classic board games Go, chess and shogi 2 , as benchmarks for challenging planning problems, and to all 57 games in the Atari Learning Environment [2], as benchmarks for visually complex RL domains.
In each case we trained MuZero for K = 5 hypothetical steps. Training proceeded for 1 million mini-batches of size 2048 in board games and of size 1024 in Atari. During both training and evaluation, MuZero used 800 simulations for each search in board games, and 50 simulations for each search in Atari. The representation function uses the same convolutional [23] and residual [15] architecture as AlphaZero, but with 16 residual blocks instead of 20. The dynamics function uses the same architecture as the representation function and the prediction 1 For chess, Go and shogi, the same squared error loss as AlphaZero is used for rewards and values. A cross-entropy loss was found to be more stable than a squared error when encountering rewards and values of variable scale in Atari. Cross-entropy was used for the policy loss in both cases. 2 Imperfect information games such as Poker are not directly addressed by our method.

4
Chess Shogi Go Atari Figure 2: Evaluation of MuZero throughout training in chess, shogi, Go and Atari. The x-axis shows millions of training steps. For chess, shogi and Go, the y-axis shows Elo rating, established by playing games against Alp-haZero using 800 simulations per move for both players. MuZero's Elo is indicated by the blue line, AlphaZero's Elo by the horizontal orange line. For Atari, mean (full line) and median (dashed line) human normalized scores across all 57 games are shown on the y-axis. The scores for R2D2 [21], (the previous state of the art in this domain, based on model-free RL) are indicated by the horizontal orange lines. Performance in Atari was evaluated using 50 simulations every fourth time-step, and then repeating the chosen action four times, as in prior work [25]. function uses the same architecture as AlphaZero. All networks use 256 hidden planes (see Methods for further details). Figure 2 shows the performance throughout training in each game. In Go, MuZero slightly exceeded the performance of AlphaZero, despite using less computation per node in the search tree (16 residual blocks per evaluation in MuZero compared to 20 blocks in AlphaZero). This suggests that MuZero may be caching its computation in the search tree and using each additional application of the dynamics model to gain a deeper understanding of the position.
In Atari, MuZero achieved a new state of the art for both mean and median normalized score across the 57 games of the Arcade Learning Environment, outperforming the previous state-of-the-art method R2D2 [21] (a model-free approach) in 42 out of 57 games, and outperforming the previous best model-based approach SimPLe [20] in all games (see Table S1).
We also evaluated a second version of MuZero that was optimised for greater sample efficiency. Specifically, it reanalyzes old trajectories by re-running the MCTS using the latest network parameters to provide fresh targets (see Appendix H). When applied to 57 Atari games, using 200 million frames of experience per game, MuZero Reanalyze achieved 731% median normalized score, compared to 192%, 231% and 431% for previous state-ofthe-art model-free approaches IMPALA [9], Rainbow [17] and LASER [36] respectively.
To understand the role of the model in MuZero we also ran several experiments, focusing on the board game of Go and the Atari game of Ms. Pacman.
First, we tested the scalability of planning ( Figure 3A), in the canonical planning problem of Go. We compared the performance of search in AlphaZero, using a perfect model, to the performance of search in MuZero, using a learned model. Specifically, the fully trained AlphaZero or MuZero was evaluated by comparing MCTS with different thinking times. MuZero matched the performance of a perfect model, even when doing much larger searches (up to 10s thinking time) than those from which the model was trained (around 0.1s thinking time, see also Figure S3A). We also investigated the scalability of planning across all Atari games (see Figure 3B). We compared MCTS with different numbers of simulations, using the fully trained MuZero. The improvements due to planning are much less marked than in Go, perhaps because of greater model inaccuracy; performance improved slightly with search time, but plateaued at around 100 simulations. Even with a single simulation -i.e. when selecting moves solely according to the policy network -MuZero performed well, suggesting that, by the end of training, the raw policy has learned to internalise the benefits of search (see also Figure S3B).
Next, we tested our model-based learning algorithm against a comparable model-free learning algorithm (see Figure 3C). We replaced the training objective of MuZero (Equation 1) with a model-free Q-learning objective (as used by R2D2), and the dual value and policy heads with a single head representing the Q-function Q(·|s t ). Subsequently, we trained and evaluated the new model without using any search. When evaluated on Ms. Pacman, our model-free algorithm achieved identical results to R2D2, but learned significantly slower than MuZero and converged to a much lower final score. We conjecture that the search-based policy improvement step of MuZero provides a stronger learning signal than the high bias, high variance targets used by Q-learning.
To better understand the nature of MuZero's learning algorithm, we measured how MuZero's training scales with respect to the amount of search it uses during training. Figure 3D shows the performance in Ms. Pacman, using an MCTS of different simulation counts per move throughout training. Surprisingly, and in contrast to previous work [1], even with only 6 simulations per move -fewer than the number of actions -MuZero learned an effective policy and improved rapidly. With more simulations performance jumped significantly higher. For analysis of the policy improvement during each individual iteration, see also Figure S3 C and D.

Conclusions
Many of the breakthroughs in artificial intelligence have been based on either high-performance planning [5,38,39] or model-free reinforcement learning methods [25,29,46]. In this paper we have introduced a method that combines the benefits of both approaches. Our algorithm, MuZero, has both matched the superhuman performance of high-performance planning algorithms in their favored domains -logically complex board games such as chess and Go -and outperformed state-of-the-art model-free RL algorithms in their favored domains -visually complex Atari games. Crucially, our method does not require any knowledge of the game rules or environment dynamics, potentially paving the way towards the application of powerful learning and planning methods to a host of realworld domains for which there exists no perfect simulator.

Acknowledgments
Lorrayne Bennett, Oliver Smith and Chris Apps for organizational assistance; Koray Kavukcuoglu for reviewing the paper; Thomas Anthony, Matthew Lai, Nenad Tomasev, Ulrich Paquet, Sumedh Ghaisas for many fruitful discussions; and the rest of the DeepMind team for their support. [

Supplementary Materials
• Pseudocode description of the MuZero algorithm.
Supplementary materials can be accessed from the ancillary file section of the arXiv submission.

Appendix A Comparison to AlphaZero
MuZero is designed for a more general setting than AlphaGo Zero [40] and AlphaZero [39].
In AlphaGo Zero and AlphaZero the planning process makes use of two separate components: a simulator implements the rules of the game, which are used to update the state of the game while traversing the search tree; and a neural network jointly predicts the corresponding policy and value of a board position produced by the simulator (see 1) State transitions. AlphaZero had access to a perfect simulator of the true dynamics process. In contrast, MuZero employs a learned dynamics model within its search. Under this model, each node in the tree is represented by a corresponding hidden state; by providing a hidden state s k−1 and an action a k to the model the search algorithm can transition to a new node s k = g(s k−1 , a k ).
2) Actions available. AlphaZero used the set of legal actions obtained from the simulator to mask the prior produced by the network everywhere in the search tree. MuZero only masks legal actions at the root of the search tree where the environment can be queried, but does not perform any masking within the search tree. This is possible because the network rapidly learns not to predict actions that never occur in the trajectories it is trained on.
3) Terminal nodes. AlphaZero stopped the search at tree nodes representing terminal states and used the terminal value provided by the simulator instead of the value produced by the network. MuZero does not give special treatment to terminal nodes and always uses the value predicted by the network. Inside the tree, the search can proceed past a terminal node -in this case the network is expected to always predict the same value. This is achieved by treating terminal states as absorbing states during training.
In addition, MuZero is designed to operate in the general reinforcement learning setting: single-agent domains with discounted intermediate rewards of arbitrary magnitude. In contrast, AlphaGo Zero and AlphaZero were designed to operate in two-player games with undiscounted terminal rewards of ±1.

Appendix B Search
We now describe the search algorithm used by MuZero. Our approach is based upon Monte-Carlo tree search with upper confidence bounds, an approach to planning that converges asymptotically to the optimal policy in single agent domains and to the minimax value function in zero sum games [22].
Every node of the search tree is associated with an internal state s. For each action a from s there is an edge (s, a) that stores a set of statistics {N (s, a), Q(s, a), P (s, a), R(s, a), S(s, a)}, respectively representing visit counts N , mean value Q, policy P , reward R, and state transition S.
Similar to AlphaZero, the search is divided into three stages, repeated for a number of simulations. Selection: Each simulation starts from the internal root state s 0 , and finishes when the simulation reaches a leaf node s l . For each hypothetical time-step k = 1...l of the simulation, an action a k is selected according to the stored statistics for internal state s k−1 , by maximizing over an upper confidence bound [32][39], The constants c 1 and c 2 are used to control the influence of the prior P (s, a) relative to the value Q(s, a) as nodes are visited more often. In our experiments, c 1 = 1.25 and c 2 = 19652.
For k < l, the next state and reward are looked up in the state transition and reward table s k = S(s k−1 , a k ), r k = R(s k−1 , a k ).
Expansion: At the final time-step l of the simulation, the reward and state are computed by the dynamics function, r l , s l = g θ (s l−1 , a l ), and stored in the corresponding tables, R(s l−1 , a l ) = r l , S(s l−1 , a l ) = s l . The policy and value are computed by the prediction function, p l , v l = f θ (s l ). A new node, corresponding to state s l is added to the search tree. Each edge (s l , a) from the newly expanded node is initialized to {N (s l , a) = 0, Q(s l , a) = 0, P (s l , a) = p l }. Note that the search algorithm makes at most one call to the dynamics function and prediction function respectively per simulation; the computational cost is of the same order as in AlphaZero.
Backup: At the end of the simulation, the statistics along the trajectory are updated. The backup is generalized to the case where the environment can emit intermediate rewards, have a discount γ different from 1, and the value estimates are unbounded 3 . For k = l...0, we form an l − k-step estimate of the cumulative discounted reward, bootstrapping from the value function v l , For k = l...1, we update the statistics for each edge (s k−1 , a k ) in the simulation path as follows, In two-player zero sum games the value functions are assumed to be bounded within the [0, 1] interval. This choice allows us to combine value estimates with probabilities using the pUCT rule (Eqn 2). However, since in many environments the value is unbounded, it is necessary to adjust the pUCT rule. A simple solution would be to use the maximum score that can be observed in the environment to either re-scale the value or set the pUCT constants appropriately [33]. However, both solutions are game specific and require adding prior knowledge to the MuZero algorithm. To avoid this, MuZero computes normalized Q value estimates Q ∈ [0, 1] by using the minimum-maximum values observed in the search tree up to that point. When a node is reached during the selection stage, the algorithm computes the normalized Q values of its edges to be used in the pUCT rule using the equation below: Q(s k−1 , a k ) = Q(s k−1 , a k ) − min s,a∈T ree Q(s, a) max s,a∈T ree Q(s, a) − min s,a∈T ree Q(s, a)

Appendix C Hyperparameters
For simplicity we preferentially use the same architectural choices and hyperparameters as in previous work. Specifically, we started with the network architecture and search choices of AlphaZero [39]. For board games, we use the same UCB constants, dirichlet exploration noise and the same 800 simulations per search as in AlphaZero.
Due to the much smaller branching factor and simpler policies in Atari, we only used 50 simulations per search to speed up experiments. As shown in Figure 3B, the algorithm is not very sensitive to this choice. We also use the same discount (0.997) and value transformation (see Network Architecture section) as R2D2 [21].
For parameter values not mentioned in the text, please refer to the pseudocode.

Appendix D Data Generation
To generate training data, the latest checkpoint of the network (updated every 1000 training steps) is used to play games with MCTS. In the board games Go, chess and shogi the search is run for 800 simulations per move to pick an action; in Atari due to the much smaller action space 50 simulations per move are sufficient. For board games, games are sent to the training job as soon as they finish. Due to the much larger length of Atari games (up to 30 minutes or 108,000 frames), intermediate sequences are sent every 200 moves. In board games, the training job keeps an in-memory replay buffer of the most recent 1 million games received; in Atari, where the visual observations are larger, the most recent 125 thousand sequences of length 200 are kept.
During the generation of experience in the board game domains, the same exploration scheme as the one described in AlphaZero [39] is used. Using a variation of this scheme, in the Atari domain actions are sampled from the visit count distribution throughout the duration of each game, instead of just the first k moves. Moreover, the visit count distribution is parametrized using a temperature parameter T : T is decayed as a function of the number of training steps of the network. Specifically, for the first 500k training steps a temperature of 1 is used, for the next 250k steps a temperature of 0.5 and for the remaining 250k a temperature of 0.25. This ensures that the action selection becomes greedier as training progresses.

Appendix E Network Input Representation Function
The history over board states used as input to the representation function for Go, chess and shogi is represented similarly to AlphaZero [39]. In Go and shogi we encode the last 8 board states as in AlphaZero; in chess we increased the history to the last 100 board states to allow correct prediction of draws.
For Atari, the input of the representation function includes the last 32 RGB frames at resolution 96x96 along with the last 32 actions that led to each of those frames. We encode the historical actions because unlike board games, an action in Atari does not necessarily have a visible effect on the observation. RGB frames are encoded as one plane per color, rescaled to the range [0, 1], for red, green and blue respectively. We perform no other normalization, whitening or other preprocessing of the RGB input. Historical actions are encoded as simple bias planes, scaled as a/18 (there are 18 total actions in Atari).

Dynamics Function
The input to the dynamics function is the hidden state produced by the representation function or previous application of the dynamics function, concatenated with a representation of the action for the transition. Actions are encoded spatially in planes of the same resolution as the hidden state. In Atari, this resolution is 6x6 (see description of downsampling in Network Architecture section), in board games this is the same as the board size (19x19 for Go, 8x8 for chess, 9x9 for shogi).
In Go, a normal action (playing a stone on the board) is encoded as an all zero plane, with a single one in the position of the played stone. A pass is encoded as an all zero plane.
In chess, 8 planes are used to encode the action. The first one-hot plane encodes which position the piece was moved from. The next two planes encode which position the piece was moved to: a one-hot plane to encode the target position, if on the board, and a second binary plane to indicate whether the target was valid (on the board) or not. This is necessary because for simplicity our policy action space enumerates a superset of all possible actions, not all of which are legal, and we use the same action space for policy prediction and to encode the dynamics function input. The remaining five binary planes are used to indicate the type of promotion, if any (queen, knight, bishop, rook, none).
The encoding for shogi is similar, with a total of 11 planes. We use the first 8 planes to indicate where the piece moved from -either a board position (first one-hot plane) or the drop of one of the seven types of prisoner (remaining 7 binary planes). The next two planes are used to encode the target as in chess. The remaining binary plane indicates whether the move was a promotion or not.
In Atari, an action is encoded as a one hot vector which is tiled appropriately into planes.

Appendix F Network Architecture
The prediction function p k , v k = f θ (s k ) uses the same architecture as AlphaZero: one or two convolutional layers that preserve the resolution but reduce the number of planes, followed by a fully connected layer to the size of the output.
For value and reward prediction in Atari we follow [30] in scaling targets using an invertible transform h(x) = sign(x)( |x| + 1 − 1 + x), where = 0.001 in all our experiments. We then apply a transformation φ to the scalar reward and value targets in order to obtain equivalent categorical representations. We use a discrete support set of size 601 with one support for every integer between −300 and 300. Under this transformation, each scalar is represented as the linear combination of its two adjacent supports, such that the original value can be recovered by x = x low * p low + x high * p high . As an example, a target of 3.7 would be represented as a weight of 0.3 on the support for 3 and a weight of 0.7 on the support for 4. The value and reward outputs of the network are also modeled using a softmax output of size 601. During inference the actual value and rewards are obtained by first computing their expected value under their respective softmax distribution and subsequently by inverting the scaling transformation. Scaling and transformation of the value and reward happens transparently on the network side and is not visible to the rest of the algorithm.
Both the representation and dynamics function use the same architecture as AlphaZero, but with 16 instead of 20 residual blocks [15]. We use 3x3 kernels and 256 hidden planes for each convolution.
For Atari, where observations have large spatial resolution, the representation function starts with a sequence of convolutions with stride 2 to reduce the spatial resolution. Specifically, starting with an input observation of resolution 96x96 and 128 planes (32 history frames of 3 color channels each, concatenated with the corresponding 32 actions broadcast to planes), we downsample as follows: • 1 convolution with stride 2 and 128 output planes, output resolution 48x48.
The kernel size is 3x3 for all operations. For the dynamics function (which always operates at the downsampled resolution of 6x6), the action is first encoded as an image, then stacked with the hidden state of the previous step along the plane dimension.

Appendix G Training
During training, the MuZero network is unrolled for K hypothetical steps and aligned to sequences sampled from the trajectories generated by the MCTS actors. Sequences are selected by sampling a state from any game in the replay buffer, then unrolling for K steps from that state. In Atari, samples are drawn according to prioritized replay [35], with priority P (i) = p α i k p α k , where p i = |ν i − z i |, ν is the search value and z the observed n-step return. To correct for sampling bias introduced by the prioritized sampling, we scale the loss using the importance sampling ratio w i = ( 1 N · 1 P (i) ) β . In all our experiments, we set α = β = 1. For board games, states are sampled uniformly. Each observation o t along the sequence also has a corresponding MCTS policy π t , estimated value ν t and environment reward u t . At each unrolled step k the network has a loss to the value, policy and reward target for that step, summed to produce the total loss for the MuZero network (see Equation 1). Note that, in board games without intermediate rewards, we omit the reward prediction loss. For board games, we bootstrap directly to the end of the game, equivalent to predicting the final outcome; for Atari we bootstrap for n = 10 steps into the future.
To maintain roughly similar magnitude of gradient across different unroll steps, we scale the gradient in two separate locations: • We scale the loss of each head by 1 K , where K is the number of unroll steps. This ensures that the total gradient has similar magnitude irrespective of how many steps we unroll for.
• We also scale the gradient at the start of the dynamics function by 1 2 . This ensures that the total gradient applied to the dynamics function stays constant.
In the experiments reported in this paper, we always unroll for K = 5 steps. For a detailed illustration, see Figure 1.
To improve the learning process and bound the activations, we also scale the hidden state to the same range as the action input ([0, 1]): s scaled = s−min(s) max(s)−min(s) . All experiments were run using third generation Google Cloud TPUs [12]. For each board game, we used 16 TPUs for training and 1000 TPUs for selfplay. For each game in Atari, we used 8 TPUs for training and 32 TPUs for selfplay. The much smaller proportion of TPUs used for selfplay in Atari is due to the smaller number of simulations per move (50 instead of 800) and the smaller size of the dynamics function compared to the representation function. Figure S1: Repeatability of MuZero in Atari for five games. Total reward is shown on the y-axis, millions of training steps on the x-axis. Dark line indicates median score across 10 separate training runs, light lines indicate individual training runs, and the shaded region indicates 25th to 75th percentile.
Elo ratings were computed from the results of a 800 simulations per move tournament between iterations of MuZero during training, and also a baseline player: either Stockfish, Elmo or AlphaZero respectively. Baseline players used an equivalent search time of 100ms per move. The Elo rating of the baseline players was anchored to publicly available values [39].
In Atari, we computed mean reward over 1000 episodes per game, limited to the standard 30 minutes or 108,000 frames per episode [27], using 50 simulations per move unless indicated otherwise. In order to mitigate the effects of the deterministic nature of the Atari simulator we employed two different evaluation strategies: 30 noop random starts and human starts. For the former, at the beginning of each episode a random number of between 0 and 30 noop actions are applied to the simulator before handing control to the agent. For the latter, start positions are sampled from human expert play to initialize the Atari simulator before handing the control to the agent [27].    The policy improvement effect of the search over the raw policy network is clearly visible throughout training. This consistent gap between the performance with and without search highlights the policy improvement that MuZero exploits, by continually updating towards the improved policy, to efficiently progress towards the optimal policy. (D) Policy improvement in Go -a single network was trained at 800 simulations per search and is evaluated at different numbers of simulations per search. In Go, the playing strength improvement from longer searches is much larger than in Ms. Pacman and persists throughout training, consistent with previous results in [40]. This suggests, as might intuitively be expected, that the benefit of models is greatest in precision planning domains. Figure S4: Learning curves of MuZero in Atari for individual games. Total reward is shown on the y-axis, millions of training steps on the x-axis. Line indicates mean score across 1000 evaluation games, shaded region indicates standard deviation. 21