The NNUE curse.

Post Reply
User avatar
massimilianogoi
Site Admin
Posts: 369
Joined: Thu Aug 04, 2022 1:42 pm
Has thanked: 569 times
Been thanked: 608 times
Contact:

The NNUE curse.

Post by massimilianogoi »

The latest night I stumbled across an interesting chat on Playchess. There were users unhappy of this so high draw rate. They blamed the chess engines 'AI' and 'Zeus' and the opening books. But what they ignored is that this so high draw rate is only due to the NNUE net of Stockfish. This file is a compilation of pre-made position analyses from very powerful computer and if I recall correttly it's sized 40 megabytes, large enough to cover the greatest part of the moves until the middlegame. The elo gain of 100-200 of a couple of years ago came with a price.

Now the only hope we have to get out from this draw curse is that something stronger comes out.
People who have lost the hope.
User avatar
massimilianogoi
Site Admin
Posts: 369
Joined: Thu Aug 04, 2022 1:42 pm
Has thanked: 569 times
Been thanked: 608 times
Contact:

Re: The NNUE curse.

Post by massimilianogoi »

Here is how a NNUE network is made and how it works, for those interested:

[quote][b]Training Guide[/b]

Generating Training Data
To generate training data from the classic eval, use the gensfen command with the setting "Use NNUE" set to "false". The given example is generation in its simplest form. There are more commands.

uci
setoption name PruneAtShallowDepth value false
setoption name Use NNUE value false
setoption name Threads value x
setoption name Hash value y
setoption name SyzygyPath value path
isready
gensfen depth a loop b use_draw_in_training_data_generation 1 eval_limit 32000
depth is the searched depth per move, or how far the engine looks forward. This value is an integer.
loop is the amount of positions generated. This value is also an integer.
Specify how many threads and how much memory you would like to use with the x and y values. The option SyzygyPath is not necessary, but if you would like to use it, you must first have Syzygy endgame tablebases on your computer, which you can find here. You will need to have a torrent client to download these tablebases, as that is probably the fastest way to obtain them. The path is the path to the folder containing those tablebases. It does not have to be surrounded in quotes.

This will create a file named "generated_kifu.binpack" in the same folder as the binary containing the generated training data. Once generation is done, you can rename the file to something like "1billiondepth12.binpack" to remember the depth and quantity of the positions and move it to a folder named "trainingdata" in the same directory as the binaries.

You will also need validation data that is used for loss calculation and accuracy computation. Validation data is generated in the same way as training data, but generally at most 1 million positions should be used as there's no need for more and it would just slow the learning process down. It may also be better to slightly increase the depth for validation data. After generation you can rename the validation data file to "val.binpack" and drop it in a folder named "validationdata" in the same directory to make it easier.

More information about gensfen and available options can be found in the docs

[b]Training a network[/b]

Training a Completely New Network
Whether a new network is created or not is controlled by the UCI option SkipLoadingEval. If set to true then a new network will be created, which allows learning from scratch. If left at its default (false) then a network will be loaded and trained further. The second scenario is described in the reinforcement learning paragraph.

A simple command chain to start with training could look like this:

uci
setoption name EnableTranspositionTable value false
setoption name PruneAtShallowDepth value false
setoption name SkipLoadingEval value true
setoption name Use NNUE value pure
setoption name Threads value x
isready
learn targetdir trainingdata epochs 10000 batchsize 1000000 use_draw_in_training 1 use_draw_in_validation 1 lr 1 lambda 1 eval_limit 32000 nn_batch_size 1000 newbob_decay 0.5 eval_save_interval 250000000 loss_output_interval 1000000 validation_set_file_name validationdata\val.binpack
This will utilize training data files in the "trainingdata" directory and validation data from file "validationdata\val.bin". Produced nets are saved in the "evalsave" folder.

More information about learn and available parameters can be found in the docs

[b]Reinforcement Learning[/b]

If you would like to do some reinforcement learning on your original network, you must first generate training data with the setting Use NNUE set to pure and using the previous network (either name it "nn.bin" and put into alongside the binary or provide the EvalFile UCI option). Use the commands specified above. You should aim to generate less positions than the first run, around 1/10 of the number of positions generated in the first run. The depth should be higher as well. You should also do the same for validation data, with the depth being higher than the last run.

After you have generated the training data, you must move it into your training data folder and move the older data so that the binary does not train on the same data again. Do the same for the validation data. Make sure the "evalsave" folder is empty. Then, using the same binary, type in the training commands shown above. Do NOT set SkipLoadingEval to true, it must be false or you will get a completely new network, instead of a network trained with reinforcement learning. You should also set eval_save_interval to a number that is lower than the amount of positions in your training data, perhaps also 1/10 of the original value.

After training is finished, your new net should be located in the "final" folder under the "evalsave" directory. You should test this new network against the older network to see if there are any improvements. Don't rely on the automatic rejection for network quality, sometimes even rejected nets can be better than the previous ones.

Using Your Trained Net
If you want to use your generated net, copy the net located in the "final" folder under the "evalsave" directory and move it into a new folder named "eval" under the directory with the binaries. You can then use the halfkp_256x2 binaries pertaining to your CPU with a standard chess GUI, such as Cutechess. Refer to the releases page to find out which binary is best for your CPU.[/quote]


source: https://github.com/nodchip/Stockfish
People who have lost the hope.
Post Reply