A transformer-based chess model trained on grandmaster games. The model learns chess patterns from move sequences without prior knowledge of rules.
- GPT-2 Medium architecture (303M parameters)
- Trained on 180K+ master-level games (1800+ Elo)
- Outcome-based learning (trains on winning player's moves)
- Two-phase training: general chess → checkmate specialization
- Unified training workflow with automatic model versioning
Install dependencies with Poetry:
# For training and playing (requires GPU)
poetry install --with model
# For data processing only
poetry install --without modelpoetry run explore# Unified training command
poetry run train --config phase1_gpt2_medium --name my-model
# View trained models
poetry run models list
# Play against your model
poetry run play --model my-modelBefore training, prepare data and tokenizer once:
# 1. Extract games from PGN
poetry run reduce-pgn --input-pgn-file data/lichess.pgn --output-dir out
# 2. Convert to training format
poetry run prepare-training-data \
--input-reduced-pgn-file out/master.txt \
--output-training-data-file out/training.csv \
--output-validation-data-file out/validation.csv \
--max-context-length 100
# 3. Create tokenizer (only needed once)
poetry run fit-and-save-tokenizer \
--input-training-data-file out/training.csv \
--output-tokenizer-file out/chess_tokenizer.jsonOnce data is prepared, use the unified training command:
poetry run train --config phase1_gpt2_medium --name gpt2-baselineThis handles model creation, training, checkpointing, and automatic registry. Configuration files in configs/ specify architecture, hyperparameters, and data paths.
For checkmate-focused training:
# Phase 1: General chess (157K examples, 8 epochs)
poetry run train --config phase1_gpt2_medium --name model-phase1
# Phase 2: Checkmate specialization (resume from Phase 1)
poetry run train --config phase2_gpt2_medium --name model-phase2 \
--resume-from models/model-phase1/checkpoint-best# List all trained models
poetry run models list
# Show model details
poetry run models show <model-name>
# Compare two models
poetry run models compare model-a model-b
# Tag and organize models
poetry run models tag <model-name> production
# Set recommended model
poetry run models recommend <model-name>Run validation tests:
# Test checkmate ability
poetry run python scripts/test_checkmate_ability.py --model <model-name>
# Test model predictions
poetry run python scripts/test_model_predictions.py --model-dir models/<model-name>/final_modelTraining is configured via YAML files in configs/:
configs/model/- Model architectures (GPT-2 Medium, etc.)configs/training/- Training hyperparametersconfigs/data/- Dataset paths and preprocessingconfigs/pipeline/- Complete training pipelines
Override settings via CLI:
poetry run train --config phase1_gpt2_medium --name my-model --tags experimentalGames are represented as space-separated move sequences:
d4 e6 Nf3 g6 Bg5 Bg7 Bxd8 1-0
e4 c5 Nf3 e6 d4 cxd4 Nxd4 1/2-1/2
The model learns from these sequences using outcome-based masking (only trains on winning player's moves for decisive games).
GPT-2 Medium:
- 303M parameters (24 layers, 1024 embedding dim, 16 heads)
- Context length: 100 moves
- Vocabulary: 287 unique chess moves
- Mixed precision (bfloat16) for M1/M2 Macs
MIT