817 views
# Setting up KataGo and Lizzie on vast.ai ## Creating an cloud instance 1. Register and sign in to your account on vast.ai. 2. You will create an instance - which is, roughly speaking, a virtual machine on which you can do whatever you want. The instance is initialized with a Docker image, which includes the operating system and some libraries. To make things simpler, it is better to choose a proper Docker image. Go to Client-Create, and click "Edit image & config", select nvidia/cuda, and 10.1-cudnn7-devel-ubuntu18.04. Press select, and choose a machine you are going to rent. 3. Now head to Client-Instances. There will be an instance you just bought, which is currently stopped. Press the Start button, wait for a while until the blue button shows "Connect". ## Connecting to the instance 1. Now we are going to connect to the instance with ssh. Press the blue button then you will see a command like `ssh -p 12345 [email protected] -L 8080:localhost:8080`. Copy it to your clipboard. 2. If you're a Linux or Mac user, you already have OpenSSH installed so you can just open your terminal and connect (but wait for a moment and read 3. first). If you're on Windows 10, you can install OpenSSH as well but I suggest you to install [PuTTY](https://www.putty.org/) for a reason to be explained later. 3. Now generate your RSA key. The connection to the vast.ai is authorized with a RSA key, not an account, so you need to do this. A Linux or Mac user can just type `ssh-keygen` in the terminal, and copy the content of `~/.ssh/id_rsa.pub`. If you are a Windows user and have installed PuTTY, then run PuTTYGen, press the Generate button, copy the content of the "Public key for passing into OpenSSH authorized_keys file" section, and save the generated key as a file. 4. Go back to the vast.ai website, click Account, and paste the public key you copied in your clipboard into the Change SSH Key section, and hit the blue "Set SSH Key" button. 5. Now you may connect with ssh. If you're on Linux or Mac, you're good to go. If you are on Windows, open PuTTY, paste the server address (`[email protected]` in the example above) in the Host Name section and the port number (`12345` in the example above) in the Port section just next to the host name. In the menu left, go to Connection-SSH-Auth and select your SSH key file you saved in 3. as the private key file for authentication. Go back to the Session, and save this configuration for convenience, and press Open to launch the terminal. ## Installing KataGo on the server 1. Now you are connected to the instance. It is time to install KataGo on your machine. To do that, you need to install a few packages first as prerequisites. 2. The default CMake installed by `apt-get` is unfortunately outdated and has some troubles detecting CUDA. Instead, let us install CMake manually first (by the way, I owe this KataGo installation guide to [https://zhuanlan.zhihu.com/p/94142432]): ``` wget https://github.com/Kitware/CMake/releases/download/v3.15.4/cmake-3.15.4.tar.gz tar -xvf cmake-3.15.4.tar.gz cd cmake-3.15.4 ./configure make -j8 make install update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force ``` 3. And a few other things: ``` apt-get install git software-properties-common wget unzip ``` 4. And gcc8 (not sure if this is absolutely necessary, but at least it works): ``` add-apt-repository ppa:ubuntu-toolchain-r/test apt update apt install gcc-8 g++-8 ``` 5. And some more stuff: ``` apt install zlib1g-dev libzip-dev libboost-all-dev libgoogle-perftools-dev ``` 6. Now it is time to install KataGo: ``` git clone https://github.com/lightvector/KataGo cd KataGo/cpp mkdir build && cd build cmake -DBUILD_MCTS=1 -DUSE_BACKEND=CUDA -DCMAKE_C_COMPILER=/usr/bin/gcc-8 -DCMAKE_CXX_COMPILER=/usr/bin/g++-8 .. make -j8 ``` 7. Fine. Now we have the KataGo executable compiled, and you may move it to a proper location if needed. Also make sure to modify the config file according to your hardward and stuff and download the network somewhere with `wget` or `curl` and `unzip` it to get the model.txt.gz. ## Connecting the remote KataGo with Lizzie ### Linux and Mac Just make a shell script (let us name it `KataGo_vastai.sh`): ``` #/usr/bin/bash ssh -p <port> <server-address> "<KataGo executable location> gtp -model <model.txt.gz location> -config <config file location>" ``` ### Windows Create a batch file and give it a proper name like `KataGo_vastai.bat`. Ideally, you could just type in the ssh command like the Linux case, but strangely this did not work for me even if I could connect to the server on the terminal. This is why I suggested you to install PuTTY. The content of the batch file is the following (I owe this guide to [https://aws-guide.memo.wiki/]): ``` @echo off set plink_path="<The directory PuTTY is installed in>\plink.exe" set key_path="<Your ssh key file>" echo yes | %plink_path% -ssh -i %key_path% -P <port> <server-address> exit %plink_path% -ssh -C -i %key_path% -P <port> <server-address> "<KataGo executable location> gtp -model <model.txt.gz location> -config <config file location>" ``` ### Configuring Lizzie Edit your `config.txt` and edit your `engine-command` or `engine-command-list`: ``` "engine-command": "<.sh or .bat file location>" ``` Now we are good to go!