2018-09-21

GUIDE: Setting up Leela on a Chess GUI.





 Leela Chess Zero is a project started before some months inspired by Deepmind's papers about AlphaGO Zero and AlphaZero, which is based on a new paradigm of Chess engines by not using traditional AlphaBeta search with handcrafted evaluation function but uses a variant of MCTS search called puct and for evaluation function it uses a self-taught neural network that learns by deep learning methods by playing against itself million times.

Now after 6.5 months of training it seems that it has reached a place among the top 5 strongest engines available.

 Its use is not that straightforward like traditional engines since it requires some extra things one that has to make in order to run it. It's easy thought. This guide will be about running it on Microsoft Windows on various GUIs.


Leela Chess Zero works with the help of 2 things:

CCCC stage 2 continues.... Leela 3rd place. Missed 2 chances to beat Stockfish!





Stage 2 continues with Leela doing excellently being 3rd, half a point ahead of Komodo!
Stockfish
continues its unbeaten run, being the only engine with no loss, stage 1 and 2 combined!

This definitely comes as a surprise since Komodo one of the big 3 engines in the Chess world, after 31 games should already be ahead in a well defined top 3 but Leela persists to not lose! She now had in the last 17 games, 2 wins and 15 draws. 
Komodo even had 15 consecutive draws!

 She only lost once from Andscacs and that was only because of a heavy blunder of her in an equal position, while she has 13 draws with the big 3 engines Komodo, Houdini and Stockfish and if we count stage 1 results too she has 19 draws out of 19 games with the big 3.  Also, she beat Fire twice in 2 excellent games outplaying Fire, but the big games were the 2 Leela versus Stockfish games where Leela was close enough to beat Stockfish in the first and one small step for that in the 2nd. Leela outplayed Stockfish in these 2 games especially in the 2nd, to reach winning positions.
 In the first as we mentioned in the previous post, she missed a nice move that other nets find(e.g the strong 11250 finds it after 1.5 million nodes) that would lead to a huge advantage and perhaps a win if Leela could convert, but in the second Leela was really close to beating Stockfish! That would be the first loss of Stockfish in this tournament. But Leela blundered and lost the win. Afterwards analysis show that this 11089(CCCC) net with endgame tablebases would not be able to beat SF from that position while net 11250 with endgame tablebases would do it rather easily.

Fire is also underperforming being currently last in 8th position while Booot continues to surprise being 6th for now.
Stockfish is a clear leader 3 points ahead of 2nd, wining against everyone except Leela.



Standings so far:

2018-09-19

CCCC Stage 2 has started and running.....





Stage 2 of CCCC has already started before 2 days. Not without problems initially with repeating restarts but at last now it's running flawlessly.
Stockfish continues to be invincible! As it hasn't lost a single game in the first 46 games of stage 1 plus the 15th till now in stage 2.
While the so far unbeatable too Komodo, in this stage lost to Houdini.

Leela on the other hand had after 6 games with the big 3, 6 draws as in stage 1. So now she is the only engine that has not lost a game from the big 3. She is going fine also generally till now since she won 4 games also and shares 3rd place with Komodo. She lost 1 game though due to a huge blunder with a blind spot of her in an equal position.

Every engine will play 10 times all the other so 70 games for each engine will be played in this stage.
Top 2 will promote to the super final.


Below are the results, the games of Leela with some comments as also the standings and ratings.

2018-09-16

CCCC rounds 43,44 and 45. First stage is over!




1st stage is almost over, 1 round remains but the top 8 engines that will participate in stage 2 are known.
Stockfish, Komodo, Houdini, Leela, Fire, Ethereal, Andscacs and Boot promote to next round.
Next round, unlike this round, would be without pondering and every engines will play every other 10 times so we would have a total of 70 games per engine.

Andscacs won Arasan in the final round so Shredder has no hope to promote.



ROUND 43
 In this round Leela destroyed Shredder's hopes for promotion by winning him after a superb game where it completely outplayed Shredder with a startling exchange sacrifice that Shredder(as also other engines like the mighty Stockfish) had no idea about it. The defense that would lead to draw was very thin and Shredder didn't manage to find it. To him as also to other engines most moves drew easily. But that was not the case as the genius Leela knew in this game!

TB Rescoring

While test20 runs, we are running test30 in parallel to test two ideas. First test30 uses a different method to initialize the first random net, and a slightly different LR (Learning Rate) strategy for the first few nets. The idea is to see if this eliminates the large spikes seen in some key metrics -- policy loss, mse loss, reg term (see our expanded glossary).

The second idea is to test TB (Endgame Tablebase) rescoring. This may improve the accuracy of the value head. The procedure is:

  • Clients continue generating self-play games as before, no TB involved.
  • The data from these games are sent to the server.
  • The server parses these games, and when a position reaches a new WDL entry, the game result for all positions up to that point is changed to the TB result.
  • An WDL entry is when there are 5 or fewer pieces and a capture or pawn push just happened, and neither side can castle (9000 internet points for anyone who can find an Lc0 self-play game where the castling exception applies!)
  • The game is parsed for the next WDL entry, and again all positions in this new section are marked with the TB result.

This is an alternative to doing temperature reduction or other similar methods, but does not require changing the way clients generate data. So it’s easier to test and compare with and without this method. Also by doing this on the server side we don’t require all users to download TBs.

2018-09-15

CCCC quiz. 12 impressive moves!




In CCCC there have been played some very nice games and moves till now.
Can you find them? Play the move on the board and if it's correct it will show the game continuation with a comment. If not, go back with arrows and try again or press show solution if you can't find it.

CCCC rounds 37 to 42. Leela promoted to 2nd stage!





CCCC continues and Leela, along with Stockfish, Houdini, Komodo and Fire, already has secured a place in the 2nd stage.
Ethereal after a strong finish, mainly winning in the last games, has almost secured the promotion. Booot has also many chances.
While Shredder and Andscacs are the ones that are competing for the final 8th place right now with Shredder to be ahead, but having difficult opponents to face in the next 4 rounds.



ROUND 37
 Leela won a fine game against Fritz with an opposite colors Bishops ending with Rooks also. Leela outplayed Fritz that made some mistakes being short on time since it played in the beginning very slowly.

2018-09-13

CCCC rounds 32,33,34,35 and 36. Leela with 5 draws and an "almost win" against mighty Komodo!





First round CCCC approaches to its end and situation is clear by now.
Houdini, Komodo and Stockfish will be in top 3 advancing to stage 2, with Stockfish and Komodo to fight for the 1st place in this 1st stage, thatdoesn't mean much anyway, Fire and Leela would most probably advance to the next round also with some minor chances of not achieving it, and Shredder, Booot, Ethereal and Andscacs will fight for the other 3 places for stage 2.

Leela had 5 draws in these 5 rounds with 2 easy and 3 very hard opponents and she has 7 consecutive draws.

Simulations using Bayeselo give right now(after and the Andscacs-Inavhoe 1-0 game of round 37):
Probability to promote:
Stockfish 100 %
Komodo    100 %
Houdini   100 %
Fire      100 %
Lc0       99.67 %
Shredder  90.33 %
Booot     81.67 %
Andscacs  77.67 %
Ethereal  44.67 %


ROUND 32
Leela had an extra-disastrous opening with Senpai and never managed to recover so it ended in a draw. Against the very weak in this CCCC Senpai, Leela had to win but the selection of the opening moves was a nightmare and even with Senpai playing sub optimal moves, Leela never really managed to get an advantage so it was easy draw.

2018-09-12

A Standard Dataset

When doing machine learning it helps to use a standardized dataset such that methods can be compared in an objective manner. For machine vision, one of the earliest standard datasets is MNIST, a set of handwritten characters that was also used in the (arguably) first deep learning paper.

We should define such a dataset in the world of chess programming as we try to improve training algorithms for our new chess engines based on neural networks. This blogpost introduces such a dataset called the CCRL Dataset (also giving a huge hint as to where it comes from).

Introducing the CCRL Dataset

This dataset was constructed from CCRL 40/40 and 40/4 data combined. It consists of 2'500'000 games, 20% of which is the testset and 80% the trainingset. You can download the dataset in pgn-format (539M) and v3-format (11G).



This figure shows a distribution of all the gameover types within the testset of this data. Games with over 500 plies have been excluded from this figure to keep it readable, and as such the game count is slightly smaller than 500'000 with 0.02% ignored. The double bands for black/white wins show wins on checkmates and resignations. 38% was won with white, 30% with black and 32% draw. Finally, the testset has ~86% unique positions (including history planes).

Baseline results

For training a simple baseline network the following yaml scheme was used as input to train.py:

%YAML 1.2 --- name: '128x10-base' gpu: 0
dataset: num_chunks: 2500000
train_ratio: 0.80
input_train: '/home/fhuizing/Downloads/chess/computer/cclr/v3/train/'
input_test: '/home/fhuizing/Downloads/chess/computer/cclr/v3/test/'
training: batch_size: 1024
num_batch_splits: 1
test_steps: 1000
train_avg_report_steps: 500
total_steps: 200000
checkpoint_steps: 10000
shuffle_size: 250000
lr_values: - 0.1
- 0.01
- 0.001
- 0.0001
lr_boundaries: - 80000
- 140000
- 180000
policy_loss_weight: 1.0 value_loss_weight: 0.01 path: '/mnt/storage/home/fhuizing/chess/networks'
model: filters: 128
residual_blocks: 10
...

This resulted in an accuracy of 47.0583%, policy loss of 1.591 and mse loss of 0.10882. The network can be downloaded as ccrl-baseline.pb.gz.

Potential ideas

For inspiration, here's a list of ideas where using such a dataset may be useful:
  • Testing a multigpu training algorithm
  • Different neural network architectures
  • Different input encoding (e.g. removing history planes)
  • Different move encoding on the policy head
  • Finishing resign or adjudicated games to get more endgame data with n-man tablebases
And much more...

Final notes

This dataset is very different from our selfplay data runs which improve over time through reinforcement learning. Sliding a training window across the vast number of games produced by clients as new networks are trained. As such one can only test a subset of ideas/parameters using this data. Still, it's probably safe to say one should never regress in terms of performance on this dataset.

Have fun experimenting and please share your results (good or bad, as both can be very useful)!

2018-09-11

CCCC rounds 28, 29, 30 and 31. Leela draws Stockfish and wins in drawn position again!




 It seems Leela is hiding something that is beyond us. How else can be explained that after Fizbo a 3325 CCRL Elo engine with endgame tablebases in a dead 4-men position lost to Leela, now Leela in another dead draw position made Xiphos, a 3200 CCRL Elo engines, to lose!
At round 29 there was the first loss in this tournament of one of the big 3, as Houdini with black lost to Ethereal!


ROUND 28
Andscacs lost to Stockfish and lost ground for the battle of 8th place but Ethereal and Booot lost to Komodo and Leela respectively so they did not took advantage of it so things remained the same.
Fire won against Ivanhoe so now it has a comfortable place inside top 8.

 Leela playing with Booot a French defense(what else?) opening, she took a very easy win by playing simple Chess. She initially pushed all her Pawns, h4,f4,g4, in from of the castled King gaining all the space in Kingside and first thoughts were that she is planning an attack. But suddenly she forced the
exchange of Queens getting a huge Knight on d6 and from then on some almost forced trades have been made going to an endgame that as it seems it was almost lost for black since its King was too far away and white had a 3-2 Pawn majority on Queenside.

2018-09-10

CCCC rounds 26 and 27. Leela with a crazy game as also her first loss!




Leela had its first loss in the tournament after 27 games that went undefeated. It lost against Ethereal with black after she blundered in endgame.
But before that, a real circus game happened in the Leela game of course again. It was the Leela-Fisbo game with Fizbo the known drawmaster with 19 draws out of 25 games but Leela managed to hypnotize Fizbo to lose, while Fizbo was playing with tablebases and the position was a drawn with just 4 pieces remaining!


ROUND 26
In this round Arasan upset Shredder by drawing him, while the big 3 won their games as usual and Fire won against Nemorino. While for the battle of the top 8 place Booot, Ethereal and Andscacs won their games, even though all had the black pieces.

The real craziness happened in the Leela-Fisbo game. Fizbo till now is drawing most of its games with 19 draws out of 25 games and 9 draws out of the last 10!