KataGo's public distributed training run is ongoing! See https://katagotraining.org/ for more details, to download the latest and strongest neural nets, or to learn how to contribute if you want to help KataGo improve further! Also check out the computer Go discord channel!
As of 2024, KataGo remains one of the strongest open source Go bots available online. KataGo was trained using an AlphaZero-like process with many enhancements and improvements, and is capable of reaching top levels rapidly and entirely from scratch with no outside data, improving only via self-play. Some of these improvements take advantage of game-specific features and training targets, but also many of the techniques are general and could be applied in other games. As a result, early training is immensely faster than in other self-play-trained bots - with only a few strong GPUs for a few days, any researcher/enthusiast should be able to train a neural net from nothing to high amateur dan strength on the full 19x19 board. If tuned well, a training run using only a single top-end consumer GPU could possibly train a bot from scratch to superhuman strength within a few months.
Experimentally, KataGo did also try some limited ways of using external data at the end of its June 2020 run, and has continued to do so into its most recent public distributed run, "kata1" at https://katagotraining.org/. External data is not necessary for reaching top levels of play, but still appears to provide some mild benefits against some opponents, and noticeable benefits in a useful analysis tool for a variety of kinds of situations that don't occur in self-play but that do occur in human games and games that users wish to analyze.
KataGo's engine aims to be a useful tool for Go players and developers, and supports the following features:
Here are some links to some docs/papers/posts about KataGo's research and training!
Paper about the major new ideas and techniques used in KataGo: Accelerating Self-Play Learning in Go (arXiv). Many of the specific parameters are outdated, but the general methods continue to be used.
Many major further improvements have been found since then, which have been incorporated into KataGo's more recent runs and are documented here: KataGoMethods.md.
KataGo has a fully working implementation of Monte-Carlo Graph Search, extending MCTS to operate on graphs instead of just trees! An explanation can be found here Monte-Carlo Graph Search from First Principles. This explanation is written to be general (not specific to KataGo) and to fill a big gap in explanatory material in the academic literature and hopefully it can be useful to others!
Many thanks to Jane Street for supporting the training of KataGo's major earlier published runs, as well as numerous many smaller testing runs and experiments. Blog posts about the initial release and some interesting subsequent experiments:
For more details about KataGo's older training runs, including comparisons to other bots, see Older Training History and Research!
Also if you're looking to ask about general information about KataGo or how it works, or about some past Go bots besides KataGo, consider the computer Go discord channel.
Precompiled executables for KataGo can be found at the releases page for Windows and Linux.
And the latest neural nets are available at https://katagotraining.org/.
KataGo implements just a GTP engine, which is a simple text protocol that Go software uses. It does NOT have a graphical interface on its own. So generally, you will want to use KataGo along with a GUI or analysis program. A few of them bundle KataGo in their download so that you can get everything from one place rather than downloading separately and managing the file paths and commands.
This is by no means a complete list - there are lots of things out there. But, writing as of 2020, a few of the easier and/or popular ones might be:
Generally, for GUIs that don't offer an all-in-one package, you will need to download KataGo (or any other Go engine of your choice!) and tell the GUI the proper command line to run to invoke your engine, with the proper file paths involved. See How To Use below for details on KataGo's command line interface.
KataGo currently officially supports both Windows and Linux, with precompiled executables provided each release. On Windows, the executables should generally work out of the box, on Linux if you encounter issues with system library versions, as an alternative building from source is usually straightforward. Not all different OS versions and compilers have been tested, so if you encounter problems, feel free to open an issue. KataGo can also of course be compiled from source on Windows via MSVC on Windows or on Linux via usual compilers like g++, documented further down.
The community also provides KataGo packages for Homebrew on MacOS - releases there may lag behind official releases slightly.
Use brew install katago
. The latest config files and networks are installed in KataGo's share
directory. Find them via brew list --verbose katago
. A basic way to run katago will be katago gtp -config $(brew list --verbose katago | grep 'gtp.*\.cfg') -model $(brew list --verbose katago | grep .gz | head -1)
. You should choose the Network according to the release notes here and customize the provided example config as with every other way of installing KataGo.
KataGo has four backends, OpenCL (GPU), CUDA (GPU), TensorRT (GPU), and Eigen (CPU).
The quick summary is:
More in detail:
For any implementation, it's recommended that you also tune the number of threads used if you care about optimal performance, as it can make a factor of 2-3 difference in the speed. See "Tuning for Performance" below. However, if you mostly just want to get it working, then the default untuned settings should also be still reasonable.
KataGo is just an engine and does not have its own graphical interface. So generally you will want to use KataGo along with a GUI or analysis program. If you encounter any problems while setting this up, check out Common Questions and Issues.
First: Run a command like this to make sure KataGo is working, with the neural net file you downloaded. On OpenCL, it will also tune for your GPU.
./katago.exe benchmark # if you have default_gtp.cfg and default_model.bin.gz
./katago.exe benchmark -model <NEURALNET>.bin.gz # if you have default_gtp.cfg
./katago.exe benchmark -model <NEURALNET>.bin.gz -config gtp_custom.cfg # use this .bin.gz neural net and this .cfg file
It will tell you a good number of threads. Edit your .cfg file and set "numSearchThreads" to that many to get best performance.
Or: Run this command to have KataGo generate a custom gtp config for you based on answering some questions:
./katago.exe genconfig -model <NEURALNET>.bin.gz -output gtp_custom.cfg
Next: A command like this will run KataGo's engine. This is the command to give to your GUI or analysis program so that it can run KataGo.
./katago.exe gtp # if you have default_gtp.cfg and default_model.bin.gz
./katago.exe gtp -model <NEURALNET>.bin.gz # if you have default_gtp.cfg
./katago.exe gtp -model <NEURALNET>.bin.gz -config gtp_custom.cfg # use this .bin.gz neural net and this .cfg file
You may need to specify different paths when entering KataGo's command for a GUI program, e.g.:
path/to/katago.exe gtp -model path/to/<NEURALNET>.bin.gz
path/to/katago.exe gtp -model path/to/<NEURALNET>.bin.gz -config path/to/gtp_custom.cfg
You can also have KataGo imitate human play if you download the human SL model b18c384nbt-humanv0.bin.gz from https://github.com/lightvector/KataGo/releases/tag/v1.15.0, and run a command like the following, providing both the normal model and the human SL model:
./katago.exe gtp -model <NEURALNET>.bin.gz -human-model b18c384nbt-humanv0.bin.gz -config gtp_human5k_example.cfg
The gtp_human5k_example.cfg configures KataGo to imitate 5-kyu-level players. You can change it to imitate other ranks too, as well as to do many more things, including making KataGo play in a human style but still at a strong level or analyze in interesting ways. Read the config file itself for documentation on some of these possibilities!
And see also this guide to using the human SL model, which is written from the perspective of the JSON-based analysis engine mentioned below, but is also applicable to gtp as well.
Run a JSON-based analysis engine that can do efficient batched evaluations for a backend Go service:
./katago analysis -model <NEURALNET>.gz -config <ANALYSIS_CONFIG>.cfg
Run a high-performance match engine that will play a pool of bots against each other sharing the same GPU batches and CPUs with each other:
./katago match -config <MATCH_CONFIG>.cfg -log-file match.log -sgf-output-dir <DIR TO WRITE THE SGFS>
Force OpenCL tuner to re-tune:
./katago tuner -config <GTP_CONFIG>.cfg
Print version:
./katago version
The most important parameter to optimize for KataGo's performance is the number of threads to use - this can easily make a factor of 2 or 3 difference.
Secondarily, you can also read over the parameters in your GTP config (default_gtp.cfg
or gtp_example.cfg
or configs/gtp_example.cfg
, etc). A lot of other settings are described in there that you can set to adjust KataGo's resource usage, or choose which GPUs to use. You can also adjust things like KataGo's resign threshold, pondering behavior or utility function. Most parameters are documented directly inline in the example config file. Many can also be interactively set when generating a config via the genconfig
command described above.
This section summarizes a number of common questions and issues when running KataGo.
If you are observing any crashes in KataGo while attempting to run the benchmark or the program itself, and you have one of the below GPUs, then this is likely the reason.
Found OpenCL Platform 0: ... (Mesa) (OpenCL 1.1 Mesa ...) ...
then you are using the Mesa drivers. You will need to change your drivers, see for example this KataGo issue which links to this thread.KataGo seems to hang or is "loading" forever on startup in Lizzie/Sabaki/q5go/GoReviewPartner/etc.
benchmark
or gtp
directly on the command line, as described above.benchmark
command directly in the command line. After tuning, then subsequent runs will be faster.KataGo works on the command line but having trouble specifying the right file paths for the GUI.
default_gtp.cfg
and name whichever network file you've downloaded to default_model.bin.gz
(for newer .bin.gz
models) or default_model.txt.gz
(for older .txt.gz
models). Stick those into the same directory as KataGo's executable, and then you don't need to specify -config
or -model
paths at all.KataGo gives an error like Could not create file
when trying to run the initial tuning.
Program Files
directory and its subdirectories are often restricted to only allow writes with admin-level permissions. Try placing KataGo somewhere else.I'm new to the command line and still having trouble knowing what to tell Lizzie/q5go/Sabaki/whatever to make it run KataGo.
I'm getting a different error or still want further help.
How do I make KataGo use Japanese rules or other rules?
default_gtp.cfg
or gtp_example.cfg
or gtp.cfg
, or whatever you've named it) to use rules=japanese
or rules=chinese
or whatever you need, or set the individual rules koRule
,scoringRule
,taxRule
, etc. to what they should be. See here for where this is in the config, or and see this webpage for the full description of KataGo's ruleset.genconfig
command (./katago genconfig -model <NEURALNET>.gz -output <PATH_TO_SAVE_GTP_CONFIG>.cfg
) to generate a config, and it will interactively help you, including asking you for what default rules you want.E
in Lizzie), then you can run kata-set-rules japanese
or similar for other rules directly in the GTP console, to change the rules dynamically in the middle of a game or an analysis session.Which model/network should I use?
In addition to a basic set of GTP commands, KataGo supports a few additional commands, for use with analysis tools and other programs.
KataGo's GTP extensions are documented here.
Notably: KataGo exposes a GTP command kata-analyze
that in addition to policy and winrate, also reports an estimate of the expected score and a heatmap of the predicted territory ownership of every location of the board. Expected score should be particularly useful for reviewing handicap games or games of weaker players. Whereas the winrate for black will often remain pinned at nearly 100% in a handicap game even as black makes major mistakes (until finally the game becomes very close), expected score should make it more clear which earlier moves are losing points that allow white to catch up, and exactly how much or little those mistakes lose. If you're interested in adding support for this to any analysis tool, feel free to reach out, I'd be happy to answer questions and help.
KataGo also exposes a few GTP extensions that allow setting what rules are in effect (Chinese, AGA, Japanese, etc). See again here for details.
KataGo also implements a separate engine that can evaluate much faster due to batching if you want to analyze whole games at once and might be much less of a hassle than GTP if you are working in an environment where JSON parsing is easy. See here for details.
KataGo also includes example code demonstrating how you can invoke the analysis engine from Python, see here!
KataGo is written in C++. It should compile on Linux or OSX via g++ that supports at least C++14, or on Windows via MSVC 15 (2017) and later. Instructions may be found at Compiling KataGo.
See the cpp readme or the python readme for some high-level overviews of the source code in this repo, if you want to get a sense of what is where and how it fits together.
If you'd also like to run the full self-play loop and train your own neural nets using the code here, see Selfplay Training.
Many thanks to the various people who have contributed to this project! See CONTRIBUTORS for a list of contributors.
Except for several external libraries that have been included together in this repo under cpp/external/
as well as the single file cpp/core/sha2.cpp
, which all have their own individual licenses, all code and other content in this repo is released for free use or modification under the license in the following file: LICENSE.
License aside, if you end up using any of the code in this repo to do any of your own cool new self-play or neural net training experiments, I (lightvector) would to love hear about it.