# katago-docker
**Repository Path**: amiok926/katago-docker
## Basic Information
- **Project Name**: katago-docker
- **Description**: 在容器中运行带有 TensorRT 的 KataGo。适用于 KataGo 的其他版本(OpenCL、CUDA、Eigen)
- **Primary Language**: Unknown
- **License**: Unlicense
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-07-08
- **Last Updated**: 2025-07-08
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# KataGo Docker
This guide is meant to run KataGo with TensorRT in a container.
在容器中运行带有 TensorRT 的 KataGo。
It may also work with other version of KataGo (OpenCL, CUDA, Eigen), but you will have to edit the Dockerfile.
适用于 KataGo 的其他版本(OpenCL、CUDA、Eigen),
## Build KataGo in a Docker container
在 Docker 容器中构建 KataGo
1. Clone the repository.
克隆本仓库。
2. Build the docker image or use `darkness4/katago:latest` :+1:
构建 docker 镜像或使用 darkness4/katago:latest :
```sh
docker build -t katago:tensorrt .
```
You can customize the Dockerfile by setting `--build-arg` parameters like `CUDA_VERSION`, `OS_VERSION` and `TRT_VERSION`. Note that `TRT_VERSION` must be available in the container.
通过设置 `--build-arg` 参数(如 `CUDA_VERSION` 、 `OS_VERSION` 和 `TRT_VERSION` )来自定义 Dockerfile。注意 `TRT_VERSION` 必须在容器中可用。
## Run KataGo in Docker
在 Docker 中运行 KataGo
1. Install Docker and the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
安装 Docker 和 NVIDIA 容器工具包。
2. Create an executable shell script to run KataGo:
创建一个可执行的 shell 脚本以运行 KataGo:
```sh
#!/bin/sh
# katago.sh
set -e
SCRIPTPATH="$(dirname "$(realpath "$0")")"
# Change this if you want to use an another model, see https://katagotraining.org
RELEASE=kata1-b18c384nbt-s7192213760-d3579182099
if [ ! -f "$SCRIPTPATH/default_model.bin.gz" ]; then
curl -fsSL https://media.katagotraining.org/uploaded/networks/models/kata1/$RELEASE.bin.gz -o "$SCRIPTPATH/default_model.bin.gz"
fi
docker run --rm --gpus all -it \
-v "$SCRIPTPATH/default_gtp.cfg:/app/default_gtp.cfg:ro" \
-v "$SCRIPTPATH/default_model.bin.gz:/app/default_model.bin.gz" \
katago:tensorrt \
$@
```
3. Use `katago.sh` as the main entrypoint.
使用 `katago.sh` 作为主入口。
```sh
chmod +x katago.sh
./katago.sh gtp
# KataGo v1.13.2
# Using TrompTaylor rules initially, unless GTP/GUI overrides this
# Initializing board with boardXSize 19 boardYSize 19
# Loaded config /app/default_gtp.cfg
# Loaded model /app/default_model.bin.gz
# Model name: kata1-b18c384nbt-s5832081920-d3223508649
# GTP ready, beginning main protocol loop
```
## Run KataGo remotely with Docker and SSH
使用 Docker 和 SSH 远程运行 KataGo
**On the remote machine:**
**在远程机器上:**
1. Install the SSH server and [push your public SSH key to your user authorized_keys file](https://www.ssh.com/academy/ssh/copy-id). The authentication must not use a password.
安装 SSH 服务器并将您的公钥推送到用户 authorized_keys 文件。认证过程不能使用密码。
2. Install Docker and the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
安装 Docker 和 NVIDIA 容器工具包。
**On your local machine:**
**在您的本地机器上:**
1. Prepare the `default_gtp.cfg`.
准备 `default_gtp.cfg` 。
2. Alongside the `default_gtp.cfg`, create an executable shell script to run KataGo:
在 `default_gtp.cfg` 的基础上,创建一个可执行的 shell 脚本以运行 KataGo:
```sh
#!/bin/sh
# katago-remote.sh
set -e
SCRIPTPATH="$(dirname "$(realpath "$0")")"
# Change this if you want to use an another model, see https://katagotraining.org
RELEASE=kata1-b18c384nbt-s7192213760-d3579182099
scp "$SCRIPTPATH/default_gtp.cfg" remote-user@remote-machine:/tmp/default_gtp.cfg
ssh remote-user@remote-machine "set -e
if [ ! -f /tmp/default_model.bin.gz ]; then
curl -fsSL https://media.katagotraining.org/uploaded/networks/models/kata1/$RELEASE.bin.gz -o /tmp/default_model.bin.gz
fi
docker run --rm -it \
--gpus all \
-v /tmp/default_gtp.cfg:/app/default_gtp.cfg:ro \
-v /tmp/default_model.bin.gz:/app/default_model.bin.gz:ro \
docker.io/darkness4/katago:latest \
$@"
```
Edit the script to match your configuration (ssh parameters, etc.).
编辑脚本以匹配你的配置(ssh 参数等)。
3. Make it executable and test it.
使其可执行并测试它。
```sh
chmod +x katago-remote.sh
./katago-remote.sh gtp
# KataGo v1.13.2
# Using TrompTaylor rules initially, unless GTP/GUI overrides this
# Initializing board with boardXSize 19 boardYSize 19
# Loaded config /app/default_gtp.cfg
# Loaded model /app/default_model.bin.gz
# Model name: kata1-b18c384nbt-s5832081920-d3223508649
# GTP ready, beginning main protocol loop
```
## Run KataGo remotely with Enroot and SSH
使用 Enroot 和 SSH 远程运行 KataGo
**On the remote machine:**
**在远程机器上:**
1. Install the SSH server and [push your public SSH key to your user authorized_keys file](https://www.ssh.com/academy/ssh/copy-id). The authentication must not use a password.
安装 SSH 服务器并将您的公钥推送到用户 authorized_keys 文件中。认证过程不能使用密码。
2. Install Enroot and the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
安装 Enroot 和 NVIDIA 容器工具包。
**On your local machine:**
**在你的本地计算机上:**
1. Prepare the `default_gtp.cfg`.
准备 `default_gtp.cfg` 。
2. Alongside the `default_gtp.cfg`, create an executable shell script to run KataGo with Enroot:
在 `default_gtp.cfg` 的基础上,创建一个可执行的 shell 脚本,用于运行带有 Enroot 的 KataGo:
```sh
#!/bin/sh
# katago-remote.sh
set -e
SCRIPTPATH="$(dirname "$(realpath "$0")")"
# Change this if you want to use an another model, see https://katagotraining.org
RELEASE=kata1-b18c384nbt-s7192213760-d3579182099
# Copy config file to remote server
scp "$SCRIPTPATH/default_gtp.cfg" remote-user@remote-machine:/tmp/default_gtp.cfg
ssh remote-user@remote-machine "set -e
rm -f /tmp/katago.sqsh
enroot remove -f -- katago || true
enroot import -o /tmp/katago.sqsh -- docker://registry-1.docker.io#darkness4/katago:latest
enroot create -n katago -- /tmp/katago.sqsh
if [ ! -f /tmp/default_model.bin.gz ]; then
curl -fsSL https://media.katagotraining.org/uploaded/networks/models/kata1/$RELEASE.bin.gz -o /tmp/default_model.bin.gz
fi
enroot start \
--mount /tmp/default_gtp.cfg:/app/default_gtp.cfg:ro,x-create=file,bind \
--mount /tmp/default_model.bin.gz:/app/default_model.bin.gz:ro,x-create=file,bind \
katago \
$@"
```
Edit the script to match your configuration (ssh parameters, etc.).
编辑脚本以匹配你的配置(ssh 参数等)。
3. Make it executable and test it.
使其可执行并测试。
```sh
chmod +x katago-remote.sh
./katago-remote.sh gtp
# KataGo v1.13.2
# Using TrompTaylor rules initially, unless GTP/GUI overrides this
# Initializing board with boardXSize 19 boardYSize 19
# Loaded config /app/default_gtp.cfg
# Loaded model /app/default_model.bin.gz
# Model name: kata1-b18c384nbt-s5832081920-d3223508649
# GTP ready, beginning main protocol loop
```
## Running on DeepSquare
在 DeepSquare 上运行
DeepSquare is a decentralized HPC as a service. You can read more about it on [DeepSquare's official website](https://deepsquare.io) and try the [portal](https://app.deepsquare.run).
DeepSquare 是一个去中心化的 HPC 即服务。您可以在 DeepSquare 的官方网站上了解更多信息,并尝试使用该门户。

### How to use with Neko
如何与 Neko 一起使用
Install the [`dps`](https://docs.deepsquare.run/workflow/cli/getting-started), [the DeepSquare CLI](https://docs.deepsquare.run/workflow/cli/getting-started).
安装 `dps` ,DeepSquare 命令行工具。
Using with [Neko](https://neko.m1k1o.net/#/) is the easiest way to use Sabaki and Katago.
使用 Neko 是与 Sabaki 和 Katago 一起使用最简单的方法。
Just submit the job:
只需提交任务:
```shell
dps submit -w -e --no-ts --job-name katago --credits 10000 ./job.katago.yaml
```
A bore URL will appear in the logs, just connect to it (credentials: user: `admin` and pass: `neko`).
日志中会出现一个 bore URL,直接连接它(凭证:用户名: `admin` ,密码: `neko` )。
You can start the engine by opening the Engines Sidebar (Engines > Show Engines Sidebar).

Then, you can toggle the Analysis mode with F4.
然后,你可以使用 F4 切换分析模式。
### How to use with SSH
如何使用 SSH
1. Edit the job, and replace the SSH public key.
编辑任务,并替换 SSH 公钥。
2. You need to start Sabaki locally.
您需要在本地启动 Sabaki。
3. Then, you can submit the job:
然后,您可以提交任务:
```shell
dps submit -w -e --no-ts --job-name katago --credits 10000 ./job.yaml
```
The user ID and bore URL will appear. This is the URL to the SSH server. You need to use the TCP one.
将显示用户 ID 和 bore URL。这是 SSH 服务器的 URL。您需要使用 TCP 那个。
4. Write a script on your computer to connect to the server via SSH and launch katago with Sabaki:
在你的电脑上编写一个脚本,通过 SSH 连接到服务器并使用 Sabaki 启动 katago:
**/projects/katago/script**
```shell
#!/bin/sh
set -e
SCRIPTPATH="$(dirname "$(realpath "$0")")"
# Copy config file to remote server
scp -P "$SCRIPTPATH/default_gtp.cfg" @bore.deepsquare.run:/tmp/default_gtp.cfg
ssh -p @bore.deepsquare.run "set -e
# Change this if you want to use an another model, see https://katagotraining.org
RELEASE=kata1-b18c384nbt-s8493331456-d3920571699
if [ ! -f \$DEEPSQUARE_DISK_TMP/default_model.bin.gz ]; then
curl -fsSL https://media.katagotraining.org/uploaded/networks/models/kata1/\$RELEASE.bin.gz -o \$DEEPSQUARE_DISK_TMP/default_model.bin.gz
fi
/app/katago $@ -model \$DEEPSQUARE_DISK_TMP/default_model.bin.gz -config /tmp/default_gtp.cfg"
```
Replace `` and `` with the user ID and bore port.
将 `` 和 `` 替换为用户 ID 和端口号。
5. Add an Engine from the Engines Sidebar (Engines > Show Engines Sidebar) with:
从引擎侧边栏添加一个引擎(引擎 > 显示引擎侧边栏),使用:
Path: The path to the script (`/projects/katago/script`)
路径:脚本路径
Arguments: `gtp`
参数: `gtp`

6. Then start the engine:
然后启动引擎:

7. Finally, you can toggle the Analysis mode with F4.
最后,你可以使用 F4 切换分析模式。