Difference between revisions of "Stockfish NNUE"
GerdIsenberg (talk | contribs) |
(→For Developers) (Tags: Mobile edit, Mobile web edit) |
||
Line 46: | Line 46: | ||
* Reuses and gets benefits from the very optimized [[Search|search]] function of Stockfish as well as almost all Stockfish's code | * Reuses and gets benefits from the very optimized [[Search|search]] function of Stockfish as well as almost all Stockfish's code | ||
* Requires much smaller training sets. Some high score networks can be built with the effort of one or a few people within a few days. It doesn't require the massive computing from a supercomputer and/or from community | * Requires much smaller training sets. Some high score networks can be built with the effort of one or a few people within a few days. It doesn't require the massive computing from a supercomputer and/or from community | ||
− | * Relative simple for computer chess programmers as well as being encouraged by some impressive successes, many developers joined or continued to work. The [[#Source|Official Stockfish]] repository shows the numbers of commits, ideas increased significantly after merging NNUE. | + | * Doesn’t require complicated systems such as client/server to train networks. Just a single binary from Nodchip’ repo is enough to train |
+ | * Relative simple for computer chess programmers | ||
+ | |||
+ | Being attracted by new advantages as well as being encouraged by some impressive successes, many developers joined or continued to work. The [[#Source|Official Stockfish]] repository shows the numbers of commits, ideas increased significantly after merging NNUE. | ||
=Elo Progress with NNUE= | =Elo Progress with NNUE= |
Revision as of 07:12, 24 August 2020
Home * Engines * Stockfish * NNUE
![](/images/thumb/6/69/Sfnnue.png/250px-Sfnnue.png)
Stockfish NNUE,
a Stockfish branch by Hisayori Noda aka Nodchip, which uses Efficiently Updatable Neural Networks - stylized as ƎUИИ or reversed as NNUE - to replace its standard evaluation.
NNUE, introduced in 2018 by Yu Nasu [2],
were previously successfully applied in Shogi evaluation functions embedded in a Stockfish based search [3], such as YaneuraOu [4],
and Kristallweizen [5]. He made an unbelievable prediction that NNUE can help to increase Stockfish strength by around 100 points, almost one year before revealing[6] [7].
In 2019, Nodchip incorporated NNUE into Stockfish 10 - as a proof of concept, and with the intention to give something back to the Stockfish community [8].
After support and announcements by Henk Drost in May 2020 [9]
and subsequent enhancements, Stockfish NNUE was established and recognized. In summer 2020, with more people involved in testing and training,
the computer chess community bursts out enthusiastically due to its rapidly raising playing strength with different networks trained using a mixture of supervised and reinforcement learning methods. Despite the approximately halved search speed, Stockfish NNUE seemingly became stronger than its original [10].
In August 2020, Fishtest revealed Stockfish NNUE was stronger than the classical one at least 80 Elo [11]. In July 2020, the playing code of NNUE was put into the official Stockfish repository as a branch for further development and examination. In August that playing code merged to the master branch and become an official part of the engine. However, the training code still remained in Nodchip's repository [12] [13].
Contents
NNUE Structure
The neural network consists of four layers. The input layer is heavily overparametrized, feeding in the board representation for all king placements per side. The efficiency of NNUE is due to incremental update of the input layer outputs in make and unmake move, where only a tiny fraction of its neurons need to be considered [14]. The remaining three layers with 2x256x32, 32x32 and 32x1 weights are computational less expensive, hidden layer 1 and 2 with ReLu activation [15] [16], best calculated using appropriate SIMD instructions performing fast 8-bit/16-bit integer vector arithmetic, like MMX, SSE2 or AVX2 on x86/x86-64, or, if available, AVX-512.
NNUE layers in action [17]
Nodchip explained on Discord on June 2020 [18]:
41,024 = 64 * 641. 64 comes from the number of the cells where king may exist. 641 = 64 * 5 * 2 + 1. 64 here comes from the number of the cells where a piece other than king may exist. 5 is the number of piece types other than king. 2 is the number of the colors, white and black. 1 is a captured piece. "+ 1" is BONA_PIECE_ZERO. Here "bona" means "bonanza" which is a popular computer shogi engine. It introduced the feature "p" for the first time. BonaPieces are contained in the evalList. It is updated by Position::do_move() and Position::undo_move(), and used by NNUE to calculate the network parameters between the input layer and the first hidden layer. About the calculation, the following text will be helpful. This text is sent to RocketMiningPoo on Twitter. "We add the i-th COLUMN of the W{0} to the z{0} for each i, where the i-th element is set to 1. And we subtract the i-th COULMN of the W{0} from the z{0} for each i, where the i-th element is set to 0. This operation is "accumulate" in your question." may be right... I hope that someone will double check.
Networks
All networks are built by some volunteers but not by any big community (differs from Leela Chess Zero) and can be uploaded into Fishtest for testing. Networks with good test results will be released officially on Fishtest website [19].
Hybrid
In August 2020 a new patch changed Stockfish NNUE into a hybrid engine: it uses NNUE evaluation only on quite balanced material positions, otherwise uses the classical one. It could speed up to 10% and gain 20 Elo [20]. At that point, NNUE helped to increase already around 100 Elo for Stockfish. In the same month, Stockfish changed the default mode of using evaluation functions from classic to hybrid one, the last step to completely accept NNUE.
Strong Points
For Users
- Runs with CPU only, and doesn't require expensive video cards, as well the need for installing drivers and 3rd specific libraries. Thus it is much easier to install (compared to engines using deep convolutional neural networks, such as Leela Chess Zero) and suitable for almost all modern computers. Using a GPU is even not practical for that small net - host-device-latency aka. kernel-launch-overhead [21] [22] to a then underemployed GPU are not sufficient for the intended NPS range [23]
- Releases with only one network (via UCI options), that help to delete users' confusion from finding, selecting and setting up. The network is selected carefully from Fishtest
For Developers
- Reuses and gets benefits from the very optimized search function of Stockfish as well as almost all Stockfish's code
- Requires much smaller training sets. Some high score networks can be built with the effort of one or a few people within a few days. It doesn't require the massive computing from a supercomputer and/or from community
- Doesn’t require complicated systems such as client/server to train networks. Just a single binary from Nodchip’ repo is enough to train
- Relative simple for computer chess programmers
Being attracted by new advantages as well as being encouraged by some impressive successes, many developers joined or continued to work. The Official Stockfish repository shows the numbers of commits, ideas increased significantly after merging NNUE.
Elo Progress with NNUE
Fishtest team did a Regression Tests [24] in August 2020, exclusively from 40.000 games tests at long time control (60sec + 0.6 for single-core, 30sec + 0.3 for 8 cores tests). The result was used to create the graph of Stockfish progress since version 11. The chart lines first increased sharply after merging NNUE.
Rotation vs Flip
Since the 9x9 Shogi board has a centered king file and castling is not known in Shogi, color flip versus180 degree rotate differs in a horizontal mirrored position from the other side's point of view, with otherwise identical playing options. The NNUE is trained and probed from the side to move point of view, where the used 180 degree rotation (xor 63 instead of 56) to flip sides looks rather strange for chess [25]. i.e color flipping the white king from e1 to d8 rather than e8. Does it consider castling short on the queen side?
It is a little bit unclear, how that rotation rather than flip affects the playing strength [26] and whether NNUE for chess suffers from associative visual agnosia. Maybe Fishtest needs to play many games with color-flipped openings, i.e. 1.e4 e5 and 1.e3 e5 2.e4, to look whether results differ or not. Anyway, a fix from rotate to flip has to be done from producer and consumer sides, and is likely to void some training sessions.
Yu Nasu's Suggestions
In reply to Unai Corzo, Yu Nasu suggested 3 techniques that applied successfully to Shogi and can be brought back to Stockfish NNUE and may improve it another 100 - 200 Elo [27] [28]:
- Optimizing all parameters together by stochastic optimization
- Switching between multi-evaluation functions, according to game phases
- Automatic generation of opening book on the fly
See also
Forum Posts
2020 ...
January ...
- The Stockfish of shogi by Larry Kaufman, CCC, January 07, 2020 » Shogi
- Stockfish NNUE by Henk Drost, CCC, May 31, 2020 » Stockfish
- Stockfish NN release (NNUE) by Henk Drost, CCC, May 31, 2020
- nnue-gui 1.0 released by Norman Schmidt, CCC, June 17, 2020
- stockfish-NNUE as grist for SF development? by Warren D. Smith, FishCooking, June 21, 2020
July
- Can the sardine! NNUE clobbers SF by Henk Drost, CCC, July 16, 2020
- End of an era? by Michel Van den Bergh, FishCooking, July 20, 2020
- Sergio Vieri second net is out by Sylwy, CCC, July 21, 2020
- NNUE accessible explanation by Martin Fierz, CCC, July 21, 2020
- Re: NNUE accessible explanation by Jonathan Rosenthal, CCC, July 23, 2020
- Re: NNUE accessible explanation by Jonathan Rosenthal, CCC, July 24, 2020
- Re: NNUE accessible explanation by Jonathan Rosenthal, CCC, August 03, 2020
- Stockfisch NNUE macOS binary requested by Steppenwolf, CCC, July 25, 2020
- Stockfish NNUE by Lion, CCC, July 25, 2020
- 7000 games testrun of SFnnue sv200724_0123 finished by Stefan Pohl, FishCooking, July 26, 2020
- SF-NNUE going forward... by Zenmastur, CCC, July 27, 2020
- New sf+nnue play-only compiles by Norman Schmidt, CCC, July 27, 2020
- Stockfish+NNUEsv +80 Elo vs Stockfish 17jul !! by Kris, Rybka Forum, July 28, 2020
- LC0 vs. NNUE - some tech details... by Srdja Matovic, CCC, July 29, 2020 » Lc0
- Stockfish NNUE and testsuites by Jouni Uski, CCC, July 29, 2020
- Stockfish NNue [download ] by Ed Schröder, CCC, July 30, 2020
August
- Repository for Stockfish+NNUE Android Builds by AdminX, CCC, August 02, 2020
- SF NNUE Problem by Stephen Ham, CCC, August 03, 2020
- Re: NNUE accessible explanation by Jonathan Rosenthal, CCC, August 03, 2020 » NNUE accessible explanation
- [NNUE] Worker update on fishtest by Joost VandeVondele, FishCooking, August 03, 2020
- this will be the merge of a lifetime : SF 80 Elo+ by MikeB, CCC, August 04, 2020
- Re: this will be the merge of a lifetime : SF 80 Elo+ by Henk Drost, CCC, August 04, 2020
- You can now look inside NNUE and look at its Per square value estimation by Henk Drost, CCC, August 04, 2020
- Is this SF NN almost like 20 MB book? by Jouni Uski, CCC, August 04, 2020
- NNUE evaluation merged in master by Joost VandeVondele, FishCooking, August 06, 2020
- SF NNUE training questions by Jouni Uski, CCC, August 10, 2020
- Neural Networks weights type by Fabio Gobbato, CCC, August 13, 2020
- Don't understand NNUE by Lucasart, CCC, August 14, 2020
External Links
Basics
- Stockfish NNUE – The Complete Guide, June 19, 2020 (Japanese and English)
- Stockfish NNUE Wiki
- NNUE merge · Issue #2823 · official-stockfish/Stockfish · GitHub by Joost VandeVondele, July 25, 2020 [29]
- Stockfish Evaluation Guide [30]
Source
- GitHub - Official-stockfish
- GitHub - nodchip/Stockfish: UCI chess engine by Nodchip
- GitHub - vondele/Stockfish at nnue-player-wip by Joost VandeVondele
- GitHub - tttak/Stockfish: UCI chess engine
- GitHub - joergoster/Stockfish-NNUE: UCI Chess engine Stockfish with an Efficiently Updatable Neural-Network-based evaluation function hosted by Jörg Oster
- GitHub - FireFather/sf-nnue: Stockfish NNUE (efficiently updateable neural network) by Norman Schmidt
- GitHub - FireFather/nnue-gui: basic windows application for using nodchip's stockfish-nnue software by Norman Schmidt
Networks
Binaries
Rating Lists
Misc
- Stockfish from Wikipedia
- Nue from Wikipedia
- Hiromi - Spectrum, 2019, YouTube Video
References
- ↑ Stockfish NNUE Logo from GitHub - nodchip/Stockfish: UCI chess engine by Nodchip
- ↑ Yu Nasu (2018). ƎUИИ Efficiently Updatable Neural-Network based Evaluation Functions for Computer Shogi. Ziosoft Computer Shogi Club, pdf (Japanese with English abstract)
- ↑ The Stockfish of shogi by Larry Kaufman, CCC, January 07, 2020
- ↑ GitHub - yaneurao/YaneuraOu: YaneuraOu is the World's Strongest Shogi engine(AI player), WCSC29 1st winner, educational and USI compliant engine
- ↑ GitHub - Tama4649/Kristallweizen: 第29回世界コンピュータ将棋選手権 準優勝のKristallweizenです。
- ↑ 将棋ソフト開発者がStockfishに貢献する日 The day when shogi software developers contribute to Stockfish by Yu Nasu, June 2019
- ↑ shogi engine developer claims he can make Stockfish stronger, Reddit, August 2019
- ↑ Stockfish NNUE – The Complete Guide, June 19, 2020 (Japanese and English)
- ↑ Stockfish NN release (NNUE) by Henk Drost, CCC, May 31, 2020
- ↑ Can the sardine! NNUE clobbers SF by Henk Drost, CCC, July 16, 2020
- ↑ Introducing NNUE Evaluation, August 06, 2020
- ↑ NNUE merge · Issue #2823 · official-stockfish/Stockfish · GitHub by Joost VandeVondele, July 25, 2020
- ↑ GitHub - nodchip/Stockfish: UCI chess engine by Nodchip
- ↑ Re: NNUE accessible explanation by Jonathan Rosenthal, CCC, July 23, 2020
- ↑ Stockfish/halfkp_256x2-32-32.h at master · official-stockfish/Stockfish · GitHub
- ↑ Stockfish/clipped_relu.h at master · official-stockfish/Stockfish · GitHub
- ↑ Image courtesy Roman Zhukov, revised version of the image posted in Re: Stockfish NN release (NNUE) by Roman Zhukov, CCC, June 17, 2020
- ↑ Don't understand NNUE by Lucasart, CCC, August 14, 2020
- ↑ Neural Net download and statistics
- ↑ NNUE evaluation threshold by MJZ1977 · Pull Request #2916 · official-stockfish/Stockfish · GitHub, August 06, 2020
- ↑ AB search with NN on GPU... by Srdja Matovic, CCC, August 13, 2020 » GPU
- ↑ kernel launch latency - CUDA / CUDA Programming and Performance - NVIDIA Developer Forums by LukeCuda, June 18, 2018
- ↑ stockfish with graphics card by h1a8, CCC, August 06, 2020
- ↑ Regression Tests, August 22, 2020
- ↑ Stockfish/types.h at 615d98da2447e79ceceae205e0cd4e878115acc3 · official-stockfish/Stockfish · GitHub
- ↑ NNUE eval rotate vs mirror · Issue #3021 · official-stockfish/Stockfish · GitHub by Terje Kirstihagen, August 17, 2020
- ↑ 3 technologies in shogi AI that could be used for chess AI, Yu Nasu, August 2020
- ↑ GitHub - NNUE ideas and discussion (post-merge). #2915, August 2020
- ↑ An info by Sylwy, CCC, July 25, 2020
- ↑ You can now look inside NNUE and look at its Per square value estimation by Henk Drost, CCC, August 04, 2020