← Notes

AlphaPoisson: Training Chess Engines in a Weekend

November 16, 2025 · Updated November 7, 2026

AlphaPoisson started at ChessHacks in November 2025, where Mohamed Traore, Shiva Priyan Shanmuga Sundaram and I had a weekend to build a chess engine. We ended up with a family of neural bots you can play against in the browser.

The AlphaPoisson web interface

Learning from games

We trained on existing games rather than self-play, since supervised learning only needs a good dataset. Each position in a game becomes one example, with the move that was played as the target.

Every board becomes a 13-channel 8x8 tensor: twelve channels for the pieces, plus one that marks every square a legal move can reach. The output is a vocabulary of 1,917 moves, built from the moves that appear in the data.

Our first attempt ran on a CPU, on 2.5 million positions from about 49,000 games. Each epoch took around 17 minutes, which is far too slow for a hackathon. Moving to Kaggle GPUs made it practical to compare model sizes and datasets, and our largest dataset reached 8.8 million positions.

Two kinds of bot

All the models share a residual CNN backbone with 64 channels, ranging from 1 to 50 residual blocks. They differ in how they pick a move.

Policy bots run the network once on the current position. We mask out illegal moves, keep the top three, and sample from them by probability. Sampling means the bot doesn’t play the same game every time. On held-out positions, these bots reached 79% top-3 accuracy, meaning the move actually played was among their top three guesses 79% of the time.

Value bots add a second head that predicts the game result from a position, trained with cross-entropy for the policy plus 0.5 times mean squared error for the value. To move, the bot plays out each legal move and scores the resulting position. At first this was a 1-ply search, so it couldn’t see the opponent’s reply.

Making it faster

After the hackathon, I came back to the project to make it faster. The first problem wasn’t the network at all: the server was rebuilding the model and reloading its weights from disk on every move.

The work came down to three changes:

  1. Cache the model so each one loads once per process.
  2. Batch the search so the value bots score many positions in one call instead of one at a time.
  3. Quantize to INT8 with static quantization in ONNX Runtime.

Together, caching and INT8 made policy-bot moves about 77x faster end to end:

Policy bot Reloading every move Cached INT8
15-block 30.6 ms 0.4 ms
50-block 68.9 ms 0.9 ms

Median time per move on an M3, measured in the speed PR, before the search changes below.

Quantization alone accounts for part of that:

Model PyTorch FP32 (batch 1 / 32) ONNX Runtime INT8 (batch 1 / 32) Speedup
8-block policy 1.22 / 19.29 ms 0.16 / 2.90 ms 7.5x / 6.6x
15-block policy 2.90 / 35.16 ms 0.47 / 5.11 ms 6.2x / 6.9x
50-block policy 5.83 / 115.22 ms 0.69 / 16.07 ms 8.5x / 7.2x
1-block value 0.45 / 3.90 ms 0.09 / 1.35 ms 4.8x / 2.9x
8-block value 1.23 / 19.94 ms 0.18 / 3.42 ms 6.8x / 5.8x

Median time per model call, measured after the fixes below.

INT8 makes each call 2.9x to 8.5x faster. A policy bot’s move is a single call, so it takes well under a millisecond. For the value bots, the speedup turns into search depth: at 0.1 to 0.2 ms per call, the search evaluates 2,400 to 3,800 positions within its one-second budget.

What quantization cost

Static quantization needs calibration data to set its scales. I generated it from seeded self-play, so the positions look like the ones the bots actually see. Value models were also calibrated on child positions, since those are what their search evaluates.

The policy head’s large linear layer stayed in FP32. Quantizing it lowered agreement with the FP32 model for only a small speedup, which wasn’t worth it.

Quantization still isn’t free. On 960 self-play positions, across nine models, against their FP32 versions:

  • The INT8 model picked the same top legal move 93.6% of the time on average, ranging from 91.1% to 97.5%.
  • Their top three moves overlapped 95.2% of the time.
  • The value models’ outputs differed by 0.012 to 0.019 on average.

Fixing the bots

The bots still played far worse than their models should allow. Four fixes made the difference, across two PRs. Two were bugs that made the bots play badly no matter how good the models were. The other two made the value bots search better.

White was playing for its opponent

While checking the quantization numbers, I found a bug that had been in the value bots since the hackathon: as White, they played for their opponent.

The value head was trained from the perspective of the side to move, but the search treated its output as White’s perspective. A simple test showed the mismatch. With White up a queen, the 8-block model scored the position 0.85 with White to move and -0.77 with Black to move.

After any move, it’s the opponent’s turn, so the search should negate the value of every position it scores. The old code only did that for Black. Black played correctly, while White picked the position that was best for its opponent.

The fix was to negate the value for both colors:

8-block value bot Wins Draws Losses Hit 200-ply cap
White, before 0 1 9 20
White, after 5 24 1 0
Black, unchanged 6 23 1 0

30 games each against a random mover.

Every bot read its moves from the wrong list

This was the biggest bug. The policy head outputs a probability for each of the 1,917 moves in the vocabulary, and a saved mapping says which output means which move. That mapping matched none of the models: they put only 1% to 3% of their probability on legal moves, about what random guessing gives. Each training run had shuffled the order of the vocabulary, and the order used in training was never saved.

The policy bots were playing close to random legal moves. The value bots were affected too, since their search tried moves in a meaningless order, which made it slow and shallow.

I recovered each model’s real mapping from the models themselves, by matching each output to the moves that are legal whenever it fires. The recovered mappings put 96% to 98% of the probability on legal moves, and each model now ships with its own.

The quantization calibration positions had come from self-play with the broken policy, so I reran the INT8 quantization as well.

Searching ahead

The second PR also replaced the 1-ply search. The value bots now:

  • Look several moves deep: usually three to five within a one-second limit, trying the policy’s preferred moves first.
  • Finish exchanges: they keep following captures before scoring a position, so they don’t grab a pawn and lose a piece.
  • Know when the game is over: checkmate, stalemate and repetition are scored exactly, which fixed most of the draws by repetition.
Value bot Median depth Positions evaluated per move
1-block 3.5 (3 to 5) ~3,800
4-block 3 (2 to 4) ~3,100
8-block 3 (2 to 4) ~2,400

One second per move, over 30 positions.

Scoring positions

Two smaller changes went into how positions are scored:

  • Material: the value model barely noticed material, since a whole extra knight changed its score by only about 0.2. Blending in a simple piece count made it take free pieces much more often.
  • Openings: the value model judges openings poorly and chose moves like 1.f3. A small bonus for the policy’s preferred moves fixed that, and it now plays normal openings such as the Sicilian.

Where it stands

Before the fixes After
Policy bots Near-random moves Real moves
Value bots as White Played for the opponent Correct
Search One move ahead 3 to 5 moves deep, plus captures
Free queen test Often missed Taken by every value model
Openings 1.f3, 1.f4 1.e4 c5 2.Nf3 d6

The new 8-block bot beat the first version of the second PR 10-0. The value model itself is unchanged and still judges quiet positions poorly, so retraining it on engine evaluations is the next big step.

Both bugs survived for the same reason: everything else still worked. The bots played legal moves, the server responded, and my quantization agreement numbers looked fine, since they compared two models with the same bug against each other. Thirty games against a random mover, or a check of how much probability lands on legal moves, would have caught them right away. An engine needs a test of whether it wins, not just whether it runs.

The code is on GitHub.

References

[1] nikonoel. Lichess Elite Database. The filtered high-rated games behind our elite models.

[2] He, K., et al. “Deep Residual Learning for Image Recognition.” CVPR 2016. The residual blocks our backbone is built from.

[3] Oshri, B. & Khandwala, N. “Predicting Moves in Chess using Convolutional Neural Networks.” Stanford CS231n. 2015. An early example of predicting chess moves with a CNN.

[4] Silver, D., et al. “Mastering the game of Go with deep neural networks and tree search.” Nature 529. 2016. Pairs policy and value networks, with supervised training on human games.

[5] Silver, D., et al. “A general reinforcement learning algorithm that masters chess, shogi, and Go through self-play.” Science 362. 2018. AlphaZero, which applies a policy and value network to chess through self-play.

[6] McIlroy-Young, R., et al. “Aligning Superhuman AI with Human Behavior: Chess as a Model System.” KDD 2020. Maia, an AlphaZero-style model trained on human games.

[7] Jacob, B., et al. “Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference.” arXiv:1712.05877. 2017. The 8-bit integer inference approach behind quantization like ours.

[8] ONNX Runtime. “Quantize ONNX models.” Documentation for the static quantization tools used here.