mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-23 10:36:26 +08:00
Do not use lazy evaluation inside NNUE
This simplification patch implements two changes: 1. it simplifies away the so-called "lazy" path in the NNUE evaluation internals, where we trusted the psqt head alone to avoid the costly "positional" head in some cases; 2. it raises a little bit the NNUEThreshold1 in evaluate.cpp (from 682 to 800), which increases the limit where we switched from NNUE eval to Classical eval. Both effects increase the number of positional evaluations done by our new net architecture, but the results of our tests below seem to indicate that the loss of speed will be compensated by the gain of eval quality. STC: LLR: 2.95 (-2.94,2.94) <-2.50,0.50> Total: 26280 W: 2244 L: 2137 D: 21899 Ptnml(0-2): 72, 1755, 9405, 1810, 98 https://tests.stockfishchess.org/tests/view/60ae73f112066fd299795a51 LTC: LLR: 2.95 (-2.94,2.94) <-2.50,0.50> Total: 20592 W: 750 L: 677 D: 19165 Ptnml(0-2): 9, 614, 8980, 681, 12 https://tests.stockfishchess.org/tests/view/60ae88e812066fd299795a82 closes https://github.com/official-stockfish/Stockfish/pull/3503 Bench: 3817907
This commit is contained in:
@@ -134,7 +134,7 @@ namespace Stockfish::Eval::NNUE {
|
||||
}
|
||||
|
||||
// Evaluation function. Perform differential calculation.
|
||||
Value evaluate(const Position& pos, bool adjusted, Value lazyThreshold) {
|
||||
Value evaluate(const Position& pos, bool adjusted) {
|
||||
|
||||
// We manually align the arrays on the stack because with gcc < 9.3
|
||||
// overaligning stack variables with alignas() doesn't work correctly.
|
||||
@@ -158,27 +158,21 @@ namespace Stockfish::Eval::NNUE {
|
||||
ASSERT_ALIGNED(buffer, alignment);
|
||||
|
||||
const std::size_t bucket = (pos.count<ALL_PIECES>() - 1) / 4;
|
||||
const auto [psqt, lazy] = featureTransformer->transform(pos, transformedFeatures, bucket, lazyThreshold);
|
||||
const auto psqt = featureTransformer->transform(pos, transformedFeatures, bucket);
|
||||
const auto output = network[bucket]->propagate(transformedFeatures, buffer);
|
||||
|
||||
if (lazy)
|
||||
return static_cast<Value>(psqt / OutputScale);
|
||||
else
|
||||
{
|
||||
const auto output = network[bucket]->propagate(transformedFeatures, buffer);
|
||||
int materialist = psqt;
|
||||
int positional = output[0];
|
||||
|
||||
int materialist = psqt;
|
||||
int positional = output[0];
|
||||
int delta_npm = abs(pos.non_pawn_material(WHITE) - pos.non_pawn_material(BLACK));
|
||||
int entertainment = (adjusted && delta_npm <= BishopValueMg - KnightValueMg ? 7 : 0);
|
||||
|
||||
int delta_npm = abs(pos.non_pawn_material(WHITE) - pos.non_pawn_material(BLACK));
|
||||
int entertainment = (adjusted && delta_npm <= BishopValueMg - KnightValueMg ? 7 : 0);
|
||||
int A = 128 - entertainment;
|
||||
int B = 128 + entertainment;
|
||||
|
||||
int A = 128 - entertainment;
|
||||
int B = 128 + entertainment;
|
||||
int sum = (A * materialist + B * positional) / 128;
|
||||
|
||||
int sum = (A * materialist + B * positional) / 128;
|
||||
|
||||
return static_cast<Value>( sum / OutputScale );
|
||||
}
|
||||
return static_cast<Value>( sum / OutputScale );
|
||||
}
|
||||
|
||||
// Load eval, from a file stream or a memory stream
|
||||
|
||||
Reference in New Issue
Block a user