Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXPERIMENT] NNUE #21

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
84f3e86
Add NNUE evaluation
nodchip Aug 5, 2020
3dca13a
NNUE evaluation threshold
MJZ1977 Aug 6, 2020
8b8412e
Add tempo also to NNUE eval.
locutus2 Aug 6, 2020
af93536
Tuned pawn values
FauziAkram Aug 7, 2020
7f336dd
Remove QueenInfiltration
unaiic Aug 4, 2020
615d98d
Do move legality check before pruning.
locutus2 Aug 5, 2020
857e045
Update default net to nn-9931db908a9b.nnue
sergiovieri Aug 7, 2020
dc5af66
Tweak futility pruning depth.
unaiic Aug 8, 2020
5ccff25
Expand outposts to minors shielded by pawns
Lolligerhans Aug 7, 2020
f4c27cd
Reintroduce late irreversible move extension
SFisGOD Aug 7, 2020
910f779
Do more futility pruning for parent nodes.
Vizvezdenec Aug 8, 2020
23ecf3d
simplified and increased threshold to switch between NNUE and classical
jjoshua2 Aug 7, 2020
450b60a
Remove unnecessay legality check
loco-loco Aug 8, 2020
3368d03
update Null Move Pruning parameters
MJZ1977 Aug 8, 2020
e663bc5
Do more aggressive futility pruning for captures
Vizvezdenec Aug 8, 2020
6d6267c
Parallelize Link Time Optimization for GCC, CLANG and MINGW
gvreuls Aug 8, 2020
1949eb8
Singular extension search tweak
unaiic Aug 8, 2020
add890a
LMR search tweak
unaiic Aug 8, 2020
d7a2689
Use fallback implementation for C++ aligned_alloc
ddugovic Aug 8, 2020
320fa1b
Improve error message on missing net.
vondele Aug 9, 2020
cd1bb27
Fix aligned_alloc on MinGW
vondele Aug 9, 2020
2bfde55
Adjust NNUE usage based on number of pawns in position
Vizvezdenec Aug 9, 2020
a6e8929
Avoid special casing for MinGW
dorzechowski Aug 9, 2020
27b593a
Fix a data race for NNUE
vondele Aug 9, 2020
651ec3b
Revert "Avoid special casing for MinGW"
vondele Aug 10, 2020
bcdf41d
Update default net to nn-112bb1c8cdb5.nnue
sergiovieri Aug 10, 2020
a54f901
simplying hybrid condition
jjoshua2 Aug 9, 2020
875183b
Workaround using unaligned loads for gcc < 9
Aug 10, 2020
ad2ad4c
Modify castling extension
SFisGOD Aug 10, 2020
cb05040
Makefile rework/cleanup
sf-x Aug 9, 2020
f948cd0
Cleanup and optimize SSE/AVX code
Aug 9, 2020
21df37d
Provide vectorized NNUE code for SSE2 and MMX targets
Fanael Aug 9, 2020
220ef1d
Assorted search parameter tune
unaiic Aug 10, 2020
a72cec1
Add comments to probCut code
Vizvezdenec Jul 18, 2020
4ab8b0b
Fix parallel LTO issues on Windows
gvreuls Aug 11, 2020
399cddf
More aligned_alloc changes to support Android
vondele Aug 10, 2020
f46c730
Fix AVX512 build with older compilers
Aug 10, 2020
ea6220f
This commit enables a mixed bench, to improve CI and allow for PGO (p…
gvreuls Aug 7, 2020
ee06046
Tweak castling extension
SFisGOD Aug 10, 2020
992f549
Restrict avx2 hack to windows target
vondele Aug 11, 2020
6bc0256
Use posix_memalign for Apple Silicon instead of _mm_malloc
daylen Aug 11, 2020
dd63b98
Add support for VNNI
Aug 11, 2020
69cfe28
Output the SSE2 flag in compiler_info
vondele Aug 12, 2020
67e4841
Update default net to nn-82215d0fd0df.nnue
sergiovieri Aug 12, 2020
e8ea215
Clean-up Makefile help
snicolet Aug 13, 2020
ce009ea
Verify SHA of downloaded net file
vondele Aug 13, 2020
e5f450c
Also dampen NNUE eval with 50 move rule
miguel-l Aug 10, 2020
6eb186c
Try to match relative magnitude of NNUE eval to classical
Aug 14, 2020
4e456a5
Merge remote-tracking branch 'official-stockfish/master' into nnue
niklasf Aug 15, 2020
e38ac20
stockfish.wasm: Remove EvalFile option
niklasf Aug 15, 2020
d313d30
stockfish.wasm: Fetch eval file
niklasf Aug 15, 2020
fc24878
stockfish.wasm: Add debug for NNUE loading
niklasf Aug 15, 2020
2b9474f
stockfish.wasm: Enable SIMD
niklasf Aug 15, 2020
6f0f56e
stockfish.wasm: Fix ssse3
niklasf Aug 16, 2020
87d56f5
Merge remote-tracking branch 'origin/master' into nnue
niklasf Nov 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# List of authors for Stockfish, as of March 30, 2020
# List of authors for Stockfish, as of August 4, 2020

# Founders of the Stockfish project and fishtest infrastructure
Tord Romstad (romstad)
Marco Costalba (mcostalba)
Joona Kiiski (zamar)
Gary Linscott (glinscott)

# Authors and inventors of NNUE, training, NNUE port
Yu Nasu (ynasu87)
Motohiro Isozaki (yaneurao)
Hisayori Noda (nodchip)

# all other authors of the code in alphabetical order
Aditya (absimaldata)
Adrian Petrescu (apetresc)
Ajith Chandy Jose (ajithcj)
Expand Down Expand Up @@ -36,6 +43,7 @@ Dariusz Orzechowski
David Zar
Daylen Yang (daylen)
DiscanX
Dominik Schlösser (domschl)
double-beep
Eduardo Cáceres (eduherminio)
Eelco de Groot (KingDefender)
Expand All @@ -45,6 +53,7 @@ Ernesto Gatti
Linmiao Xu (linrock)
Fabian Beuke (madnight)
Fabian Fichter (ianfab)
Fanael Linithien (Fanael)
fanon
Fauzi Akram Dabat (FauziAkram)
Felix Wittmann
Expand All @@ -71,6 +80,7 @@ Jean Gauthier (OuaisBla)
Jean-Francois Romang (jromang)
Jekaa
Jerry Donald Watson (jerrydonaldwatson)
jjoshua2
Jonathan Calovski (Mysseno)
Jonathan Dumale (SFisGOD)
Joost VandeVondele (vondele)
Expand Down Expand Up @@ -115,7 +125,8 @@ Nick Pelling (nickpelling)
Nicklas Persson (NicklasPersson)
Niklas Fiekas (niklasf)
Nikolay Kostov (NikolayIT)
Nguyen Pham
Nguyen Pham (nguyenpham)
Norman Schmidt (FireFather)
Ondrej Mosnáček (WOnder93)
Oskar Werkelin Ahlin
Pablo Vazquez
Expand All @@ -135,14 +146,17 @@ Richard Lloyd
Rodrigo Exterckötter Tjäder
Ron Britvich (Britvich)
Ronald de Man (syzygy1, syzygy)
rqs
Ryan Schmitt
Ryan Takker
Sami Kiminki (skiminki)
Sebastian Buchwald (UniQP)
Sergei Antonov (saproj)
Sergei Ivanov (svivanov72)
Sergio Vieri (sergiovieri)
sf-x
Shane Booth (shane31)
Shawn Varghese (xXH4CKST3RXx)
Stefan Geschwentner (locutus2)
Stefano Cardanobile (Stefano80)
Steinar Gunderson (sesse)
Expand All @@ -155,9 +169,11 @@ Tom Vijlbrief (tomtor)
Tomasz Sobczyk (Sopel97)
Torsten Franz (torfranz, tfranzer)
Tracey Emery (basepr1me)
tttak
Unai Corzo (unaiic)
Uri Blass (uriblass)
Vince Negri (cuddlestmonkey)
zz4032


# Additionally, we acknowledge the authors and maintainers of fishtest,
Expand Down
File renamed without changes.
125 changes: 86 additions & 39 deletions Readme.upstream.md → README.upstream.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
[![Build Status](https://ci.appveyor.com/api/projects/status/github/official-stockfish/Stockfish?branch=master&svg=true)](https://ci.appveyor.com/project/mcostalba/stockfish/branch/master)

[Stockfish](https://stockfishchess.org) is a free, powerful UCI chess engine
derived from Glaurung 2.1. It is not a complete chess program and requires a
derived from Glaurung 2.1. It features two evaluation functions, the classical
evaluation based on handcrafted terms, and the NNUE evaluation based on
efficiently updateable neural networks. The classical evaluation runs efficiently
on most 64bit CPU architectures, while the NNUE evaluation benefits strongly from the
vector intrinsics available on modern CPUs (avx2 or similar).

Stockfish is not a complete chess program and requires a
UCI-compatible GUI (e.g. XBoard with PolyGlot, Scid, Cute Chess, eboard, Arena,
Sigma Chess, Shredder, Chess Partner or Fritz) in order to be used comfortably.
Read the documentation for your GUI of choice for information about how to use
Expand All @@ -22,20 +28,19 @@ This distribution of Stockfish consists of the following files:
* src, a subdirectory containing the full source code, including a Makefile
that can be used to compile Stockfish on Unix-like systems.

To use the NNUE evaluation an additional data file with neural network parameters
needs to be downloaded. The filename for the default set can be found as the default
value of the `EvalFile` UCI option, with the format
`nn-[SHA256 first 12 digits].nnue` (e.g. nn-c157e0a5755b.nnue). This file can be downloaded from
```
https://tests.stockfishchess.org/api/nn/[filename]
```
replacing `[filename]` as needed.

## UCI parameters

Currently, Stockfish has the following UCI options:

* #### Debug Log File
Write all communication to and from the engine into a text file.

* #### Contempt
A positive value for contempt favors middle game positions and avoids draws.
## UCI options

* #### Analysis Contempt
By default, contempt is set to prefer the side to move. Set this option to "White"
or "Black" to analyse with contempt for that side, or "Off" to disable contempt.
Currently, Stockfish has the following UCI options:

* #### Threads
The number of CPU threads used for searching a position. For best performance, set
Expand All @@ -44,50 +49,51 @@ Currently, Stockfish has the following UCI options:
* #### Hash
The size of the hash table in MB. It is recommended to set Hash after setting Threads.

* #### Clear Hash
Clear the hash table.

* #### Ponder
Let Stockfish ponder its next move while the opponent is thinking.

* #### MultiPV
Output the N best lines (principal variations, PVs) when searching.
Leave at 1 for best performance.

* #### Skill Level
Lower the Skill Level in order to make Stockfish play weaker (see also UCI_LimitStrength).
Internally, MultiPV is enabled, and with a certain probability depending on the Skill Level a
weaker move will be played.
* #### Use NNUE
Toggle between the NNUE and classical evaluation functions. If set to "true",
the network parameters must be available to load from file (see also EvalFile).

* #### UCI_LimitStrength
Enable weaker play aiming for an Elo rating as set by UCI_Elo. This option overrides Skill Level.
* #### EvalFile
The name of the file of the NNUE evaluation parameters. Depending on the GUI the
filename should include the full path to the folder/directory that contains the file.

* #### UCI_Elo
If enabled by UCI_LimitStrength, aim for an engine strength of the given Elo.
This Elo rating has been calibrated at a time control of 60s+0.6s and anchored to CCRL 40/4.
* #### Contempt
A positive value for contempt favors middle game positions and avoids draws,
effective for the classical evaluation only.

* #### Analysis Contempt
By default, contempt is set to prefer the side to move. Set this option to "White"
or "Black" to analyse with contempt for that side, or "Off" to disable contempt.

* #### UCI_AnalyseMode
An option handled by your GUI.

* #### UCI_Chess960
An option handled by your GUI. If true, Stockfish will play Chess960.

* #### UCI_ShowWDL
If enabled, show approximate WDL statistics as part of the engine output.
These WDL numbers model expected game outcomes for a given evaluation and
game ply for engine self-play at fishtest LTC conditions (60+0.6s per game).

* #### Move Overhead
Assume a time delay of x ms due to network and GUI overheads. This is useful to
avoid losses on time in those cases.

* #### Slow Mover
Lower values will make Stockfish take less time in games, higher values will
make it think longer.

* #### nodestime
Tells the engine to use nodes searched instead of wall time to account for
elapsed time. Useful for engine testing.
* #### UCI_LimitStrength
Enable weaker play aiming for an Elo rating as set by UCI_Elo. This option overrides Skill Level.

* #### UCI_Chess960
An option handled by your GUI. If true, Stockfish will play Chess960.
* #### UCI_Elo
If enabled by UCI_LimitStrength, aim for an engine strength of the given Elo.
This Elo rating has been calibrated at a time control of 60s+0.6s and anchored to CCRL 40/4.

* #### UCI_AnalyseMode
An option handled by your GUI.
* #### Skill Level
Lower the Skill Level in order to make Stockfish play weaker (see also UCI_LimitStrength).
Internally, MultiPV is enabled, and with a certain probability depending on the Skill Level a
weaker move will be played.

* #### SyzygyPath
Path to the folders/directories storing the Syzygy tablebase files. Multiple
Expand All @@ -114,6 +120,47 @@ Currently, Stockfish has the following UCI options:
Limit Syzygy tablebase probing to positions with at most this many pieces left
(including kings and pawns).

* #### Move Overhead
Assume a time delay of x ms due to network and GUI overheads. This is useful to
avoid losses on time in those cases.

* #### Slow Mover
Lower values will make Stockfish take less time in games, higher values will
make it think longer.

* #### nodestime
Tells the engine to use nodes searched instead of wall time to account for
elapsed time. Useful for engine testing.

* #### Clear Hash
Clear the hash table.

* #### Debug Log File
Write all communication to and from the engine into a text file.

## Classical and NNUE evaluation

Both approaches assign a value to a position that is used in alpha-beta (PVS) search
to find the best move. The classical evaluation computes this value as a function
of various chess concepts, handcrafted by experts, tested and tuned using fishtest.
The NNUE evaluation computes this value with a neural network based on basic
inputs (e.g. piece positions only). The network is optimized and trained
on the evalutions of millions of positions at moderate search depth.

The NNUE evaluation was first introduced in shogi, and ported to Stockfish afterward.
It can be evaluated efficiently on CPUs, and exploits the fact that only parts
of the neural network need to be updated after a typical chess move.
[The nodchip repository](https://github.com/nodchip/Stockfish) provides additional
tools to train and develop the NNUE networks.

On CPUs supporting modern vector instructions (avx2 and similar), the NNUE evaluation
results in stronger playing strength, even if the nodes per second computed by the engine
is somewhat lower (roughly 60% of nps is typical).

Note that the NNUE evaluation depends on the Stockfish binary and the network parameter
file (see EvalFile). Not every parameter file is compatible with a given Stockfish binary.
The default value of the EvalFile UCI option is the name of a network that is guaranteed
to be compatible with that binary.

## What to expect from Syzygybases?

Expand Down
31 changes: 24 additions & 7 deletions appveyor.upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ clone_depth: 50
branches:
only:
- master
- appveyor

# Operating system (build VM template)
os: Visual Studio 2017
os: Visual Studio 2019

# Build platform, i.e. x86, x64, AnyCPU. This setting is optional.
platform:
Expand Down Expand Up @@ -36,8 +35,11 @@ before_build:
$src = $src.Replace("\", "/")

# Build CMakeLists.txt
$t = 'cmake_minimum_required(VERSION 3.8)',
$t = 'cmake_minimum_required(VERSION 3.17)',
'project(Stockfish)',
'set(CMAKE_CXX_STANDARD 17)',
'set(CMAKE_CXX_STANDARD_REQUIRED ON)',
'set (CMAKE_CXX_EXTENSIONS OFF)',
'set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/src)',
'set(source_files', $src, ')',
'add_executable(stockfish ${source_files})'
Expand All @@ -51,13 +53,28 @@ before_build:
$b = git log HEAD | sls "\b[Bb]ench[ :]+[0-9]{7}" | select -first 1
$bench = $b -match '\D+(\d+)' | % { $matches[1] }
Write-Host "Reference bench:" $bench
$g = "Visual Studio 15 2017"
If (${env:PLATFORM} -eq 'x64') { $g = $g + ' Win64' }
cmake -G "${g}" .
Write-Host "Generated files for: " $g
$g = "Visual Studio 16 2019"
If (${env:PLATFORM} -eq 'x64') { $a = "x64" }
If (${env:PLATFORM} -eq 'x86') { $a = "Win32" }
cmake -G "${g}" -A ${a} .
Write-Host "Generated files for: " $g $a

build_script:
- cmake --build . --config %CONFIGURATION% -- /verbosity:minimal
- ps: |
# Download default NNUE net from fishtest
$nnuenet = Get-Content -Path src\ucioption.cpp | Select-String -CaseSensitive -Pattern "Option" | Select-String -CaseSensitive -Pattern "nn-[a-z0-9]{12}.nnue"
$dummy = $nnuenet -match "(?<nnuenet>nn-[a-z0-9]{12}.nnue)"
$nnuenet = $Matches.nnuenet
Write-Host "Default net:" $nnuenet
$nnuedownloadurl = "https://tests.stockfishchess.org/api/nn/$nnuenet"
$nnuefilepath = "src\${env:CONFIGURATION}\$nnuenet"
if (Test-Path -Path $nnuefilepath) {
Write-Host "Already available."
} else {
Write-Host "Downloading $nnuedownloadurl to $nnuefilepath"
Invoke-WebRequest -Uri $nnuedownloadurl -OutFile $nnuefilepath
}

before_test:
- cd src/%CONFIGURATION%
Expand Down
6 changes: 4 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
sf.postMessage('setoption name Analysis Contempt value Off');
setTimeout(() => {
console.log('============ START ============');
sf.postMessage('setoption name Threads value 16');
/* sf.postMessage('setoption name Threads value 16');
sf.postMessage('setoption name Hash value 1024');
sf.postMessage('position fen 4r1k1/r1q2ppp/ppp2n2/4P3/5Rb1/1N1BQ3/PPP3PP/R5K1 w - - 1 17');
sf.postMessage('go depth ' + depth);
sf.postMessage('go depth ' + depth); */
sf.postMessage('setoption name Use NNUE value true');
sf.postMessage('isready');
}, 3000);
});
</script>