AlphaZero & MuZero: Search + Learning in One Loop
In the search-and-learning lesson we sketched the recipe: a network gives MCTS a prior, MCTS gives the network a target, the loop closes. Here we open the hood. We derive the PUCT formula AlphaZero actually uses, write down its loss term by term, and then watch MuZero strip away the one assumption AlphaZero still depends on, the simulator. What's left is the same recipe applied to Atari, Go, chess, shogi, and (in 2024) Olympiad math. Three networks, three losses, one self-play loop.
After this lesson, you will be able to:
- Derive PUCT, the AlphaZero variant of UCB1, and explain exactly what term the neural policy adds to the standard exploration bonus
- Write down the AlphaZero loss (value MSE + policy cross-entropy + L2) term by term and understand why each piece is needed
- Distinguish AlphaZero (needs a perfect simulator) from MuZero (learns a latent dynamics), and trace MuZero's three networks: representation, dynamics, prediction
- Read MuZero's K-step unrolled loss and explain why K > 1 is required to keep the learned dynamics from collapsing
- Connect the AlphaZero recipe to modern reasoning systems, AlphaProof, AlphaGeometry, and the o1/R1 lineage of math-and-code RL
Before you start
Don't be intimidated by the names. AlphaZero and MuZero are just MCTS with a smarter prior, trained by self-play. Once you've seen the three equations (PUCT, AZ loss, MuZero loss) the rest is engineering.
#What AlphaZero Actually Is
Concretely, the single AlphaZero network is
(π, v) = f_θ(s)s is the raw board state (no human features), π is a probability distribution over legal actions, and v ∈ [-1, 1] is the predicted value of s from the current player's perspective. One forward pass, two outputs. Silver et al. 2017 ("Mastering the Game of Go without Human Knowledge") used a ResNet with 20–40 blocks; newer reproductions often swap in a transformer.#PUCT: Adding a Neural Prior to UCB1
Standard MCTS uses UCB1 to choose which child to descend during selection:
P(s, a) directly into the selection rule. This is the PUCT formula:Three things change between UCB1 and PUCT:
- The denominator becomes
1 + N(s, a)instead ofN(s, a): no special-case for unvisited children, the prior already biases toward them. - The numerator becomes
√N(s)instead of√(ln N(s)): grows faster, gives the prior longer-lasting influence. - The bonus is multiplied by
P(s, a): the network's prior on this move.
If the network is uniform (every move equally likely), PUCT is roughly UCB1 with a different schedule. If the network is sharp, PUCT spends almost all the simulation budget on the moves the network believes in, which is what you want with a finite simulation count and a 250-wide branching factor.
Where do the simulations actually go? The derivation below freezes the Q values and finds where PUCT's visits settle. The answer has a closed form, and it is a policy improvement over the prior.
MuZero keeps this selection rule but replaces the constant c by a slowly growing factor c(N) = c1 + log((N + c2 + 1) / c2), with c1 = 1.25 and c2 = 19652 (MuZero paper, appendix B), and it rescales Q to the range 0 to 1 using the smallest and largest values seen in the tree.
PUCT vs UCB1: what does PUCT add that UCB1 lacks?
#The Four Phases: With a Network at the Leaves
The four MCTS phases (selection, expansion, simulation, backup) survive into AlphaZero, but two of them change in important ways:
- Selection. Walk down the tree from the root, picking the child that maximizes PUCT, until you reach a node that hasn't been expanded.
- Expansion. Add the new node. Query the network:
(P, v) = f_θ(s_new). Initialize children's priors toP, set the new node's value tov. - Simulation. No random rollouts. Classic MCTS plays random moves from the leaf until the game ends: slow and noisy on Go. AlphaZero replaces this entire phase with the network's value estimate
v. One forward pass instead of a full random game. - Backup. Walk back to the root, incrementing
N(s, a)and updatingQ(s, a)as a running mean of the value estimates seen along the path. Crucially, when backing up across a turn change in a two-player game, flip the sign: a position that's good for me is bad for you.
π_MCTS(a | s) ∝ N(s, a)^(1/τ)τ is a temperature. AlphaZero's paper says the search returns a distribution over moves "either proportionally or greedily with respect to the visit counts at the root state": in practice τ = 1 (proportional) in the opening of self-play games for exploration, then τ → 0 (greedy on visit count); the exact cutoff is a per-game setting, not a universal constant. Visit count, not Q, because the most-visited child is the one MCTS has the most evidence about, while a high-Q but rarely-visited child might be an optimistic outlier.Why does AlphaZero use the visit-count distribution π_MCTS(a|s) ∝ N(s,a)^(1/τ) as its policy target instead of the network's own output π?
#Self-Play: Where the Targets Come From
θ_0, no pretraining, no human games, no opening book. Then:- The current network
θ_tplays many games against itself. Each move uses MCTS guided byθ_t. - For every visited state
s, record the MCTS visit distributionπ_MCTS(a | s): this becomes the policy target. - When the game ends with result
z ∈ {-1, 0, +1}(from the player-to-move's perspective in each position), assignzas the value target for every state in the game. - Train
θ_{t+1}by gradient descent on the loss below using a buffer of recent self-play data. - Replace
θ_t←θ_{t+1}. Repeat for millions of games.
That's the entire training loop. No human expert data, no curriculum, no demonstrations. The only inputs are the rules of the game (for the simulator) and the initial state.
#The AlphaZero Loss
A few things to internalize about this loss:
- The value MSE forces the network to be calibrated. If the network says
v = 0.8for a position and the game ends in a loss (z = -1), the gradient pullsvdown. Over millions of self-play games,v_θ(s)converges to the true expected outcome under the search-augmented policy. - The cross-entropy is KL divergence in disguise. Up to constants in
π_MCTS, minimizing-π_MCTS · log pis the same as minimizingKL(π_MCTS || p_θ). The network is being pulled to match the MCTS distribution. - There is no separate "policy gradient" term. AlphaZero is not REINFORCE. It's pure supervised learning, where the labels come from MCTS rollouts.
- L2 is essential. Without it, the network overfits the recent replay buffer and self-play diversity collapses: every game becomes a copy of the last.
The first two terms of the loss have a precise meaning that follows from two short derivations. The L2 term is a penalty chosen by design, not a result, so it has no derivation.
AlphaProof, DeepMind's 2024 IMO silver-medalist, is best described as AlphaZero applied to what domain?
#MuZero: AlphaZero Without the Simulator
s_k has no fixed meaning. It's whatever vector the dynamics network finds useful for predicting reward and value. It doesn't have to match the actual Atari frame, the actual board position, or anything physically interpretable. The training loss is the only thing that constrains it.#MuZero's K-Step Loss
K steps from each training position and demands consistency across all of them:Three details worth dwelling on:
- Why K > 1 is essential. If K = 0, the dynamics network never has to produce a useful next latent: only the representation head matters. If K = 1, the dynamics is constrained at one step out, but nothing prevents it from "forgetting" the action by step 2. K = 5 (the value used in MuZero) forces five consecutive single-step predictions to all be consistent with real observed rewards and bootstrapped returns. The dynamics has to encode information about the action long enough to predict rewards five steps later.
z_kis a bootstrapped n-step return. Specifically,z_k = ∑_{i=0}^{n-1} γ^i r_{t+k+i+1} + γ^n ν_{t+k+n}, whereνis the search value at the root n steps later (MuZero paper, section 3); in board games there are no intermediate rewards andzis simply the final game outcome. This is the samen-step TD target used elsewhere in deep RL: it interpolates between Monte Carlo (high variance, unbiased) and one-step bootstrapping (low variance, biased).- The policy target
π_MCTS,kcomes from MCTS run in real environment time, not in latent space. During self-play, you run MCTS at every real timestep and record its visit distribution. During training, those distributions become targets at the corresponding latent step.
In MuZero's K-step loss, why is K > 1 essential? What would break if you trained with K = 1?
MuZero uses three separate networks. Match them to their roles:
#Why MuZero's Killer Feature Is Its Generality
AlphaZero needs the rules of the game. MuZero needs only four things:
- A stream of observations
o_0, o_1, o_2, ...: pixels, sensor readings, raw text tokens, whatever. - A discrete action space: must be enumerable (so MCTS can branch over it).
- A scalar reward signal
r_t: even sparse rewards (zero everywhere except at game-end) work. - A done flag: when each episode terminates.
#The Recipe Outside Games: AlphaProof and Reasoning RL
The same loop now powers reasoning models. The mapping is direct:
| AlphaZero on Go | AlphaProof / Reasoning RL |
|---|---|
Board state s | Partial proof / partial reasoning trace |
| Legal moves | Tactic applications / next-token candidates |
Network f_θ(s) = (π, v) | LLM head, policy over next tokens, value of partial solution |
Game result z ∈ {-1, +1} | Verifier verdict, proof checker, code executor, math grader |
| Self-play | Self-generation of attempted solutions |
| MCTS over moves | Search over reasoning steps / tree-of-thought |
#Practical Hyperparameters (Silver 2017 + Schrittwieser 2020)
Reproductions of AlphaZero and MuZero converge on a similar set of numbers, which is useful both for sanity-checking your own implementation and for understanding the compute budget.
- Simulations per move at training time. Go: 800. Chess/shogi: 800. Atari (MuZero): 50. The training process is robust to lowering this; the played strength at deployment scales roughly linearly with simulations per move.
c_puct. Typically 1.0–2.5. MuZero replaces the constant with c(N) = c1 + log((N + c2 + 1) / c2), with c1 = 1.25 and c2 = 19652 (paper, appendix B). Larger values bias toward exploration; smaller values trust the network's prior more.- Dirichlet noise at the root. Mix Dirichlet noise into the prior at the root for exploration:
P' = (1 - ε) P + ε ηwithη ~ Dir(α). AlphaZero usedα = 0.3for chess,0.15for shogi and0.03for Go, scaled in inverse proportion to the typical number of legal moves. Without it, self-play collapses to a single deterministic policy and stops generating diverse data. - Replay buffer size. Order of 1M positions (Go) to 10M (Atari). Older self-play data ages out.
- Network depth. Go uses 20–40 ResNet blocks. Modern reproductions use transformers of comparable parameter count.
- Training scale. Original AlphaZero Go: ~5M games of self-play across thousands of TPUs. MuZero on Atari: ~1B environment steps. Educational reproductions on toy games (tic-tac-toe, Connect 4) converge in minutes on a laptop.
#Build It: AlphaZero on Tic-Tac-Toe
The playground below is a complete, runnable AlphaZero implementation on a 3x3 tic-tac-toe board. It uses a tiny two-layer policy/value network, runs MCTS with PUCT, generates self-play games, and trains the network on the AlphaZero loss. After 100 self-play games and 200 gradient steps, the win rate against a random opponent climbs from ~33% (chance for the first player on tic-tac-toe) to near-perfect.
Edit anything. Try:
- Setting
C_PUCT = 0.1(network trusted too much) orC_PUCT = 10(search too random) and watch training stall. - Setting
N_SIMS = 5and noting how the learned policy gets noisy. - Setting
SELFPLAY_GAMES = 5and watching the value head fail to converge for lack of data.
What to look for in the output:
- The first eval line (before any training) is close to random: roughly the chance a first-mover gets on tic-tac-toe.
- By 60–80 self-play games, losses should drop near zero. Tic-tac-toe is a draw under optimal play, so a fully-trained agent draws or wins but never loses against random.
- The losses-going-to-zero behavior is the AlphaZero loop visibly working in your browser. There is no domain knowledge in this script: only the rules of tic-tac-toe in
step()andwinner().
#Where This Goes Next
A frontier since 2024 is applying the AlphaZero recipe to domains that aren't board games. The recipe needs three ingredients:
- A model. AlphaZero needs a simulator; MuZero needs only an observation stream. For LLM reasoning, the model is the language model itself acting as both policy and dynamics: every generated token is both a "move" and the next "state."
- A verifier. Game outcome for Go; Lean proof checker for AlphaProof; unit tests for code RL; math graders for o1/R1. Without a verifier, MCTS has nothing to back up. RLHF's learned reward model is a noisy substitute that introduces gaming.
- A search procedure over a discrete-enough action space. AlphaZero searches over board moves; AlphaProof over tactic applications; reasoning RL over CoT branches or tool calls. Continuous high-dimensional actions (robotics) push toward MCTS variants or policy gradient methods instead.
When all three are present (a model, a verifier, and a search) the AlphaZero loop applies. When any is missing, you get something weaker (RLHF, behavior cloning, vanilla policy gradient). The bet behind reasoning RL is that more and more domains will become verifier-rich as auto-grading, formal methods, and tool execution mature.
Key takeaways
- AlphaZero is a loop: MCTS turns the network's policy into a stronger policy, the network is trained to imitate the search (policy loss) and to predict the game outcome (value loss), and self-play generates all the data.
- PUCT is UCB1 with the network's prior as a multiplier on the exploration bonus, so the search spends simulations where the network already thinks moves are promising.
- The AlphaZero loss has three terms: value mean-squared error against the outcome z, cross-entropy against the MCTS visit distribution, and L2 weight decay.
- MuZero removes the simulator: a representation network, a dynamics network and a prediction network let MCTS run entirely in a learned latent space, trained with a K-step unrolled loss.
- The recipe needs a model, a verifier and a search over a discrete-enough action space; where one is missing, weaker methods such as RLHF or behavior cloning are used instead.
In AlphaZero, what is the training target for the policy head?