Thumbnail

A Guide to Go AI Programs

In this post, I’ll be teaching you how to install the main AI Go tools of today, at least the freely available ones. These are very valuable items to have at your disposal — after all, who wouldn’t like to have AlphaGo reviewing your own game? 🙂 —, and they do not take that long to install. This guide is composed of 4 tools with different objectives and different pros and cons:

  1. Leela, to analyze games and play against an AI;
  2. Lizzie, to analyze games on the spot (without registering the variations);
  3. Leela + Sabaki (and the ELF and PhoenixGo versions), to play against an AI and make them play against each other;
  4. Go Review Partner, to analyze games in more detail and in a more automated manner.

Huge thanks to George from the Igo Baduk Weiqi Youtube Channel for the help; and pnprog, author of the Go Review Partner, for the corrections to my mistakes.

Leela’s Interface.

Leela is the most famous item of this list, since it is available from even before the Deep Learning storm. It was created by the Belgian scientist, Gian-Carlo Pascutto, who, originally, worked with chess. After AlphaGo, Pascutto was one of the quickest online creators to make a new artificial intelligence utilizing Deep Learning available.

There are two versions of the program, one that contains AlphaGo’s basic algorithm Leela, and another, which has the latest version of the algorithm, starting from scratch, without any prior knowledge of Go: Leela Zero. For those who don’t know much about this branch of Go, I would suggest downloading Leela and playing with it for a bit, the interface is quite complete and its level is around 9d KGS, i.e., extremely strong, just as good as a strong insei at least.

Leela Zero is an under-construction project. Despite Deep Mind's last article’s algorithm — in which AlphaGo Zero learned, by itself and from scratch, to become even stronger than its last version in only about 8 hours — being elegant and simple, calculating the tuned parameters would take approximately 1700 years with an average (not so average actually) computer. To produce AlphaGo Zero, Google utilized special hardware for a more efficient computation of tensors, with GPUs specialized in Deep Learning that cost millions of dollars. To try to replicate the weights of the neural network, Pascutto created a sharing system where each user can help with his or her own computer. Since the project is not yet finished, if you wish to use Leela Zero, you will have to use a graphical interface, which we will discuss later on.

The AlphaGo Teach tool.
Lizzie’s interface.

This is a graphical interface which makes studying with AIs much more pleasant. Lizzie uses Leela Zero to generate candidates for the next moves, while showing live variations, besides a graph of the winning percentages. Some of the most useful commands are:

  1. X for showing the commands menu;
  2. Space for turning the pondering on and off;
  3. O for opening SGF files;
  4. A for starting the autoanalysis and specifying the number of variations per move.

Although very pleasant and powerful, Lizzie doesn’t solve the demand problem completely. There are still some imperfections. The biggest flaw would be not having a way to save the variations in the SGF file or even being able to recover them while running the program, this problem with recording makes the software a bit impractical for some purposes. Fortunately, this last issue can be solved in a very automated way with another tool, the Go Review Partner.

Sabaki is one of the most modern Go editors nowadays. The software was focuses in customization, better feel and the contribution of the community. The code is open source, anybody can create new themes, there are new editing tools, the variations tree is vertical and, more importantly, there is an integration with executables of AIs. Through this software, we can play against AIs and make them play against each other.

Before we continue with the implementation, we must first download the essential files. An AI is composed basically of two files: its executable, which contains the algorithm; and its text file, which contains the calculated parameters of the neural network. The executable which I recommend is the one inside Lizzie — I’ve tried others, but only got errors. As for the text file with the weights, there are several options.

The first one is to directly download the best Leela Zero weights, also found in Leela Zero’s GitHub Page, under the section I just want to play right now. The other is to go where they are actually stored. In the site dedicated to Leela Zero, we can find an enormous number of its versions, in each line of the tables, the strength being roughly proportional to the product of the dimensions of the column Size. According to Igo Baduk Weiqi, the 128×6 versions would already be strong enough to give me (1d KGS) 3 handicap stones. However, the fun doesn’t end there. On the table to the right, at some point, we will encounter, with bold percentages, a version with the numbers 83% (this number might change in the future); this is the winning probability of these weights against the best Leela Zero version.

How is that possible? That’s the iteration created by Facebook: ELF. If you wish, you can download its weights directly here. After downloading the files, let’s finally get to the implementation…

Facebook ELF inside zero.sjeng.org.

There are many possible configurations in Leela’s implementation, but I will only show here what worked for me — obviously, feel free to test others.

Upon opening Sabaki, go to Engines Manage Engines..., click on Add and name the AI you’re going to implement. Below, you will either type the path to the AI’s executable (.exe) or simply click on the folder symbol and point to the file directly. Next, on the next line, we will need to to provide some specifications for the simulation, besides the path to the text file with the weights (to find the path you can simply click on the path bar from Windows Explorer; but keep in mind that you should avoid paths that use spaces). What worked for me was:

          --gtp -w C:\Users\Philippe\Desktop\GoAI\elf_converted_weights.txt -t 2 --noponder --timemanage off
        

If you have additional GPUs, you can include the command --gpu 0 or --gpu 1:

          --gtp --gpu 0 --gpu 1 -w C:\Users\Philippe\Desktop\GoAI\elf_converted_weights.txt -t 2 --noponder --timemanage off
        

Lastly, it is necessary to place the initial commands of the simulation. What I use is simply the time configurations for each move. The second parameter of this command is probably the most important, informing the amount of seconds for each play, therefore; if we wish to make the AI think for only 5 seconds, we will have:

          time_settings 0 5 1
        
An example of AI creation inside of Sabaki.

Voilà! We now have our first pet AI (maybe two if you’ve also implemented Facebook ELF). To use them, you only need to go to Engines > Attach... and click on the arrows right next to Black and White.

Creating a game with AIs.

There is still another AI that deserves some attention: PhoenixGo. At the beginning of this year, surprisingly, we had a different AI winning the World AI Go Tournament 2018 PhoenixGo, from Tencent, dethroning Fine Art (also from Tencent; PhoenixGo was most likely only created so they could win the tournament) and Leela Zero. You can find its executable and text files here. PhoenixGo is the AI which runs the fastest and smoothest among the ones I’ve tested so far, but, actually, it doesn’t seem to be the strongest (perhaps Leela Zero has improved a lot since its loss in the world championship?). Apparently, among the three, ELF is still the strongest AI.

A game between Leela Zero (White) and PhoenixGo (Black). PhoenixGo is even playing the most recent variation of the 3-3 invasion. The moves analyzed by the AIs can be seen on the left.
The end of the same game between Leela Zero (White) and PhoenixGo (Black), Leela Zero+R.
GRP’s Menu.

The objective of Go Review Partner (there is also a GRP GitHub page) is to automate the AI analysis process. The standard output of the software is, however, an .rsgf file and not a .sgf file, as usual. The .rsgf standard was created to handle files .sgf files which have a very big amount of variations, leading to big and almost intractable variation trees. The GRP itself is able to open them, but, if you want, there are two alternatives. The first one would be to open them with another program, MultiGo; and the second would be to convert the .rsgf file to a .sgf one through the GRP.

To use the software, you’ll first need to have Python installed. Pay attention, though, to the version you’re installing because the more recent ones will yield errors. Only the 2.7.X versions will work properly (I use the 2.7.13, for example). If you have Windows, you only need to download the .msi file and continue the installation process normally. If you have another operating system, installing the TkInter library is necessary, which can be achieved through a command like:

          sudo apt-get install python python-tk
        

Next, inside Windows, after downloading one of the packages containing an AI, you will only need to open the GoReviewPartner.exe file. I warn you, however, that, after several tests, I’ve had problems with some AIs: some of them were not changing the winning percentages by more than 1% throughout the whole analysis. I would suggest starting with the Leela and Leela Zero versions which use no GPU. If you still have questions and problems related to the GRP, its creator is available in the Life in 19×19 forum answering comments inside this post.

An analysis example from the GRP.
The GRP also analyzes other board sizes. (Although Leela Zero apparently rejects them.)

It is possible to test a vast number of AIs with the various software mentioned. For example, we can try to replace the executable inside Lizzie with that of PhoenixGo, along with its weights, to have a new version of Lizzie. Nevertheless, I haven’t had much success with that technique and it seems the reason for the failure is, in fact, my hardware.

On a sidenote, I would like to mention a smartphone app that runs Leela Zero. There are still some imperfections and bugs but it works well in general. The app is called Go Grid Master and has both a free and a paid versions.

Another update is a chinese app that featers AQ and Leela Zero in your phone, try it out.