-
-
Notifications
You must be signed in to change notification settings - Fork 197
NNUE
By default Fairy-Stockfish uses a handcrafted evaluation function in order to evaluate chess variant positions. In order to improve playing strength compared to the classical/handcrafted evaluation, variant-specific NNUE (efficiently updatable neural network) evaluation files can be used. An overview of available NNUE evaluation files for variants can be found in the list of networks on the website.
NNUE are efficiently updateable neural networks, which were first applied to shogi, then later also applied to official Stockfish. From there it made its way into Fairy-Stockfish. Several generalizations have been applied to the architecture of the neural network so that it can be used for different board sizes, arbitrary piece types, variants without kings, as well as variants with piece drops. See the wiki of the training code for technical details on these generalizations.
An overview over NNUE in general (not specific to variants or Fairy-Stockfish) can be found in the chessprogramming wiki as well as in the documentation of the training code.
For official Stockfish NNUE networks are trained using https://github.com/glinscott/nnue-pytorch. Variant NNUE evaluation files for Fairy-Stockfish are trained using a fork of that code which contains many generalizations for variants with respect to board size, piece types, etc.
- Variant NNUE training code: https://github.com/fairy-stockfish/variant-nnue-pytorch
- Fairy-Stockfish based training data generation: https://github.com/fairy-stockfish/variant-nnue-tools
Documentation about the data generation and training process is available at https://github.com/fairy-stockfish/variant-nnue-pytorch/wiki. Trained networks can be uploaded using a google form and are then available for download here. The list of networks should be updated accordingly after a new strongest network has been uploaded.
In Fairy-Stockfish NNUE evaluation parameters can either be loaded at runtime from a file or included into the binary at compile-time. There is no functional difference between the two ways of loading them, it is just about convenience and file size. In order to use NNUE evaluation for chess variants in Fairy-Stockfish, you can either download a release with built-in NNUE if you are only interested in Xiangqi, Janggi, and Makruk, or follow the below steps to load NNUE networks at runtime for arbitrary variants:
- Download the NNUE evaluation file you want to use from google drive. You can look up the current best networks in the list of networks.
- Download a compatible Fairy-Stockfish release.
- For HalfKA networks (v2.x) use the latest release, at least Fairy-Stockfish 14.
- For Half(K)A networks after the architecture generalization (>=v2.5) at least Fairy-Stockfish 14.0.1 is required. This mainly applies to variants without one royal king per side (e.g., antichess, horde) or restrictions to the king (Xiangqi/Janggi).
- For old HalfKP networks (v1.x) or
nn.bin
NNUE networks from the shogi community (such as Suisho) use Fairy-Stockfish 13.1.
- For HalfKA networks (v2.x) use the latest release, at least Fairy-Stockfish 14.
- Set the path of the downloaded NNUE file in the
EvalFile
parameter, either in your GUI or via the command line. Make sure that the name of the NNUE file starts with the name of the variant, as the file name is used to detect whether an NNUE file should be used for a given variant. - When you select a variant for which an NNUE file was defined in the
EvalFile
, it will start using NNUE automatically. If the GUI you are using supports to print engine debug output (such as cutechess), you can check there whether Fairy-Stockfish prints a message starting likeNNUE evaluation using ... enabled
to make sure that it correctly detected it.