Changes

Jump to: navigation, search

Stockfish NNUE

6,559 bytes added, 06:22, 3 January 2022
no edit summary
'''Stockfish NNUE''',<br/>
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)[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>,
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>.
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>.
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=
<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,503502,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.
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=
All networks are Networks were built by some volunteers but not by any big community (differs from [[Leela Chess Zero]]) and can be , uploaded into [[Stockfish#Fishtest|Fishtest]] for testing. Networks with good test results will be 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.
After long discussing In late 2020, [[Gary Linscott]] started an implementation of the best way to publish networks with 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/officialglinscott/nnue-pytorch GitHub -stockfishglinscott/Stockfishnnue-pytorch: NNUE (Chess evaluation) trainer in Pytorch]</issues/3030 Improve dealing ref> using [[GPU]] resources to efficiently train networks. Further, the collaboration with the default net? Issue ##3030 · official[[Leela Chess Zero]] team in February 2021 <ref>[https://groups.google.com/g/fishcooking/c/AzYDbbv-stockfish/Coo Stockfish · GitHub13] by [[Joost VandeVondele]], August [[Computer Chess Forums|FishCooking]], February 19, 20202021 </ref>payed off, the developing team decided in providing billions of positions to embed train the default network into new networks <ref>[https://stockfishchess.org/blog/2021/stockfish-14/ Stockfish 14], The Stockfish binariesTeam, July 02, making sure NNUE always works as well as bringing more convenience to users2021</ref>.
=Hybrid=
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=
=See also=
* [[:Category:NN|Category: Neural Network Engines]]
* [[Fat Fritz#Fat Fritz 2|Fat Fritz 2.0]]
* [[Neural Networks]]
* [[NNUE]]
=Forum Posts=
==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=7&t=74058 Stockfish NNUE] by [[Henk Drost]], [[CCC]], May 31, 2020 » [[Stockfish]]
===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=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=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=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=
* [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]
==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==
* [https://en.wikipedia.org/wiki/Stockfish Stockfish from Wikipedia]
* [https://en.wikipedia.org/wiki/Nue Nue from Wikipedia]
* [[:Category:Hiromi UeharaSenri Kawaguchi|HiromiSenri Kawaguchi]] - [https://en.wikipediaameliaray.org/wikinet/Spectrum_(Hiromi_album) Spectrumquarantuned The Quarantuned Music Festival], 2019May 2020, [https://en.wikipedia.org/wiki/YouTube YouTube] Video: {{#evu:https://www.youtube.com/watch?v=A8RCz_RoefMjO8VlSqw7do|alignment=left|valignment=top}}
=References=
[[Category:Mac]]
[[Category:Fish]]
[[Category:Hiromi UeharaSenri Kawaguchi]]

Navigation menu