Skip to content

Commit

Permalink
Re-evaluate some small net positions for more accurate evals
Browse files Browse the repository at this point in the history
Use main net evals when small net evals hint that higher eval
accuracy may be worth the slower eval speeds. With Finny caches,
re-evals with the main net are less expensive than before.

Original idea by mstembera who I've added as co-author to this PR.

Based on reEval tests by mstembera:
https://tests.stockfishchess.org/tests/view/65e69187b6345c1b934866e5
https://tests.stockfishchess.org/tests/view/65e863aa0ec64f0526c3e991

A few variants of this patch also passed LTC:
https://tests.stockfishchess.org/tests/view/663d2108507ebe1c0e91f407
https://tests.stockfishchess.org/tests/view/663e388c3a2f9702074bc152

Passed STC:
https://tests.stockfishchess.org/tests/view/663dadbd1a61d6377f190e2c
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 92320 W: 23941 L: 23531 D: 44848
Ptnml(0-2): 430, 10993, 22931, 11349, 457

Passed LTC:
https://tests.stockfishchess.org/tests/view/663ef48b2948bf9aa698690c
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 98934 W: 24907 L: 24457 D: 49570
Ptnml(0-2): 48, 10952, 27027, 11382, 58

closes #5238

bench 1876282

Co-Authored-By: mstembera <5421953+mstembera@users.noreply.github.com>
  • Loading branch information
2 people authored and vondele committed May 13, 2024
1 parent 53f3630 commit 0b08953
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ Value Eval::evaluate(const Eval::NNUE::Networks& networks,
Value nnue = smallNet ? networks.small.evaluate(pos, &caches.small, true, &nnueComplexity)
: networks.big.evaluate(pos, &caches.big, true, &nnueComplexity);

if (smallNet && (nnue * simpleEval < 0 || std::abs(nnue) < 500))
nnue = networks.big.evaluate(pos, &caches.big, true, &nnueComplexity);

const auto adjustEval = [&](int nnueDiv, int pawnCountMul, int evalDiv, int shufflingConstant) {
// Blend optimism and eval with nnue complexity and material imbalance
optimism += optimism * (nnueComplexity + std::abs(simpleEval - nnue)) / 584;
Expand Down
2 changes: 1 addition & 1 deletion src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Position;

namespace Eval {

constexpr inline int SmallNetThreshold = 1274;
constexpr inline int SmallNetThreshold = 1174;

// The default net name MUST follow the format nn-[SHA256 first 12 digits].nnue
// for the build process (profile-build and fishtest) to work. Do not change the
Expand Down

0 comments on commit 0b08953

Please sign in to comment.