Difference between revisions of "Stockfish NNUE"

From Chessprogramming wiki
Jump to: navigation, search
(Created page with "'''Home * Engines * Stockfish * NNUE''' border|right|thumb|250px| [[:Category:Toriyama Sekien|Toriyama Sekien - [https://en....")
 
 
(195 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
'''[[Main Page|Home]] * [[Engines]] * [[Stockfish]] * NNUE'''
 
'''[[Main Page|Home]] * [[Engines]] * [[Stockfish]] * NNUE'''
  
[[FILE:SekienAyakashi.jpg|border|right|thumb|250px| [[:Category:Toriyama Sekien|Toriyama Sekien]] - [https://en.wikipedia.org/wiki/Ikuch Ikuchi] <ref>[https://en.wikipedia.org/wiki/Ikuchi Ikuchi] drawn as the [https://en.wikipedia.org/wiki/Ayakashi_(y%C5%8Dkai) Ayakashi] from the [https://en.wikipedia.org/wiki/Konjaku_Gazu_Zoku_Hyakki Konjaku Gazu Zoku Hyakki] (今昔画図続百鬼) by [[:Category:Toriyama Sekien|Toriyama Sekien]], circa 1779, [https://en.wikipedia.org/wiki/Wikimedia_Commons Wikimedia Commons]</ref> ]]  
+
[[FILE:Sfnnue.png|border|right|thumb|250px| Stockfish NNUE Logo <ref>Stockfish NNUE Logo from [https://github.com/nodchip/Stockfish GitHub - nodchip/Stockfish: UCI chess engine] by [[Hisayori Noda|Nodchip]]</ref> ]]  
  
 
'''Stockfish NNUE''',<br/>
 
'''Stockfish NNUE''',<br/>
a Stockfish branch by [[Nodchip]] which uses [[NNUE|Efficiently Updatable Neural Networks]] - stylized as (&#398;U&#1048;&#1048;) or reversed as NNUE - to replace its standard [[Stockfish#Evaluation|evaluation]].
+
a Stockfish branch by [[Hisayori Noda]] aka Nodchip, which uses [[NNUE|Efficiently Updatable Neural Networks]] - stylized as '''&#398;U&#1048;&#1048;''' or reversed as '''NNUE''' - to replace its standard [[Stockfish#Evaluation|evaluation]].
NNUE, introduced in 2018 by [[Yu Nasu]] <ref>[[Yu Nasu]] ('''2018'''). ''&#398;U&#1048;&#1048; Efficiently Updatable Neural-Network based Evaluation Functions for Computer Shogi''.  Ziosoft Computer Shogi Club, [https://github.com/ynasu87/nnue/blob/master/docs/nnue.pdf pdf] (Japanese with English abstract)</ref>,  
+
NNUE, introduced in 2018 by [[Yu Nasu]] <ref>[[Yu Nasu]] ('''2018'''). ''&#398;U&#1048;&#1048; Efficiently Updatable Neural-Network based Evaluation Functions for Computer Shogi''.  Ziosoft Computer Shogi Club, [https://github.com/ynasu87/nnue/blob/master/docs/nnue.pdf pdf] (Japanese with English abstract) [https://github.com/asdfjkl/nnue GitHub - asdfjkl/nnue translation] </ref>,  
 
were previously successfully applied in [[Shogi]] evaluation functions embedded in a Stockfish based search <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=2&t=72754 The Stockfish of shogi] by [[Larry Kaufman]], [[CCC]], January 07, 2020</ref>, such as [[YaneuraOu]] <ref>[https://github.com/yaneurao/YaneuraOu GitHub - yaneurao/YaneuraOu: YaneuraOu is the World's Strongest Shogi engine(AI player), WCSC29 1st winner, educational and USI compliant engine]</ref>,
 
were previously successfully applied in [[Shogi]] evaluation functions embedded in a Stockfish based search <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=2&t=72754 The Stockfish of shogi] by [[Larry Kaufman]], [[CCC]], January 07, 2020</ref>, such as [[YaneuraOu]] <ref>[https://github.com/yaneurao/YaneuraOu GitHub - yaneurao/YaneuraOu: YaneuraOu is the World's Strongest Shogi engine(AI player), WCSC29 1st winner, educational and USI compliant engine]</ref>,
and [[Kristallweizen-kai]] <ref>[https://github.com/Tama4649/Kristallweizen/ GitHub - Tama4649/Kristallweizen: 第29回世界コンピュータ将棋選手権 準優勝のKristallweizenです。]</ref>.
+
and [[Kristallweizen]] <ref>[https://github.com/Tama4649/Kristallweizen/ GitHub - Tama4649/Kristallweizen: 第29回世界コンピュータ将棋選手権 準優勝のKristallweizenです。]</ref>. YaneuraOu's author [[Motohiro Isozaki]] made an unbelievable prediction that NNUE can help to increase Stockfish strength by around 100 points, almost one year before revealing <ref>[http://yaneuraou.yaneu.com/2019/06/24/%E5%B0%86%E6%A3%8B%E3%82%BD%E3%83%95%E3%83%88%E9%96%8B%E7%99%BA%E8%80%85%E3%81%8Cstockfish%E3%81%AB%E8%B2%A2%E7%8C%AE%E3%81%99%E3%82%8B%E6%97%A5/ 将棋ソフト開発者がStockfishに貢献する日 The day when shogi software developers contribute to Stockfish] by [[Motohiro Isozaki]], June 2019</ref> <ref>[https://www.reddit.com/r/chess/comments/cltich/shogi_engine_developer_claims_he_can_make/ shogi engine developer claims he can make Stockfish stronger], [[Computer Chess Forums|Reddit]], August 2019</ref>.
 
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 <ref>[http://yaneuraou.yaneu.com/2020/06/19/stockfish-nnue-the-complete-guide/ Stockfish NNUE – The Complete Guide], June 19, 2020 (Japanese and English)</ref>.
 
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 <ref>[http://yaneuraou.yaneu.com/2020/06/19/stockfish-nnue-the-complete-guide/ Stockfish NNUE – The Complete Guide], June 19, 2020 (Japanese and English)</ref>.
 
After support and announcements by [[Henk Drost]] in May 2020 <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74059 Stockfish NN release (NNUE)] by [[Henk Drost]], [[CCC]], May 31, 2020</ref>  
 
After support and announcements by [[Henk Drost]] in May 2020 <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74059 Stockfish NN release (NNUE)] by [[Henk Drost]], [[CCC]], May 31, 2020</ref>  
and subsequent enhancements, Stockfish NNUE was established. In summer 2020 with more people involved in [[Engine Testing|testing]] and training,  
+
and subsequent enhancements, Stockfish NNUE was established and recognized. In summer 2020, with more people involved in [[Engine Testing|testing]] and [[Learning|training]],  
and the computer chess community bursts out enthusiastically due to its rapidly raising [[Playing Strength|playing strength]] with different networks trained using a mixture of [[Supervised Learning|supervised]] and [[Reinforcement Learning|reinforcement learning]] methods -
+
the computer chess community bursts out enthusiastically due to its rapidly raising [[Playing Strength|playing strength]] with different networks trained using a mixture of [[Supervised Learning|supervised]] and [[Reinforcement Learning|reinforcement learning]] methods. Despite the approximately halved search speed, Stockfish NNUE became stronger than its original <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74484 Can the sardine! NNUE clobbers SF] by [[Henk Drost]], [[CCC]], July 16, 2020</ref>.
despite the approximately halved search speed, seemingly becoming stronger than its original <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74484 Can the sardine! NNUE clobbers SF] by [[Henk Drost]], [[CCC]], July 16, 2020</ref>. In July 2020, the playing code of NNUE is put into the official Stockfish repository as a branch for further development and examination. However, the training code still remains in Nodchip's repository <ref>[https://github.com/official-stockfish/Stockfish/issues/2823 NNUE merge · Issue #2823 · official-stockfish/Stockfish · GitHub] by [[Joost VandeVondele]], July 25, 2020</ref> <ref>[https://github.com/nodchip/Stockfish GitHub - nodchip/Stockfish: UCI chess engine] by [[Nodchip]]</ref>.
+
 
 +
In August 2020, [[Stockfish#Fishtest|Fishtest]] revealed Stockfish NNUE was stronger than the classical one at least 80 Elo <ref>[https://blog.stockfishchess.org/post/625828091343896577/introducing-nnue-evaluation Introducing NNUE Evaluation], August 06, 2020</ref>. 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 <ref>[https://github.com/official-stockfish/Stockfish/issues/2823 NNUE merge · Issue #2823 · official-stockfish/Stockfish · GitHub] by [[Joost VandeVondele]], July 25, 2020</ref> <ref>[https://github.com/nodchip/Stockfish GitHub - nodchip/Stockfish: UCI chess engine] by [[Hisayori Noda|Nodchip]]</ref> then replaced by [https://en.wikipedia.org/wiki/PyTorch PyTorch] <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=7&t=75724 Pytorch NNUE training] by [[Gary Linscott]], [[CCC]], November 08, 2020</ref><ref>[http://talkchess.com/forum3/viewtopic.php?f=7&t=79020 Why NNUE trainer requires an online qsearch on each training position?] by [[nkg114mc]], [[CCC]], January 01, 2022
 +
</ref>. On September 02, 2020, '''Stockfish 12''' was released with a huge jump in playing strength due to the introduction of [[NNUE]] and further tuning <ref>[https://blog.stockfishchess.org/post/628172810852925440/stockfish-12 Stockfish 12], The Stockfish Team, [https://blog.stockfishchess.org/ Stockfish Blog], September 02, 2020</ref>.
 +
 
 +
=NNUE Structure=
 +
The [[Neural Networks|neural network]] consists of four layers. The input layer is heavily overparametrized, feeding in the [[Board Representation|board representation]] for all king placements per side
 +
<ref>[http://www.talkchess.com/forum3/viewtopic.php?f=7&t=74531&start=1 Re: NNUE accessible explanation] by [[Jonathan Rosenthal]], [[CCC]], July 23, 2020</ref>.
 +
 
 +
==HalfKP==
 +
The so called '''HalfKP''' structure consists of two halves covering input layer and first hidden layer, each half of the input layer associated to one of the two [[King|kings]], cross coupled with the side to move or not to move halves of the first hidden layer.
 +
For each either black or white king placement, the 10 none king pieces on their particular squares are the boolean {0,1} inputs, along with a relict from Shogi piece drop (BONA_PIECE_ZERO),
 +
64 x (64 x 10 + 1) = 41,024 inputs for each half, which are multiplied by a 16-bit integer weight vector for 256 outputs per half, in total, 256 x 41,024 = 10,502,144 weights.
 +
As emphasized by [[Ronald de Man]] in a [[CCC]] forum discussion <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=7&t=75506&start=7 Re: NNUE Question - King Placements] by [[Ronald de Man|syzygy]], [[CCC]], October 23, 2020</ref>,
 +
the input weights are arranged in such a way, that [[Color Flipping|color flipped]] king-piece configurations in both halves share the same index.
 +
However, and that seems also a relict from Shogi with its [https://en.wikipedia.org/wiki/Rotational_symmetry 180 degrees rotational] 9x9 board symmetry, instead of [[Vertical Flipping|vertical flipping]] (xor 56), [[Flipping Mirroring and Rotating#Rotationby180degrees|rotation]] is applied (xor 63) <ref>[https://github.com/official-stockfish/Stockfish/issues/3021 NNUE eval rotate vs mirror · Issue #3021 · official-stockfish/Stockfish · GitHub] by [[Terje Kirstihagen]], August 17, 2020</ref>.
 +
 
 +
The efficiency of [[NNUE]] is due to [[Incremental Updates|incremental update]] of the input layer outputs in [[Make Move|make]] and [[Unmake Move|unmake move]],
 +
where only a tiny fraction of its neurons need to be considered in case of none king moves.
 +
The remaining three layers with 2x256x32, 32x32 and 32x1 weights are computational less expensive, hidden layers apply a [https://en.wikipedia.org/wiki/Rectifier_(neural_networks) ReLu activation] <ref>[https://github.com/official-stockfish/Stockfish/blob/master/src/nnue/architectures/halfkp_256x2-32-32.h#L42 Stockfish/halfkp_256x2-32-32.h at master · official-stockfish/Stockfish · GitHub]</ref> <ref>[https://github.com/official-stockfish/Stockfish/blob/master/src/nnue/layers/clipped_relu.h#L82 Stockfish/clipped_relu.h at master · official-stockfish/Stockfish · GitHub]</ref>, best calculated using appropriate [[SIMD and SWAR Techniques|SIMD instructions]] performing fast [[Byte|8-bit]]/[[Word|16-bit]] integer vector arithmetic, like [[MMX]], [[SSE2]] or [[AVX2]] on [[x86]]/[[x86-64]], or, if available, [[AVX-512]].
 +
 
 +
[[FILE:StockfishNNUELayers.png|none|border|text-bottom|1024px]]
 +
NNUE layers in action <ref>Image courtesy Roman Zhukov, revised version of the image posted in [http://talkchess.com/forum3/viewtopic.php?f=2&t=74059&start=139 Re: Stockfish NN release (NNUE)] by Roman Zhukov, [[CCC]], June 17, 2020, labels corrected October 23, 2020, see [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=75506&start=1 Re: NNUE Question - King Placements] by [[Andrew Grant]], [[CCC]], October 23, 2020</ref>
 +
 
 +
Explanation by [[Ronald de Man]] <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=7&t=75506&start=9 Re: NNUE Question - King Placements] by [[Ronald de Man|syzygy]], [[CCC]], October 23, 2020</ref>, who did the Stockfish NNUE port to [[CFish]] <ref>[https://github.com/syzygy1/Cfish/blob/master/src/nnue.c Cfish/nnue.c at master · syzygy1/Cfish · GitHub]</ref>:
 +
The accumulator has a "white king" half and a "black king" half, where each half is a 256-element vector of 16-bit ints, which is equal to the sum of the weights of the "active" (pt, sq, ksq) features  plus a 256-element vector of 16-bit biases.
 +
 
 +
The "transform" step of the NNUE evaluation forms a 512-element vector of 8-bit ints where the first half is formed from the 256-element vector of the side to move and the second half is formed from the 256-element vector of the other side. In this step the 16-bit elements are clipped/clamped to a value from 0 to 127. This is the output of the input layer.
 +
 
 +
This 512-element vector of 8-bit ints is then multiplied by a 32x512 matrix of 8-bit weights to get a 32-element vector of 32-bit ints, to which a vector of 32-bit biases is added. The sum vector is divided by 64 and clipped/clamped to a 32-element vector of 8-bit ints from 0 to 127. This is the output of the first hidden layer.
 +
 
 +
The resulting 32-element vector of 8-bit ints is multiplied by a 32x32 matrix of 8-bit weights to get a 32-element vector of 32-bit ints, to which another vector of 32-bit biases is added. These ints are again divided by 64 and clipped/clamped to 32 8-bit ints from 0 to 127. This is the output of the second hidden layer.
 +
 
 +
This 32-element vector of 8-bits ints is then multiplied by a 1x32 matrix of 8-bit weights (i.e. the inner product of two vectors is taken). This produces a 32-bit value to which a 32-bit bias is added. This gives the output of the output layer.
 +
 
 +
The output of the output layer is divided by FV_SCALE = 16 to produce the NNUE evaluation. SF's evaluation then take some further steps such as adding a Tempo bonus (even though the NNUE evaluation inherently already takes into account the side to move in the "transform" step) and scaling the evaluation towards zero as rule50_count() approaches 50 moves.
 +
 
 +
==HalfKA==
 +
In subsequent Stockfish versions the network architecture was further improved by [[Tomasz Sobczyk]] et al.. The '''HalfKA''' architecture uses 12x64x64 = 45056 inputs for each of the 12 piece types times 64 squares for each of the 64 own king squares, times two, for both the side to move and other side perspective, further using the [[Vertical Flipping|vertical flip]] instead of the HalfKP rotate.
 +
'''HalfKAv2''' as applied in Stockfish '''14''' saves some space considering the king square redundancy using 11x64x64 = 45056 inputs per side, mapped to a 2x520 linear feature transformer <ref>[https://github.aom/official-stockfish/Stockfish/commit/e8d64af1230fdac65bb0da246df3e7abe82e0838 New NNUE architecture and net · official-stockfish/Stockfish@e8d64af · GitHub]</ref> <ref>[https://github.com/official-stockfish/Stockfish/pull/3474 Update default net to nn-8a08400ed089.nnue by Sopel97 · Pull Request #3474 · official-stockfish/Stockfish · GitHub]</ref> <ref>[https://github.com/glinscott/nnue-pytorch/blob/master/docs/nnue.md#halfkav2-feature-set HalfKAv2 feature set | nnue-pytorch/nnue.md at master · glinscott/nnue-pytorch · GitHub]</ref>, further feeding 8x2 outputs of this feature transformer directly to the output for better learning of unbalanced material configurations <ref>[https://github.com/glinscott/nnue-pytorch/blob/master/docs/nnue.md#a-part-of-the-feature-transformer-directly-forwarded-to-the-output A part of the feature transformer directly forwarded to the output  | nnue-pytorch/nnue.md at master · glinscott/nnue-pytorch · GitHub]</ref>. Another improvement was using eight 512x2->16->32->1 output sub-networks discriminated by (piece_count-1) div 4 in the 0 to 7 range
 +
<ref>[https://github.com/glinscott/nnue-pytorch/blob/master/docs/nnue.md#multiple-psqt-outputs-and-multiple-subnetworks Multiple PSQT outputs and multiple subnetworks | nnue-pytorch/nnue.md at master · glinscott/nnue-pytorch · GitHub]</ref>.
 +
 
 +
[[FILE:HalfKAv2.png|none|border|text-bottom|658px]]
 +
HalfKAv2 architecture by [[Tomasz Sobczyk]] <ref>[https://user-images.githubusercontent.com/8037982/118656988-553a1700-b7eb-11eb-82ef-56a11cbebbf2.png HalfKAv2.png] Image courtesy by [[Tomasz Sobczyk]]</ref>
 +
 
 +
=Network=
 +
Networks were built by volunteers, uploaded into [[Stockfish#Fishtest|Fishtest]] for testing.
 +
Networks with good test results are released officially on the Fishtest website <ref>[https://tests.stockfishchess.org/nns Neural Net download and statistics]</ref> with average speed of 2 weeks per network <ref>[https://github.com/official-stockfish/Stockfish/discussions/3628#discussioncomment-1047323 One year of NNUE.... · official-stockfish/Stockfish · GitHub] by [[Joost VandeVondele]], July 26, 2021</ref>.
 +
After long discussing the best way to publish networks with Stockfish <ref>[https://github.com/official-stockfish/Stockfish/issues/3030 Improve dealing with the default net? Issue ##3030 · official-stockfish/Stockfish · GitHub]  by [[Joost VandeVondele]], August 19, 2020</ref>, the developing team decided to embed the default network into Stockfish binaries, making sure NNUE always works as well as bringing more convenience to users.
 +
 
 +
In late 2020, [[Gary Linscott]] started an implementation of the Stockfish NNUE training in [https://en.wikipedia.org/wiki/PyTorch PyTorch] <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=7&t=75724 Pytorch NNUE training] by [[Gary Linscott]], [[CCC]], November 08, 2020</ref> <ref>[https://github.com/glinscott/nnue-pytorch GitHub - glinscott/nnue-pytorch: NNUE (Chess evaluation) trainer in Pytorch]</ref> using [[GPU]] resources to efficiently train networks.
 +
Further, the collaboration with the [[Leela Chess Zero]] team in February 2021 <ref>[https://groups.google.com/g/fishcooking/c/AzYDbbv-Coo Stockfish 13] by [[Joost VandeVondele]], [[Computer Chess Forums|FishCooking]], February 19, 2021 </ref> payed off, in providing billions of positions to train the new networks <ref>[https://stockfishchess.org/blog/2021/stockfish-14/ Stockfish 14], The Stockfish Team, July 02, 2021</ref>.
 +
 
 +
=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 <ref>[https://github.com/official-stockfish/Stockfish/pull/2916 NNUE evaluation threshold by MJZ1977 · Pull Request #2916 · official-stockfish/Stockfish · GitHub], August 06, 2020</ref>. 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=
 
=Strong Points=
* Reuses and gets benefits from the very optimized [[Search|search]] function of Stockfish as well as almost all Stockfish's code
+
==For Users==
* Runs with CPU only, doesn't require expensive video cards, and the need for installing video drivers and specific libraries, thus it becomes much easier to install (compare with other NN engines such as [[Leela Chess Zero]]) for users and can run with almost all modern computers
+
* Runs with CPU only, and doesn't require expensive [https://en.wikipedia.org/wiki/Video_card video cards], as well the need for installing drivers and 3rd specific libraries. Thus it is much easier to install (compared to engines using [[Neural Networks#Deep|deep]] [[Neural Networks#Convolutional|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 <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=7&t=74771 AB search with NN on GPU...] by [[Srdja Matovic]], [[CCC]], August 13, 2020 » [[GPU]]</ref>  <ref>[https://forums.developer.nvidia.com/t/kernel-launch-latency/62455 kernel launch latency - CUDA / CUDA Programming and Performance - NVIDIA Developer Forums] by LukeCuda, June 18, 2018</ref> to a then underemployed GPU are not sufficient for the intended [[Nodes per Second|NPS]] range <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74702 stockfish with graphics card] by h1a8, [[CCC]], August 06, 2020</ref>
* Requires much smaller training sets. Some high score networks can be built with the effort of one or a few people. It doesn't require the massive computing from a supercomputer and/or from community
+
* 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 [[Stockfish#Fishtest|Fishtest]]
 +
 
 +
==For Developers==
 +
* Requires small 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 a sophisticated [https://en.wikipedia.org/wiki/Client%E2%80%93server_model client-server model] to train networks. Just a single binary from Nodchip’ repo is enough to train
 +
* The NNUE code is independent and can be separated easily from the rest and integrated to other engines <ref>[[NNUE#NNUE Engines|NNUE Engines]]</ref>
 +
 
 +
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 gain=
 +
[[Joost VandeVondele]] has created a graph to show how Stockfish gains Elo with NNUE after a year:<ref>[https://github.com/official-stockfish/Stockfish/discussions/3628#discussioncomment-1047728 One year of NNUE.... · official-stockfish/Stockfish · GitHub] by [[Joost VandeVondele]], July 26, 2021</ref>
 +
[[FILE:NNEUOneYearEloGain.png|none|border|text-bottom|1024px]]
 +
 
 +
=Suggestions=
 +
In reply to [[Unai Corzo]], [[Motohiro Isozaki]] aka Yaneurao, suggested 3 techniques that applied successfully to Shogi and can be brought back to Stockfish NNUE and may improve it another 100 - 200 Elo <ref>[http://yaneuraou.yaneu.com/2020/08/21/3-technologies-in-shogi-ai-that-could-be-used-for-chess-ai/ 3 technologies in shogi AI that could be used for chess AI], [[Motohiro Isozaki]], August 2020</ref> <ref>[https://github.com/official-stockfish/Stockfish/issues/2915#issuecomment-678112885, GitHub - NNUE ideas and discussion (post-merge). #2915], August 2020</ref>:
 +
* Optimizing all parameters together by [https://en.wikipedia.org/wiki/Stochastic_optimization stochastic optimization]
 +
* Switching between multi-evaluation functions, according to [[Game Phases|game phases]]
 +
* Automatic generation of [[Opening Book|opening book]] on the fly
 +
 
 +
=See also=
 +
* [[:Category:NN|Category: Neural Network Engines]]
 +
* [[Fat Fritz#Fat Fritz 2|Fat Fritz 2.0]]
 +
* [[Neural Networks]]
 +
* [[NNUE]]
 +
* [[Winter]]
  
 
=Forum Posts=  
 
=Forum Posts=  
 
==2020 ...==
 
==2020 ...==
 +
===January ...===
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=72754 The Stockfish of shogi] by [[Larry Kaufman]], [[CCC]], January 07, 2020 » [[Shogi]]
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=72754 The Stockfish of shogi] by [[Larry Kaufman]], [[CCC]], January 07, 2020 » [[Shogi]]
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=74058 Stockfish NNUE] by [[Henk Drost]], [[CCC]], May 31, 2020 » [[Stockfish]]
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=74058 Stockfish NNUE] by [[Henk Drost]], [[CCC]], May 31, 2020 » [[Stockfish]]
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74059 Stockfish NN release (NNUE)] by [[Henk Drost]], [[CCC]], May 31, 2020
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74059 Stockfish NN release (NNUE)] by [[Henk Drost]], [[CCC]], May 31, 2020
==July==
+
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74212 nnue-gui 1.0 released] by [[Norman Schmidt]], [[CCC]], June 17, 2020
 +
* [https://groups.google.com/d/msg/fishcooking/rIAO2SXkT00/48-DFzHFBwAJ stockfish-NNUE as grist for SF development?] by [[Warren D. Smith]], [[Computer Chess Forums|FishCooking]], June 21, 2020
 +
===July===
 +
* [https://groups.google.com/d/msg/lczero/BvhCa-muLt0/ZzINQk_vCQAJ How strong is Stockfish NNUE compared to Leela..] by OmenhoteppIV, [[Computer Chess Forums|LCZero Forum]], July 13, 2020 » [[Leela Chess Zero]]
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74484 Can the sardine! NNUE clobbers SF] by [[Henk Drost]], [[CCC]], July 16, 2020
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74484 Can the sardine! NNUE clobbers SF] by [[Henk Drost]], [[CCC]], July 16, 2020
 
* [https://groups.google.com/d/msg/fishcooking/8j68W3GL6Q0/__Pf0FRNCQAJ End of an era?] by [[Michel Van den Bergh]], [[Computer Chess Forums|FishCooking]], July 20, 2020
 
* [https://groups.google.com/d/msg/fishcooking/8j68W3GL6Q0/__Pf0FRNCQAJ End of an era?] by [[Michel Van den Bergh]], [[Computer Chess Forums|FishCooking]], July 20, 2020
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74520 Sergio Vieri second net is out] by Sylwy, [[CCC]], July 21, 2020
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74520 Sergio Vieri second net is out] by Sylwy, [[CCC]], July 21, 2020
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=74531 NNUE accessible explanation] by [[Martin Fierz]], [[CCC]], July 21, 2020
+
* <span id="NNUEaccExp"></span>[http://www.talkchess.com/forum3/viewtopic.php?f=7&t=74531 NNUE accessible explanation] by [[Martin Fierz]], [[CCC]], July 21, 2020
 +
: [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=74531&start=1 Re: NNUE accessible explanation] by [[Jonathan Rosenthal]], [[CCC]], July 23, 2020
 +
: [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=74531&start=5 Re: NNUE accessible explanation] by [[Jonathan Rosenthal]], [[CCC]], July 24, 2020
 +
: [[#Continue|Re: NNUE accessible explanation]] by [[Jonathan Rosenthal]], [[CCC]], August 03, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74564 Stockfisch NNUE macOS binary requested] by Steppenwolf, [[CCC]], July 25, 2020
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74565 Stockfish NNUE] by Lion, [[CCC]], July 25, 2020
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74565 Stockfish NNUE] by Lion, [[CCC]], July 25, 2020
 +
* [https://groups.google.com/d/msg/fishcooking/fDY3dXqxgIQ/7Z5V0tATAQAJ 7000 games testrun of SFnnue sv200724_0123 finished] by [[Stefan Pohl]], [[Computer Chess Forums|FishCooking]], July 26, 2020
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74585 SF-NNUE going forward...] by Zenmastur, [[CCC]], July 27, 2020
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74585 SF-NNUE going forward...] by Zenmastur, [[CCC]], July 27, 2020
* [https://groups.google.com/d/msg/fishcooking/fDY3dXqxgIQ/7Z5V0tATAQAJ 7000 games testrun of SFnnue sv200724_0123 finished] by [[Stefan Pohl]], [[Computer Chess Forums|FishCooking]], July 26, 2020
+
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74594 New sf+nnue play-only compiles] by [[Norman Schmidt]], [[CCC]], July 27, 2020
 +
* [http://rybkaforum.net/cgi-bin/rybkaforum/topic_show.pl?tid=33622 Stockfish+NNUEsv +80 Elo vs Stockfish 17jul !! ] by Kris, [[Computer Chess Forums|Rybka Forum]], July 28, 2020
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74607 LC0 vs. NNUE - some tech details...] by [[Srdja Matovic]], [[CCC]], July 29, 2020 » [[Leela Chess Zero#Lc0|Lc0]]
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74607 LC0 vs. NNUE - some tech details...] by [[Srdja Matovic]], [[CCC]], July 29, 2020 » [[Leela Chess Zero#Lc0|Lc0]]
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74613 Stockfish NNUE and testsuites] by [[Jouni Uski]], [[CCC]], July 29, 2020
 
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74613 Stockfish NNUE and testsuites] by [[Jouni Uski]], [[CCC]], July 29, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74627 Stockfish NNue <nowiki>[download ]</nowiki>] by [[Ed Schroder|Ed Schröder]], [[CCC]], July 30, 2020
 +
===August===
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74654 Repository for Stockfish+NNUE Android Builds] by [[Ted Summers|AdminX]], [[CCC]], August 02, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74666 SF NNUE Problem] by [[Stephen Ham]], [[CCC]], August 03, 2020
 +
* <span id="Continue"></span>[http://www.talkchess.com/forum3/viewtopic.php?f=7&t=74531&start=8 Re: NNUE accessible explanation] by [[Jonathan Rosenthal]], [[CCC]], August 03, 2020 » [[#NNUEaccExp|NNUE accessible explanation]]
 +
* [https://groups.google.com/d/msg/fishcooking/6OI3AejYvpQ/dNmluMLBAgAJ <nowiki>[NNUE] Worker update on fishtest</nowiki>] by [[Joost VandeVondele]], [[Computer Chess Forums|FishCooking]], August 03, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74680 this will be the merge of a lifetime : SF 80 Elo+] by [[Michael Byrne|MikeB]], [[CCC]], August 04, 2020
 +
: [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74680&start=22 Re: this will be the merge of a lifetime : SF 80 Elo+] by [[Henk Drost]], [[CCC]], August 04, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74681 You can now look inside NNUE and look at its Per square value estimation] by [[Henk Drost]], [[CCC]], August 04, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74683 Is this SF NN almost like 20 MB book?] by [[Jouni Uski]], [[CCC]], August 04, 2020
 +
* [https://groups.google.com/d/msg/fishcooking/Kzw1W_Yr1d8/YNEmCqIyBAAJ NNUE evaluation merged in master] by [[Joost VandeVondele]], [[Computer Chess Forums|FishCooking]], August 06, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74705 What happens with my hyperthreading?] by [[Kai Laskos]], [[CCC]], August 06, 2020 » [[Thread]]
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74722 Stockfish NNUE style] by Rowen, [[CCC]], August 08, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?t=74739 SF NNUE training questions] by [[Jouni Uski]], [[CCC]], August 10, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74765 Progress of Stockfish in 6 days] by [[Kai Laskos]], [[CCC]], August 12, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=74777 Neural Networks weights type] by [[Fabio Gobbato]], [[CCC]], August 13, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=74780 Don't understand NNUE] by Lucasart, [[CCC]], August 14, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74901 SF+NNUE reach the ceiling?] by Corres, [[CCC]], August 27, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74933 The most stupid idea by the Stockfish Team] by Damir, [[CCC]], August 30, 2020
 +
===September===
 +
* [https://groups.google.com/d/msg/fishcooking/TJHsiI61yQ4/liQoZ-AzAgAJ Stockfish 12] by [[Joost VandeVondele]], [[Computer Chess Forums|FishCooking]], September 02, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74974 Stockfish 12 is released today!] by Nay Lin Tun, [[CCC]], September 02, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74978 Stockfish 12 has arrived!] by daniel71, [[CCC]], September 02, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=75008 AVX2 optimized SF+NNUE and processor temperature]  by corres, [[CCC]], September 05, 2020 » [[AVX2]]
 +
===October===
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=75296 BONA_PIECE_ZERO] by [[Marco Belli|elcabesa]], [[CCC]], October 04, 2020
 +
* [https://groups.google.com/d/msg/fishcooking/yjh1YOxy7nw/rJA6u1ODAAAJ SF NNUE/Classical] by [[Fauzi Akram Dabat|Fauzi]], [[Computer Chess Forums|FishCooking]], October 05, 2020
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=75415 How to scale stockfish NNUE score?] by [[Maksim Korzh]], [[CCC]], October 17, 2020 » [[Stockfish NNUE]], [[Scorpio#NNUE|Scorpio NNUE]]
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=75418 Embedding Stockfish NNUE to ANY CHESS ENGINE: YouTube series] by [[Maksim Korzh]], [[CCC]], October 17, 2020 » [[BBC#NNUE|BBC NNUE]]
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=75506 NNUE Question - King Placements] by [[Andrew Grant]], [[CCC]], October 23, 2020 » [[#NNUE Structure|NNUE Structure]]
 +
: [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=75506&start=7 Re: NNUE Question - King Placements] by [[Ronald de Man|syzygy]], [[CCC]], October 23, 2020
 +
: [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=75506&start=9 Re: NNUE Question - King Placements] by [[Ronald de Man|syzygy]], [[CCC]], October 23, 2020
 +
==2021 ...==
 +
* [https://groups.google.com/g/fishcooking/c/cad1MGSdpU4/m/Ury4iBqSBgAJ Shouldn't positional attributes drive SF's NNUE input features (rather than king position)?] by [[Nick Pelling]], [[Computer Chess Forums|FishCooking]], January 10, 2021
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=76381 stockfish NNUE question] by [[Jon Dart]], [[CCC]], January 21, 2021
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=76437 256 in NNUE?] by Ted Wong, [[CCC]], January 28, 2021
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=76537 Fat Fritz 2] by [[Jouni Uski]], [[CCC]], February 09, 2021 » [[Fat Fritz#Fat Fritz 2|Fat Fritz 2.0]]
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=76833 NNUE Research Project] by [[Ed Schroder|Ed Schröder]], [[CCC]], March 10, 2021 » [[NNUE]]
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=76844 NNUE ranking] by Jim Logan, [[CCC]], March 12, 2021
 +
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=77344 Stockfish with new NNUE architecture and bigger net released] by [[Stefan Pohl]], [[CCC]], May 19, 2021  <ref>[https://github.com/official-stockfish/Stockfish/pull/3474 Update default net to nn-8a08400ed089.nnue by Sopel97 · Pull Request #3474 · official-stockfish/Stockfish · GitHub] by [[Tomasz Sobczyk]]</ref>
 +
* [http://talkchess.com/forum3/viewtopic.php?f=7&t=79020 Why NNUE trainer requires an online qsearch on each training position?] by [[nkg114mc]], [[CCC]], January 01, 2022
  
 
=External Links=  
 
=External Links=  
==Chess Engine==
+
==Basics==
 
* [http://yaneuraou.yaneu.com/2020/06/19/stockfish-nnue-the-complete-guide/ Stockfish NNUE – The Complete Guide], June 19, 2020 (Japanese and English)
 
* [http://yaneuraou.yaneu.com/2020/06/19/stockfish-nnue-the-complete-guide/ Stockfish NNUE – The Complete Guide], June 19, 2020 (Japanese and English)
* [https://github.com/nodchip/Stockfish GitHub - nodchip/Stockfish: UCI chess engine] by [[Nodchip]]
+
* [http://yaneuraou.yaneu.com/2020/08/21/3-technologies-in-shogi-ai-that-could-be-used-for-chess-ai/ 3 technologies in shogi AI that could be used for chess AI] by [[Motohiro Isozaki]], August 21, 2020
 
* [https://www.qhapaq.org/shogi/shogiwiki/stockfish-nnue/ Stockfish NNUE Wiki]
 
* [https://www.qhapaq.org/shogi/shogiwiki/stockfish-nnue/ Stockfish NNUE Wiki]
 
* [https://github.com/official-stockfish/Stockfish/issues/2823 NNUE merge · Issue #2823 · official-stockfish/Stockfish · GitHub] by [[Joost VandeVondele]], July 25, 2020 <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74560 An info] by Sylwy, [[CCC]], July 25, 2020</ref>
 
* [https://github.com/official-stockfish/Stockfish/issues/2823 NNUE merge · Issue #2823 · official-stockfish/Stockfish · GitHub] by [[Joost VandeVondele]], July 25, 2020 <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74560 An info] by Sylwy, [[CCC]], July 25, 2020</ref>
 +
* [https://hxim.github.io/Stockfish-Evaluation-Guide/?p=nnue Stockfish Evaluation Guide] <ref>[http://www.talkchess.com/forum3/viewtopic.php?f=2&t=74681 You can now look inside NNUE and look at its Per square value estimation] by [[Henk Drost]], [[CCC]], August 04, 2020</ref>
 +
* [https://github.com/glinscott/nnue-pytorch/blob/master/docs/nnue.md NNUE Guide (nnue-pytorch/nnue.md at master · glinscott/nnue-pytorch · GitHub)] hosted by [[Gary Linscott]]
 +
* [https://github.com/official-stockfish/Stockfish/discussions/3628 One year of NNUE.... · official-stockfish/Stockfish · GitHub] by [[Joost VandeVondele]], July 26, 2021
 +
 +
==Source==
 +
* [https://github.com/official-stockfish/Stockfish GitHub - Official-stockfish]
 +
* [https://github.com/nodchip/Stockfish GitHub - nodchip/Stockfish: UCI chess engine] by [[Hisayori Noda|Nodchip]]
 +
* [https://github.com/vondele/Stockfish/tree/nnue-player-wip GitHub - vondele/Stockfish at nnue-player-wip] by [[Joost VandeVondele]]
 +
* [https://github.com/tttak/Stockfish GitHub - tttak/Stockfish: UCI chess engine]
 +
* [https://github.com/joergoster/Stockfish-NNUE GitHub - joergoster/Stockfish-NNUE: UCI Chess engine Stockfish with an Efficiently Updatable Neural-Network-based evaluation function] hosted by [[Jörg Oster]]
 +
* [https://github.com/FireFather/sf-nnue GitHub - FireFather/sf-nnue: Stockfish NNUE (efficiently updateable neural network)] by [[Norman Schmidt]]
 +
* [https://github.com/FireFather/nnue-gui GitHub - FireFather/nnue-gui: basic windows application for using nodchip's stockfish-nnue software] by [[Norman Schmidt]]
 +
==Networks==
 +
* [https://tests.stockfishchess.org/nns Neural Net download and statistics]
 
* [https://www.comp.nus.edu.sg/~sergio-v/nnue/ Index of /~sergio-v/nnue] by [[Sergio Vieri]]
 
* [https://www.comp.nus.edu.sg/~sergio-v/nnue/ Index of /~sergio-v/nnue] by [[Sergio Vieri]]
 +
==Rating==
 +
* [https://github.com/glinscott/fishtest/wiki/Regression-Tests Regression Tests]
 +
* [http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?match_length=30&each_game=1&print=Details&each_game=1&eng=Stockfish%2014%2064-bit%208CPU#Stockfish_14_64-bit_8CPU Stockfish 14 64-bit 8CPU]  in [[CCRL|CCRL Blitz]]
 +
* [http://ccrl.chessdom.com/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Stockfish%2012%2064-bit#Stockfish_12_64-bit Stockfish 12 64-bit] in [[CCRL|CCRL Blitz]]
 +
* [http://computerchess.org.uk/ccrl/404/cgi/engine_details.cgi?print=Details&each_game=1&eng=Stockfish%2BNNUE%20150720%2064-bit%204CPU#Stockfish%2BNNUE_150720_64-bit_4CPU Stockfish+NNUE 150720 64-bit 4CPU] in [[CCRL|CCRL Blitz]]
 
==Misc==
 
==Misc==
 
* [https://en.wikipedia.org/wiki/Stockfish Stockfish from Wikipedia]
 
* [https://en.wikipedia.org/wiki/Stockfish Stockfish from Wikipedia]
 
* [https://en.wikipedia.org/wiki/Nue Nue from Wikipedia]
 
* [https://en.wikipedia.org/wiki/Nue Nue from Wikipedia]
* [https://en.wikipedia.org/wiki/Ikuchi Ikuchi from Wikipedia]
+
* [[:Category:Senri Kawaguchi|Senri Kawaguchi]] - [https://ameliaray.net/quarantuned The Quarantuned Music Festival], May 2020, [https://en.wikipedia.org/wiki/YouTube YouTube] Video
 +
: {{#evu:https://www.youtube.com/watch?v=jO8VlSqw7do|alignment=left|valignment=top}}
  
 
=References=  
 
=References=  
Line 53: Line 201:
 
[[Category:Open Source]]
 
[[Category:Open Source]]
 
[[Category:GPL]]
 
[[Category:GPL]]
[[Category:NN]]
+
[[Category:Chess960]]
 +
[[Category:X86]]
 +
[[Category:X64]]
 +
[[Category:NNUE]]
 
[[Category:PC]]
 
[[Category:PC]]
 
[[Category:Windows]]
 
[[Category:Windows]]
Line 59: Line 210:
 
[[Category:Mac]]
 
[[Category:Mac]]
 
[[Category:Fish]]
 
[[Category:Fish]]
[[Category:Demonology]]
+
[[Category:Senri Kawaguchi]]
[[Category:Toriyama Sekien]]
 

Latest revision as of 06:22, 3 January 2022

Home * Engines * Stockfish * NNUE

Stockfish NNUE Logo [1]

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]. YaneuraOu's author Motohiro Isozaki 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 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] then replaced by PyTorch [14][15]. On September 02, 2020, Stockfish 12 was released with a huge jump in playing strength due to the introduction of NNUE and further tuning [16].

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 [17].

HalfKP

The so called HalfKP structure consists of two halves covering input layer and first hidden layer, each half of the input layer associated to one of the two kings, cross coupled with the side to move or not to move halves of the first hidden layer. For each either black or white king placement, the 10 none king pieces on their particular squares are the boolean {0,1} inputs, along with a relict from Shogi piece drop (BONA_PIECE_ZERO), 64 x (64 x 10 + 1) = 41,024 inputs for each half, which are multiplied by a 16-bit integer weight vector for 256 outputs per half, in total, 256 x 41,024 = 10,502,144 weights. As emphasized by Ronald de Man in a CCC forum discussion [18], the input weights are arranged in such a way, that color flipped king-piece configurations in both halves share the same index. However, and that seems also a relict from Shogi with its 180 degrees rotational 9x9 board symmetry, instead of vertical flipping (xor 56), rotation is applied (xor 63) [19].

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 in case of none king moves. The remaining three layers with 2x256x32, 32x32 and 32x1 weights are computational less expensive, hidden layers apply a ReLu activation [20] [21], 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.

StockfishNNUELayers.png

NNUE layers in action [22]

Explanation by Ronald de Man [23], who did the Stockfish NNUE port to CFish [24]:

The accumulator has a "white king" half and a "black king" half, where each half is a 256-element vector of 16-bit ints, which is equal to the sum of the weights of the "active" (pt, sq, ksq) features  plus a 256-element vector of 16-bit biases.
The "transform" step of the NNUE evaluation forms a 512-element vector of 8-bit ints where the first half is formed from the 256-element vector of the side to move and the second half is formed from the 256-element vector of the other side. In this step the 16-bit elements are clipped/clamped to a value from 0 to 127. This is the output of the input layer.
This 512-element vector of 8-bit ints is then multiplied by a 32x512 matrix of 8-bit weights to get a 32-element vector of 32-bit ints, to which a vector of 32-bit biases is added. The sum vector is divided by 64 and clipped/clamped to a 32-element vector of 8-bit ints from 0 to 127. This is the output of the first hidden layer.
The resulting 32-element vector of 8-bit ints is multiplied by a 32x32 matrix of 8-bit weights to get a 32-element vector of 32-bit ints, to which another vector of 32-bit biases is added. These ints are again divided by 64 and clipped/clamped to 32 8-bit ints from 0 to 127. This is the output of the second hidden layer.
This 32-element vector of 8-bits ints is then multiplied by a 1x32 matrix of 8-bit weights (i.e. the inner product of two vectors is taken). This produces a 32-bit value to which a 32-bit bias is added. This gives the output of the output layer.
The output of the output layer is divided by FV_SCALE = 16 to produce the NNUE evaluation. SF's evaluation then take some further steps such as adding a Tempo bonus (even though the NNUE evaluation inherently already takes into account the side to move in the "transform" step) and scaling the evaluation towards zero as rule50_count() approaches 50 moves.

HalfKA

In subsequent Stockfish versions the network architecture was further improved by Tomasz Sobczyk et al.. The HalfKA architecture uses 12x64x64 = 45056 inputs for each of the 12 piece types times 64 squares for each of the 64 own king squares, times two, for both the side to move and other side perspective, further using the vertical flip instead of the HalfKP rotate. HalfKAv2 as applied in Stockfish 14 saves some space considering the king square redundancy using 11x64x64 = 45056 inputs per side, mapped to a 2x520 linear feature transformer [25] [26] [27], further feeding 8x2 outputs of this feature transformer directly to the output for better learning of unbalanced material configurations [28]. Another improvement was using eight 512x2->16->32->1 output sub-networks discriminated by (piece_count-1) div 4 in the 0 to 7 range [29].

HalfKAv2.png

HalfKAv2 architecture by Tomasz Sobczyk [30]

Network

Networks were built by volunteers, uploaded into Fishtest for testing. Networks with good test results are released officially on the Fishtest website [31] with average speed of 2 weeks per network [32]. After long discussing the best way to publish networks with Stockfish [33], the developing team decided to embed the default network into Stockfish binaries, making sure NNUE always works as well as bringing more convenience to users.

In late 2020, Gary Linscott started an implementation of the Stockfish NNUE training in PyTorch [34] [35] using GPU resources to efficiently train networks. Further, the collaboration with the Leela Chess Zero team in February 2021 [36] payed off, in providing billions of positions to train the new networks [37].

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 [38]. 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 [39] [40] to a then underemployed GPU are not sufficient for the intended NPS range [41]
  • 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

  • Requires small 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 a sophisticated client-server model to train networks. Just a single binary from Nodchip’ repo is enough to train
  • The NNUE code is independent and can be separated easily from the rest and integrated to other engines [42]

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 gain

Joost VandeVondele has created a graph to show how Stockfish gains Elo with NNUE after a year:[43]

NNEUOneYearEloGain.png

Suggestions

In reply to Unai Corzo, Motohiro Isozaki aka Yaneurao, suggested 3 techniques that applied successfully to Shogi and can be brought back to Stockfish NNUE and may improve it another 100 - 200 Elo [44] [45]:

See also

Forum Posts

2020 ...

January ...

July

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

August

Re: this will be the merge of a lifetime : SF 80 Elo+ by Henk Drost, CCC, August 04, 2020

September

October

Re: NNUE Question - King Placements by syzygy, CCC, October 23, 2020
Re: NNUE Question - King Placements by syzygy, CCC, October 23, 2020

2021 ...

External Links

Basics

Source

Networks

Rating

Misc

References

  1. Stockfish NNUE Logo from GitHub - nodchip/Stockfish: UCI chess engine by Nodchip
  2. Yu Nasu (2018). ƎUИИ Efficiently Updatable Neural-Network based Evaluation Functions for Computer Shogi. Ziosoft Computer Shogi Club, pdf (Japanese with English abstract) GitHub - asdfjkl/nnue translation
  3. The Stockfish of shogi by Larry Kaufman, CCC, January 07, 2020
  4. GitHub - yaneurao/YaneuraOu: YaneuraOu is the World's Strongest Shogi engine(AI player), WCSC29 1st winner, educational and USI compliant engine
  5. GitHub - Tama4649/Kristallweizen: 第29回世界コンピュータ将棋選手権 準優勝のKristallweizenです。
  6. 将棋ソフト開発者がStockfishに貢献する日 The day when shogi software developers contribute to Stockfish by Motohiro Isozaki, June 2019
  7. shogi engine developer claims he can make Stockfish stronger, Reddit, August 2019
  8. Stockfish NNUE – The Complete Guide, June 19, 2020 (Japanese and English)
  9. Stockfish NN release (NNUE) by Henk Drost, CCC, May 31, 2020
  10. Can the sardine! NNUE clobbers SF by Henk Drost, CCC, July 16, 2020
  11. Introducing NNUE Evaluation, August 06, 2020
  12. NNUE merge · Issue #2823 · official-stockfish/Stockfish · GitHub by Joost VandeVondele, July 25, 2020
  13. GitHub - nodchip/Stockfish: UCI chess engine by Nodchip
  14. Pytorch NNUE training by Gary Linscott, CCC, November 08, 2020
  15. Why NNUE trainer requires an online qsearch on each training position? by nkg114mc, CCC, January 01, 2022
  16. Stockfish 12, The Stockfish Team, Stockfish Blog, September 02, 2020
  17. Re: NNUE accessible explanation by Jonathan Rosenthal, CCC, July 23, 2020
  18. Re: NNUE Question - King Placements by syzygy, CCC, October 23, 2020
  19. NNUE eval rotate vs mirror · Issue #3021 · official-stockfish/Stockfish · GitHub by Terje Kirstihagen, August 17, 2020
  20. Stockfish/halfkp_256x2-32-32.h at master · official-stockfish/Stockfish · GitHub
  21. Stockfish/clipped_relu.h at master · official-stockfish/Stockfish · GitHub
  22. Image courtesy Roman Zhukov, revised version of the image posted in Re: Stockfish NN release (NNUE) by Roman Zhukov, CCC, June 17, 2020, labels corrected October 23, 2020, see Re: NNUE Question - King Placements by Andrew Grant, CCC, October 23, 2020
  23. Re: NNUE Question - King Placements by syzygy, CCC, October 23, 2020
  24. Cfish/nnue.c at master · syzygy1/Cfish · GitHub
  25. New NNUE architecture and net · official-stockfish/Stockfish@e8d64af · GitHub
  26. Update default net to nn-8a08400ed089.nnue by Sopel97 · Pull Request #3474 · official-stockfish/Stockfish · GitHub
  27. HalfKAv2 feature set | nnue-pytorch/nnue.md at master · glinscott/nnue-pytorch · GitHub
  28. A part of the feature transformer directly forwarded to the output | nnue-pytorch/nnue.md at master · glinscott/nnue-pytorch · GitHub
  29. Multiple PSQT outputs and multiple subnetworks | nnue-pytorch/nnue.md at master · glinscott/nnue-pytorch · GitHub
  30. HalfKAv2.png Image courtesy by Tomasz Sobczyk
  31. Neural Net download and statistics
  32. One year of NNUE.... · official-stockfish/Stockfish · GitHub by Joost VandeVondele, July 26, 2021
  33. Improve dealing with the default net? Issue ##3030 · official-stockfish/Stockfish · GitHub by Joost VandeVondele, August 19, 2020
  34. Pytorch NNUE training by Gary Linscott, CCC, November 08, 2020
  35. GitHub - glinscott/nnue-pytorch: NNUE (Chess evaluation) trainer in Pytorch
  36. Stockfish 13 by Joost VandeVondele, FishCooking, February 19, 2021
  37. Stockfish 14, The Stockfish Team, July 02, 2021
  38. NNUE evaluation threshold by MJZ1977 · Pull Request #2916 · official-stockfish/Stockfish · GitHub, August 06, 2020
  39. AB search with NN on GPU... by Srdja Matovic, CCC, August 13, 2020 » GPU
  40. kernel launch latency - CUDA / CUDA Programming and Performance - NVIDIA Developer Forums by LukeCuda, June 18, 2018
  41. stockfish with graphics card by h1a8, CCC, August 06, 2020
  42. NNUE Engines
  43. One year of NNUE.... · official-stockfish/Stockfish · GitHub by Joost VandeVondele, July 26, 2021
  44. 3 technologies in shogi AI that could be used for chess AI, Motohiro Isozaki, August 2020
  45. GitHub - NNUE ideas and discussion (post-merge). #2915, August 2020
  46. Update default net to nn-8a08400ed089.nnue by Sopel97 · Pull Request #3474 · official-stockfish/Stockfish · GitHub by Tomasz Sobczyk
  47. An info by Sylwy, CCC, July 25, 2020
  48. You can now look inside NNUE and look at its Per square value estimation by Henk Drost, CCC, August 04, 2020

Up one Level