Skip to main content
QUICK REVIEW

[Paper Review] Mastering Chess with a Transformer Model

Daniel Monroe, Chalmers, Philip A.|arXiv (Cornell University)|Sep 18, 2024
Artificial Intelligence in GamesComputer Science3 citations
TL;DR

This paper introduces ChessFormer, a transformer-based architecture for chess that leverages a versatile position encoding scheme from Shaw et al. to achieve state-of-the-art playing strength and puzzle-solving performance at a fraction of the computational cost. It outperforms AlphaZero at 8x fewer FLOPS and matches grandmaster-level agents at 30x fewer FLOPS, demonstrating that domain-specific inductive biases in position encoding are critical for efficient self-attention in chess.

ABSTRACT

Transformer models have demonstrated impressive capabilities when trained at scale, excelling at difficult cognitive tasks requiring complex reasoning and rational decision-making. In this paper, we explore the application of transformers to chess, focusing on the critical role of the position representation within the attention mechanism. We show that transformers endowed with a sufficiently expressive position representation can match existing chess-playing models at a fraction of the computational cost. Our architecture, which we call the Chessformer, significantly outperforms AlphaZero in both playing strength and puzzle solving ability with 8x less computation and matches prior grandmaster-level transformer-based agents in those metrics with 30x less computation. Our models also display an understanding of chess dissimilar and orthogonal to that of top traditional engines, detecting high-level positional features like trapped pieces and fortresses that those engines struggle with. This work demonstrates that domain-specific enhancements can in large part replace the need for model scale, while also highlighting that deep learning can make strides even in areas dominated by search-based methods.

Motivation & Objective

  • To investigate whether transformer models can achieve high performance in chess with significantly reduced computational cost compared to existing methods.
  • To evaluate the impact of different position encoding schemes—absolute, relative, and learnable relative encodings—on transformer performance in chess.
  • To demonstrate that a well-designed position encoding can enable transformers to match or exceed the performance of specialized architectures like AlphaZero and grandmaster-level agents.
  • To provide a scalable, open-source training framework for training efficient, high-strength chess agents using self-supervised self-play.

Proposed method

  • Adopt the self-attention mechanism with scaled dot-product attention, where query, key, and value projections are computed from input tokens.
  • Integrate a learnable relative position encoding (from Shaw et al.) that introduces learnable vectors $a_{ij}^Q$, $a_{ij}^K$, and $a_{ij}^V$ to model positional relationships between chess squares.
  • Train the model via self-play using Monte Carlo Tree Search (MCTS) with a policy head predicting move probabilities and a value head predicting game outcomes.
  • Use a dual-head architecture: one for policy (move selection) and one for value (position evaluation), both trained via self-supervised self-play.
  • Apply input representations that encode chess positions as a sequence of 64 square features, including piece types and colors, with learnable position embeddings.
  • Optimize the model using a combination of policy and value loss, with temperature scaling and label smoothing to improve training stability.
Figure 1 : Elo strength comparison of agents constructed from our CF-6M and CF-240M models against prior art. Our evaluation methodology is described in Section 4 .
Figure 1 : Elo strength comparison of agents constructed from our CF-6M and CF-240M models against prior art. Our evaluation methodology is described in Section 4 .

Experimental results

Research questions

  • RQ1Can a transformer-based architecture achieve competitive chess-playing strength with significantly reduced FLOPS compared to AlphaZero and other grandmaster-level agents?
  • RQ2How does the choice of position encoding (absolute, relative bias, or learnable relative) affect the performance of transformers in chess?
  • RQ3To what extent can a versatile position encoding that captures non-Euclidean relationships (e.g., diagonals) improve attention efficiency and model accuracy?
  • RQ4Can a lightweight transformer model trained via self-play match or exceed the performance of larger, more complex models in both gameplay and puzzle-solving?
  • RQ5What is the impact of architectural choices such as input representation and auxiliary heads on convergence and final strength?

Key findings

  • The ChessFormer model with the Shaw et al. position encoding outperforms AlphaZero in both Elo rating and puzzle-solving accuracy at 8x fewer FLOPS.
  • At 30x fewer FLOPS, the CF-240M-policy model matches the puzzle-solving accuracy of the grandmaster-level GC-270M agent and exceeds its Elo performance.
  • The ablation study confirms that the learnable relative position encoding from Shaw et al. significantly outperforms both absolute and relative bias encodings in both value loss and policy accuracy.
  • Doubling the model size from 6M to 12M parameters increased policy accuracy by approximately 1.5%, indicating strong scaling behavior.
  • The CF-6M-policy agent achieves superior puzzle-solving and Elo performance compared to AlphaZero-policy, despite using only 1/8th the FLOPS.
  • The open-source training code has been released at https://github.com/Ergodice/lczero-training, enabling reproducibility and further research in efficient chess AI.
Figure 2 : Puzzle-solving ability on puzzles rated 1000-3000 of our CF-240M-policy and CF-240M-value agents against the GC-136M and GC-270M agents of Ruoss et al. [ 9 ] .
Figure 2 : Puzzle-solving ability on puzzles rated 1000-3000 of our CF-240M-policy and CF-240M-value agents against the GC-136M and GC-270M agents of Ruoss et al. [ 9 ] .

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.