Skip to content

Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.

Container: forward SIGTERM (a background job in a non-interactive shell ignores SIGINT), document cold-start cache and untested sections

YanissAmz99ac5c99e247
diff --git a/doc/container.md b/doc/container.md
index bfc12c6..e842292 100644
--- a/doc/container.md
+++ b/doc/container.md
@@ -21,6 +21,8 @@ docker run --rm --name kyojin \
kyojin
```
+Not tested (no podman on the build machine):
+
```bash
podman run --rm --name kyojin \
--device /dev/kfd --device /dev/dri --group-add keep-groups \
@@ -30,7 +32,7 @@ podman run --rm --name kyojin \
kyojin
```
-Then `curl http://localhost:8000/health` and `python tools/bench.py --base http://localhost:8000/v1` from the host. The port stays closed while the model loads (about a minute for Qwen). GLM tunes its kernels for about 10 minutes on a first launch (see README); keep the container, or mount a volume on `/root/.cache`, between runs if you want that kept.
+Then `curl http://localhost:8000/health` and `python tools/bench.py --base http://localhost:8000/v1` from the host. The port stays closed while the model loads. First start of a new container: about 6 minutes for Qwen (measured 370 s), because the dense GEMM kernels are compiled and cached under `/root/.cache` and a fresh container has an empty cache. The same start on bare metal with a warm cache takes about 1 minute. Keep the cache between runs with a named volume, `-v kyojin-cache:/root/.cache` (not yet measured). GLM tunes its kernels for about 10 minutes on a first launch (see README); keep the container, or mount a volume on `/root/.cache`, between runs if you want that kept.
The image has no `video` or `render` group by name, so docker needs the numeric group ids of the host (`getent group video render`). In the llama-swap example below, replace `${VIDEO_GID}` and `${RENDER_GID}` by those numbers.
@@ -58,6 +60,8 @@ Arguments after the image name are appended too: `docker run ... kyojin --defaul
## Compose, behind llama-swap
+Not tested: the compose file and the llama-swap entry below were written from the tested `docker run` line above.
+
```yaml
services:
kyojin-qwen:
@@ -95,7 +99,7 @@ models:
## Stopping
-The entrypoint runs the server as a child and turns SIGTERM into SIGINT, which the servers handle. `docker stop` ends the container as soon as the server exits. A GPU-memory-heavy server can take some seconds to free the device; keep `stop_grace_period` at 30 s or more.
+The entrypoint runs the server as a child and forwards SIGTERM to it. Measured on the Qwen pack: `docker stop` returns in about a second, exit code 143, the same as SIGTERM on a bare-metal server. A GPU-memory-heavy server can take some seconds to free the device; keep `stop_grace_period` at 30 s or more.
## Notes
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
index 00a95c8..d905b9e 100755
--- a/docker/entrypoint.sh
+++ b/docker/entrypoint.sh
@@ -14,11 +14,12 @@ mapfile -d '' ARGS < <(python docker/kyojin_args.py --null) || true
[ "${#ARGS[@]}" -gt 0 ] || exit 2
echo "[kyojin] python ${ARGS[*]} $*" >&2
-# Run the server as a child so this shell (PID 1) can forward SIGTERM as SIGINT.
-# The servers stop on SIGINT; a bare PID 1 ignores SIGTERM and docker would wait for SIGKILL.
+# Run the server as a child so this shell (PID 1) can forward SIGTERM. A bare PID 1 ignores SIGTERM and docker
+# would wait for SIGKILL. Forward SIGTERM, not SIGINT: a background job of a non-interactive shell starts with SIGINT
+# ignored, so python never sees it (measured: docker stop took the full timeout and ended in exit 137).
python "${ARGS[@]}" "$@" &
PID=$!
-stop() { echo "[kyojin] signal received, stopping server" >&2; kill -INT "$PID" 2>/dev/null; }
+stop() { echo "[kyojin] signal received, stopping server" >&2; kill -TERM "$PID" 2>/dev/null; }
trap stop TERM INT
while kill -0 "$PID" 2>/dev/null; do wait "$PID" 2>/dev/null; done
wait "$PID" 2>/dev/null; RC=$?