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

Remove material imbalance from nnue eval adjustment #5135

Closed

Conversation

gahtan-syarif
Copy link
Contributor

Passed non-reg STC:
https://tests.stockfishchess.org/tests/view/65fdf11f0ec64f0526c52b57
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 76480 W: 19893 L: 19712 D: 36875
Ptnml(0-2): 339, 9107, 19157, 9308, 329

Passed non-reg LTC:
https://tests.stockfishchess.org/tests/view/65fee22e0ec64f0526c53885
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 150948 W: 38078 L: 37988 D: 74882
Ptnml(0-2): 111, 16997, 41148, 17127, 91

Bench: 1709945

Passed non-reg STC:
https://tests.stockfishchess.org/tests/view/65fdf11f0ec64f0526c52b57
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 76480 W: 19893 L: 19712 D: 36875
Ptnml(0-2): 339, 9107, 19157, 9308, 329

Passed non-reg LTC:
https://tests.stockfishchess.org/tests/view/65fee22e0ec64f0526c53885
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 150948 W: 38078 L: 37988 D: 74882
Ptnml(0-2): 111, 16997, 41148, 17127, 91

Bench: 1709945
Copy link

clang-format 17 needs to be run on this PR.
If you do not have clang-format installed, the maintainer will run it when merging.
For the exact version please see https://packages.ubuntu.com/mantic/clang-format-17.

(execution 8425803864 / attempt 1)

@Lowform
Copy link

Lowform commented Mar 25, 2024

Seems to me it could be rewritten like:

const auto adjustEval = [&](int optDiv, int nnueDiv, int pawnCountConstant, int pawnCountMul,
                                int npmConstant, int evalDiv, int shufflingConstant,
                                int shufflingDiv) {
        // Blend optimism and eval with nnue complexity and material imbalance
        optimism += optimism * (nnueComplexity + std::abs(simpleEval - nnue)) / optDiv;
        nnue -= nnue * nnueComplexity / nnueDiv;// no parenthesis and 3/5 in nnueDiv argument

        int npm = pos.non_pawn_material() / 64;
        v       = (nnue * (npm + pawnCountConstant + pawnCountMul * pos.count<PAWN>())
             + optimism * (npmConstant + npm))
          / evalDiv;

        // Damp down the evaluation linearly when shuffling
        int shuffling = pos.rule50_count();
        v             = v * (shufflingConstant - shuffling) / shufflingDiv;
    };

    if (!smallNet)
        adjustEval(513, 19437, 919, 11, 145, 1036, 178, 204);// 32395*3/5 = 19437
    else if (psqtOnly)
        adjustEval(517,  19714 , 908, 7, 155, 1019, 224, 238);// 32857*3/5 = 19714.2
    else
        adjustEval(499,  19676, 903, 9, 147, 1067, 208, 211);// 32793*3/5 = 19675.8

I'm uncertain about the computational difference in putting 5/3 in nnueDiv (still learning coding), but it seems logical to me. Apologies for the noise if it's nonsense.

@Lowform
Copy link

Lowform commented Mar 25, 2024

Also, don't know if above comment needs an update for not blending material imbalance into nnue. v has optimism and optimism has std::abs(simpleEval - nnue).

@gahtan-syarif
Copy link
Contributor Author

gahtan-syarif commented Mar 25, 2024

Seems to me it could be rewritten like:

const auto adjustEval = [&](int optDiv, int nnueDiv, int pawnCountConstant, int pawnCountMul,
                                int npmConstant, int evalDiv, int shufflingConstant,
                                int shufflingDiv) {
        // Blend optimism and eval with nnue complexity and material imbalance
        optimism += optimism * (nnueComplexity + std::abs(simpleEval - nnue)) / optDiv;
        nnue -= nnue * nnueComplexity / nnueDiv;// no parenthesis and 3/5 in nnueDiv argument

        int npm = pos.non_pawn_material() / 64;
        v       = (nnue * (npm + pawnCountConstant + pawnCountMul * pos.count<PAWN>())
             + optimism * (npmConstant + npm))
          / evalDiv;

        // Damp down the evaluation linearly when shuffling
        int shuffling = pos.rule50_count();
        v             = v * (shufflingConstant - shuffling) / shufflingDiv;
    };

    if (!smallNet)
        adjustEval(513, 19437, 919, 11, 145, 1036, 178, 204);// 32395*3/5 = 19437
    else if (psqtOnly)
        adjustEval(517,  19714 , 908, 7, 155, 1019, 224, 238);// 32857*3/5 = 19714.2
    else
        adjustEval(499,  19676, 903, 9, 147, 1067, 208, 211);// 32793*3/5 = 19675.8

I'm uncertain about the computational difference in putting 5/3 in nnueDiv (still learning coding), but it seems logical to me. Apologies for the noise if it's nonsense.

i was planning to reformat it like this but it results in bench change due to idiv, so ill have to run a new set of tests. for now the multiplier constant is enough to achieve my goal which is to remove the material imbalance scaling from nnue

@Disservin Disservin added simplification A simplification patch functional-change to be merged Will be merged shortly labels Mar 26, 2024
@Disservin Disservin closed this in ed24e3a Mar 26, 2024
linrock pushed a commit to linrock/Stockfish that referenced this pull request Mar 27, 2024
Passed non-reg STC:
https://tests.stockfishchess.org/tests/view/65fdf11f0ec64f0526c52b57
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 76480 W: 19893 L: 19712 D: 36875
Ptnml(0-2): 339, 9107, 19157, 9308, 329

Passed non-reg LTC:
https://tests.stockfishchess.org/tests/view/65fee22e0ec64f0526c53885
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 150948 W: 38078 L: 37988 D: 74882
Ptnml(0-2): 111, 16997, 41148, 17127, 91

closes official-stockfish#5135

Bench: 2103324
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
functional-change simplification A simplification patch to be merged Will be merged shortly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants