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

develop NN #16

Closed
tissatussa opened this issue Dec 3, 2021 · 99 comments
Closed

develop NN #16

tissatussa opened this issue Dec 3, 2021 · 99 comments
Assignees

Comments

@tissatussa
Copy link

You and I mentioned this subject in Issue #9 : "draw simple (winning) endgame" ?

[tissatussa commented]
i gathered many engines, also NN, but honestly i don't know the real strength and advantage of any NN, compared to regular eval .. some engines can disable their NN in the UCI options, and some can play in "hybrid" mode : their best move depends on both "normal" eval and NN eval -- such engines consider both evals as an "advisor" for its best move, but i have no clue how this works ..

you state that millions of positions were used to train an NN .. can we train one for the "4N position" ? That would be awsome ! I think in that position black must be able to ALWAYS win !?

the "4N position" : 8/p5pp/1pk5/5p2/P1nn4/2NN3P/5PPK/8 w - - 0 1

4Npos

[bagaturchess commented]
Yes, we can switch the starting position from initial FEN to any FEN, including 4N :-), and generate millions of positions out of it.
How this will help?
Normally I train NN for all game phases - only 1 NN is used for the whole game.
If we start creating different NNs for different positions, where this will end ... how many you would like to have for the whole game and how to split them? (e.g. by material factor etc.)

FYI: here are my first and last (for now) unsuccessful try of NNUE implementation: https://github.com/bagaturchess/Bagatur/tree/master/Sources/LearningImpl/src/bagaturchess/deeplearning/impl_nnue
It is exactly, what you were looking for - simple evaluation with material and PSQT ... https://github.com/bagaturchess/Bagatur/blob/master/Sources/LearningImpl/src/bagaturchess/deeplearning/impl_nnue/NeuralNetworkUtils_NNUE_PSQT_Material.java

It's an endgame from a fixed starting position, which was composed to induce all kinds of complications, while 'zugzwang' occurs because each player has only two knights and some pawns.
Black has a plus pawn and should be able to win this position, but White can draw in many ways.
A few basic chess principles are involved in this position : it shows how tempo, material and the threat of promotion intertwine.

NNs are said to play more intuitively and i just like to test such NN to get a better understanding of it by this rather simple endgame position. I don't know "how this will help" to improve Bagatur in general - we can contemplate later .. therefor I hope the training of such NN will not be too complicated.

Can a max depth be set when training the NN ? I think this position does not deserve searching in great depth, better evaluate a wide spectrum of variations, including all kinds of sacrifices : maybe offer knights for pawn(s), especially the last black pawn, because even when black keeps the 2 knights he can not win without any pawn left on the board .. the engine should know this chess fact in this position !

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 4, 2021

I found these 2 nice links for NNUE implementations in chess:
https://lczero.org/dev/backend/nn/
https://lczero.org/dev/wiki/technical-explanation-of-leela-chess-zero/
This is very good!
In the past there were only 1 pdf document, which has difficult to read content. :-)
Best regards,
Krasimir

@tissatussa
Copy link
Author

Nice finding .. those papers are to complicated for me .. lots of unknown terms .. i see the global picture though, i recognize some principles & terms .. however, i like you mention this here, also for any other developer who ever joins this Issue.

@tissatussa
Copy link
Author

can you briefly explain in general how we can use many positions (variations from the 4N position) to build / train a NN ? This is basic for me to understand NNs ..

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 4, 2021

Sure.
We can start simpler, even not using NNs.
In the past, I have used this proprietary algorithm to tune the evaluation function.
I have called it Gold Middle tuning algorithm, because of the idea, which it implements.
Code locations:
https://github.com/bagaturchess/Bagatur/tree/master/Sources/LearningAPI
https://github.com/bagaturchess/Bagatur/tree/master/Sources/LearningImpl/src/bagaturchess/learning/goldmiddle

It works very similar to feed forward NNs with 1 layer and liner activation function.
Just tune weights of list of features and sums them.
For example: 0.9 * material + 0.5 * mobility + 1.1 * king safety + ...

Its ideal is to check the sign of the expected evaluation of the position (generated by SF14.1 as example) minus actual evaluation of own evaluation function. For source code, look at method newAdjustment, here: https://github.com/bagaturchess/Bagatur/blob/master/Sources/LearningImpl/src/bagaturchess/learning/goldmiddle/visitors/LearningVisitorImpl.java

Than the algorithm accumulates all changes - millions of +1 and -1.
The goal is to make the counts of +1 and -1 equal for each feature and moves the weights up and down accordingly. This is why the algorithm is called Gold Middle.

At the end of each tuning iteration, the weights are multiplied by weight, so next time the error / delta between both evaluations will be smaller.
Code location is method multiplyCurrentWeightByAmountAndDirection in https://github.com/bagaturchess/Bagatur/blob/master/Sources/LearningAPI/src/bagaturchess/learning/impl/features/advanced/Weight.java

We can start with it.

I also have used standard Java NN frameworks, like Neuroph, Deep Netts and DeepLearning4J.
But if we have only 1 layer and weights, Gold Middle tuning algorithm achieves similar results.
Even better sometimes. :-)
We can later switch to Deep Netts if we need more layers.
But for this tuning for the 4Ns position, we can tune Bagatur evaluation function parameters using Gold Middle tuning algorithm. Than I could upload the Dev version for you to test Bagatur in this position after the tunning.

Is this starting point works for you?

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 4, 2021

Regarding this: "Can a max depth be set when training the NN ?"
In general, no, because we tune the evaluation function, not the search - there is no depth at all.
But actually we cannot track engine play with depth 0.
SF works with depth = 1 very well.
There are engines which cannot be used for positions generations and their evaluations - they don't work correctly with depth = 1 or Multi PV set to 500. We need these UCI options!

Just for information. The code of positions generator is here: https://github.com/bagaturchess/Bagatur/tree/master/Sources/UCITracker

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 4, 2021

A bit more comments on this:

"In general, no, because we tune the evaluation function, not the search - there is no depth at all.
But actually we cannot track engine play with depth 0."

This is general problem for tuning accuracy ... it is valid issue in all cases, when we use Neuroph, Deep Netts, DeepLearning4J or Gold Middle tuning algorithm.

In order to know for which position we have evaluation, we need to know the best moves line. We have to play it and then to assign the evaluation to this position. This is problematic, because for example SF very often cuts the move lines, which are send over the UCI protocol. Only the first move appears very often.

From this perspective SF is not good choice at all.

Do you have observations on that during your engines testing? We need strong engine in endgames, which always produce full move lists and send them to UCI. We talk about the PV line.

@tissatussa
Copy link
Author

for that, do you need an engine with MPV ?

@tissatussa
Copy link
Author

and then each MPV line must be full / long ?

@tissatussa
Copy link
Author

i should test your UCITracker .. is it for Linux also ? Should i be able to compile it ?

@bagaturchess
Copy link
Owner

Yes, I use:
setoption name MultiPV value 500

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 4, 2021

i should test your UCITracker .. is it for Linux also ? Should i be able to compile it ?

Yes, this is the main benefit from using Java :-) The only negative is that you have to install Java for your OS. :-)

@tissatussa
Copy link
Author

500 ? In most positions only 10 moves are relevant ? Maybe even max 50 moves possible ? So why 500 ?

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 4, 2021

We need all possible moves, it is set to higher value to be on the safe side.

@tissatussa
Copy link
Author

Java runs nice on my OS until now.

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 4, 2021

The GitHub repo of Bagatur is Eclipse workspace. This is the best IDE for Java in this case, because it will be very easy to make it working.

@tissatussa
Copy link
Author

tissatussa commented Dec 4, 2021

mmm .. can i do without Elipse ? I think i can install it but i like not to ..
using a MakeFile suits me good : i can compile in terminal and easily trace errors, if any.

@tissatussa
Copy link
Author

regarding the real value of a NN just for the 4N position : then we have created game from a "fixed chess position", and white player can try to draw or even win this psotion, but the NN will never loose and often win !? Because i think the black position can ALWAYS be won - i could be wrong here ..

@bagaturchess
Copy link
Owner

You have to write build scripts and run code in console.
With Eclipse it will be much easier ...

@tissatussa
Copy link
Author

OK, i will install Elipse and let you know.

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 4, 2021

regarding the real value of a NN just for the 4N position : then we have created game from a "fixed chess position", and white player can try to draw or even win this psotion, but the NN will never loose and often win !? Because i think the black position can ALWAYS be won - i could be wrong here ..

The color / winner doesn't matter, we use all positions for tuning, just switch the sign, working always from white player point of view.

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 4, 2021

Just to mention this: when I use SF, at the end of the tuning I reach 60% accuracy, because of this issue with incomplete PV lines. With some engines, I have tested Glaurung in the past, it may reach even 85% accuracy ...
So, we have to find the most stronger endgame engine, which has full PV lines during MultiPV search.

@tissatussa
Copy link
Author

regarding the UCITracker : can (2) differnet engines play multi games ? Or can it do only self play ?

@tissatussa
Copy link
Author

tissatussa commented Dec 4, 2021

So, we have to find the most stronger endgame engine, which has full PV lines during MultiPV search.

I will investigate my archive .. I will find a nice strong (endgame) engine like that :-)

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 4, 2021

regarding the UCITracker : can (2) differnet engines play multi games ? Or can it do only self play ?

Only one engine is supported at the moment https://github.com/bagaturchess/Bagatur/blob/master/Sources/UCITracker/src/bagaturchess/ucitracker/run/GamesGenerator_MultiPv.java
This is the main class, which you have to run ...

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 4, 2021

So, we have to find the most stronger endgame engine, which has full PV lines during MultiPV search.

I will investigate my archive .. I will find a nice strong (endgame) engine like that :-)

Hopefully you will find an engine with 3000+ ELO strength.
Latest Glaurung 2.2 has 2782 ELO ...

@tissatussa
Copy link
Author

here is the list of all my engines above 3000 :

SF v14 NNUE                     3514
SF v13 NNUE                     3506
------------------------------------
SugaR AI v2.40                  3497
ShashChess v19.3 NNUE           3490  (we have v20)
SF v12                          3477
SF v11                          3433
Berserk v7 NNUE                 3433  (4 CPU)
SugaR NN 310719                 3411  (we have 151120)
------------------------------------
Ethereal v13.25                 3396  (we have v13.35)
SlowChess Blitz v2.7            3385
Koivisto v7.0                   3371  (we have v7.5)
McBrain v9.6                    3370
Nemorino v6.00                  3347  (we have v6.08)
Komodo v13.3                    3344  (we have v13.02)
Igel v3.0.5 NN                  3342  (we have v3.0.10)
RubiChess v2.1 NNUE             3338  (we have v2.3-dev)
Pedone v3.1 NN                  3334
Fire v8 NN                      3330
Komodo v12.2.2                  3321  (we have v12.1)
Ethereal v12.75 NNUE            3319
Weiss v2.0                      3318  (we have v2.1-dev)
Seer v2.3.0 NN                  3305  (we have v2.3.1)
Fat Titz 1.1 NNUE               3300  (?)
------------------------------------
Lc0 v0.28.0                     3260  (we have v0.26.1)
Xiphos v0.6.1                   3253
RofChade v2.3                   3239
Stash v31.0                     3222  (we have v31.7)
Laser v1.7                      3206  (we have v1.8 beta)
Defenchess v2.2                 3202  (we have v2.3 dev)
Schooner v2.2                   3202
SF Storm v2                     3200  (?)
------------------------------------
Clover v2.4                     3199  (we have v3.0-dev41)
Andscacs v0.95                  3180
Wasp v4.50                      3159
Arasan v22.2.0                  3157  (we have v23.0.1-5)
Halogen v10                     3156  (we have v10.20.1)
Minic v3.10 NNUE                3146  (we have v3.14)
Texel v1.07                     3140  (we have v1.08)
Demolito 2021-07-09             3138  (we have the dev of 210928)
Winter v0.9                     3128  (we have v0.9.7a)
Combusken v1.4.0                3107  (we have v1.9.9 dev)
Marvin v5.1.0 NNUE              3106  (we have v5.2.0)
Strelka v5                      3102
------------------------------------
Vajolet v2.8.0                  3099
Critter v1.6a                   3098
PeSTo v2.210                  B 3098
Beef v0.3.6                     3097
Toga III v0.2 NNUE              3093  (we have v0.3.12)
Protector v1.9.0                3057
Drofa v3.2.0                    3053  (we have v3.2.13)
Elektro v1.2                    3038
SmarThink v1.98                 3024
Bagatur v2.2g                   3024  (we have v2.3)
Bit-Genie v9                    3079  (we have v9.01)
Chess22k v1.14                  3077
Senpai v2.0                     3031	
Pirarucu v3.3.5                 3012
Topple v0.8.1                   3006
Monolith v2                     3004
Mayhem v5.7 NNUE                3000  (we have v6.3) 

@tissatussa
Copy link
Author

however these engine ELOs functuate among the existing (CCRL) lists ..

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 4, 2021

Nice, we can start from the top of this list and go down (but skip SF engines)

What about Ethereal v13.25 ?

@tissatussa
Copy link
Author

tissatussa commented Dec 4, 2021

i don't often use Ethereal .. it tends to crash or disconnect etc .. reaaly, it's strange but true .. most other engines run fine here .. the ShashChess engine is very strong and i like it, but in fact a SF derivative ..

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 4, 2021

Ok, then which is the next, which works stable ?

Komodo v13.3 or Weiss v2.0?

@tissatussa
Copy link
Author

UCITracker has hanged after a few games running this engine.

that's a pitty, i never had problems with Pedone .. nevermind .. what about Stash ? Has 3222 rating, see https://gitlab.com/mhouppin/stash-bot/-/releases

@tissatussa
Copy link
Author

Stash : Hash can be minimal 1 Mb (!), it can Ponder, and MPV max 500 !
However, in my many-captures position the pv lines are short but not just 1 move ..

@tissatussa
Copy link
Author

The author of Wasp, John Stanbeck, is a long time chess engine programmer, he also did Zarkov more then 40 years ago ! I did some communication with him, some years ago. My intuition tells me Wasp is not suitable for this 4N pos NN, but Wasp is now even v5.00 with a NN ! So it might have evolved ..

@tissatussa
Copy link
Author

tissatussa commented Dec 5, 2021

Wasp v5.00 (with or without NNUE, it's an option)

  • Hash can be minimal 0 Mb !
  • Threads can be high
  • It can log
  • It can Ponder
  • It has MPV max 255
  • It has Contempt (but 0 = default)
  • ...

However, its pv lines in the many-captures position are not long .. all engines have their disadvantages .. that's what i discovered yesterday ..

@tissatussa
Copy link
Author

Recently I discovered "Fat Titz" .. it's a SF clone .. but at depth 1 it gives rather long (3..) pv lines compared to most other engines and it has nice features :

$ ./fat_titz_compiled_pgo 
Fat Titz 231021 64 BMI2 NUMA by Tomasz Sobczyk, Syzygy, and The Stockfish developers
info string Loading the evaluation network...
info string Evaluation network successfully loaded.
uci
id name Fat Titz 231021 64 BMI2 NUMA
id author The Stockfish developers

option name PersistentTTMinDepth type spin default 4 min 0 max 255
option name PersistentTTFileName type string default tt.ptt
option name PersistentTTSerialize type button
option name PersistentTTDeserialize type button
option name Threads type spin default 1 min 1 max 512
option name Hash type spin default 16 min 1 max 33554432
option name Clear Hash type button
option name Ponder type check default false
option name Anarchy type check default false
option name MultiPV type spin default 1 min 1 max 500
option name Move Overhead type spin default 10 min 0 max 5000
option name Slow Mover type spin default 100 min 10 max 1000
option name nodestime type spin default 0 min 0 max 10000
option name UCI_AnalyseMode type check default false
option name UCI_Chess960 type check default false
option name SyzygyPath type string default <empty>
option name SyzygyProbeDepth type spin default 1 min 1 max 100
option name Syzygy50MoveRule type check default true
option name SyzygyProbeLimit type spin default 7 min 0 max 7
option name SyzygyUseDTM type check default true
option name BookFile type string default <empty>
option name BookFile2 type string default <empty>
option name BestBookMove type check default true
option name BookDepth type spin default 255 min 1 max 255
option name Use NNUE type combo default Hybrid var Hybrid var Pure var Classical
option name LargePages type check default true
uciok
setoption name MultiPV value 5
position fen 1r2rbk1/2p1npp1/3pbq1p/1p6/3pP3/1BP1BN1P/1P3PP1/R2QR1K1 w - - 0 1
isready
readyok
go depth 1 
info string Hybrid NNUE evaluation enabled.
info depth 1 seldepth 1 multipv 1 score cp 59 nodes 380 nps 190000 tbhits 0 time 2 pv f3d4 e6b3 d1b3
info depth 1 seldepth 1 multipv 2 score cp 59 nodes 380 nps 190000 tbhits 0 time 2 pv c3d4 e6b3 d1b3
info depth 1 seldepth 1 multipv 3 score cp 48 nodes 380 nps 190000 tbhits 0 time 2 pv e3d4 e6b3 d1b3
info depth 1 seldepth 1 multipv 4 score cp 1 nodes 380 nps 190000 tbhits 0 time 2 pv e4e5 e6b3 d1b3
info depth 1 seldepth 1 multipv 5 score cp -88 nodes 380 nps 190000 tbhits 0 time 2 pv b3e6
bestmove f3d4 ponder e6b3

@tissatussa
Copy link
Author

see https://github.com/Sopel97/FatTitz .. the release page offers Windows binaries also.

@bagaturchess
Copy link
Owner

see https://github.com/Sopel97/FatTitz .. the release page offers Windows binaries also.

This will be the best option if the author somehow succeeded to improve the PV line of standard SF!

I will test it ...

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 5, 2021

No changes in this cloning in regards to PV collection
image

I will test now Wasp v5.00 ...

image

This is the result of WASP 500 with 0.5M positions

image

It is around SF as PV accuracy.
But if you know an Author, you could contact him and discuss whether PV collection can be improved.
I am also willing to help with ideas. For example, I use something, which I found in the past implemented in a Checkers game and later I have implemented this idea for PV collection in Bagatur: https://github.com/bagaturchess/Bagatur/blob/master/Sources/Search/src/bagaturchess/search/impl/pv/PVManager.java
It is very time and space efficient, I liked this idea very much! It is also simple to understand ....

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 5, 2021

Give me some time, I have to investigate and think a bit whether I make the tests correctly ... I will re-test if necessary.
I want to check if the generated positions are not similar. The engines are not restarted after each game during the moves/evals capturing up to now in this tests. This issue in UCITracker is coming from the transposition tables, the engines are using. Not all engines support this UCI option Clear Hash ... when search on depth 1, the engines move directly moves taken from the transposition table.

@tissatussa
Copy link
Author

Give me some time, I have to investigate and think a bit whether I make the tests correctly

That is what i thought also .. when doing wrong tests (i know) the conclusions and next steps are nonsense :-)

@tissatussa
Copy link
Author

It's hard to find a proper engine for our needs .. i stumbled upon Ivanhoe, also for Windows .. rating about 3050 .. it has an impressive option list and rather long pv lines ! .. MPV max 250 ! .. also 'TryPVinAnalysis' and 'AlwaysAnalyze' (which i didn't test yet) :

$ ./IvanHoe999946f 
IvanHoe 9.46b x64 GamePlay
Compiled By KLO
IvanHoe-Beta-999946f
Workers mode enabled! (no WINDOWS)
Yet: RobboBases accrue WINDOWS namingsakes
Battle Mode Enabled
Prefetch Enabled
PopCnt Enabled
CPUs Detected 4
Multicore Enabled
RobboBases Support Enabled
Zugzwang Detect Enabled
Chess960 Support Enabled
RobboBaseLib Dynamic_Link
./RobboBaseLib.so found (file name), to do dynamic load functions
TotalBaseCache is 1mb + (1mb)
TripleCacheSize is 1mb
TripleCacheSize is 1mb
RobboBaseLib Version 0.65b (dynamic)
uci
id name IvanHoe 9.46b x64
id author Yakov Petrovich Golyadkin, Igor Igorovich Igoronov, Roberto Pescatore, Yusuf Ralf Weisskopf, Ivan Skavinsky Skavar plus Decembrists (all)
id copyright Yakov Petrovich Golyadkin, 92th plus 93th plus 94th year from Revolution, PUBLICDOMAIN (workers)
id dedication To Vladimir Ilyich plus Zog 1 with Albania
option name Hash type spin min 1 max 65536 default 32
option name PawnsHash type spin min 1 max 1024 default 4
option name PawnsHashOneEighth type check default true
option name PVHash type spin min 1 max 1024 default 2
option name EvalHash type spin min 1 max 1048576 default 256
option name Threads type spin min 1 max 8 default 8
option name Ponder type check default false
option name VerifyNullMove type check default true
option name AlternativeTimeUsage type check default false
option name AllowInstantMoveFromHash type check default true
option name BufferTime type spin min 0 max 10000 default 0
option name OutputDelay type spin min 0 max 60000 default 0
option name RobboBaseDynamicLibraryFile type string default NULL
option name RobboTripleBaseDirectory type string default NULL
option name UnloadAllRobboTripleBases type button
option name RobboTotalBaseDirectory type string default NULL
option name DeregisterAllRobboTotalBases type button
option name RobboTotalBaseCacheSize type spin min 1 max 1024 default 1
option name DynamicLoadTripleBaseCacheSize type spin min 1 max 65536 default 1
option name TripleHashSize type spin min 1 max 4096 default 1
option name TripleWeakProbeDepthHalfPly type spin min -10 max 255 default -10
option name TripleDefiniteProbeDepthHalfPly type spin min -10 max 255 default 40
option name TripleDefiniteProbeHeight type spin min 1 max 255 default 5
option name LoadOnWeakProbe type combo var AllWays var UnlessPondered var Refrain default AllWays
option name RobboTripleBulkLoadThisDirectory type string default NULL
option name RobboTripleBulkLoadThisName type string default NULL
option name RobboTripleBulkDetachThisDirectory type string default NULL
option name RobboTripleBulkDetachThisName type string default NULL
option name RobboInformatory type button
option name MultiPV type spin min 1 max 250 default 1
option name MultiCentiPawnPV type spin min 1 max 65535 default 65535
option name RandomCount type spin min 0 max 8 default 0
option name RandomBits type spin min 1 max 3 default 1
option name SplitAtCUT type check default true
option name SplitDepthCUT type spin min 16 max 20 default 16
option name SplitDepthALL type spin min 12 max 20 default 14
option name SplitDepthPV type spin min 10 max 20 default 14
option name WhiteBishopPair type spin min 1 max 150 default 45
option name WhitePawn type spin min 50 max 200 default 100
option name WhiteKnight type spin min 150 max 500 default 300
option name WhiteLightBishop type spin min 150 max 500 default 310
option name WhiteDarkBishop type spin min 150 max 500 default 310
option name WhiteRook type spin min 300 max 700 default 500
option name WhiteQueen type spin min 500 max 1500 default 950
option name BlackBishopPair type spin min 1 max 150 default 45
option name BlackPawn type spin min 50 max 200 default 100
option name BlackKnight type spin min 150 max 500 default 300
option name BlackLightBishop type spin min 150 max 500 default 310
option name BlackDarkBishop type spin min 150 max 500 default 310
option name BlackRook type spin min 300 max 700 default 500
option name BlackQueen type spin min 500 max 1500 default 950
option name MaterialWeighting type spin min 512 max 2048 default 1024
option name KingSafetyWeighting type spin min 512 max 2048 default 1024
option name StaticWeighting type spin min 512 max 2048 default 1024
option name MobilityWeighting type spin min 512 max 2048 default 1024
option name PawnsWeighting type spin min 512 max 2048 default 1024
option name AlwaysAnalyze type check default false
option name TryPVinAnalysis type check default true
option name FixedAgeAnalysis type check default false
option name SendCurrmove type check default true
option name DoHashFull type check default true
option name Clear Hash type button
option name TimeImitateOpponent type check default false
option name TimeMoreWhenLosing type check default false
option name TimeMoreWhenWinning type check default false
option name TimeEasyFactor type spin min 10 max 100 default 15
option name TimeEasyFactorPonder type spin min 10 max 100 default 33
option name TimeBattleFactor type spin min 10 max 500 default 100
option name TimeOrdinaryFactor type spin min 10 max 500 default 75
option name TimeAbsolutePercent type spin min 10 max 100 default 25
option name TimeDesiredMillis type spin min 10 max 1000 default 40
option name TimeBookExitMoves type spin min 0 max 20 default 0
option name ExtraExtendInCheck type check default false
option name TryLargePages type check default false
option name SendHash type check default false
option name UCI_Chess960 type check default false
uciok
setoption name MultiPV value 5
info string Optional MultiPV 5
position fen 1r2rbk1/2p1npp1/3pbq1p/1p6/3pP3/1BP1BN1P/1P3PP1/R2QR1K1 w - - 0 1
isready
readyok
go depth 1 
info multipv 1 time 0 nodes 19 nps 0 score cp -28 depth 1 pv b3e6 d4e3
info multipv 1 time 0 nodes 30 nps 0 score cp 15 depth 1 pv c3d4
info multipv 2 time 0 nodes 30 nps 0 score cp -28 depth 1 pv b3e6 d4e3
info multipv 1 time 0 nodes 42 nps 0 score cp 47 depth 1 pv f3d4
info multipv 2 time 0 nodes 42 nps 0 score cp 15 depth 1 pv c3d4
info multipv 3 time 0 nodes 42 nps 0 score cp -28 depth 1 pv b3e6 d4e3
info multipv 1 time 0 nodes 85 nps 0 score cp 47 depth 1 pv f3d4
info multipv 2 time 0 nodes 85 nps 0 score cp 15 depth 1 pv c3d4
info multipv 3 time 0 nodes 85 nps 0 score cp -28 depth 1 pv b3e6 d4e3
info multipv 4 time 0 nodes 85 nps 0 score cp -166 depth 1 pv e3h6 f6h6 b3e6 h6e6 f3d4
info multipv 1 time 1 nodes 123 nps 123000 score cp 47 depth 1 pv f3d4
info multipv 2 time 1 nodes 123 nps 123000 score cp 39 depth 1 pv e3d4
info multipv 3 time 1 nodes 123 nps 123000 score cp 15 depth 1 pv c3d4
info multipv 4 time 1 nodes 123 nps 123000 score cp -28 depth 1 pv b3e6 d4e3
info multipv 5 time 1 nodes 123 nps 123000 score cp -166 depth 1 pv e3h6 f6h6 b3e6 h6e6 f3d4
info multipv 1 time 1 nodes 279 nps 279000 score cp 47 depth 1 pv f3d4
info multipv 2 time 1 nodes 279 nps 279000 score cp 39 depth 1 pv e3d4
info multipv 3 time 1 nodes 279 nps 279000 score cp 15 depth 1 pv c3d4
info multipv 4 time 1 nodes 279 nps 279000 score cp -28 depth 1 pv b3e6 d4e3
info multipv 5 time 1 nodes 279 nps 279000 score cp -78 depth 1 pv e4e5 d6e5 c3d4
info multipv 1 time 2 nodes 612 nps 306000 score cp 47 depth 1 pv f3d4
info multipv 2 time 2 nodes 612 nps 306000 score cp 39 depth 1 pv e3d4
info multipv 3 time 2 nodes 612 nps 306000 score cp 15 depth 1 pv c3d4
info multipv 4 time 2 nodes 612 nps 306000 score cp -28 depth 1 pv b3e6 d4e3
info multipv 5 time 2 nodes 612 nps 306000 score cp -68 depth 1 pv e3d2
info multipv 1 time 4 nodes 1687 nps 421000 score cp 47 depth 1 pv f3d4
info multipv 2 time 4 nodes 1687 nps 421000 score cp 39 depth 1 pv e3d4
info multipv 3 time 4 nodes 1687 nps 421000 score cp 15 depth 1 pv c3d4
info multipv 4 time 4 nodes 1687 nps 421000 score cp -28 depth 1 pv b3e6 d4e3
info multipv 5 time 4 nodes 1687 nps 421000 score cp -68 depth 1 pv e3d2
info multipv 1 time 5 nodes 1687 nps 337000 score cp 47 depth 1 pv f3d4
info multipv 2 time 5 nodes 1687 nps 337000 score cp 39 depth 1 pv e3d4
info multipv 3 time 5 nodes 1687 nps 337000 score cp 15 depth 1 pv c3d4
info multipv 4 time 5 nodes 1687 nps 337000 score cp -28 depth 1 pv b3e6 d4e3
info multipv 5 time 5 nodes 1687 nps 337000 score cp -68 depth 1 pv e3d2
bestmove f3d4 ponder NULL
complete-search

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 5, 2021

Give me some time, I have to investigate and think a bit whether I make the tests correctly

That is what i thought also .. when doing wrong tests (i know) the conclusions and next steps are nonsense :-)

Sure, although we relay on data/facts and logic, we are people and make mistakes ...

Here is the last result with engines restart after each game with small amount of positions (below 1M):

  • glaurung-2.2 reaches around 66% accuracy
  • stockfish-14.1 reaches around 60% accuracy
  • wasp-5-0-0 reaches around 58% accuracy
  • pedone-3.1 reaches around 30% accuracy

Now, I would like to tune Bagatur Dev against stockfish-14.1 evaluations capturing and then measure the ELO difference with 50-100 games in Arena. With the previous test, Bagatur had -320 ELO degradation.

@tissatussa
Copy link
Author

tissatussa commented Dec 5, 2021

maybe this SF page is interesting for you : it has several custom builds for many OS .. binary assets for download or to compile : https://abrok.eu/stockfish/ -- this is updated regularly.

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 5, 2021

With engines restart before each game and with 7M positions captured by SF 14.1, we reached 61% accuracy after the weights tuning.
Now I will update Bagatur Dev and run test tournament.

For years, I never achieved better version via this tuning.
It was possible only in the beginning, when the Bagatur's ELO was up to 2500.
Last years, my record, which I remember, was -30 ELO degradation only.
Normally the tuned version of Bagatur become even weaker, e.g. -100 ELO.
One explanation is that now Bagatur has perfect evaluation, which cannot be improved further.
Just kidding :-)
But seriously, I think each chess engine has set of features and their optimal weights are fixed. If the evaluation function, calculating these features, is close to this optimal state, than it is difficult to make it much better.
Probably only around +/-50 ELO change is theoretically possible in such cases.

I am also not completely sure, that what we are doing now with UCITracker is correct ...

@bagaturchess
Copy link
Owner

Currently, we generate positions with initial FEN as starting position, because we have to start more general from the whole game.

Next step after the Bagatur Dev vs. Bagatur 2.3 testing, will be to tune for positions produced from 4N position as a starting point.
We have to collect some numbers and facts and then to decide how to continue ...

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 5, 2021

Now I remember how much time I have invested in supervised learning experiments.
This is quite time consuming exercise.

May be the approach used in UCI Tracker, which I have explained in this issue is wrong.
The assumption is, if we search with depth 1 and than move the moves from PV line, we achieve a position on which the evaluation function of the tracked engine is applied in pure form.

May be this is not correct ...

We face many examples of this:

  • Previously calculated transposition table moves
  • Contempt factor
  • TB usage

Yes, some engines support switching them off, but there are also other factors, even when the PV is correct:

  • We just implemented the idea to adjust the evaluation with the function of the the material factor (in this issue draw simple (winning) endgame ? #9)
  • Some engines have special handling for some positions (e.g. specific endgames)
  • The engines are also adjusting the evaluation with draw probabilities (e.g. 50 move rule)
  • Transposition table scores are returned as a result of the search without collection the accurate PV
  • There are probably many other examples

One option to resolve all this issues is to call directly SF evaluation function in Java. We could use Java Native Interface (JNI) for this, but it will need a lot of work.

Another direction would be to start with something new, like NNUE.
I don't have experience with this. It will also needs time investment, but could be better.
Nowadays, almost all engines have NNUE versions, which are stronger in ELO strength, than the original versions.

@tissatussa
Copy link
Author

Thanks for the info.
Unfortunately i can not help you with this ..

@bagaturchess
Copy link
Owner

bagaturchess commented Dec 5, 2021

I made some fixes and changes.
Then generated new positions and have used Deep Netts for weights tuning.
This time the Dev version is with -130 ELO weaker then version 2.3

For now, I would propose to pause the work here for a while and continue working on the online syzygy feature.

What do you think?

@bagaturchess
Copy link
Owner

This NNUE architecture looks like 2 rockets! ;-)

image

Screenshot taken from https://www.chessprogramming.org/NNUE

@tissatussa
Copy link
Author

...continue working on the online syzygy feature

yes, i agree, that's better .. take your time to read about the newest NNUE info & tools etc. The 4Npos NN was just an experiment .. maybe it leads to more insights :-)

@tissatussa
Copy link
Author

i find a lot of info about training NNUE .. eg. "NN Trainer for use with the Berserk Chess Engine" : https://github.com/jhonnold/berserk-trainer .

@bagaturchess
Copy link
Owner

bagaturchess commented Jan 14, 2022

Hi,

I have started to collect some ideas and code for this topic. Mainly the architecture and incremental updates of the NN's input layer.
The incremental part is easier, but I face many new things in the NNUE architecture. Concepts like residual tower with Squeeze and Excitation are new for me ...

Currently, for experiment, I have done, what I can - have used 1 layer NN with weights, just liner function. Based on Deep Netts Java NN Framework. I use 12x64 inputs - PSQT for each piece type of both colors.

Here it playes agains very old version of Bagatur
image
White is with this NN. Next move is Rxb7 ... not soo bad :-))) ... but is quite weak.

Best regards,
Krasimir

@tissatussa
Copy link
Author

So you are developing a NN version of Bagatur .. i just stumbled upon the GAiA chess engine, see https://github.com/Plagiat01/GAiA .. i managed to compile it on Linux, following its README and copy the concerning ONNX library files .. GAiA uses a special NN, based on ONNX, which is some layer for NN or so .. i have no insight if ONNX is a good technique, but it feels unique and genius - see also its page https://github.com/microsoft/onnxruntime.

I hope this will help -- i like to know if ONNX is a good idea, so please give feedback .. no other engines use ONNX, as far as i know - regarding NN there's a lot "on the market" :-)

Here's a document about it (the link is in the GitHub text) : Performing Regression on Complex Data.pdf

@bagaturchess
Copy link
Owner

bagaturchess commented Jan 16, 2022

Hi,

yes, but I am in the beginning and don't know whether and when it will be ready ...

I want to achieve better version in ELO. This is what all others have reported when NNUE was widely adopted in the chess engines field.

For example, the author of GAiA chess engines reports the opposite. He uses Stockfish 14 and change its static evaluation function with NN. There is ELO drop from 3500 to 2300. Still good chess play and achievement (Congratulations to the author!), but this is not what I am looking for.

ONNX should be an optimization of the training speed and/or accuracy ...

These code and frameworks again are non-java ... it is always easier to understand algorithms by having look at their code or usage. I only found whitepapers with diagrams, but without enough details regarding the exact NNUE architecture (layers, sizes, connections, activations, and the actual code which creates it) ... including into the PDF document you shared in the previous post.

Best regards,
Krasimir

@bagaturchess
Copy link
Owner

There is a not productive implementation (not included in the distribution) of NNUE evaluation function. More information and final results could be found here: https://github.com/bagaturchess/Bagatur/tree/master/NNUE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants