How to scale stockfish NNUE score?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

How to scale stockfish NNUE score?

Post by maksimKorzh »

Hi guys, thanks to amazing library to probe stockfish NNUE by Daniel Shawul even a noob like me can now get NNUE score for each position, but it turns out that using that score directly leads to a VERY STRANGE behavior of my engine = it makes strange moves from time to time and sacrifices the queen for nothing in every game. I feel a bit confused at this point.

My questions are:
1. Do I need to evaluate material if I want to use pure NNUE eval?
2. Do I need to scale NNUE eval?
3. Do I need to tune material weights? (I heard SF uses around 200 for paen value while my engine does around 100)

Actually what should I do with NNUE score to make my engine play normal chess?

Please help.
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: How to scale stockfish NNUE score?

Post by maksimKorzh »

Well, it seems like I've managed to fix this issue:

1. Scaled NNUE score like in PURE NNUE in CFish

Code: Select all

int score = eval_nnue(side, pieces, squares) * 5 / 4;
2. Assuming SF's relative pawn score is around 200 points (while my engine used around 100 points, depending on game phase) I've multiplied my piece weights by 2:

Code: Select all

// get opening/endgame material score
score_opening += material_score[opening][piece] * 2;
score_endgame += material_score[endgame][piece] * 2;
3. Finally I've added NNUE score to interpolated material score:

Code: Select all

// return final evaluation based on side
score += evaluate_nnue();
This resulted the following game (I used fixed depth 8 to make sure that search is the same while only eval difers):
[pgn][Event "Computer chess game"]
[Site "maksim-Inspiron-3582"]
[Date "2020.10.17"]
[Round "?"]
[White "BBC 1.2"]
[Black "BBC NNUE"]
[Result "0-1"]
[BlackElo "2200"]
[ECO "B45"]
[Opening "Sicilian"]
[Time "12:49:05"]
[Variation "Taimanov, Four Knights, 6.Nxc6 bxc6 7.e5 Nd5"]
[WhiteElo "2000"]
[Termination "normal"]
[PlyCount "136"]
[WhiteType "program"]
[BlackType "program"]

1. e4 {(e2-e4 d7-d5 e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 {(Kf3-e3 Kc7-d6 Ke3-d2 Kd6-e5 Kd2-e1 Qc4-e4+ Ke1-d1 Qe4-d3+ Kd1-e1
Ke5-d6) -16.62/8 0} Kd6 {(Kc7-d6 Ke3-f3 Qc4-b4 Kf3-e3 Kd6-e7 Ke3-d3 Ke7-f8
Kd3-c2) +62.44/8 0} 64. Kf3 {(Ke3-f3 Kd6-e5 Kf3-f2 Qc4-h4+ Kf2-g2 Qh4-d4
Kg2-g3 Qd4-e4 Kg3-h3) -16.64/8 0} Qc3+ {(Qc4-c3+ Kf3-f4 Qc3-c1+ Kf4-g3
Qc1-d1 Kg3-g2 Kd6-e7 Kg2-g3 Qd1-d2 Kg3-h4) +62.45/8 0} 65. Ke4 {(Kf3-e4
Qc3-e5+ Ke4-d3 Kd6-e7 Kd3-c4 Qe5-d5+ Kc4-c3 Qd5-e4 Kc3-d2 Ke7-d6 Kd2-c3)
-16.58/8 0} Ke7 {(Kd6-e7 Ke4-f4 Qc3-c5 Kf4-e4 Qc5-c1 Ke4-d4 Ke7-f8 Kd4-e5)
+62.19/8 1} 66. Kf4 {(Ke4-f4 Qc3-d4+ Kf4-g3 h5-h4+ Kg3-h3 Ke7-d6 Kh3-g2
Qd4-g4+ Kg2-f2 Qg4-e4 Kf2-g1) -16.70/8 0} Kf6 {(Ke7-f6 Kf4-e4 d7-d5+ Ke4-f4
e6-e5+) +M3/7 0} 67. Ke4 {(Kf4-e4 d7-d5+ Ke4-f4 e6-e5+) -M3/8 0} d5+
{(d7-d5+ Ke4-f4 e6-e5+) +M2/8 0} 68. Kf4 {(Ke4-f4 e6-e5+) -M2/8 0} e5#
{(e6-e5+) +M1/8 0} 0-1
[/pgn]

Can I now say NNUE scores are now scaled correctly?
User avatar
hgm
Posts: 27795
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: How to scale stockfish NNUE score?

Post by hgm »

Let me get this straight: NNUE is just one term of the Stockfish evaluation, and there are other terms?

Is material the only other term (and is it tapered from opening to end-game)?
Daniel Shawul
Posts: 4185
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: How to scale stockfish NNUE score?

Post by Daniel Shawul »

maksimKorzh wrote: Sat Oct 17, 2020 10:42 am Hi guys, thanks to amazing library to probe stockfish NNUE by Daniel Shawul even a noob like me can now get NNUE score for each position, but it turns out that using that score directly leads to a VERY STRANGE behavior of my engine = it makes strange moves from time to time and sacrifices the queen for nothing in every game. I feel a bit confused at this point.

My questions are:
1. Do I need to evaluate material if I want to use pure NNUE eval?
2. Do I need to scale NNUE eval?
3. Do I need to tune material weights? (I heard SF uses around 200 for paen value while my engine does around 100)

Actually what should I do with NNUE score to make my engine play normal chess?

Please help.
FYI I have now added support for the incremental evaluation of NNUE in the library.
This gives a speed bump of 14 to 18%, so maybe worth it for those in need of the highest performance.
The engine has to keep track of dirtyPiece and Accumulator using the same data structure as what the library use.
Make sure accumulator is cache aligned i.e. 64 bytes.
It maybe possible to move some of the code for incremental evaluation from the engine to the library in the future.

For an example implementation of "NNUE incremental" in an engine, look here
https://github.com/dshawul/Scorpio/comm ... 7b7322bf84
If you want "NNUE without incremental evalution", the implementation is much easier
https://github.com/dshawul/Scorpio/comm ... 94cd4b2c5c

I got more that 400 elos out of my implementation with a shared library.
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: How to scale stockfish NNUE score?

Post by maksimKorzh »

hgm wrote: Sat Oct 17, 2020 2:35 pm Let me get this straight: NNUE is just one term of the Stockfish evaluation, and there are other terms?

Is material the only other term (and is it tapered from opening to end-game)?
Yes, material is the ONLY other term and YES it's tapered from opening to end-game.
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: How to scale stockfish NNUE score?

Post by maksimKorzh »

Daniel Shawul wrote: Sat Oct 17, 2020 5:27 pm
maksimKorzh wrote: Sat Oct 17, 2020 10:42 am Hi guys, thanks to amazing library to probe stockfish NNUE by Daniel Shawul even a noob like me can now get NNUE score for each position, but it turns out that using that score directly leads to a VERY STRANGE behavior of my engine = it makes strange moves from time to time and sacrifices the queen for nothing in every game. I feel a bit confused at this point.

My questions are:
1. Do I need to evaluate material if I want to use pure NNUE eval?
2. Do I need to scale NNUE eval?
3. Do I need to tune material weights? (I heard SF uses around 200 for paen value while my engine does around 100)

Actually what should I do with NNUE score to make my engine play normal chess?

Please help.
FYI I have now added support for the incremental evaluation of NNUE in the library.
This gives a speed bump of 14 to 18%, so maybe worth it for those in need of the highest performance.
The engine has to keep track of dirtyPiece and Accumulator using the same data structure as what the library use.
Make sure accumulator is cache aligned i.e. 64 bytes.
It maybe possible to move some of the code for incremental evaluation from the engine to the library in the future.

For an example implementation of "NNUE incremental" in an engine, look here
https://github.com/dshawul/Scorpio/comm ... 7b7322bf84
If you want "NNUE without incremental evalution", the implementation is much easier
https://github.com/dshawul/Scorpio/comm ... 94cd4b2c5c

I got more that 400 elos out of my implementation with a shared library.
Thanks Daniel!
I've annoyed you with couple more issues on github...

Can you please clarify one more question - I still can't figure it out from CFish's source:
Should I use pawn material weight relatively equal to 100 or 200
the reason why I'm asking is here:
[url]view-source:https://hxim.github.io/Stockfish-Evaluation-Guide/[/url]
see line 1153
It says

Code: Select all

var PAWNVALUE = 206;
and this confuses me... may be it's specific to stockgish evaluation guide GUI...
User avatar
hgm
Posts: 27795
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: How to scale stockfish NNUE score?

Post by hgm »

OK, thanks. I ask because I am interested in trying out this NNUE technique in a new engine, for Janggi. I know absolutely nothing about that game, but I do have a PGN file with 25000 games in it. And perhaps this is enough to train it, and get somewhat reasonable play.

It could also be interesting to try it for Paco Shako.
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: How to scale stockfish NNUE score?

Post by maksimKorzh »

hgm wrote: Sat Oct 17, 2020 6:56 pm OK, thanks. I ask because I am interested in trying out this NNUE technique in a new engine, for Janggi. I know absolutely nothing about that game, but I do have a PGN file with 25000 games in it. And perhaps this is enough to train it, and get somewhat reasonable play.

It could also be interesting to try it for Paco Shako.
I am always getting excited when you're trying to implement engines for games other but chess. I'm just wondering what motivates you?
I mean usually people developing one engine for years and it's difficult to master chess programming at a decent level...
But you're trying many other games! This is incredible, so what motivates you? Thanks in advance.
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: How to scale stockfish NNUE score?

Post by maksimKorzh »

After a consultation with Daniel Shawul and fixing the bugs I can now say for sure:
1. NNUE scores already incorporate material weights in them
2. Daniel's library returns positive score for whites and negative for black, so no need to alter that
3. Scaling is not needed if pure NNUE eval is used, only for hybrid solutions

May be it helps someone
Daniel Shawul
Posts: 4185
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: How to scale stockfish NNUE score?

Post by Daniel Shawul »

Some may want to do scaling to get better compatibility with search prunings such as
futility pruning and razoring, etc. where the margins are tuned probably with your old centi-pawn scores.
Other than that, you don't need scaling unless you use classic evaluation in some way.