
Training an RL agent to play 2048 with MCTS
Published on September 17, 2024 by Zoey Drassinower
monte carlo tree search mcts reinforcement learning deep mind alphazero muzero uct 2048 python
3 min READ
Version 1 of the project attempted to train an agent to play 2048 using Deep Mind’s DQN Algorithm.
This version continues the trend of exploring Deep Mind’s latest work, this time training a 2048 agent with AlphaZero. Specifically, this project aims to implement the scheme outlined in the Stochastic MuZero Paper. While the focus of the paper is the novel Stochastic MuZero algorithm, it also includes a scheme for training an AlphaZero agent in 2048, which is then used to benchmark Stochastic MuZero. It is this AlphaZero scheme which I implement in this project.
AlphaZero supplements “vanilla” reinforcement learning with a variety of novel ideas. These ideas bridge the gap from theory to practice, and are what separates succesful and unsuccessful models. Below I’ve summarized what I believe to be the key ideas for this implementation of AlphaZero.
MCTS is an algorithm for value estimate and policy generation. It uses the current network’s policy and value estimates to produce an improved policy and value estimate for the agent’s current state. This project uses a specific variant of MCTS called Upper Confidence Bounds Applied to Trees, aka UCT. For an in-depth explanation, check out my blog post MCTS, (Deep Mind Edition).
AlphaZero divides training loop into 2 jobs: acting and learning.
Neural networks are incredibly finicky. It turns out that a great deal of care is required when choosing representations for states, actions, and network outputs. If the wrong representations are chosen, the network weights will blow up to infinity, and the learning process will fail. Here are a few of the techniques used by Deep Mind in the MuZero paper.
AlphaZero uses a single deep neural network following the ResNet v2 architecture with Layer Normalization. Both layer normalization and the resnet architecture work to keep the magnitude of layer activations consistent (and bounded) within the network. This structure helps control the magnitude of gradients, effectively stabilizing learning.
The original DQN paper found that too much variance in the magnitude of network targets can interfere with training, and de-stabilize the network. Their solution was to clip rewards to the range [-1, +1]. Later papers found that this is an imperfect solution, and proposed an improved reward transformation. Scaling rewards in this
Wherever possible, inputs and outputs are represented as either one-hot or categorical vectors. This has 3 effects: