Leela Chess Zero: AlphaZero for the PC

by Albert Silver
4/26/2018 – It might sound like a joke, but it is not: the revolutionary techniques used to create Alpha Zero, the famous AI chess program developed by DeepMind, are now being used to engineer an engine that runs on the PC. This project has now been underway for about two months, and the engine, Leela Chess Zero, is already quite strong, playing at 2700 on good hardware, and is freely available. As will be seen, just about every aspect of this new engine is revolutionary and breaks all the paradigms that had dominated the field until now.

ChessBase 17 - Mega package - Edition 2024 ChessBase 17 - Mega package - Edition 2024

It is the program of choice for anyone who loves the game and wants to know more about it. Start your personal success story with ChessBase and enjoy the game even more.

More...

From Alpha Zero to Leela Zero

When Alpha Go, and then Alpha Go Zero, was released, it cracked one of the most challenging strategic games in the world, and one that experts all over had thought would resist for at least another decade. It was the result of a powerful artificial intelligence technique known as deep reinforcement learning, which built a neural network combined with the Monte Carlo Tree Search that allowed the program, equipped with just the barebones rules of the game, to play itself millions upon millions of times, learning as it went until it reached, as was the case, superhuman playing strength.

All the more remarkable was that the Deep Mind group published peer-reviewed papers that detailed exactly how it was achieved. In a sense, this was the equivalent of IBM creating the world-beating Deep Blue, and then publishing blueprints the very same day so that anyone could build their own. As a sidenote, Feng Hsu and the Deep Blue team did eventually publish papers describing the entire thing inside and out. Nevertheless, it was believed that while a game such as Go, might fit this form of software engineering, it would never really work for a chess program. At least not at the highest level. After all, Go is less about calculating exact lines, and more about extensive pattern recognition, while chess is highly tactical and seeing just a single extra move ahead can make or break a program.

Then along came Deep Mind, who poured in their resources and built a world-beating engine that learned the game itself within 24 hours. Naturally, there were plenty of special conditions in play, such as having access to thousands of incredibly powerful processors to help develop its ability in such a short time, but they did it. Consider that if Murray Campbell and Co. had thought that just piling in special hardware would somehow solve chess for them in 24 hours, they would have done it. Deep Blue had a system performance of 12 GFLOPS, while the horsepower DeepMind used easily exceeded 40 million GLOPS.

DeepMind's professor David Silver explains the new 'Zero' approach in AlphaGo Zero, which preceded Alpha Zero (chess)

The new Alpha Zero chess program lead to an astounding media frenzy, and just as much controversy in the chess world. Much was made about the conditions of the match against a 64-thread version of Stockfish used to test its strength, but this was to completely overlook the important aspect of it all: a new world-class engine, using a completely new method and technique, had been developed in 24 hours. What was more, anyone was invited to make their own.

The paper "Mastering Chess and Shogi by Self-Play with a General Reinforcement Learning Algorithm" at Cornell University

This was not nearly as easy as might seem. For one thing, a single person could hardly do it at home with a single machine, or even a room full. Then there is the matter of trying to translate Deep Mind’s explanations in their paper into concrete computer code.

But some programmers took up the challenge, and after developing a Go program, Leela Zero, the strongest one publicly available now, based on community effort and contributions, it has been transferred to chess.

Leela Chess Zero is based on the seminal Alpha Zero paper, using the same self-learning techniques and the same Monte Carlo Tree Search technique. It is hosted at the LCZero site and there one can not only find the engine but the latest version of the neural networks — the brain if you will.

How strong is Leela Chess Zero?

The project is still in its infancy, having only really started two months ago. As it depends very much on help by others to contribute computer time, the beginning was slow as time was needed for word to get around, tools developed to make it easy, etc. Because of the unique nature of the engine’s design, using a huge evaluation function (over 80MB), it gains exponentially in strength when used with a good graphics card.

Without a graphics card, using only my CPU, I barely get 20% the performance I get with the GPU (graphics processing unit). On a laptop equipped with a quad-core i7 and a fast GTX980M graphics card, it plays at around 2700 Elo or so. Remember that this is after just two months of self-learning. However, the engine’s play is quite different from anything I have seen or tested before, and I am speaking from over 20 years experience.

Without exception, until now, an engine’s strength was clearly determined by its speed and tactics. Sure an engine could compensate a slight tactical deficiency with more knowledge, but not by much, and more often than not, the ‘dumber but faster’ engine would compensate its ignorance with slightly deeper calculations. This give and take has defined engines on the PC since the beginning of computer chess.

Therefore you can imagine what I thought after the following: I gave a fairly weak engine — Firefly (rated 2250) — a basic tactics test of 100 positions, a set so easy I would expect myself to score 100, and it scored 94/100. I then fed it to Leela Zero, which barely scored 41/100. I grimaced, knowing this meant Leela was going to get trounced, but still decided to play a small match of 10-minute games just to gauge its play. I found myself forced to stop the match early after it was 10-0 for…. Leela!?! I check and triple-checked the settings to make sure everything was fine. 

I then tried another engine, Delphil 3.2 (rated 2494) with the same 10-minute conditions, and stopped it after 20 games with Leela bullying it 15½-4½. What on earth was going on?? I never heard of an engine compensating hundreds of Elo of tactical gaps with pure positional play. That is a human thing, not a machine. Eventually, it found its match with Nebula, a 2700+ engine with a  14½-14½ score, enough to suggest this is about where it stands.

With a description of an engine compensating tactical weaknesses with massive positional play, you might expect games that looked like Carlsen or Capablanca, with controlled complications, and then a boa constrictor win later, right? Not even close! Leela Zero makes Topalov, the king of exchange sacrifices, look like a timid milkmaid. It plays a ton of speculative moves, readily giving up pawns, exchanges and more for activity and play. Please note the word speculative, because I doubt very much these are all correct. However, they do make for very entertaining games, and what is more, it plays the endgame impressively well.

Take a look at the following game, which sort of illustrates some of the surprises it can come up with:

Nebula 2.0 vs Leela Chess Zero (NN189)

[Event "Match"] [Date "2018.04.25"] [Round "6"] [White "Nebula 2.0 64bit"] [Black "Lczero 0.7 NN189"] [Result "1/2-1/2"] [ECO "A30"] [WhiteElo "2726"] [BlackElo "2700"] [PlyCount "191"] [EventDate "2018.??.??"] 1. c4 c5 2. Nf3 Nf6 3. g3 b6 4. Bg2 Bb7 5. Nc3 e6 6. O-O Be7 7. d4 cxd4 8. Qxd4 d6 9. Rd1 a6 10. b3 Nc6 11. Qd3 Qc7 12. Bf4 Rd8 13. Qc2 O-O 14. a3 Nb8 15. e4 h6 16. Rac1 Nbd7 17. h3 Nc5 18. Re1 Ncd7 19. Be3 Rfe8 20. Nd4 Qb8 21. f4 Rc8 22. Rcd1 b5 $5 {[#] It is more than a little astonishing to see an engine play this thematic double-strike with ...b5 and ...d5 in the hedgehog. It isn't quite correct, though Black does get play for it.} 23. cxb5 d5 $1 {In for a penny, in for a pound.} 24. e5 Ne4 25. Bxe4 dxe4 26. Nc6 Bxc6 27. bxc6 Rxc6 28. Rxd7 Bxa3 29. Rd4 Rec8 30. Rc4 Rxc4 31. bxc4 Rxc4 32. Qb1 Rb4 33. Qa2 Bb2 34. Nd1 Qb5 35. Kg2 h5 36. Kh2 Rb3 37. Bf2 Rb4 38. Kg2 a5 39. Nxb2 Rxb2 40. Qa3 Rb3 41. Qe7 Qc6 42. Qc5 Qb7 43. Qa7 Qc6 44. Be3 a4 45. g4 h4 46. Rc1 Qd5 47. Qe7 Rb8 48. Qxh4 a3 49. Qe1 Qd3 50. Rd1 Qb3 51. Qd2 a2 52. Ra1 Ra8 53. Qc1 Rd8 54. g5 Rd3 55. Bf2 e3 56. Be1 Qb7+ 57. Kh2 e2 58. Rxa2 Qf3 59. Qc8+ Kh7 60. Qc2 Qxh3+ 61. Kg1 Qf1+ 62. Kh2 Qh3+ 63. Kg1 Qg4+ 64. Kh1 Qf3+ 65. Kg1 Qf1+ 66. Kh2 Qxf4+ 67. Kg2 Qxg5+ 68. Kh1 Qh6+ 69. Kg1 Qe3+ 70. Kg2 Qe4+ 71. Kf2 Qf4+ 72. Kg2 Qf3+ 73. Kg1 Qg4+ 74. Kh2 Qh5+ 75. Kg1 Qg6+ 76. Kh2 Qh5+ 77. Kg1 Qg5+ 78. Kh1 Qh6+ 79. Kg1 Qe3+ 80. Kg2 Qe4+ 81. Kf2 Qd5 82. Ra4 Qf3+ 83. Kg1 g5 84. Ra3 Qf1+ 85. Kh2 Qxe1 86. Qxd3+ Kh6 $4 {An unfortunate blunder that allows White to save the game.} ({After} 86... Kg7 $1 {Black would win.}) 87. Qd4 Qf1 88. Rg3 e1=Q 89. Qh4+ gxh4 90. Rg6+ Kh7 91. Rg7+ Kh8 92. Rg8+ Kh7 93. Rg7+ Kh6 94. Rg6+ Kh5 95. Rg5+ Kh6 96. Rg6+ 1/2-1/2

Bear in mind that while it misses some easy tactics it also catches some hard ones very quickly.

 

In the position above, White (Leela) played the lovely 38.c5!! And went on to win after 38…dxc5 39.Rd7!

Interview with Gary Linscott

I caught up with Gary Linscott (pictured), the person who spearheaded the Leela Chess Zero project and helped make it what it is today. (Please note that another interview with Gian-Carlo Pascutto, creator of Leela Zero — which led to Leela Chess Zero — will appear soon.)

Albert Silver: Hi Gary, congratulations on the fascinating project. How did it come into existence? Concept, execution, etc

Gary Linscott

Gary Linscott: The AlphaZero paper was a landmark — it was the first time traditional techniques had been defeated in over 20 years. I had wanted to learn about reinforcement learning, and this provided a great motivation. I even started a small version of this project in python with a co-worker, but we weren't generating anywhere near enough games to make reasonable progress. Then, Leela Zero really started to take off. A user named benediamond got the ball rolling with a non-working prototype of chess support for Leela Zero. It needed a fair bit of additional work, which I did, and then coded up the server and client in Go [the coding language, not the game -Ed.] to learn more about that language. Then, I launched it on Talkchess, and the support has been incredible since then!

AS: How is Leela Chess Zero being developed? Is it just you, or others, or...? 

GL: There is an extremely active community! Folkert Huizinga (Error323) was one of the earliest to join and has been the driving force behind the training process, which generates the new networks. It's an extremely hard, and time-consuming part of the project, and he's done an amazing job. We got a donation of the training hardware as well, which has been fantastic. Then a bunch of great developers have stepped up to help out as well, special mention to Andy Olsen (KillerDucky) and Alexander Lyashuk (mooskagh).

AS: How close is it to Alpha Zero, or how different? 

GL: It's quite close to AlphaZero in concept. The paper doesn't really reveal all the little details, so we aren't 100% sure. For example, there is a critical change in the network architecture that was required for chess that wasn't in the paper (the number of layers in the policy head for the technically inclined).

AS: What has been the biggest challenge so far in creating/developing it?

GL: Keeping up with the community! There is a lot of passion, but it's a part-time project on my side. Others have really stepped up and made huge contributions thankfully.

AS: Roughly how strong is Leela Chess Zero right now in FIDE Elo terms?

GL: It depends (smiley). It's very sensitive to the hardware, and the time control used. However, in recent blitz/bullet matches, it was able to defeat human IM/GMs convincingly. Against other machines, it's still a long ways from the top — estimates vary between 2600 and 2800, while something like Stockfish is ~3300.

AS: How much strength does a decent video card add? 

GL: A huge amount! For example, the TCEC competition is playing it on ~40 cores, and it would be roughly the same speed on a 1080Ti.  We will also improve the efficiency significantly on GPU as time goes on, with things like CUDNN, and TensorRT.

AS: What has been the biggest surprise so far?

GL: How much interest and passion there is around this project. It's been fantastic to watch the community really get excited, and all the chess personalities who have tried playing it.

AS: While testing the engine in Fritz, I noticed a number of very strange tactical oversights, even in fairly simple positions. Is this normal, and if so, when would they be overcome?

GL: Definitely normal, the network is still learning tactics, especially at low depths. Also, we are on a much smaller network than DeepMind used (10x128 instead of 20x256).

AS: How many games did AlphaZero need to be trained to its famous level, and how many has Leela Chess Zero used? Also, at the current rate of development, how long would it take to reach that level (presuming similar hardware)?

GL: From their paper, 44 million if I recall correctly, while we are at 8.2 million as of this email. However, we've also had some significant bugs during the training process, and have been learning a lot as we go. I wouldn't be surprised if our run took longer.

AS: Can you tell a bit about yourself

GL: I've always loved the combination of distributed systems and chess. A few years back I also developed "fishtest", which helped take Stockfish to number one on the rating lists (although these days, a wonderful community has taken it on). My professional work is on developing autonomous cars, which is extremely fun and challenging.

How to install Leela Chess Zero in Fritz/ChessBase

Leela Chess Zero can be installed as a UCI engine in Fritz or ChessBase, though it does require a few extra steps. Also, you most definitely want a video card to run it properly. The faster the better, but anything beyond Intel integrated graphics should be a plus.

1) Download the latest Windows build (there are Mac versions too), it comes with the needed DLLs: https://github.com/glinscott/leela-chess/releases.

If you have a discrete GPU (graphics card), get the gpu-win.zip version instead

Unzip into a folder of your choice. I created one called \LCZero.

2) You may also need to download and install the VC Redistributable 2015 x64. Many other programs rely on this library so you may have it already.

3) You will now need to double-click on the LCZero.exe engine one time. It is vital this be done before trying to install it as a UCI engine.

4) Go to the Network page and download the latest network file. Naturally, you can download any version really, even when it was rated a big fat zero. Right-click on the blue Network number and save.

You then unzip it to the main Leela folder. Now you will have a very large file with a long name that looks like a secret code. Rename it to weights.txt

5) If you have a GPU, then I strongly suggest you download this .bat file and unzip it in the same folder as Leela and then run it. This is a simple command that will have the computer run a full tuning of your computer to get best results with Leela. It may take 20-30 minutes, so be patient.

Running the script will do a full tune of your graphics card to get optimal results. Please note this can improve performance to almost double even!

You are now ready to install it in Fritz/ChessBase!

6) In Fritz/ChessBase, select Create UCI engine 

Then find LCZero.exe file, and that is it!

When you want to update the neural network with the latest version, all you need to do is download the newest Network file, and rename it again.

Contributing to Leela Chess Zero

If you would like to contribute some of your computer time to help Leela, just double-click on the client.exe file in the folder. It will start running self-play games, and send them to the site. To stop the process, just close the window. For more information, please see the Getting Started page.

Questions and suggestions

If you are having trouble with Leela, or have any questions or suggestions, be sure to check out the official forum for it.

Links


Born in the US, he grew up in Paris, France, where he completed his Baccalaureat, and after college moved to Rio de Janeiro, Brazil. He had a peak rating of 2240 FIDE, and was a key designer of Chess Assistant 6. In 2010 he joined the ChessBase family as an editor and writer at ChessBase News. He is also a passionate photographer with work appearing in numerous publications, and the content creator of the YouTube channel, Chess & Tech.

Discuss

Rules for reader comments

 
 

Not registered yet? Register