Leela Chess Zero: A History

Leela Chess Zero: A History

Avatar of BugMeLater
| 4

Hello Chess.com'ers! Today, I come to you with a more fun blog, (hopefully making up for my absence over the past couple weeks, which I attribute to being very busy with work).


One topic that I don't see getting much attention is the fascinating history of the neural network (NN) chess engine: Leela Chess Zero (Lc0). For those who might not be familiar with computer chess over the past six years, Leela Chess Zero is a fascinating neural net-based engine that learns how to evaluate positions purely through self-play. This method is fundamentally different from traditional chess engines, and I’ll delve into those differences, and what all these terms mean, later in the blog. But first, I think we should take a quick look at the origins of chess engines and the precursor leading up to the creation of Leela Chess Zero.


Origins of Computer Chess


The first real Chess computer was invented and developed by the well-known mathematician Alan Turing in 1948. The Mechanical Turk in the 19th century was just a chess master in a box, and while interesting, doesn't count. Turing was known for his work in the UK decoding German Enigma machines and was a hero in World War 2. He is regarded as the father of modern Computer Science, and developing a chess engine before computers shows that well. Turing wrote an algorithm on paper, which represented what an engine would run, and he did all the evaluations by hand! He would later use a computer as shown below.

Turing used a computer later on
Credit to Chess Programming Wiki

Skip to 1977 at MIT, a different chess computer had been developed, with the culmination of computer and chess engine development of the last 29 years. Originating in the early 60s, Greenblatt (named after Richard Greenblatt) or MacHack (unaffiliated with Apple Mac) was one of the strongest computers of its time, but estimated at just 1500 by some, and nearly expert by others. The most notable player who fought it was none other than World Champion Bobby Fischer, in 1977, 5 years after his World Championship win, and his leaving chess.

MacHack VI from MIT

Fischer was paid an unknown amount to play the three games he did against the Greenblatt computer. Though it used some remarkable features for the time, including a hash table, which means it won't evaluate the same position through transpositions, and an opening book curated by future GM and Engine Dev Larry Kaufman, Fischer remarked on how weak it was and said he could give it Queen+Rook odds and win. Bobby was the 11th World Champ for a reason, though.

In this game, it's clear Fischer did not take it too seriously while making a game that feels out of place in the century.

The bot is clearly outclassed, and yet with new innovations it is still weak.


We jump forward another 2 decades to a very recognizable event in Chess History, by the 90s, engines were over Expert level but certainly not GM level. IBM, yes, the renowned business and technology company, sought to generate popularity for itself by developing a custom chess engine with its own special processor designed specifically for playing chess, it incorporated pruning techniques (methods to reduce the number of moves needed to search), hash tables (mentioned before), and human-described evaluation terms so it could understand chess. With an astounding 480 chips, this computer searched over 1 BILLION positions per second. 

This engine was named Deep Blue, "Deep" was a common naming term for engines at the time, and 'Big Blue' was IBM's nickname.

This publicity stunt was collaborated with a few Chess masters to help IBM, and World Champion Garry Kasparov on the other side, fighting this beast.

Garry Kasparov would lose the first of his 6-game match, but clap back, not dropping another game with a 4/6 score, defeating Deep Blue.

His 6 games in that match can be found here on ChessGames.

When Garry played Deep Blue again, he was defeated and had a score of 2.5/6. It was the first time engines showed themselves to be above the World's peak.

From kasparov.com

As the 2000s progressed, many engines reigned at the top, surpassing human capabilities by utilizing and building upon previous engine developments to improve code, evaluation, and search. Engines like Fritz and Rebel led the way, followed by Junior, then the open-source engines Fruit and Toga, whose code inspired many other engines. A few years later, Rybka started its domination, achieving a rating of around 3000. Although this seems weaker compared to modern engines rated around 3600-3700, it was groundbreaking at the time. After Rybka's decline, Houdini and Komodo took the lead. Houdini was much more tactically deep, while Komodo, developed by GM Larry Kaufman, excelled with deep understanding through its vast array of chess knowledge coded in. Eventually, an open-source engine named Stockfish, which I'm sure you've heard of, took over. This led to fierce competition for the top spot, as developers continually sought optimizations for engines that far surpassed human capabilities, with ratings around 3200-3300, leading us to 2015....



AlphaZero and Neural Network Engines


Neural nets are crude attempts to represent, with code, the human brain, which is composed of neurons and transmits signals. Developers had long considered neural nets as an approach for various purposes in engines beyond evaluation for a couple of decades; however, in the early 2000s, computer processors were neither strong enough to handle them nor to train them in a reasonable time. In 2014, DeepMind, a Google-based company (very well funded), had been experimenting with neural nets and the game Go, a more complex game quite different from chess, where Go engines struggled to surpass humans because of its depth on such a large board. At first, they tried creating a neural net trained on the games of professional Go players and computers, with exceptional results, crushing many of them and causing one to retire.

You can watch the free documentary they made about AlphaGo here!



In 2015, a developer named Matthew Lai worked on a project for his master's thesis called Giraffe, a new experimental chess engine aiming to use Deep Learning to power its evaluation. He provided it with the base information of piece values (1, 3, 3, 5, 9) and trained it on the games of top chess engines and it learned from the positions with no other human input. Deep Learning is a neural network machine learning technique. Giraffe's score output was probability-based rather than centipawns like its contemporaries. Its search was also probability-based, on the likelihood that each move would be the best move without looking further.
Matthew Lai discontinued this project despite working on it after getting his master's degree, due to his hiring at Google Deepmind in 2016 to work on the AlphaZero project.
You can read Matthew Lai's paper on Arxiv here.


Interestingly, some university students based in Israel and the US wrote another paper on a deep learning engine the following year. They took a different approach using the same training dataset of top chess engine games and developed a chess engine in 2016 that achieved grandmaster strength. Their engine exhibited a style similar to AlphaZero, despite being released before it, playing aggressively and aiming for long-term positional advantages with sacrifices.
Their paper is here.


Unless you were in niche communities, missing out on the previous 2 would be easy. So when Google's Deepmind dropped the bombshell about AlphaZero, you would have to have lived under a rock to not hear about it.
With their past success, Deepmind focused their efforts on developing AlphaZero, a neural net engine (playing Go, Shogi [Japanese Chess], and Chess) trained on 0 human knowledge except for the rules, and learns through playing itself in billions of games what works and doesn't.
Most chess engines use a search algorithm called alpha-beta. Alpha-beta, simply put, prunes the search tree of moves to avoid searching more positions than necessary. That is how, despite Chess being an ever-expanding tree of possible moves from the starting position, it can be searched efficiently. Our brains can do a similar thing when planning candidates, since we don't even consider obvious bad moves.
The reason I mention this is because AlphaZero did not use AB pruning! It used a different kind of search, whose use has been seen in other games: Monte Carlo Tree Search (MCTS). Instead of endlessly searching, MCTS anticipates that it is too complex to outright search the ENTIRE game and instead is based on outcomes. Well, for an engine like AlphaZero that plays itself to learn Chess through outcomes, MCTS is the perfect option. The search works by playouts, "simulations" of playing out the game to the end at "random" to determine the likelihood of results. Of course, I am grossly simplifying it since I'm no software dev. Because of this, AlphaZero need not search the billions of positions as an AB engine, and would instead search tens of thousands.

AlphaZero would discover its own patterns and concepts and eventually surpassed human and top computer strength after only 4 hours of training. AlphaZero would play a 100-game match in 2017 losing 0 games to Stockfish 8, with both engines running on 44-core machines, and A0 with Google TPUs. This match was played with no opening books, but was subject to scrutiny when people didn't read the paper clearly enough to understand they used equal hardware. Because of this, a rematch was held in 2018, where it was assured the hardware was equal to TCEC (Top Chess Engine Championship) standards, and AlphaZero would go on to win this 1000-game match. Deepmind remarked, "AlphaZero sacrificed pieces for long-term strategic advantage, suggesting that it has a more fluid, context-dependent positional evaluation" than traditional engines. This was something many chess players noted about AlphaZero, to the point of calling its positional aspect "humanlike", since most engines of the time struggled to give up material as much, and equally struggled with long term chess plans. 

Here in this groundbreaking game, AlphaZero uncorked a novelty that was so effective, that it is now the most played move.

In the second match, with 1000 games, they also had a large series of human openings played, where AlphaZero was meant to see if it could play other positions than stuff it forces on the board. It won convincingly too.

The 2017 Paper can be found here, while the 2018 paper is here.



Leela Chess Zero (Lc0) Arrives!


In 2017, programmer and Go and Chess engine developer Gian-Carlo Pascutto created an engine based on the 2017 AlphaZero paper for the game Go. However, he has an issue which is how Google trained the engine. They used hundreds of TPU processors, each of which blasted GPUs out of the water on performance. Because of this, Leela Zero was started and still is an open-source project with distributed help, meaning the community submits their own GPU to help. 
Released in Early 2018, Leela Chess Zero (Lc0) was created by Pascutto and some collaborators to follow in the footsteps of AlphaZero to become the strongest chess engine. 
With only the paper to work off of, they worked to ensure Leela Chess Zero incorporated the Monte Carl Tree Search algorithm and was capable of self-play to learn from itself. Despite drawbacks from being a community effort, Lc0 had surpassed the GM level within a few months. Still, it would lose almost every game in a tournament as the first neural network engine to compete in TCEC (Top Chess Engine Championship). 

Leela Chess Zero Logo

The light was near when Leela had reached 3rd overall in the Chess.com Computer Chess Championship (CCCC) within 9 months of its release, ensuring its presence was known. In the next couple of years, Lc0 would remain in the top 3, and win 2 TCEC seasons while being runner-up in the majority after.


One of the first early releases of Leela was T10. It was released in July 2018. T10 newly used a 10x128 (10 Blocks x 128 Filters) net architecture instead of the previous 6x64. People look back fondly on this net for its stylistic similarities to the first games of AlphaZero. Like AlphaZero, T10 pushed for long-term strategic advantages and loved thorn pawns.

As we can see in this exaggerated position, the thorn pawn on h6 clamps down on Black's position, restricting movement. Both AlphaZero and Leela loved thorn pawns. An iconic AlphaZero game with a thorn pawn resulted in Stockfish's Queen comically being trapped on h8. 

Here is a position from a Leela game where it has a thorn pawn:

Leela would go on to beat Fire 7.1 in this game.


A later iteration titled T30 was also likened to AlphaZero for loving pawn storms and finally reaching AlphaZero strength, released in September 2018. The major change again with this net is the architecture with a much larger 20x256 net.

In this game, the wonderful play loved of Leela is shown, where Leela sacs several pawns throughout the game and clamps down on Black with a pawn on g6. 


 Leela's Evolution


As Leela's team surpassed their initial goal of replicating AlphaZero, they had further goals to constantly get stronger. Beyond changing the net size, many different approaches to machine learning were considered, but determined to not be effective nor efficient:

  • Evolution
  • Image Scanning
  • LLMs (think ChatGPT)

As time passed, Leela continually got stronger, and soon, in 2019, Stockfish would follow suit with its own neural network, quite different from Leela's. It had a lightweight EUNN(Efficiently Updatable Neural Network [NNUE commonly]) inspired by a Shogi engine, and it was much more appropriate for the AB engine Stockfish, which immediately gained 100 Elo from it. Most engines have started to join in with this trend, and now every top engine has some sort of neural net equipped.
Leela continued with major net versions T40, T60, and T70, over the next couple of years into 2022.
In 2020, however, a unique net was created by some University of Toronto students, who wrote an interesting paper utilizing Leela to train a net on Lichess games. Many of you will know this as 'Maia'. They trained a series of nets from 1100-1900, with 1 net for every 100 Elo. The point was to create a neural net that could predict human moves at a much higher rate than traditional engines, including regular Leela.

Maia Chess

This chart illustrates the move-matching accuracy of Leela, Stockfish, and Maia across various ratings. While a stronger Leela matched very strong players decently, even the weaker Maia's did better in predicting moves; Stockfish was generally worse, and only as players got stronger did it match more. Most importantly is that we see with the solid, colored lines how Maia, at much higher likelihood, predicts the moves of, first their trained rating, and also other ratings.

This paper is available here.

In 2020, Stockfish would begin using the training data from Leela to supplement its own growth, and it was seen. Both Stockfish and Leela also started training on Fischer Random (Chess960) positions for further diversification, which saw some gains outside of 960. Now in 2024, its unlikely that an engine in the top 10 doesn't use at least some Leela data.

Finally, as we approach today's era, the major changes in Leela remain in the architecture. A new, revolutionary type of net is being used, called a Transformer, and no, not like the robots. Despite being experimented with a potential try for Leela from 2019 to 2021, little success was seen. Transformers like ChatGPT (Generative Pre-trained Transformer) use large blocks to create a massive net. For reference, older Leela nets from T10-T40 hovered around 40-50MB in size. Current Leela nets are now an astounding 150MB with the very newest test nets at 300+. They can handle more long-term complexity and store vast amounts of data. They don't memorize positions or stuff like that but rather generalize (to use a computer science term). Generalizing is the concept of how the net can take a position it has never seen and can still evaluate and understand it. Likewise, humans can be shown a position and through pattern recognition and understanding, make some assumptions and come up with our own evaluation. Because these nets are so massive, however, you need a pretty decent GPU to be able to compute it, or else the net would be too slow. A final, recent advancement was made with Leela, as it had some struggles to win against weaker engines. They added a contempt feature, where it can treat its opponent as weaker than itself and opt towards lines with more risk and sharpness. Humans have already snapped up on this, to prepare more tricky, sharp lines for OTB, and GM Matthew Sadler has made an entertaining series on both, playing against Leela with a very high contempt, to get wild chess, and taking these wild lines to online blitz to see how they play out.


The article on contempt is available here.

Matthew Sadler's videos can be found on his channel.

And Leela is available for download on every device here.


Conclusion


Wrapping up, the story of Leela Chess Zero (Lc0) is pretty amazing. ⁤⁤Inspired by AlphaZero, Lc0 uses neural networks and self-play to learn chess. ⁤⁤It started weak but quickly climbed the ranks in the best computer chess championships like TCEC and CCCC. ⁤⁤Leela eventually became a cornerstone in the Chess Engine development community with its data used to help train stronger engines, along with inspiring new NN engines and some concepts and new opening ideas always being unveiled in OTB chess. This progress shows what human innovation does and how open-source projects keep pushing the boundaries of AI and chess. ⁤⁤It's quite the journey and an important chapter in the history of chess engines.

I hope you learned something new about Leela or chess computers. If you did, feel free to leave a comment, or if you have a suggestion. I'll catch you on the next blog.

Hi! I'm an amateur blog writer. 

Here's some of my works:

Hans' Return to Chess
Leela Chess Zero: A History
3...g5!?: against the Rossolimo
The Greatest Blitz Tournament Ever