Yet another parameter tuner using optuna framework

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

chrisw
Posts: 4313
Joined: Tue Apr 03, 2012 4:28 pm

Re: Yet another parameter tuner using optuna framework

Post by chrisw »

jdart wrote: Thu Sep 17, 2020 4:47 pm Interesting. I also found this software:

https://github.com/automl/HpBandSter

which seems kind of similar. I have tried this sort of thing before especially for search parameters, but the problem I've found is that the effect of varying these can be quite small. So you are trying to find the optimum point but basically on a very "flat" surface, and furthermore with a method that produces noisy objective measures. It is therefore hard to get convergence.
Yup, check. I was really quite surprised at just how dull search parameters proved to be, it's almost as if 'doing' a process is the most important bit and attempts to fine tune relatively fruitless. Compared to eval tuning where results plus/minus are semi-immediate and changes have strong effects. But search is not like eval, eval is grey scale accumulative, search is full of binary decision points (do I prune or not) and although the binary can be ameliorated to some extent (by adjusting how much depth left to search and so on, rather than yes/no cut/don't) there are still plenty of points where decision is full on binary, and a number that works for one case won't work for another etc. etc. Difficult problem.
Joerg Oster
Posts: 937
Joined: Fri Mar 10, 2006 4:29 pm
Location: Germany

Re: Yet another parameter tuner using optuna framework

Post by Joerg Oster »

Ferdy wrote: Thu Sep 17, 2020 12:05 am
Joerg Oster wrote: Wed Sep 16, 2020 4:30 pm
Ferdy wrote: Wed Sep 16, 2020 3:17 pm
3. I'm not sure if parameter changes to a 'quick match' change all five parameters at a time, or just one?
Sorry I don't understand the question.
I guess he wants to know if the tuner changes all parameters at once or one by one for a new trial.
In the document they refer to this as relational sampling and independent sampling.
We can ask the optimizer either one by one or all at once. I did all at once. https://github.com/fsmosca/Optuna-Game- ... ner.py#L65
Which seems to be the most reasonable, imho. :)
Jörg Oster
No4b
Posts: 105
Joined: Thu Jun 18, 2020 3:21 pm
Location: Moscow
Full name: Alexander Litov

Re: Yet another parameter tuner using optuna framework

Post by No4b »

Ferdy wrote: Thu Sep 17, 2020 12:53 am
No4b wrote: Wed Sep 16, 2020 8:58 pm Very interesting tool!
I will definitely try to work with it.

Am i understanding correctly that the engine itself obtain parameters via command line fe as "QueenValueOp=975"?
Not at the moment (will add it later), you need to modify the code around here https://github.com/fsmosca/Optuna-Game- ... er.py#L197
I mean should the chess engine itself (one that i want to tune) obtain parameters via command line fe as "QueenValueOp=975" ?
I want to know what to implement to work with your tool.

It is quite clear from your info that i should just write needed params in the tuner file itself, my question is how it (the tuner) communicate this params to the engine I want to tune. I tried to looked into the tuner code and my best guess is that tuner will run engine with smth like

Code: Select all

engine.exe "QueenValueOp=975" 
(so i should write some script into the engine to process lines like this), but i`m not sure... Thats why i`m asking.

Sorry if it is obvious and i`m being stupid. Im not that good at coding.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Yet another parameter tuner using optuna framework

Post by Ferdy »

No4b wrote: Thu Sep 17, 2020 11:21 pm
Ferdy wrote: Thu Sep 17, 2020 12:53 am
No4b wrote: Wed Sep 16, 2020 8:58 pm Very interesting tool!
I will definitely try to work with it.

Am i understanding correctly that the engine itself obtain parameters via command line fe as "QueenValueOp=975"?
Not at the moment (will add it later), you need to modify the code around here https://github.com/fsmosca/Optuna-Game- ... er.py#L197
I mean should the chess engine itself (one that i want to tune) obtain parameters via command line fe as "QueenValueOp=975" ?
I want to know what to implement to work with your tool.

It is quite clear from your info that i should just write needed params in the tuner file itself, my question is how it (the tuner) communicate this params to the engine I want to tune.
I use cutechess-cli to set the suggested params to the engine.

Once I get the suggested param from the optimizer, I build a text string containing,

Code: Select all

option.PawnValueEn=92 option.BishopValueOp=324
Then add that in the main cutechess-cli command line.

Code: Select all

cutechess-cli.exe -engine cmd=deuterium.exe proto=uci name=deuterium_piecevalue option.PawnValueEn=92 option.BishopValueOp=324 -engine cmd=deuterium.exe proto=uci name=deuterium_default ...
It is at https://github.com/fsmosca/Optuna-Game- ... ner.py#L63
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Yet another parameter tuner using optuna framework

Post by Ferdy »

@Joerg
Could you create a Stockfish where it exposes its material piece value and other evaluation param perhaps and a couple of search parameters. I can make it but may take sometime. I want to test optuna with it and later compare with other tuner like spsa and chess tuning tools and others perhaps. Stockfish params are well optimized, want to see how many elo optuna can increase or decrease. Or unoptimize it and try to optimize it back. Don't put a space in the uci option name and build an exe for modern. You can use the one with nnue but I prefer the one without it. Even a revised Stockfish 11 would do. Thanks.
Joerg Oster
Posts: 937
Joined: Fri Mar 10, 2006 4:29 pm
Location: Germany

Re: Yet another parameter tuner using optuna framework

Post by Joerg Oster »

Ferdy wrote: Fri Sep 18, 2020 1:25 am @Joerg
Could you create a Stockfish where it exposes its material piece value and other evaluation param perhaps and a couple of search parameters. I can make it but may take sometime. I want to test optuna with it and later compare with other tuner like spsa and chess tuning tools and others perhaps. Stockfish params are well optimized, want to see how many elo optuna can increase or decrease. Or unoptimize it and try to optimize it back. Don't put a space in the uci option name and build an exe for modern. You can use the one with nnue but I prefer the one without it. Even a revised Stockfish 11 would do. Thanks.
Hi, I also intended to run some Optuna tuning sessions with Stockfish.
There were some SPSA sessions running in fishtest for the mobility values recently.
I'm also very interested if Optuna can handle high-dimensional problems.

Not sure if I manage to get the piece values exposed for tuning, but some search and eval parameters for sure.
Not sure if I get it done today, though.

As for the number of games to be played per trial, I think I have to step back from my previous statement.
It seems more important to get more trials done in a reasonable amount of time, than to (further) decrease the noise of the measurements.
Even when playing 512 games per round/trial, there would still be much noise involved.
Jörg Oster
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Yet another parameter tuner using optuna framework

Post by Ferdy »

Joerg Oster wrote: Fri Sep 18, 2020 12:19 pm
Ferdy wrote: Fri Sep 18, 2020 1:25 am @Joerg
Could you create a Stockfish where it exposes its material piece value and other evaluation param perhaps and a couple of search parameters. I can make it but may take sometime. I want to test optuna with it and later compare with other tuner like spsa and chess tuning tools and others perhaps. Stockfish params are well optimized, want to see how many elo optuna can increase or decrease. Or unoptimize it and try to optimize it back. Don't put a space in the uci option name and build an exe for modern. You can use the one with nnue but I prefer the one without it. Even a revised Stockfish 11 would do. Thanks.
Hi, I also intended to run some Optuna tuning sessions with Stockfish.
There were some SPSA sessions running in fishtest for the mobility values recently.
I'm also very interested if Optuna can handle high-dimensional problems.
Looking forward on your results.
Not sure if I manage to get the piece values exposed for tuning, but some search and eval parameters for sure.
Not sure if I get it done today, though.
No problem, I will take what you will have. Sending it next month is fine with me.
As for the number of games to be played per trial, I think I have to step back from my previous statement.
It seems more important to get more trials done in a reasonable amount of time, than to (further) decrease the noise of the measurements.
Even when playing 512 games per round/trial, there would still be much noise involved.
This tuning is getting fun while it consumes lots of resources too.
In one of my studies, I looked at the importances plot - if value is high that parameter has more influence on the match result.

Image

Those are the bishops.

Now if we look at the slice plot, the tuner is somewhat confused, the trials are all over the place for the BishopValueEn. Trials are somewhat divided in the 320 to 340 range and also in the 340 to 360 range. The number of trials for those plots are 300 from 24 games/trial at tc=15s+100ms. In this situation I can continue the trials to perhaps another 100 trials and see what happens to importances and slice plot. After 300 trials I get around +12 wins in favor of the tuned param values over the default, at around 800 games in the actual game match at tc=15s+100ms. I discontinued this study.

Image


It is also showing in the contour plot for BishopValueEn. Majority of trials are in the range 320 to 340 and 340 to 360.
Image
Joerg Oster
Posts: 937
Joined: Fri Mar 10, 2006 4:29 pm
Location: Germany

Re: Yet another parameter tuner using optuna framework

Post by Joerg Oster »

Joerg Oster wrote: Fri Sep 18, 2020 12:19 pm
Ferdy wrote: Fri Sep 18, 2020 1:25 am @Joerg
Could you create a Stockfish where it exposes its material piece value and other evaluation param perhaps and a couple of search parameters. I can make it but may take sometime. I want to test optuna with it and later compare with other tuner like spsa and chess tuning tools and others perhaps. Stockfish params are well optimized, want to see how many elo optuna can increase or decrease. Or unoptimize it and try to optimize it back. Don't put a space in the uci option name and build an exe for modern. You can use the one with nnue but I prefer the one without it. Even a revised Stockfish 11 would do. Thanks.
Hi, I also intended to run some Optuna tuning sessions with Stockfish.
There were some SPSA sessions running in fishtest for the mobility values recently.
I'm also very interested if Optuna can handle high-dimensional problems.

Not sure if I manage to get the piece values exposed for tuning, but some search and eval parameters for sure.
Not sure if I get it done today, though.

As for the number of games to be played per trial, I think I have to step back from my previous statement.
It seems more important to get more trials done in a reasonable amount of time, than to (further) decrease the noise of the measurements.
Even when playing 512 games per round/trial, there would still be much noise involved.
@Ferdy
I've put something online here https://github.com/joergoster/Stockfish/releases/tag/v1

It's a modern build from end of July version, pre NNUE, with some eval parameters made tunable, plus 2 search margins.
Hope it works for you.

If you want some other parameters exposed for tuning, please let me know.
Jörg Oster
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Yet another parameter tuner using optuna framework

Post by Ferdy »

Joerg Oster wrote: Sat Sep 19, 2020 9:14 am @Ferdy
I've put something online here https://github.com/joergoster/Stockfish/releases/tag/v1

It's a modern build from end of July version, pre NNUE, with some eval parameters made tunable, plus 2 search margins.
Hope it works for you.

If you want some other parameters exposed for tuning, please let me know.
I got the file thanks.
Damir
Posts: 2801
Joined: Mon Feb 11, 2008 3:53 pm
Location: Denmark
Full name: Damir Desevac

Re: Yet another parameter tuner using optuna framework

Post by Damir »

Hi Jörg

Thanks a lot for this tunable Stockfish. If possible can you also put NNUE inside, ( whitout) embeeded net :) :)