python3 -m venv env
source env/bin/activate
pip install python-chess==0.31.4 pytorch-lightning torch matplotlib
This requires a C++17 compiler.
Windows:
compile_data_loader.bat
Linux/Mac:
sh compile_data_loader.bat
source env/bin/activate
python train.py train_data.bin val_data.bin
python train.py --resume_from_checkpoint <path> ...
python train.py --gpus 1 ...
By default the trainer uses a factorized HalfKP feature set (named "HalfKP^")
If you wish to change the feature set used then you can use the --features=NAME
option. For the list of available features see --help
The default is:
python train.py ... --features="HalfKP^"
--smart-fen-skipping
currently skips over moves where the king is in check, or where the bestMove is a capture (typical of non-quiet positions).
--random-fen-skipping N
skip N fens on average before using one. Uses fewer fens per game, useful with large data sets.
python train.py --smart-fen-skipping --random-fen-skipping 10 --batch-size 16384 --threads 8 --num-workers 8 --gpus 1 trainingdata validationdata
best nets have been trained with 16B d9-scored nets, training runs >200 epochs
Using either a checkpoint (.ckpt
) or serialized model (.pt
),
you can export to SF NNUE format. This will convert last.ckpt
to nn.nnue
, which you can load directly in SF.
python serialize.py last.ckpt nn.nnue
Import an existing SF NNUE network to the pytorch network format.
python serialize.py nn.nnue converted.pt
Visualize a network from either a checkpoint (.ckpt
), a serialized model (.pt
)
or a SF NNUE file (.nnue
).
python visualize.py nn.nnue --features="HalfKP"
Visualize the difference between two networks from either a checkpoint (.ckpt
), a serialized model (.pt
)
or a SF NNUE file (.nnue
).
python visualize.py nn.nnue --features="HalfKP" --ref-model nn.cpkt --ref-features="HalfKP^"
pip install tensorboard
tensorboard --logdir=logs
Then, go to http://localhost:6006/
python run_games.py --concurrency 16 --stockfish_exe ./stockfish.master --c_chess_exe ./c-chess-cli --ordo_exe ./ordo --book_file_name ./noob_3moves.epd run96
Automatically converts all .ckpt
found under run96
to .nnue
and runs games to find the best net. Games are played using c-chess-cli
and nets are ranked using ordo
.
This script runs in a loop, and will monitor the directory for new checkpoints. Can be run in parallel with the training, if idle cores are available.
- Sopel - for the amazing fast sparse data loader
- connormcmonigle - https://github.com/connormcmonigle/seer-nnue, and loss function advice.
- syzygy - http://www.talkchess.com/forum3/viewtopic.php?f=7&t=75506
- https://github.com/DanielUranga/TensorFlowNNUE
- https://hxim.github.io/Stockfish-Evaluation-Guide/
- dkappe - Suggesting ranger (https://github.com/lessw2020/Ranger-Deep-Learning-Optimizer)