pylos⁠ (opens in a new tab)

Play Pylos against a transformer trained by self-play reinforcement learning.

How it works

The model is a transformer with 411,000 parameters. It reads the 30 cells as tokens, each empty, its own or its opponent's, with one more token for the reserves. It outputs a probability for each legal move and its chance of winning. It learned only by playing against itself with Gumbel AlphaZero (Danihelka et al., 2022): 139,000 games in 20 minutes on a $350 GPU.

Pylos architecture A position becomes 31 tokens: a global token, a linear map of both reserves and the phase of the turn, and one token per cell of the pyramid, the embedding of its state plus a vector for the cell. Two encoder blocks of width 128 follow, each a pre-LayerNorm attention with 4 heads and an MLP from 128 to 256 to 128, both added back to the stream. From the global token, a policy head gives probabilities for 961 moves and a value head the chance of winning. In self-play, the search scores each sampled move by the value of the position after it. Gumbel noise added to the log-probabilities chooses which moves are searched and which is played. The policy target is softmax(log p + σ(q)), the network's log-probabilities plus a bonus that grows with the value after each move, and the loss adds the cross-entropy of the network's probabilities against this target to the cross-entropy of the value head against the game's result. Over 139,483 games in 20 minutes on one GPU, this loop took the network from random play to beating a 3-turn alpha-beta search 96% of the time. Pylos architecture Encoder-only transformer, 411,076 parameters, trained by self-play A Model B Training target Position reserves 12 and 12 phase: place [g] 31 tokens Linear reserves, phase Embedding state + cell vector Encoder block × 2 width 128 LayerNorm, attention, 4 heads LayerNorm, MLP 128→256→128 [g] Policy head 961 moves Value head win, draw, loss Move probabilities Chance of winning One position, 6 legal moves move 1 2 3 4 5 6 p network .35 .25 .15 .12 .08 .05 g Gumbel noise +0.3 +1.2 -0.4 +1.6 -0.2 +0.5 searched yes yes yes yes no no q value after -0.3 +0.5 +0.1 +0.4 +0.1 +0.1 σ value bonus 0.0 5.1 2.6 4.5 2.5 2.5 5.1 × q rescaled -0.7 4.9 0.3 3.9 Move played max of log p + g + σ among searched moves Target softmax(log p + σ) .01 .74 .03 .19 .02 .01 Loss = policy + value policy: cross-entropy of p against the target value: cross-entropy of the value head against who won The noise g never enters the target. Searched: the top 4 by log p + g, 16 in training, one visit each. Grey values are estimates. Over 139,483 games in 20 minutes on one GPU, this loop took the network from random play to beating a 3-turn alpha-beta search 96% of the time.
Pylos architecture A position becomes 31 tokens: a global token, a linear map of both reserves and the phase of the turn, and one token per cell of the pyramid, the embedding of its state plus a vector for the cell. Two encoder blocks of width 128 follow, each a pre-LayerNorm attention with 4 heads and an MLP from 128 to 256 to 128, both added back to the stream. From the global token, a policy head gives probabilities for 961 moves and a value head the chance of winning. In self-play, the search scores each sampled move by the value of the position after it. Gumbel noise added to the log-probabilities chooses which moves are searched and which is played. The policy target is softmax(log p + σ(q)), the network's log-probabilities plus a bonus that grows with the value after each move, and the loss adds the cross-entropy of the network's probabilities against this target to the cross-entropy of the value head against the game's result. Over 139,483 games in 20 minutes on one GPU, this loop took the network from random play to beating a 3-turn alpha-beta search 96% of the time. Pylos architecture Encoder-only transformer, 411,076 parameters, trained by self-play A Model Position reserves 12 and 12 phase: place [g] 31 tokens Linear reserves, phase Embedding state + cell vector Encoder block × 2 width 128 LayerNorm, attention, 4 heads LayerNorm, MLP 128→256→128 [g] Policy head 961 moves Value head win, draw, loss Move probabilities Chance of winning B Training target One position, 6 legal moves move 1 2 3 4 5 6 p network .35 .25 .15 .12 .08 .05 g Gumbel noise +0.3 +1.2 -0.4 +1.6 -0.2 +0.5 searched yes yes yes yes no no q value after -0.3 +0.5 +0.1 +0.4 +0.1 +0.1 σ value bonus 0.0 5.1 2.6 4.5 2.5 2.5 5.1 × q rescaled -0.7 4.9 0.3 3.9 Move played max of log p + g + σ among searched moves Target softmax(log p + σ) .01 .74 .03 .19 .02 .01 Loss = policy + value policy: cross-entropy of p against the target value: cross-entropy of the value head against who won The noise g never enters the target. Searched: the top 4 by log p + g, 16 in training, one visit each. Grey values are estimates. Over 139,483 games in 20 minutes on one GPU, this loop took the network from random play to beating a 3-turn alpha-beta search 96% of the time.

On this page, before each move, it tries its 16 likeliest moves and scores the position after each with its own estimate. It then looks further ahead on the better half, then on the best four and the best two, 64 positions in all. Here it won 383 of 400 games against an alpha-beta search three turns deep. The rules and the search are written in Rust and compiled to WebAssembly for this page.

Self-play used a cheaper search, which sampled 16 moves and scored each once. The training target multiplies the probability of each move by the exponential of a bonus that grows with its value after the move, then renormalises. This is the form of the optimal policy in KL-regularised reinforcement learning, π* ∝ π_ref · exp(r/β): the model is the reference policy, the search's values are the reward, and a factor of 5.1 plays the role of 1/β. Training the policy head toward this target is distillation from a teacher, the search, that is one step smarter than the student. The value head learns who wins.