Page 1 of 2

Compiling some engines for linux

Posted: Fri Sep 07, 2018 8:59 pm
by xela
I've decided to try out a few of the latest go-playing engines, as well a a few golden oldies. I plan to do something along vaguely similar lines to the engine tournament https://www.lifein19x19.com/viewtopic.php?f=18&t=13322 but using BayesElo for rankings. I'll post results in a separate thread, if I get that far.

Installing and configuring some of the engines has been a bit of an adventure in itself. I've learned a few things over the past few days, so I should write some of this down before I forget it all again.

I'm using Ubuntu 18.o4.

Gnugo

Installation was a piece of cake: it's in the official Ubuntu repositories, so it's as easy as typing "sudo apt install gnugo" on a command line (or finding it in the Ubuntu software centre if you prefer to do things graphically).

Configuration: It pretty much works out of the box. To use it via GTP (e.g. if you want to plug it into gogui or sabaki), use "gnugo --mode gtp". Add "--chinese-rules" for Chinese rules (recommended for engine vs engine games). It has ten levels of play via the --level argument, but my early experiments suggest that level doesn't make much of a difference. Also you can adjust the cache size (default 10Mb, puny by modern standards), but it doesn't seem to get stronger if you give it more cache.

Pachi

Installation: Compiling from source was mildly annoying because of all the dependencies, but not too bad. I got the source code from https://github.com/pasky/pachi, spent a bit of time trying to build it and getting messages about "lib whatever not found", googling for "Ubuntu package whatever", install whatever came up, try again. It worked after I'd installed caffe-cuda, libcaffe-cuda-dev, libgflags-dev, libgoogle-glog-dev, libprotobuf-dev, protobuf-compiler, libatlas-base-dev, libboost-system-dev.

Configuration: It took a little while to realise that "pachi" and "pachi DCNN" are actually the same software, just with different configurations. The DCNN version is quite a bit stronger. For DCNN, you need the network from http://physik.de/CNNlast.tar.gz Pachi also comes with some alternative engines: you can type things like "pachi -e montecarlo" or "pachi -e patternplay". The other engines seem to be very weak.

Michi

Installation: I think this is an older version of pachi. Source code at https://github.com/db3108/michi-c2/releases It was just as easy to compile, except for one trick. Michi needs the pattern files from http://pachi.or.cz/michi-pat/ Then it looks for the pattern files in the current working directory that it's launched from, and there's no configuration option to change that. If you want to install the pattern files somewhere else, then in the source code you need to open the file ui.c, find the string "patterns.prob", and add the pathname of where you're storing the files.

Configuration: Nothing to do here, just type "michi gtp" from the command line and you're good to go.

Fuego

Installation: This one was painful. I used subversion to get the source code, with the command line "svn checkout svn://svn.code.sf.net/p/fuego/code/trunk". Compilation gave a ton of error messages. Here are some links that helped:
http://fuego.sourceforge.net/mac-install.html
https://unixnme.blogspot.com/2016/01/ho ... -1404.html
https://stackoverflow.com/questions/199 ... mmand-line
https://www.reddit.com/r/cbaduk/comment ... uego_code/

Configuration: Not much to do. Make sure it can find its opening book, but I think the installer put the book in the right place (once I'd sorted out the compilation issues).

Oakfoam

Installation: Like pachi, this one can work with or without DCNN. Unlike pachi, it's pretty hopeless without, and you need to recompile it to work with. For the non-DCNN version, there's a prebuilt package at http://oakfoam.com/, and you can install it with the command line "dpkg -i oakfoam_0.1.3-1_amd64.deb". For DCNN, I got the newer version from https://bitbucket.org/dsmic/oakfoam There were a few issues with compiling it. In the Makefile, find the "aclocal" line and change the version number from 1.14 to 1.15. I needed to install the "nvidia-cuda-dev" package as a dependency. And you have to tell it to use the caffe libraries: run "./configure --with-caffe=/usr/include/caffe" before compiling.

Configuration: This one comes with a configuration file called "nicego-cnn-06.gtp" which contains some gtp commands. The file tells it where to load the pattern files and weights. You'll need to edit that file and put in the correct pathnames for your installation. Then run it with "oakfoam -c path/to/nicego-cnn-06.gtp"

Leela

This was easy, except for one trick. There's a Debian package with prebuilt binaries at https://sjeng.org/leela.html Use "leela_gtp" to run in gtp mode, or LeelaGUI to open a nice interface for analysis. The trick is: I couldn't figure out why it wasn't using my graphics gard. There didn't seem to be any options for turning GPU mode on or off. It turns out that the GPU version is a separate pair of executables: if you have a graphics card, then you should use leela_gtp_opencl and LeelaGUI_OpenCL.

Leela Zero

Installation: Source code from https://github.com/gcp/leela-zero/releases Dependencies (Ubuntu packages): libboost-dev libboost-program-options-dev libopenblas-dev opencl-headers ocl-icd-libopencl1 ocl-icd-opencl-dev zlib1g-dev. Compile just by running "make" (no ./configure step needed). Easy. If you want a cpu-only version though, you need to hack and recompile. Open the file config.h and add a new line that says "#define USE_CPU_ONLY" just before the line "#ifndef USE_CPU_ONLY", and then compile it again.

Configuration: You need a set of weights. There seems to be a gazillion weights files out there, and multiple teams making new ones every week. The Leela Zero weights are at https://zero.sjeng.org/ The file are gzipped, but there's no need to unzip them, Leela Zero can already read them in this format. The Facebook ELF weights are http://zero.sjeng.org/networks/62b5417b ... 97df4b9.gz The "Leela Master" weights (trained on some human games as well as self-play) are at https://github.com/pangafu/LeelaMasterWeight I think there's also Phoenix weights out there somewhere. Run "leelaz --gtp -w /path/to/weightsfile".

AQ

Installation: The .tar.gz file at https://github.com/ymgaq/AQ/releases is a prebuilt binary, just unpack it, and then run the executable called AQ. The bad news is that AQ requires the CUDA version 8 libraries (it needs to be exactly v8, not "v8 or newer", and Ubuntu 18 only has CUDA version 9. The good news is that the download includes the library files. The annoying news is that you have to tell Ubuntu where to find the libraries. You do this by creating a file called /etc/ld.so.conf.d/cuda8.conf which contains exactly one line, that line being the path where you unpacked AQ (e.g. "/opt/AQ"), and then you run "sudo ldconfig".

Configuration: I haven't got this to work yet. It keeps crashing when it gets GTP commands to change the time settings. I think you can set the time limits using a config file, but I don't know how to stop gogui-twogtp from sending time commands anyway.

Ray

Source code at https://github.com/zakki/Ray/ I gave up on this one. It depends on the CNTK libraries. CNTK is massive, and it looks like installing it in a clean way would be a week's work in itself. (Microsoft provide a binary installer, but it's packaged together with a whole lot of other stuff that I don't want.)

Darkgo

Work in progress. Home page at https://pjreddie.com/darknet/darkgo-go-in-darknet/ and source code at https://github.com/pjreddie/darknet It looks like I need the NVidia CUDA toolkit as a dependency, and that's another big install, but I'll probably get around to it at some stage.

Other things I might try over the next couple of weeks: Dream Go https://github.com/Chicoryn/dream-go , Facebook ELF https://github.com/pytorch/ELF , PhoenixGo https://github.com/Tencent/PhoenixGo, LZ dynamic komi version (for playing handicap games) https://github.com/alreadydone/lz/tree/komi , and I'm open to other suggestions.

Re: Compiling some engines for linux

Posted: Fri Sep 07, 2018 11:51 pm
by as0770
xela wrote: Fuego
Configuration: Not much to do. Make sure it can find its opening book, but I think the installer put the book in the right place (once I'd sorted out the compilation issues).
You can setup a config file for Fuego and load it by command line: fuego.exe –config fuego.cfg:

Code: Select all

uct_param_search number_threads 1
uct_param_search lock_free 0
uct_max_memory 1024000000
uct_param_player reuse_subtree 1
uct_param_player ponder 0
uct_param_player early_pass 1

Re: Compiling some engines for linux

Posted: Sun Sep 09, 2018 6:49 am
by pnprog
xela wrote:I've decided to try out a few of the latest go-playing engines, as well a a few golden oldies. I plan to do something along vaguely similar lines to the engine tournament https://www.lifein19x19.com/viewtopic.php?f=18&t=13322 but using BayesElo for rankings. I'll post results in a separate thread, if I get that far.

Installing and configuring some of the engines has been a bit of an adventure in itself. I've learned a few things over the past few days, so I should write some of this down before I forget it all again.

I'm using Ubuntu 18.o4.
Excellent work! thank you so much! :tmbup:

Especially for AQ, I will try as soon as possible :bow: :bow: :bow:

I suggest that you send patch/commit/PR to those projects on Github by adding those instructions in their README.md
In fact, I had figured out how to compile Pachi on Ubuntu a few weeks ago, then sent a PR that was accepted. Those developers are very happy to received such PR that help increase visibility for their projects.
xela wrote:Ray

Source code at https://github.com/zakki/Ray/ I gave up on this one. It depends on the CNTK libraries. CNTK is massive, and it looks like installing it in a clean way would be a week's work in itself. (Microsoft provide a binary installer, but it's packaged together with a whole lot of other stuff that I don't want.)
I haven't been able to crack that one neither, but the latest version does not use CNTK/CUDA any more and now uses OpenCL. This was confirmed by the developer. The make file only needs to be updated apparently.

Re: Compiling some engines for linux

Posted: Tue Sep 11, 2018 5:34 am
by xela
as0770 wrote: You can setup a config file for Fuego and load it by command line: fuego.exe –config fuego.cfg:
Thanks! I've found a little fuego manual at http://svn.code.sf.net/p/fuego/code/tru ... index.html

Re: Compiling some engines for linux

Posted: Tue Sep 11, 2018 5:42 am
by xela
pnprog wrote:Ray
I haven't been able to crack that one neither, but the latest version does not use CNTK/CUDA any more and now uses OpenCL. This was confirmed by the developer. The make file only needs to be updated apparently.
Unfortunately that is not actually true. I've just downloaded the most recent version of the source code. The file UctSearch.cpp is full of references to CNTK. Changing the makefile isn't going to fix that. I don't understand the developer's comment.

Re: Compiling some engines for linux

Posted: Tue Sep 11, 2018 5:57 am
by xela
I've managed to compile DarkGo now, but I can't get it to play a good game. As black, it makes beginner moves. As white, it just passes all the time. In either case it causes my GPU to make an alarming whistling sound, which doesn't happen with any of the other engines.

Compiling was easy once I got the nvidia CUDA toolkit installed. But installing the toolkit was a bit interesting, as it's not officially supported in Ubuntu 18.04. I decided to use version 9.1, as this works with driver version 390 (the latest stable one); 9.2 is available but requires updating to a newer driver that I don't trust yet. The instructions at https://www.pugetsystems.com/labs/hpc/H ... 8-04-1184/ and https://devtalk.nvidia.com/default/topi ... tu-18-04/1 between them had everything I needed.

To run DarkGo as a GTP engine, you need a command line that looks like "/opt/darkgo/darknet/darknet go engine /opt/darkgo/darknet/cfg/go.test.cfg /opt/darkgo/go.weights" (change /opt/darkgo to a different path if needed). The trick is to use the "engine" keyword (as opposed to one of train, test or valid, which is what the documentation tells you to do).

Re: Compiling some engines for linux

Posted: Wed Sep 12, 2018 2:58 am
by zakki
xela wrote:
pnprog wrote:Ray
I haven't been able to crack that one neither, but the latest version does not use CNTK/CUDA any more and now uses OpenCL. This was confirmed by the developer. The make file only needs to be updated apparently.
Unfortunately that is not actually true. I've just downloaded the most recent version of the source code. The file UctSearch.cpp is full of references to CNTK. Changing the makefile isn't going to fix that. I don't understand the developer's comment.
That is issue about lz branch.
But lz branch has no Makefile/CMakeFile now.

Re: Compiling some engines for linux

Posted: Wed Sep 12, 2018 6:17 am
by xela
zakki wrote: That is issue about lz branch.
But lz branch has no Makefile/CMakeFile now.
Hi, thanks for replying here! My mistake, I was still trying with the nn branch. I'm new to github, so it took a little while to figure out how I could download a specific branch. The command line

Code: Select all

git clone https://github.com/zakki/Ray.git --branch lz --single-branch .
seemed to do what I wanted.

I've managed to compile the lz branch now, but I haven't tried playing a game with it yet. I'll test it later in the week. I've attached my Makefile to your github issue.

Re: Compiling some engines for linux

Posted: Wed Sep 12, 2018 7:52 am
by pnprog
xela wrote:I've managed to compile the lz branch now, but I haven't tried playing a game with it yet. I'll test it later in the week. I've attached my Makefile to your github issue.
Excellent! :tmbup:

Re: Compiling some engines for linux

Posted: Sun Sep 16, 2018 6:40 am
by xela
OK, I can report that ray (lz branch) is happily reading LZ weight files and playing games.

@zakki, can you explain how using Ray with LZ weights is different from using LZ with the same weights?

Re: Compiling some engines for linux

Posted: Mon Sep 17, 2018 9:45 pm
by zakki
xela wrote:@zakki, can you explain how using Ray with LZ weights is different from using LZ with the same weights?
RLO is experimental branch to understand how AlphaGo Zero style policy and value network behave, and to experiment integrating monte carlo playout to AGZ's dual network.

It has some advantage in end game and ladder, but LeelaZero plays better in most case.
Latest value network seems to much precise than Ray's playout and AlphaGo Fan style APV-MCTS doesn't work well. Maybe another algorithm or more tuning are needed.

Re: Compiling some engines for linux

Posted: Tue Sep 25, 2018 7:48 pm
by xela
DreamGo

Installation: Currently, the "released" versions don't support GTP time controls, so at https://github.com/Chicoryn/dream-go you should ignore the "releases" tab and check out the most recent version using Git. (This should change soon!) It's written in the Rust programming language, so the usual make/gcc tools won't compile it. Instead, here's what I did:
  1. Install CUDNN from https://developer.nvidia.com/rdp/cudnn-download You'll need to sign up for a free NVidia developer account. This is sometimes painful, because their web site doesn't always work (if you don't get a confirmation email within a few minutes of registering, then clear your browser cache and try again).
  2. Install the rust compiler (stable version) by following the instructions at https://www.rust-lang.org/en-US/install.html
  3. Install the rust compiler ("nightly" version) by typing the command line

    Code: Select all

    rustup install nightly
  4. cd to the directory where you cloned the git repository
  5. Type

    Code: Select all

    rustup override add nightly
    followed by

    Code: Select all

    cargo build
    The executable will be in the target/debug subdirectory
  6. Download the weights file attached as dream_go.json.zip at https://github.com/Chicoryn/dream-go/is ... -421859306 and unzip it into the same directory as the executable.
Configuration: Just run the executable. It understands the usual gtp commands.

Facebook ELF

Installation: The instructions at https://github.com/pytorch/ELF are pretty detailed. If you follow them exactly then you shouldn't have any problems. If you want to use Ubuntu's default python/pip installation instead of conda though, it gets a little more complicated. First you'll need to install python3-pip from the Ubuntu repositories. Then, I've posted some instructions at https://github.com/pytorch/ELF/issues/98

Configuration: There's a bunch of options that you can specify on the command line, again listed at https://github.com/pytorch/ELF . I've had some trouble getting it to play at the same speed as other engines (so that I can do engine vs engine matches on a fair basis). On my machine, if I set mcts_rollout_per_thread to 80, then it plays about 280 moves per minute, just right for 1-minute games. So I thought that mcts_rollout_per_thread=400 would give me a five-minute game. No. It takes 2-3 seconds per move for the first 50 or 60 moves, then suddenly slows down a lot (between 7 and 30 seconds per move). I tried a few variations, then gave up because once in a while it crashes and hangs my machine. Maybe it's triggering a bug in my NVidia graphics driver? I might try again when the next stable driver version comes out.

Phoenix Go

I gave up on this one. I tried following the instructions at https://github.com/Tencent/PhoenixGo The problem is that it uses bazel as its build system, which is new to me, so I'm not well qualified to troubleshoot the problems. Bazel will download a few hundred megabytes of stuff, then try to build TensorFlow configured according to the selected PhoenixGo options, spit out a bunch of compiler warnings, then fail on one of the TensorFlow components. I didn't want to keep retrying it because it's downloading an awful lot of stuff each time. I did find some old forum posts saying that TensorFlow won't work with bazel version 12 or 13, so you should use bazel 11. I tried that, as well as the newest bazel (version 17), with the same results each time.

Leela Zero with Phoenix weights needs a modified version of LZ. Get it from https://github.com/yenw/LeelaZero_PhoenixGo Building it is just the same as building the regular LZ, easy.

Re: Compiling some engines for linux

Posted: Wed Sep 26, 2018 11:22 am
by Drew
Thank you for your hard work, xela.

Unless you're running into post length limits, please add your most recent post to your first post to keep it all summarized in the opener. I think that would be best.

Re: Compiling some engines for linux

Posted: Mon Oct 01, 2018 4:21 am
by pnprog
Hi!
xela wrote:AQ

Installation: The .tar.gz file at https://github.com/ymgaq/AQ/releases is a prebuilt binary, just unpack it, and then run the executable called AQ. The bad news is that AQ requires the CUDA version 8 libraries (it needs to be exactly v8, not "v8 or newer", and Ubuntu 18 only has CUDA version 9. The good news is that the download includes the library files. The annoying news is that you have to tell Ubuntu where to find the libraries. You do this by creating a file called /etc/ld.so.conf.d/cuda8.conf which contains exactly one line, that line being the path where you unpacked AQ (e.g. "/opt/AQ"), and then you run "sudo ldconfig".

Configuration: I haven't got this to work yet. It keeps crashing when it gets GTP commands to change the time settings. I think you can set the time limits using a config file, but I don't know how to stop gogui-twogtp from sending time commands anyway.
I managed to compile AQ, but the executable crash (segmentation fault) when sending "genmove" GTP command. I guess this is more an issue with my old Nvidia GPU that does not handle CUDA very well :sad:
xela wrote:
zakki wrote: That is issue about lz branch.
But lz branch has no Makefile/CMakeFile now.
Hi, thanks for replying here! My mistake, I was still trying with the nn branch. I'm new to github, so it took a little while to figure out how I could download a specific branch. The command line

Code: Select all

git clone https://github.com/zakki/Ray.git --branch lz --single-branch .
seemed to do what I wanted.

I've managed to compile the lz branch now, but I haven't tried playing a game with it yet. I'll test it later in the week. I've attached my Makefile to your github issue.
I compiled and ran Ray successfully using your makefile.
Although through compiling LeelaZero, Pachi and AQ, I had installed various library, there was one still missing for Ray that took me some time to find, the error was something like:

Code: Select all

/usr/bin/x86_64-linux-gnu-ld : cannot find -lcblas
collect2: error: ld returned 1 exit status
Makefile:21: recipe for target 'ray' failed
make: *** [ray] Error 1
And the remedy:

Code: Select all

sudo apt install libatlas-base-dev

Re: Compiling some engines for linux

Posted: Mon Oct 01, 2018 5:42 am
by xela
pnprog wrote:Hi!
Hello, thanks for replying!
pnprog wrote:Although through compiling LeelaZero, Pachi and AQ, I had installed various library, there was one still missing for Ray that took me some time to find, the error was something like:

Code: Select all

/usr/bin/x86_64-linux-gnu-ld : cannot find -lcblas
collect2: error: ld returned 1 exit status
Makefile:21: recipe for target 'ray' failed
make: *** [ray] Error 1
And the remedy:

Code: Select all

sudo apt install libatlas-base-dev
Interesting: I didn't get that error for Ray because I'd previously installed libatlas-base-dev as a dependency for Pachi. I wonder how you managed to compile Pachi without it?

Also, I've recently changed Ray to add a command line option "--weights", so that you can easily switch between different weight files. My changes were merged into zakki's github repository just a couple of days ago, so if you don't have the --weights option then you might want to download the latest version of the lz branch and recompile.