Attempting to implement NNUE into my engine

Discussion of chess software programming and technical issues.

Moderator: Ras

sovaz1997
Posts: 292
Joined: Sun Nov 13, 2016 10:37 am

Re: Attempting to implement NNUE into my engine

Post by sovaz1997 »

rdhoffmann wrote: Tue Jan 28, 2025 9:48 pm The smallest network I trained was (768+64) x 28 x 1 and it is already much better than my HCE attempts.

Note the extra 64 inputs, I use it for the side to move (+/- 1) and trying out various ideas.

One question though, why would such small networks need so many positions? I don't see how (or why) that will improve performance. There is only so much a small network can learn?
Interesting!
We've actually discussed a lot of things in Discord
Starting with the fact that I didn't do sigmoid to calculate loss :lol:
There are results, there are improvements, but I can’t surpass my eval yet, maybe there are still some errors somewhere
Zevra 2 is my chess engine. Binary, source and description here: https://github.com/sovaz1997/Zevra2
Zevra v2.6 is last version of Zevra: https://github.com/sovaz1997/Zevra2/releases
sovaz1997
Posts: 292
Joined: Sun Nov 13, 2016 10:37 am

Re: Attempting to implement NNUE into my engine

Post by sovaz1997 »

One question though, why would such small networks need so many positions? I don't see how (or why) that will improve performance. There is only so much a small network can learn?
This number of positions is just an attempt to make sure that there are enough of them :)
Zevra 2 is my chess engine. Binary, source and description here: https://github.com/sovaz1997/Zevra2
Zevra v2.6 is last version of Zevra: https://github.com/sovaz1997/Zevra2/releases
sovaz1997
Posts: 292
Joined: Sun Nov 13, 2016 10:37 am

Re: Attempting to implement NNUE into my engine

Post by sovaz1997 »

Funny King run from Zevra NNUE :)

Zevra 2 is my chess engine. Binary, source and description here: https://github.com/sovaz1997/Zevra2
Zevra v2.6 is last version of Zevra: https://github.com/sovaz1997/Zevra2/releases
sovaz1997
Posts: 292
Joined: Sun Nov 13, 2016 10:37 am

Re: Attempting to implement NNUE into my engine

Post by sovaz1997 »

Some update: I have good progress here,
So, I generate new 140M positions and have this results with net 768x256 with 10+0.1:

Code: Select all

Score of Zevra NNUE vs Zevra Classic: 189 - 267 - 168  [0.438] 624
...      Zevra NNUE playing White: 110 - 120 - 82  [0.484] 312
...      Zevra NNUE playing Black: 79 - 147 - 86  [0.391] 312
...      White vs Black: 257 - 199 - 168  [0.546] 624
Elo difference: -43.7 +/- 23.4, LOS: 0.0 %, DrawRatio: 26.9 

So, really close to classic eval for now

My next goals:
1) More positions (about 500 millions)
2) the net structure with opposite inputs
3) Try lower or larger nets
4) Use WDL stats
Zevra 2 is my chess engine. Binary, source and description here: https://github.com/sovaz1997/Zevra2
Zevra v2.6 is last version of Zevra: https://github.com/sovaz1997/Zevra2/releases
sovaz1997
Posts: 292
Joined: Sun Nov 13, 2016 10:37 am

Re: Attempting to implement NNUE into my engine

Post by sovaz1997 »

Fully-zero NNUE (started from random games, and now after 4th gens) vs HCE
Still much weaker, but I just try to play one game, and it was funny



Hard to improve, I hope this way will works :)
Zevra 2 is my chess engine. Binary, source and description here: https://github.com/sovaz1997/Zevra2
Zevra v2.6 is last version of Zevra: https://github.com/sovaz1997/Zevra2/releases
nionita
Posts: 180
Joined: Fri Oct 22, 2010 9:47 pm
Location: Austria
Full name: Niculae Ionita

Re: Attempting to implement NNUE into my engine

Post by nionita »

How many epochs do you train? Did the 500 million positions still not help?
sovaz1997
Posts: 292
Joined: Sun Nov 13, 2016 10:37 am

Re: Attempting to implement NNUE into my engine

Post by sovaz1997 »

nionita wrote: Thu Feb 06, 2025 7:53 pm How many epochs do you train? Did the 500 million positions still not help?
I tried different, from maybe 10-20 to 200

Now I do self-play, and for now -300 elo to classic with 768x32. Plays beautifully, now I'm on 7th-generation

Zevra 2 is my chess engine. Binary, source and description here: https://github.com/sovaz1997/Zevra2
Zevra v2.6 is last version of Zevra: https://github.com/sovaz1997/Zevra2/releases
sovaz1997
Posts: 292
Joined: Sun Nov 13, 2016 10:37 am

Re: Attempting to implement NNUE into my engine

Post by sovaz1997 »

nionita wrote: Thu Feb 06, 2025 7:53 pm How many epochs do you train? Did the 500 million positions still not help?
Hmm, I tested my net on Depth=1

And I found that my zero-trained 768x32 net plays close to classic HCE:

Code: Select all

Score of Zevra Self (Gen 7) vs Zevra Classic: 1641 - 1807 - 225  [0.477] 3673
...      Zevra Self (Gen 7) playing White: 813 - 909 - 115  [0.474] 1837
...      Zevra Self (Gen 7) playing Black: 828 - 898 - 110  [0.481] 1836
...      White vs Black: 1711 - 1737 - 225  [0.496] 3673
Elo difference: -15.7 +/- 10.9, LOS: 0.2 %, DrawRatio: 6.1 %
SPRT: llr -2.95 (-100.2%), lbound -2.94, ubound 2.94 - H0 was accepted
But it much faster! Maybe not much, about x1.5.

So I think, tomorrow I'll adapt search params to NNUE. Maybe this will solution, because on larger tc I have lost about 300 elo points. And I feel, that my eval maybe scaled too much for my search params. Maybe I can even do other thing: calculate average evals on hce and on NNUE, after compare it's and do right scale.
Zevra 2 is my chess engine. Binary, source and description here: https://github.com/sovaz1997/Zevra2
Zevra v2.6 is last version of Zevra: https://github.com/sovaz1997/Zevra2/releases
sovaz1997
Posts: 292
Joined: Sun Nov 13, 2016 10:37 am

Re: Attempting to implement NNUE into my engine

Post by sovaz1997 »

And I was right... I try to scale eval x0.5

Code: Select all

nodes=10K
Score of Zevra Self (Gen 7 Scaled) vs Zevra Self (Gen 7): 199 - 34 - 33  [0.810] 266
...      Zevra Self (Gen 7 Scaled) playing White: 101 - 18 - 14  [0.812] 133
...      Zevra Self (Gen 7 Scaled) playing Black: 98 - 16 - 19  [0.808] 133
...      White vs Black: 117 - 116 - 33  [0.502] 266
Elo difference: 252.1 +/- 48.2, LOS: 100.0 %, DrawRatio: 12.4 %
Zevra 2 is my chess engine. Binary, source and description here: https://github.com/sovaz1997/Zevra2
Zevra v2.6 is last version of Zevra: https://github.com/sovaz1997/Zevra2/releases
sovaz1997
Posts: 292
Joined: Sun Nov 13, 2016 10:37 am

Re: Attempting to implement NNUE into my engine

Post by sovaz1997 »

Overall, it looks like I managed to catch up with HCE +-
Tomorrow there will be a new train dataset, I will train a new 768x64 on new data of a stronger version with a correctly working search

Right now I am already training 768x64 on the current data (200M train + 50M validate)
Zevra 2 is my chess engine. Binary, source and description here: https://github.com/sovaz1997/Zevra2
Zevra v2.6 is last version of Zevra: https://github.com/sovaz1997/Zevra2/releases