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.

Discover serve flavors from tools/*/serve.py (#175)

Tristin Stagg4a749ba0e48d
diff --git a/doc/nix.md b/doc/nix.md
index d3b3762..e1e8705 100644
--- a/doc/nix.md
+++ b/doc/nix.md
@@ -34,13 +34,20 @@ metadata builds (`uv lock --check`, PEP 517 `get_requires`) keep working.
```bash
nix build .#exllamav3 # engine wheel + gfx1151 extension
nix build .#exllama-ext # native extension alone (narrowed sources)
-nix build .#kyojin # serve wrappers (qwen/glm/mimo)
+nix build .#kyojin # serve wrappers (one per tools/*/serve.py flavor)
nix build .#torch-rocm # ROCm torch wheel
nix build .#rocm-sdk # expanded SDK tree (headers, hipcc, libhsa)
nix build .#docker # OCI image tarball, about 5 GB compressed
nix run .#kyojin-serve-glm -- --help
```
+Serve flavors are discovered from `tools/*/serve.py`: adding a server
+directory adds its `kyojin-serve-<flavor>` wrapper and app, and makes the
+container entrypoint accept that flavor, with no list to keep in sync. (Flake
+sources only see tracked files, so `git add` the new directory first.) A new
+flavor's Python dependencies must already be in `pyproject.toml`, since all
+wrappers share the one locked environment.
+
The engine package is split for CI caching: `.#exllama-ext` compiles the
native extension from narrowed sources only (`setup.py`,
`exllamav3/exllamav3_ext/`, `util/arch_list.py`, plus packaging metadata),
@@ -144,8 +151,8 @@ with a raised memlock limit is the usual setup for GPU inference runtimes.
The entrypoint downloads the model into the volume on first start and skips
the download when a pack is already there. Both flavor and repo are required
and fail fast; there are no silent 50 GB pulls. Each flavor gets its own slot
-(`/models/qwen`, `/models/glm`, `/models/mimo`, overridable with
-`KYOJIN_MODEL_DIR`), and a marker file records which repo filled it, so
+(`/models/<flavor>`, overridable with `KYOJIN_MODEL_DIR`), and a marker file
+records which repo filled it, so
switching repos under the same flavor errors out instead of serving a stale
pack. Tuning cache (`~/.cache/exllamav3`) lives under `HOME`, which the
entrypoint points at `/models/home` (override with `KYOJIN_HOME`) so a fresh
diff --git a/flake.nix b/flake.nix
index aed9567..ad9c1f6 100644
--- a/flake.nix
+++ b/flake.nix
@@ -48,6 +48,23 @@
inherit (pkgs) lib;
python = pkgs.python312;
+ # A flavor is any tools/<name>/serve.py. The full tools/ tree is
+ # already shipped uncurated in kyojinServe, so this one discovery
+ # rule drives the wrappers, the container entrypoint, the smoke
+ # check and the apps: adding or removing a serve.py cannot leave
+ # one of them behind.
+ flavors =
+ let
+ entries = builtins.readDir ./tools;
+ isFlavor = name: type: type == "directory" && builtins.pathExists (./tools + "/${name}/serve.py");
+ found = builtins.attrNames (lib.filterAttrs isFlavor entries);
+ in
+ assert found != [ ];
+ found;
+ # The documented default; keep it explicit (not head flavors) so a
+ # new flavor cannot silently become the default app.
+ defaultFlavor = "glm";
+
# The package version, read from upstream's single source of truth
# (exllamav3/version.py: `__version__ = "x.y.z"`). pyproject-nix
# reports 0.0.0 for a setuptools-dynamic version, so the packages
@@ -645,7 +662,7 @@
# mirror the repo-root layout it expects.
mkdir -p $out/share/exllamav3/util
cp $src/exllamav3/util/hip_compiler.py $out/share/exllamav3/util/
- for flavor in glm mimo qwen; do
+ for flavor in ${lib.concatStringsSep " " flavors}; do
makeWrapper ${kyojinEnv}/bin/python $out/bin/kyojin-serve-$flavor \
--add-flags "$out/share/kyojin/$flavor/serve.py" \
--prefix PYTHONPATH : "${pythonSet.exllamav3}/lib/python3.12/site-packages:${rocmProviders}/lib/python3.12/site-packages:$out/share/kyojin" \
@@ -660,7 +677,7 @@
'';
meta = {
description = "kyojin exllamav3 inference server (AMD gfx1151)";
- mainProgram = "kyojin-serve-glm";
+ mainProgram = "kyojin-serve-${defaultFlavor}";
};
};
@@ -713,9 +730,9 @@
set -euo pipefail
flavor="''${KYOJIN_FLAVOR:-}"
case "$flavor" in
- qwen | glm | mimo) ;;
+ ${lib.concatStringsSep " | " flavors}) ;;
*)
- echo "kyojin-entrypoint: set KYOJIN_FLAVOR to one of: qwen glm mimo" >&2
+ echo "kyojin-entrypoint: set KYOJIN_FLAVOR to one of: ${lib.concatStringsSep " " flavors}" >&2
exit 2
;;
esac
@@ -746,7 +763,7 @@
printf '%s' "$repo" > "$marker"
fi
echo "kyojin-entrypoint: serving $flavor from $model_dir" >&2
- exec "''${KYOJIN_BIN:-/bin/kyojin-serve-$flavor}" --model "$model_dir" "$@"
+ exec "''${KYOJIN_BIN:-/bin/kyojin-serve-$flavor}" --host 0.0.0.0 --model "$model_dir" "$@"
'';
# huggingface-hub CLI (hf download for the entrypoint). nixpkgs'
# anyio runs a networked TLS test suite in installCheck that fails
@@ -910,7 +927,7 @@
"${rocmSdk}/bin/hipcc" --genco --offload-arch=gfx1151 -O3 -ffp-contract=off \
-o gr_mix.hsaco exllamav3/modules/gr_fn/gr_mix.hip
test -s gr_mix.hsaco
- for flavor in glm mimo qwen; do
+ for flavor in ${lib.concatStringsSep " " flavors}; do
grep -q HIP_DEVICE_LIB_PATH ${kyojinServe}/bin/kyojin-serve-$flavor
grep -q HIPCC_COMPILE_FLAGS_APPEND ${kyojinServe}/bin/kyojin-serve-$flavor
done
@@ -950,16 +967,21 @@
type = "app";
program = "${kyojinServe}/bin/kyojin-serve-${flavor}";
};
+ serveApps = builtins.listToAttrs (
+ map (flavor: {
+ name = "kyojin-serve-${flavor}";
+ value = serveApp flavor;
+ }) flavors
+ );
in
- {
- kyojin-serve-qwen = serveApp "qwen";
- kyojin-serve-glm = serveApp "glm";
- kyojin-serve-mimo = serveApp "mimo";
+ assert lib.elem defaultFlavor flavors;
+ serveApps
+ // {
kyojin-bench = {
type = "app";
program = "${kyojinBench}/bin/kyojin-bench";
};
- default = serveApp "glm";
+ default = serveApp defaultFlavor;
};
};
};