-
Notifications
You must be signed in to change notification settings - Fork 299
Run Leela Chess Zero clients on Google Cloud (10 minute guide)
This guide should allow you to have Leela Chess Zero clients running in the cloud in 10 minutes or less. In addition, if you've never had Google Cloud account before then this is something you can do for free (for more information about the free trial click here)! This guide is aimed at everyone and assumes no technical understanding.
Note, that if you're on the free trial you will NOT be charged if you run out of credits and forget to stop the trial (see 'Do I pay anything for the free trial?' here).
Create a free account on Google Cloud Platform Once you've created an account, navigate to Google Cloud Compute.
Here you should have the option to create a VM instance. Click Create. On the Create an instance page you have many options. You can ignore most of these for now. Here are the ones you need to modify:
- Zone: This is where your VM is hosted. Generally, the closer to you the better.
-
Machine type:
Here you can select your memory and number of CPUs. You can also select machines with GPUs but this is very expensive and is not available pn the free trial. Use custom machine with minimum amount of memory allowed to save money; even several clients can run with only 2GB of memory.
Here I'd reccomend between 2vCPUs and 8vCPUs.
- 2vCPUs - around $50 a month - can run 2 clients concurrently
- 4vCPUs - around $100 a month - can run 4 clients concurrently
- 8vCPUs - around $200 a month - can run around 8 clients concurrently
- Note that you get $300 free for the period of the free trial!
- Also note that you can get around a 70% reduction in cost if you use preemptibe instances (see below)!
- Boot disk: Select 'Ubuntu 16.04 LTS'
Now click on the 'Management, disks, networking, SSH keys' drop-down. Under 'Startup script' copy and paste the following:
#! /bin/bash
mkdir /lczero
wget https://github.com/glinscott/leela-chess/releases/download/v0.5/client_linux -P /lczero/
chmod +x /lczero/client_linux
git clone https://github.com/glinscott/leela-chess.git /lczero/leela-chess
apt-get -qq update
apt-get install -y cmake g++ libboost-all-dev libopenblas-dev opencl-headers ocl-icd-libopencl1 ocl-icd-opencl-dev zlib1g-dev
sed -i '0,/\*\//s//\*\/ #define FEATURE_USE_CPU_ONLY/' /lczero/leela-chess/src/config.h
make -j -C /lczero/leela-chess/src/
cp /lczero/leela-chess/src/lczero /lczero/lczero
- Preemptibility: Setting 'Preemptibility' as On, allows you to save a ton of money (or free trial credits). If you select this option, then you can run the client on an 8vCPUs for only $60 a month! The downside is that these instances expire after 24 hours, so if you want to keep the games coming in, you'll need to create another instance.
And that's most of the hard work done. Now grab yourself a drink while the VM boots up and the startup script runs (which should take around 3-5 minutes).
Once your instance has built itself, you can now SSH into the VM. To do this, click on the 'SSH' button on the 'VM Instances' page. This should open up a terminal window for you where you're able to communicate with your VM. If you're logging into the instance for the first time then there is one thing you need to do.
- Run the command
sudo cp /lczero/* .
(with the full stop included).
If you get the error: lczero: no such file or directory
, then the script probably hasn't finished running. If this happens then just wait a couple of minutes and run the commands like you're logging in for the first time again.
To start the client running persistently, run nohup ./client_linux -user YOUR_USERNAME -password YOUR_PASSWORD &
. This will run the client in the background so you'll be able to close the terminal session and the client will continue to run. Each time you run this command a new clinet will start running and on your VM. Be careful to monitor the CPU usage on your VM so that you don't start too many clients!
To see how many clients you have running you can use the command jobs -l
. This should show you the clients along with their ID.
To stop any of these clients use kill JOB_ID
where JOB_ID is the 4-5 digit ID found when using jobs -l
. (If you have reconnected after logging out use ps ax | grep client_linux
instead.)
You can monitor your VMs by double clicking on your instance name on the 'VM instances' page. This will direct you to the 'VM Settings' page where you can see how much of your instances CPU is being used up (along with many other things).
The scripts above can also be used with Azure, Microsoft's version of Google Cloud. Azure has $200 in free trial credits for new users, but be aware that they expire in 1 month.
Warning: It appears Microsoft will disable Azure accounts for TOS violation for constant 100% CPU usage. This has not been reported with Google Cloud. If you want to try Azure even with this warning, try limiting overall CPU usage to <=25% per server (one client on a 4-core server) to avoid detection.
The following is a simple guide to Azure's interface:
- Go to the Azure dashboard after signing up.
- Click "Create a Resource". Search for "Ubuntu 16.04 LTS," select it, and click Create.
- Put in a random name, user/password of your choice, resource group name of your choice, and region.
- Choose F- or F_v2-series server (these have the fastest CPU).
- Click OK for optional features tab, and click Create to deploy.
- Once deployed, click the VPS tile, copy IP address, and use an SSH client like PuTTY to login to your server:
ssh <user>@<ip>
. Once logged in, typesudo -s
to become the root user. Open the nano text editor and create a file called "script" withnano script
. Using right-click menu (not keyboard shortcut), Paste the Google Cloud "Startup script" in the first section above into nano,CTRL-X
to exit andY
to save. Type./script
to run the script and install everything. Then, everything proceeds as above in the "Starting Leela Chess Zero" section.