From 3d5b2c8a5104888ec4d1ec44c171e29809e836a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Nicolet?= Date: Tue, 22 Sep 2020 22:43:41 +0200 Subject: [PATCH 01/11] Increase reductions with the number of threads Passed STC with 8 threads: LLR: 2.92 (-2.94,2.94) {-0.25,1.25} Total: 13520 W: 1135 L: 1012 D: 11373 Ptnml(0-2): 39, 815, 4929, 938, 39 https://tests.stockfishchess.org/tests/view/5f68e274ded68c240be73f41 Passed LTC with 8 threads: LLR: 2.96 (-2.94,2.94) {0.25,1.25} Total: 48384 W: 2183 L: 1994 D: 44207 Ptnml(0-2): 28, 1777, 20402, 1948, 37 https://tests.stockfishchess.org/tests/view/5f68f068ded68c240be747e9 closes https://github.com/official-stockfish/Stockfish/pull/3142 No functional change (for one thread) --- src/search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search.cpp b/src/search.cpp index edc020fd..4650b157 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -192,7 +192,7 @@ namespace { void Search::init() { for (int i = 1; i < MAX_MOVES; ++i) - Reductions[i] = int((22.0 + std::log(Threads.size())) * std::log(i)); + Reductions[i] = int((22.0 + 2 * std::log(Threads.size())) * std::log(i)); } From 5e6a5e48e636babe1c2ba1fc63422e84c0eee942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Nicolet?= Date: Thu, 24 Sep 2020 11:38:35 +0200 Subject: [PATCH 02/11] Suppress info strings before 'uci' On Windows, Stockfish wouldn't launch in some GUI because we output some info strings (about the use of large pages) before sending the 'uci' command. It seems more robust to suppress these info strings, and instead to add a proper section section in the Readme about large pages use. fixes https://github.com/official-stockfish/Stockfish/issues/3052 closes https://github.com/official-stockfish/Stockfish/pull/3147 No functional change --- README.md | 16 ++++++++-------- src/misc.cpp | 16 +--------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 255ebce2..409d0a10 100644 --- a/README.md +++ b/README.md @@ -198,8 +198,8 @@ the 50-move rule. Stockfish supports large pages on Linux and Windows. Large pages make the hash access more efficient, improving the engine speed, especially -on large hash sizes. Typical increases are 5..10% in terms of nps, but -speed increases up to 30% have been measured. The support is +on large hash sizes. Typical increases are 5..10% in terms of nodes per +second, but speed increases up to 30% have been measured. The support is automatic. Stockfish attempts to use large pages when available and will fall back to regular memory allocation when this is not the case. @@ -213,11 +213,11 @@ are already enabled and no configuration is needed. The use of large pages requires "Lock Pages in Memory" privilege. See [Enable the Lock Pages in Memory Option (Windows)](https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/enable-the-lock-pages-in-memory-option-windows) -on how to enable this privilege. Logout/login may be needed -afterwards. Due to memory fragmentation, it may not always be -possible to allocate large pages even when enabled. A reboot -might alleviate this problem. To determine whether large pages -are in use, see the engine log. +on how to enable this privilege, then run [RAMMap](https://docs.microsoft.com/en-us/sysinternals/downloads/rammap) +to double-check that large pages are used. We suggest that you reboot +your computer after you have enabled large pages, because long Windows +sessions suffer from memory fragmentation which may prevent Stockfish +from getting large pages: a fresh session is better in this regard. ## Compiling Stockfish yourself from the sources @@ -232,8 +232,8 @@ targets with corresponding descriptions. ``` cd src make help - make build ARCH=x86-64-modern make net + make build ARCH=x86-64-modern ``` When not using the Makefile to compile (for instance with Microsoft MSVC) you diff --git a/src/misc.cpp b/src/misc.cpp index d9bc47e3..a16a6e90 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -408,22 +408,8 @@ static void* aligned_large_pages_alloc_win(size_t allocSize) { void* aligned_large_pages_alloc(size_t allocSize) { - static bool firstCall = true; - void* mem; - // Try to allocate large pages - mem = aligned_large_pages_alloc_win(allocSize); - - // Suppress info strings on the first call. The first call occurs before 'uci' - // is received and in that case this output confuses some GUIs. - if (!firstCall) - { - if (mem) - sync_cout << "info string Hash table allocation: Windows large pages used." << sync_endl; - else - sync_cout << "info string Hash table allocation: Windows large pages not used." << sync_endl; - } - firstCall = false; + void* mem = aligned_large_pages_alloc_win(allocSize); // Fall back to regular, page aligned, allocation if necessary if (!mem) From f66c381f11b8603e2449b200227c8cfd7382b3ba Mon Sep 17 00:00:00 2001 From: SFisGOD Date: Wed, 23 Sep 2020 14:00:42 +0800 Subject: [PATCH 03/11] Switch to NNUE eval probabilistically for OCB Introduce a small chance of switching to NNUE if PSQ imbalance is large but we have opposite colored bishops and the classical eval is struggling to win. STC: LLR: 2.94 (-2.94,2.94) {-0.25,1.25} Total: 25304 W: 3179 L: 2983 D: 19142 Ptnml(0-2): 172, 2171, 7781, 2345, 183 https://tests.stockfishchess.org/tests/view/5f6b14dec7759d4ee307cfe3 LTC: LLR: 2.94 (-2.94,2.94) {0.25,1.25} Total: 84680 W: 4846 L: 4556 D: 75278 Ptnml(0-2): 89, 3933, 34011, 4213, 94 https://tests.stockfishchess.org/tests/view/5f6b3fb6c7759d4ee307cff9 closes https://github.com/official-stockfish/Stockfish/pull/3146 Bench: 3865413 --- src/evaluate.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index d3937823..1503be2d 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -1021,10 +1021,10 @@ Value Eval::evaluate(const Position& pos) { v = Evaluation(pos).value(); else { - // scale and shift NNUE for compatibility with search and classical evaluation + // Scale and shift NNUE for compatibility with search and classical evaluation auto adjusted_NNUE = [&](){ return NNUE::evaluate(pos) * 5 / 4 + Tempo; }; - // if there is PSQ imbalance use classical eval, with small probability if it is small + // If there is PSQ imbalance use classical eval, with small probability if it is small Value psq = Value(abs(eg_value(pos.psq_score()))); int r50 = 16 + pos.rule50_count(); bool largePsq = psq * 16 > (NNUEThreshold1 + pos.non_pawn_material() / 64) * r50; @@ -1032,9 +1032,14 @@ Value Eval::evaluate(const Position& pos) { v = classical ? Evaluation(pos).value() : adjusted_NNUE(); - // if the classical eval is small and imbalance large, use NNUE nevertheless. + // If the classical eval is small and imbalance large, use NNUE nevertheless. + // For the case of opposite colored bishops, switch to NNUE eval with + // small probability if the classical eval is less than the threshold. if ( largePsq - && abs(v) * 16 < NNUEThreshold2 * r50) + && (abs(v) * 16 < NNUEThreshold2 * r50 + || ( pos.opposite_bishops() + && abs(v) * 16 < (NNUEThreshold1 + pos.non_pawn_material() / 64) * r50 + && !(pos.this_thread()->nodes & 0xB)))) v = adjusted_NNUE(); } From 1dbd2a1ad548b3ca676f7da949e1a998c64b836b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Nicolet?= Date: Sat, 26 Sep 2020 23:19:53 +0200 Subject: [PATCH 04/11] Tweak nnue scaling to keep more material Current master uses a constant scale factor of 5/4 = 1.25 for the output of the NNUE network, for compatibility with search and classical evaluation. We modify this scale factor to make it dependent on the phase of the game, going from about 1.5 in the opening to 1.0 for pure pawn endgames. This helps Stockfish to avoid exchanges of pieces (heavy pieces in particular) when she has the advantage, keeping more material on the board when attacking. Passed STC: LLR: 2.95 (-2.94,2.94) {-0.25,1.25} Total: 14744 W: 1771 L: 1599 D: 11374 Ptnml(0-2): 87, 1184, 4664, 1344, 93 https://tests.stockfishchess.org/tests/view/5f6fb0a63b22d6afa506904f Passed LTC: LLR: 2.95 (-2.94,2.94) {0.25,1.25} Total: 8912 W: 512 L: 393 D: 8007 Ptnml(0-2): 7, 344, 3637, 459, 9 https://tests.stockfishchess.org/tests/view/5f6fcf533b22d6afa5069066 closes https://github.com/official-stockfish/Stockfish/pull/3154 Bench: 3943952 --- src/evaluate.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 1503be2d..710898bc 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -1022,7 +1022,10 @@ Value Eval::evaluate(const Position& pos) { else { // Scale and shift NNUE for compatibility with search and classical evaluation - auto adjusted_NNUE = [&](){ return NNUE::evaluate(pos) * 5 / 4 + Tempo; }; + auto adjusted_NNUE = [&](){ + int mat = pos.non_pawn_material(); + return NNUE::evaluate(pos) * (1024 + mat / 32) / 1024 + Tempo; + }; // If there is PSQ imbalance use classical eval, with small probability if it is small Value psq = Value(abs(eg_value(pos.psq_score()))); @@ -1037,7 +1040,7 @@ Value Eval::evaluate(const Position& pos) { // small probability if the classical eval is less than the threshold. if ( largePsq && (abs(v) * 16 < NNUEThreshold2 * r50 - || ( pos.opposite_bishops() + || ( pos.opposite_bishops() && abs(v) * 16 < (NNUEThreshold1 + pos.non_pawn_material() / 64) * r50 && !(pos.this_thread()->nodes & 0xB)))) v = adjusted_NNUE(); From c065abdcafe0486cb5cfa7de12a4ac6a905a54c5 Mon Sep 17 00:00:00 2001 From: noobpwnftw Date: Mon, 28 Sep 2020 02:29:21 +0800 Subject: [PATCH 05/11] Use incremental updates more often Use incremental updates for accumulators for up to 2 plies. Do not copy accumulator. About 2% speedup. Passed STC: LLR: 2.95 (-2.94,2.94) {-0.25,1.25} Total: 21752 W: 2583 L: 2403 D: 16766 Ptnml(0-2): 128, 1761, 6923, 1931, 133 https://tests.stockfishchess.org/tests/view/5f7150cf3b22d6afa5069412 closes https://github.com/official-stockfish/Stockfish/pull/3157 No functional change --- src/nnue/features/feature_set.h | 83 ++++++++++++++++++++++------- src/nnue/features/half_kp.cpp | 3 +- src/nnue/features/half_kp.h | 2 +- src/nnue/nnue_feature_transformer.h | 29 +++++++--- 4 files changed, 87 insertions(+), 30 deletions(-) diff --git a/src/nnue/features/feature_set.h b/src/nnue/features/feature_set.h index 558a6b22..26198114 100644 --- a/src/nnue/features/feature_set.h +++ b/src/nnue/features/feature_set.h @@ -61,26 +61,69 @@ namespace Eval::NNUE::Features { const PositionType& pos, TriggerEvent trigger, IndexListType removed[2], IndexListType added[2], bool reset[2]) { - const auto& dp = pos.state()->dirtyPiece; - if (dp.dirty_num == 0) return; - - for (Color perspective : { WHITE, BLACK }) { - reset[perspective] = false; - switch (trigger) { - case TriggerEvent::kFriendKingMoved: - reset[perspective] = dp.piece[0] == make_piece(perspective, KING); - break; - default: - assert(false); - break; + auto collect_for_one = [&](const DirtyPiece& dp) { + for (Color perspective : { WHITE, BLACK }) { + switch (trigger) { + case TriggerEvent::kFriendKingMoved: + reset[perspective] = dp.piece[0] == make_piece(perspective, KING); + break; + default: + assert(false); + break; + } + if (reset[perspective]) { + Derived::CollectActiveIndices( + pos, trigger, perspective, &added[perspective]); + } else { + Derived::CollectChangedIndices( + pos, dp, trigger, perspective, + &removed[perspective], &added[perspective]); + } } - if (reset[perspective]) { - Derived::CollectActiveIndices( - pos, trigger, perspective, &added[perspective]); + }; + + auto collect_for_two = [&](const DirtyPiece& dp1, const DirtyPiece& dp2) { + for (Color perspective : { WHITE, BLACK }) { + switch (trigger) { + case TriggerEvent::kFriendKingMoved: + reset[perspective] = dp1.piece[0] == make_piece(perspective, KING) + || dp2.piece[0] == make_piece(perspective, KING); + break; + default: + assert(false); + break; + } + if (reset[perspective]) { + Derived::CollectActiveIndices( + pos, trigger, perspective, &added[perspective]); + } else { + Derived::CollectChangedIndices( + pos, dp1, trigger, perspective, + &removed[perspective], &added[perspective]); + Derived::CollectChangedIndices( + pos, dp2, trigger, perspective, + &removed[perspective], &added[perspective]); + } + } + }; + + if (pos.state()->previous->accumulator.computed_accumulation) { + const auto& prev_dp = pos.state()->dirtyPiece; + if (prev_dp.dirty_num == 0) return; + collect_for_one(prev_dp); + } else { + const auto& prev_dp = pos.state()->previous->dirtyPiece; + if (prev_dp.dirty_num == 0) { + const auto& prev2_dp = pos.state()->dirtyPiece; + if (prev2_dp.dirty_num == 0) return; + collect_for_one(prev2_dp); } else { - Derived::CollectChangedIndices( - pos, trigger, perspective, - &removed[perspective], &added[perspective]); + const auto& prev2_dp = pos.state()->dirtyPiece; + if (prev2_dp.dirty_num == 0) { + collect_for_one(prev_dp); + } else { + collect_for_two(prev_dp, prev2_dp); + } } } } @@ -115,11 +158,11 @@ namespace Eval::NNUE::Features { // Get a list of indices for recently changed features static void CollectChangedIndices( - const Position& pos, const TriggerEvent trigger, const Color perspective, + const Position& pos, const DirtyPiece& dp, const TriggerEvent trigger, const Color perspective, IndexList* const removed, IndexList* const added) { if (FeatureType::kRefreshTrigger == trigger) { - FeatureType::AppendChangedIndices(pos, perspective, removed, added); + FeatureType::AppendChangedIndices(pos, dp, perspective, removed, added); } } diff --git a/src/nnue/features/half_kp.cpp b/src/nnue/features/half_kp.cpp index 88e384a3..116157cc 100644 --- a/src/nnue/features/half_kp.cpp +++ b/src/nnue/features/half_kp.cpp @@ -52,11 +52,10 @@ namespace Eval::NNUE::Features { // Get a list of indices for recently changed features template void HalfKP::AppendChangedIndices( - const Position& pos, Color perspective, + const Position& pos, const DirtyPiece& dp, Color perspective, IndexList* removed, IndexList* added) { Square ksq = orient(perspective, pos.square(perspective)); - const auto& dp = pos.state()->dirtyPiece; for (int i = 0; i < dp.dirty_num; ++i) { Piece pc = dp.piece[i]; if (type_of(pc) == KING) continue; diff --git a/src/nnue/features/half_kp.h b/src/nnue/features/half_kp.h index ee6a8df3..52a83eec 100644 --- a/src/nnue/features/half_kp.h +++ b/src/nnue/features/half_kp.h @@ -50,7 +50,7 @@ namespace Eval::NNUE::Features { IndexList* active); // Get a list of indices for recently changed features - static void AppendChangedIndices(const Position& pos, Color perspective, + static void AppendChangedIndices(const Position& pos, const DirtyPiece& dp, Color perspective, IndexList* removed, IndexList* added); private: diff --git a/src/nnue/nnue_feature_transformer.h b/src/nnue/nnue_feature_transformer.h index e71ee60d..2f86d20a 100644 --- a/src/nnue/nnue_feature_transformer.h +++ b/src/nnue/nnue_feature_transformer.h @@ -127,9 +127,14 @@ namespace Eval::NNUE { return true; const auto prev = now->previous; - if (prev && prev->accumulator.computed_accumulation) { - UpdateAccumulator(pos); - return true; + if (prev) { + if (prev->accumulator.computed_accumulation) { + UpdateAccumulator(pos); + return true; + } else if (prev->previous && prev->previous->accumulator.computed_accumulation) { + UpdateAccumulator(pos); + return true; + } } return false; @@ -289,11 +294,21 @@ namespace Eval::NNUE { // Calculate cumulative value using difference calculation void UpdateAccumulator(const Position& pos) const { - const auto prev_accumulator = pos.state()->previous->accumulator; + Accumulator* prev_accumulator; + assert(pos.state()->previous); + if (pos.state()->previous->accumulator.computed_accumulation) { + prev_accumulator = &pos.state()->previous->accumulator; + } + else { + assert(pos.state()->previous->previous); + assert(pos.state()->previous->previous->accumulator.computed_accumulation); + prev_accumulator = &pos.state()->previous->previous->accumulator; + } + auto& accumulator = pos.state()->accumulator; IndexType i = 0; Features::IndexList removed_indices[2], added_indices[2]; - bool reset[2]; + bool reset[2] = { false, false }; RawFeatures::AppendChangedIndices(pos, kRefreshTriggers[i], removed_indices, added_indices, reset); @@ -311,7 +326,7 @@ namespace Eval::NNUE { acc[k] = biasesTile[k]; } else { auto prevAccTile = reinterpret_cast( - &prev_accumulator.accumulation[perspective][i][j * kTileHeight]); + &prev_accumulator->accumulation[perspective][i][j * kTileHeight]); for (IndexType k = 0; k < kNumRegs; ++k) acc[k] = vec_load(&prevAccTile[k]); @@ -350,7 +365,7 @@ namespace Eval::NNUE { kHalfDimensions * sizeof(BiasType)); } else { std::memcpy(accumulator.accumulation[perspective][i], - prev_accumulator.accumulation[perspective][i], + prev_accumulator->accumulation[perspective][i], kHalfDimensions * sizeof(BiasType)); // Difference calculation for the deactivated features for (const auto index : removed_indices[perspective]) { From 36c2886302ff3f6b730fc5f69d738a5d61be8c46 Mon Sep 17 00:00:00 2001 From: Joost VandeVondele Date: Sat, 26 Sep 2020 17:47:52 +0200 Subject: [PATCH 06/11] Update default net to nn-04a843f8932e.nnue an optimization of Sergio's nn-03744f8d56d8.nnue tuning the output layer (33 parameters) on game play. WIP code to make layer parameters tunable is https://github.com/vondele/Stockfish/tree/optionOutput Optimization itself is using https://github.com/vondele/nevergrad4sf Writing of the modified net using WIP code based on the learner code https://github.com/vondele/Stockfish/tree/evalWrite Most parameters in the output layer are changed only little (~5 for int8_t). passed STC: https://tests.stockfishchess.org/tests/view/5f716f6b3b22d6afa506941a LLR: 2.94 (-2.94,2.94) {-0.25,1.25} Total: 15488 W: 1859 L: 1689 D: 11940 Ptnml(0-2): 79, 1260, 4917, 1388, 100 passed LTC: https://tests.stockfishchess.org/tests/view/5f71908e3b22d6afa506942e LLR: 2.93 (-2.94,2.94) {0.25,1.25} Total: 8728 W: 518 L: 400 D: 7810 Ptnml(0-2): 7, 338, 3556, 456, 7 closes https://github.com/official-stockfish/Stockfish/pull/3158 Bench: 3789924 --- src/evaluate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/evaluate.h b/src/evaluate.h index 56354cf5..503aa975 100644 --- a/src/evaluate.h +++ b/src/evaluate.h @@ -36,7 +36,7 @@ namespace Eval { // 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 // name of the macro, as it is used in the Makefile. - #define EvalFileDefaultName "nn-03744f8d56d8.nnue" + #define EvalFileDefaultName "nn-04a843f8932e.nnue" namespace NNUE { From a5e68d9b25539b86304a9fb26afc616dc8126a1c Mon Sep 17 00:00:00 2001 From: Vizvezdenec Date: Mon, 28 Sep 2020 20:20:06 +0300 Subject: [PATCH 07/11] Adjust null move pruning constants Idea is that division by fraction of 2 is slightly faster than by other numbers so parameters are adjusted in a way that division in null move pruning depth reduction features dividing by 256 instead of dividing by 213. Other than this patch is almost non-functional - difference starts to exist by depth 133. passed STC https://tests.stockfishchess.org/tests/view/5f70dd943b22d6afa50693c5 LLR: 2.95 (-2.94,2.94) {-0.25,1.25} Total: 57048 W: 6616 L: 6392 D: 44040 Ptnml(0-2): 304, 4583, 18531, 4797, 309 passed LTC https://tests.stockfishchess.org/tests/view/5f7180db3b22d6afa506941f LLR: 2.95 (-2.94,2.94) {0.25,1.25} Total: 45960 W: 2419 L: 2229 D: 41312 Ptnml(0-2): 43, 1779, 19137, 1987, 34 closes https://github.com/official-stockfish/Stockfish/pull/3159 bench 3789924 --- src/search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search.cpp b/src/search.cpp index 4650b157..e5f286e4 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -829,7 +829,7 @@ namespace { assert(eval - beta >= 0); // Null move dynamic reduction based on depth and value - Depth R = (817 + 71 * depth) / 213 + std::min(int(eval - beta) / 192, 3); + Depth R = (982 + 85 * depth) / 256 + std::min(int(eval - beta) / 192, 3); ss->currentMove = MOVE_NULL; ss->continuationHistory = &thisThread->continuationHistory[0][0][NO_PIECE][0]; From ba46599aa2224a78106346fb0615b0be174374f5 Mon Sep 17 00:00:00 2001 From: FauziAkram Date: Mon, 28 Sep 2020 22:09:43 +0300 Subject: [PATCH 08/11] Tweaking Mobility and Safe Check Passed STC: https://tests.stockfishchess.org/tests/view/5f70d86d3b22d6afa50693b9 LLR: 2.94 (-2.94,2.94) {-0.25,1.25} Total: 100368 W: 20323 L: 19914 D: 60131 Ptnml(0-2): 1927, 11641, 22605, 12118, 1893 Passed LTC: https://tests.stockfishchess.org/tests/view/5f71bb553b22d6afa5069457 LLR: 2.94 (-2.94,2.94) {0.25,1.25} Total: 77648 W: 10613 L: 10181 D: 56854 Ptnml(0-2): 634, 7280, 22594, 7652, 664 closes https://github.com/official-stockfish/Stockfish/pull/3160 Bench: 3861984 --- src/evaluate.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 710898bc..fe92f7d7 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -199,7 +199,7 @@ namespace { // SafeCheck[PieceType][single/multiple] contains safe check bonus by piece type, // higher if multiple safe checks are possible for that piece type. constexpr int SafeCheck[][2] = { - {}, {}, {792, 1283}, {645, 967}, {1084, 1897}, {772, 1119} + {}, {}, {803, 1292}, {639, 974}, {1087, 1878}, {759, 1132} }; #define S(mg, eg) make_score(mg, eg) @@ -207,19 +207,19 @@ namespace { // MobilityBonus[PieceType-2][attacked] contains bonuses for middle and end game, // indexed by piece type and number of attacked squares in the mobility area. constexpr Score MobilityBonus[][32] = { - { S(-62,-81), S(-53,-56), S(-12,-31), S( -4,-16), S( 3, 5), S( 13, 11), // Knight - S( 22, 17), S( 28, 20), S( 33, 25) }, - { S(-48,-59), S(-20,-23), S( 16, -3), S( 26, 13), S( 38, 24), S( 51, 42), // Bishop - S( 55, 54), S( 63, 57), S( 63, 65), S( 68, 73), S( 81, 78), S( 81, 86), - S( 91, 88), S( 98, 97) }, - { S(-60,-78), S(-20,-17), S( 2, 23), S( 3, 39), S( 3, 70), S( 11, 99), // Rook - S( 22,103), S( 31,121), S( 40,134), S( 40,139), S( 41,158), S( 48,164), - S( 57,168), S( 57,169), S( 62,172) }, - { S(-30,-48), S(-12,-30), S( -8, -7), S( -9, 19), S( 20, 40), S( 23, 55), // Queen - S( 23, 59), S( 35, 75), S( 38, 78), S( 53, 96), S( 64, 96), S( 65,100), - S( 65,121), S( 66,127), S( 67,131), S( 67,133), S( 72,136), S( 72,141), - S( 77,147), S( 79,150), S( 93,151), S(108,168), S(108,168), S(108,171), - S(110,182), S(114,182), S(114,192), S(116,219) } + { S(-62,-79), S(-53,-57), S(-12,-31), S( -3,-17), S( 3, 7), S( 12, 13), // Knight + S( 21, 16), S( 28, 21), S( 37, 26) }, + { S(-47,-59), S(-20,-25), S( 14, -8), S( 29, 12), S( 39, 21), S( 53, 40), // Bishop + S( 53, 56), S( 60, 58), S( 62, 65), S( 69, 72), S( 78, 78), S( 83, 87), + S( 91, 88), S( 96, 98) }, + { S(-61,-82), S(-20,-17), S( 2, 23) ,S( 3, 40), S( 4, 72), S( 11,100), // Rook + S( 22,104), S( 31,120), S( 39,134), S(40 ,138), S( 41,158), S( 47,163), + S( 59,168), S( 60,169), S( 64,173) }, + { S(-29,-49), S(-16,-29), S( -8, -8), S( -8, 17), S( 18, 39), S( 25, 54), // Queen + S( 23, 59), S( 37, 73), S( 41, 76), S( 54, 95), S( 65, 95) ,S( 68,101), + S( 69,124), S( 70,128), S( 70,132), S( 70,133) ,S( 71,136), S( 72,140), + S( 74,147), S( 76,149), S( 90,153), S(104,169), S(105,171), S(106,171), + S(112,178), S(114,185), S(114,187), S(119,221) } }; // KingProtector[knight/bishop] contains penalty for each distance unit to own king From 5efbaaba77b338dae7121c41f6590f6abc96912c Mon Sep 17 00:00:00 2001 From: SFisGOD Date: Tue, 29 Sep 2020 02:24:26 +0800 Subject: [PATCH 09/11] Update default net to nn-baeb9ef2d183.nnue Further optimization of Sergio's nn-03744f8d56d8.nnue This patch is the result of collaboration with Joost VandeVondele. STC: LLR: 2.96 (-2.94,2.94) {-0.25,1.25} Total: 37000 W: 4145 L: 3947 D: 28908 Ptnml(0-2): 191, 3016, 11912, 3166, 215 https://tests.stockfishchess.org/tests/view/5f71e7983b22d6afa5069475 LTC: LLR: 2.96 (-2.94,2.94) {0.25,1.25} Total: 60224 W: 2992 L: 2769 D: 54463 Ptnml(0-2): 48, 2420, 24956, 2637, 51 https://tests.stockfishchess.org/tests/view/5f722bb83b22d6afa506998f closes https://github.com/official-stockfish/Stockfish/pull/3161 Bench: 3720073 --- src/evaluate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/evaluate.h b/src/evaluate.h index 503aa975..4b57a050 100644 --- a/src/evaluate.h +++ b/src/evaluate.h @@ -36,7 +36,7 @@ namespace Eval { // 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 // name of the macro, as it is used in the Makefile. - #define EvalFileDefaultName "nn-04a843f8932e.nnue" + #define EvalFileDefaultName "nn-baeb9ef2d183.nnue" namespace NNUE { From 6f0aa186d8c9ead30a107634c438c6339b9cba09 Mon Sep 17 00:00:00 2001 From: Stefan Geschwentner Date: Mon, 28 Sep 2020 22:21:14 +0200 Subject: [PATCH 10/11] Tweak reduction formula. Replace log(i) with log(i + 0.25 * log(i)). This increases especially for low values the reductions. But for bigger values there are nearly no changes. STC: LLR: 2.94 (-2.94,2.94) {-0.25,1.25} Total: 49640 W: 5505 L: 5289 D: 38846 Ptnml(0-2): 270, 4074, 15924, 4274, 278 https://tests.stockfishchess.org/tests/view/5f71f04d3b22d6afa5069478 LTC: LLR: 2.94 (-2.94,2.94) {0.25,1.25} Total: 43856 W: 2209 L: 2021 D: 39626 Ptnml(0-2): 32, 1776, 18128, 1956, 36 https://tests.stockfishchess.org/tests/view/5f7232ee3b22d6afa50699a2 closes https://github.com/official-stockfish/Stockfish/pull/3163 Bench: 3555769 --- src/search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search.cpp b/src/search.cpp index e5f286e4..c7343ce8 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -192,7 +192,7 @@ namespace { void Search::init() { for (int i = 1; i < MAX_MOVES; ++i) - Reductions[i] = int((22.0 + 2 * std::log(Threads.size())) * std::log(i)); + Reductions[i] = int((22.0 + 2 * std::log(Threads.size())) * std::log(i + 0.25 * std::log(i))); } From 5af09cfda5b71f9470ef233298e0f4233651337d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Nicolet?= Date: Mon, 28 Sep 2020 22:32:55 +0200 Subject: [PATCH 11/11] Include pawns in NNUE scaling We now include the total pawn count in the scaling factor for the output of the NNUE evaluation network. This should have the effect of trying to keep more pawns when SF has the advantage, but exchange them when she is defending. Thanks to Alexander Pagel (Lolligerhans) for the idea of using the value of pawns to ease the comparison with the rest of the material estimation. Passed STC: LLR: 2.93 (-2.94,2.94) {-0.25,1.25} Total: 15072 W: 1700 L: 1539 D: 11833 Ptnml(0-2): 65, 1202, 4845, 1355, 69 https://tests.stockfishchess.org/tests/view/5f7235a63b22d6afa50699b3 Passed LTC: LLR: 2.93 (-2.94,2.94) {0.25,1.25} Total: 25880 W: 1270 L: 1124 D: 23486 Ptnml(0-2): 23, 980, 10788, 1126, 23 https://tests.stockfishchess.org/tests/view/5f723b483b22d6afa5069a99 closes https://github.com/official-stockfish/Stockfish/pull/3164 Bench: 3776081 --- src/evaluate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index fe92f7d7..25e3bdc1 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -1023,8 +1023,8 @@ Value Eval::evaluate(const Position& pos) { { // Scale and shift NNUE for compatibility with search and classical evaluation auto adjusted_NNUE = [&](){ - int mat = pos.non_pawn_material(); - return NNUE::evaluate(pos) * (1024 + mat / 32) / 1024 + Tempo; + int mat = pos.non_pawn_material() + PieceValue[MG][PAWN] * pos.count(); + return NNUE::evaluate(pos) * (720 + mat / 32) / 1024 + Tempo; }; // If there is PSQ imbalance use classical eval, with small probability if it is small