This repository provides docker images for running the neural net chess engine LeelaZero on Linux.
The images are build for Nvidia GPUs, but CPU backends are also supported.
The startup script is able to automatically detect the number of GPUs in the system and configures lc0
accordingly.
(Supported backends: cudnn-auto
, cudnn
, cudnn-fp16
, cuda-auto
, cuda
, cuda-fp16
, blas
, eigen
)
The evaluation network can be easily exchanged by prodiding an URL or the hash.
For convenience the binary for Stockfish is also included.
The images are confirmed to be compatible with the GPU renting service vast.ai.
CPU with instruction set from Ivy Bridge or newer For CUDA backends:
nvidia-container-runtime
Images are available here on Github and on Dockerhub at simske/lc0.
The latest stable image can be found under:
lc0
:
lc0
and Stockfish:
ghcr.io/simske/lc0-stockfish:latest
docker.io/simske/lc0:latest-stockfish
](https://hub.docker.com/r/simske/lc0/tags?name=stockfish)More specific version tags can be found in the Github Releases and the image registries.
The Docker images are based on the nvidia/cuda
cudnn images, and two variations are provided:
lc0
for Nvidia GPUlc0
for GPU and stockfish
for CPUThe combined lc0
and stockfish
images are only sensible if you can only run a single container, as on vast.ai. Otherwise it would make more sense to run a container for each engine.
lc0
needs a weights file to run.
There is a selection of good networks on lczero.org,
otherwise training networks from training.lczero.org can be used.
The container is shipped with the default network 752187, but can be easily customized by setting the
environment variable $NETWORK
for the container.
This can be either an URL to a network, or the SHA-hash of a training network.
The network will be downloaded on first use.
Networks are saved at /lc0/weights
, this location can be mounted as a docker volume to avoid redownloading networks.
The network can also be set with
/lc0/set_network network_url
To run the image locally:
docker run -i --gpus=all -a STDIN -a STDOUT ghcr.io/simske/lc0:latest
The networks are in the directory /lc0/weights
, a docker volume can be mounted to this location to cache the downloaded networks.
To use a volume mount (with Leelenstein 15.0 network as an example):
docker run -i --gpus=all -a STDIN -a STDOUT -v /lc0/weights -e NETWORK=https://www.patreon.com/file?h=38164065&i=5788117 simske/lc0:latest
Or for a directory mount (such that a weights directory is connected to a folder on the host machine):
docker run -i --gpus=all -a STDIN -a STDOUT -v /path/on/host:/lc0/weights -e NETWORK=https://www.patreon.com/file?h=38164065&i=5788117 simske/lc0:latest
To run lc0 on vast.ai create an account and make sure to have enough credit run a machine.
Then go to the Console->Create. Click on the button on the left "Edit Image & Config".
Select the custom image option with simske/lc0:latest
(or the desired tag/version).
If a custom network should be used, it can be set with in the Onstart-Script with
set_network NETWORK_URL
For connection to the chess server the SSH protocol is used. This tutorial focuses on using Windows and ChessBase, the connection with Linux is much easier.
On Windows two components (in addition to chessbase) are needed:
First make sure that you can connect to the server with PuTTY without using a password. For this a SSH key needs to be generated, and the public key has to be put on the server (External tutorial). For this use it makes most sense to use a key without a passphrase.
On vast.ai the public key needs to be entered under Account->SSH Key.
After the server has been setup and started like described in the sections above
UCI-compliant communication between server and local chess program can be achieved
by the Inbetween program. Before execution the path to the private key as well as server host name and port have to be added in the Inbetween.ini file.
For Lc0 a new UCI-Engine with the path directing to the inbetween.exe file has to be created.
If using a GPU with Turing architecture it is recommended to change the backend in the
engine parameters to "cudnn fp16". 3 threads are enough, apart from that the default settings are sufficient.
Further information can be found on https://lczero.org/.
For Stockfish another Inbetween-file and UCI-Engine need to be created. With regards to the engine parameters a higher amount of threads is recommended.
The whole process can be automated using a script.
Don't forget to change the path to your private key as well as the base path variable and make sure to have Python installed in order to execute the script.
If you encounter any issues or have suggestions for docker-lc0
feel free to open issues and pull requests on this repository
docker-lc0
is licensed under the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.