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.
Python amdapple-siliconcudadeepseekexl3exllamav3glminferencellmllm-inferencelocal-llmnvidiaopenai-apiquantizationqwenrocmstrix-halo
Hy4 Strix: one install script for the kernels, serve stops without the MoE extension and sources the Strix env itself
YanissAmz595eca739209
diff --git a/README.md b/README.mdindex 444a5f8..a4e5ef4 100644--- a/README.md+++ b/README.md@@ -31,10 +31,11 @@ hf download yamz-labs/GLM-5.3-Flash-EXL3-Yamz --local-dir ./glm-packpython tools/glm/serve.py --model ./glm-pack --port 8000 -c 131072 --num-draft 2```-Hy4-flash (GGUF Q3_K, 128K context, one Strix Halo machine): download the publisher's GGUF and run `tools/hy4/serve.py` ([doc/hy4.md](doc/hy4.md)):+Hy4-flash (GGUF Q3_K, 128K context, one Strix Halo machine): after the install of [doc/install.md](doc/install.md), download the publisher's GGUF, build the kernels once and run `tools/hy4/serve.py` ([doc/hy4.md](doc/hy4.md)):```bashhf download AngelSlim/Hy4-flash-GGUF --include "Hy4-flash-Q3_K-*.gguf" --local-dir ./hy4+bash tools/hy4/install_strix.sh # once: builds the Hy4 kernels, prints "install_strix: OK"python tools/hy4/serve.py --model ./hy4/Hy4-flash-Q3_K-00001-of-00002.gguf --port 8300 -c 131072```diff --git a/doc/hy4.md b/doc/hy4.mdindex 9b17228..0bd70f8 100644--- a/doc/hy4.md+++ b/doc/hy4.md@@ -16,31 +16,37 @@ The GGUF is published by AngelSlim: [AngelSlim/Hy4-flash-GGUF](https://huggingfahf download AngelSlim/Hy4-flash-GGUF --include "Hy4-flash-Q3_K-*.gguf" --local-dir ./hy4```-## Build the optional kernels (once)+## Build the kernels (once)-The server runs without them and falls back to slower paths. Build them for the full speed:+```bash+bash tools/hy4/install_strix.sh+```++The script uses the repository venv (`EXL3_VENV`, default `.venv`), builds three libraries and prints `install_strix: OK`:++- `hipsp/libspmla.so`: sparse prefill attention (`SP_SO` points to another build).+- `~/.cache/exl3_gm_ext/exl3_gm_ext.so`: the MoE expert kernels (`EXL3_GM_BUILD_DIR` moves the build, `HY4_GM_EXT` points the server to it).+- `~/.cache/kyojin/ck-fmha/libckmla.so`: CK latent attention (`EXL3_CKMLA_OUT` moves the build, `EXL3_CKMLA_SO` points the server to it). The script fetches composable_kernel at the pinned commit once into `~/.cache/kyojin/ck-src`; `CK_SRC` names your own checkout.++The server stops at start when the MoE extension is missing and names this script (`HY4_ALLOW_SLOW=1` starts on the slow path anyway). A missing attention library prints a warning.++Optional: a Q5_K copy of the output head for the MTP drafts (smaller than the Q8_0 default):```bash-source tools/strix_halo/env.sh build-bash hipsp/build.sh hipsp/sp_mla.cu hipsp/libspmla.so # sparse prefill attention (HIP); without it the Triton kernel runs-bash tools/strix_halo/ck_fmha/build_mla.sh # CK latent-attention core, written to ~/.cache/kyojin/ck-fmha/libckmla.so (EXL3_CKMLA_SO overrides)python tools/hy4/make_head_bin.py ./hy4/Hy4-flash-Q3_K-00001-of-00002.gguf ./hy4/head_q5_k.bin-export HY4_MTP_HEAD_BIN=$PWD/hy4/head_q5_k.bin # Q5_K copy of the output head for the MTP drafts (smaller than the Q8_0 default)+export HY4_MTP_HEAD_BIN=$PWD/hy4/head_q5_k.bin```-`hipsp/libspmla.so` is found next to `hipsp/sp_hip.py`; `SP_SO` points to another build. The expert kernels (`exl3_gm_ext`) build on first use and are cached in `~/.cache/exl3_gm_ext`.-## Run```bash-source tools/strix_halo/env.shpython tools/hy4/serve.py --model ./hy4/Hy4-flash-Q3_K-00001-of-00002.gguf --port 8300 -c 131072 --num-draft 3curl http://127.0.0.1:8300/v1/chat/completions -H 'content-type: application/json' \-d '{"messages":[{"role":"user","content":"Hello"}],"max_tokens":64}'```The server speaks the OpenAI API (`/v1/chat/completions`, `/v1/completions`, both with streaming; `/v1/models`, `/health`, `/tokenize`, `/apply-template`).-`tools/hy4/serve.py` sets the shipped kernel flags (`SHIPPED_ENV` in the file); every one can be overridden from the environment. The main ones:+`tools/hy4/serve.py` runs itself under `tools/strix_halo/env.sh` (the HSA runtime torch needs on gfx1151) and sets the shipped kernel flags (`SHIPPED_ENV` in the file); every one can be overridden from the environment. The main ones:| variable | shipped | effect ||---|---|---|diff --git a/tools/hy4/install_strix.sh b/tools/hy4/install_strix.shnew file mode 100755index 0000000..376dadf--- /dev/null+++ b/tools/hy4/install_strix.sh@@ -0,0 +1,35 @@+#!/usr/bin/env bash+# One-time build of the Hy4-flash kernels on a Strix Halo machine (gfx1151). Run from anywhere; needs the repository venv (see doc/install.md).+# bash tools/hy4/install_strix.sh+# Builds: hipsp/libspmla.so (sparse prefill attention), ~/.cache/exl3_gm_ext/exl3_gm_ext.so (MoE expert kernels), ~/.cache/kyojin/ck-fmha/libckmla.so (CK latent attention).+# Env: EXL3_VENV / VIRTUAL_ENV (default <repo>/.venv), CK_SRC (a composable_kernel checkout at the pinned commit; default: fetched once into ~/.cache/kyojin/ck-src),+# EXL3_GM_BUILD_DIR, EXL3_CKMLA_OUT (other output places; set HY4_GM_EXT / EXL3_CKMLA_SO to the same paths when serving).+ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd); cd "$ROOT" || exit 1+die() { echo "install_strix: $*" >&2; exit 1; }+export EXL3_VENV=${EXL3_VENV:-${VIRTUAL_ENV:-$ROOT/.venv}}; export VIRTUAL_ENV=$EXL3_VENV+[ -x "$EXL3_VENV/bin/python" ] || die "no venv at $EXL3_VENV: create it as in doc/install.md or set EXL3_VENV"+export PATH=$EXL3_VENV/bin:$PATH+command -v rocm-sdk >/dev/null || die "rocm-sdk not found in the venv: install the ROCm devel wheel as in doc/install.md"+export EXL3_ROCM_SDK=${EXL3_ROCM_SDK:-$(rocm-sdk path --root)}+CK_PIN=6f44fdf90f69adee742ec3660b95d32963b9bd2d+if [ -z "${CK_SRC:-}" ]; then+ CK_SRC=${XDG_CACHE_HOME:-$HOME/.cache}/kyojin/ck-src+ if [ "$(git -C "$CK_SRC" rev-parse HEAD 2>/dev/null)" != "$CK_PIN" ]; then+ echo "install_strix: fetching composable_kernel $CK_PIN into $CK_SRC"+ mkdir -p "$CK_SRC" && git -C "$CK_SRC" init -q \+ && git -C "$CK_SRC" fetch -q --depth 1 https://github.com/ROCm/composable_kernel.git "$CK_PIN" \+ && git -C "$CK_SRC" checkout -q FETCH_HEAD || die "could not fetch composable_kernel: set CK_SRC to a checkout of $CK_PIN"+ fi+fi+export CK_SRC+source tools/strix_halo/env.sh build || die "env.sh build failed"+set -e+echo "install_strix: [1/3] sparse prefill attention (hipsp/libspmla.so)"+bash hipsp/build.sh hipsp/sp_mla.cu hipsp/libspmla.so+echo "install_strix: [2/3] MoE expert kernels (exl3_gm_ext)"+EXL3_GM_BUILD=1 python -c "from exllamav3 import gm_ext; assert gm_ext.get() is not None, \"gm_ext build failed\""+echo "install_strix: [3/3] CK latent attention (libckmla.so)"+bash tools/strix_halo/ck_fmha/build_mla.sh+GM=${EXL3_GM_BUILD_DIR:-$HOME/.cache/exl3_gm_ext}; CK=${EXL3_CKMLA_OUT:-${XDG_CACHE_HOME:-$HOME/.cache}/kyojin/ck-fmha/libckmla.so}+for f in "$ROOT/hipsp/libspmla.so" "$GM/exl3_gm_ext.so" "$CK"; do [ -s "$f" ] || die "missing after build: $f"; done+echo "install_strix: OK"diff --git a/tools/hy4/serve.py b/tools/hy4/serve.pyindex dcfa5ba..19d478b 100644--- a/tools/hy4/serve.py+++ b/tools/hy4/serve.py@@ -6,8 +6,8 @@Prefill runs the prefill fast path; decode runs the HIP-graph step with MTP speculative decoding (greedy; the stream equals plain greedy decoding of thetrunk). Sampling parameters are accepted and ignored. One request is served at a time (one resident model); others queue.-The shipped kernel flag set is SHIPPED_ENV below; every entry can be overridden from the environment. Run it inside the strix env wrapper-(tools/strix_halo/env.sh) and a GPU lock / memory cap of your choice: the server takes neither.+The shipped kernel flag set is SHIPPED_ENV below; every entry can be overridden from the environment. The server sources tools/strix_halo/env.sh itself+and needs the kernels of tools/hy4/install_strix.sh (once). It takes no GPU lock and no memory cap: add your own."""from __future__ import annotations@@ -25,6 +25,19 @@ TREE = os.path.dirname(os.path.dirname(HERE))sys.path.insert(0, HERE)sys.path.insert(0, os.path.dirname(HERE))++def _env_reexec():+ """torch needs the ROCm 7 HSA runtime preloaded on gfx1151 (tools/strix_halo/env.sh): when the shell did not source it, re-run this command under it."""+ env_sh = os.path.join(TREE, "tools", "strix_halo", "env.sh")+ if "libhsa-runtime64" in os.environ.get("LD_PRELOAD", "") or os.environ.get("KYOJIN_ENV_SOURCED") or not os.path.isfile(env_sh):+ return+ os.environ["KYOJIN_ENV_SOURCED"] = "1"+ os.execvp("bash", ["bash", "-c", 'source "$1" >/dev/null && shift && exec "$@"', "_", env_sh, sys.executable, os.path.abspath(__file__), *sys.argv[1:]])+++if __name__ == "__main__":+ _env_reexec()+import serve_core as C # noqa: E402import serve_compat # noqa: E402@@ -44,6 +57,20 @@ SHIPPED_ENV = {}+def check_kernels() -> None:+ """The built kernels (tools/hy4/install_strix.sh) are part of the shipped speed. A missing MoE extension stops the start with the install step+ (HY4_ALLOW_SLOW=1 starts anyway on the slow path); a missing attention library prints a warning."""+ home_cache = os.path.expanduser("~/.cache")+ gm = os.environ.get("HY4_GM_EXT", os.path.join(home_cache, "exl3_gm_ext", "exl3_gm_ext.so"))+ sp = os.environ.get("SP_SO", os.path.join(TREE, "hipsp", "libspmla.so"))+ ck = os.environ.get("EXL3_CKMLA_SO") or os.path.join(os.environ.get("XDG_CACHE_HOME", home_cache), "kyojin", "ck-fmha", "libckmla.so")+ if os.environ.get("HY4_MOE_HIP", "0") in ("1", "2") and not os.path.isfile(gm) and os.environ.get("HY4_ALLOW_SLOW") != "1":+ sys.exit(f"hy4 serve: the MoE kernel extension is missing ({gm}).\nBuild the kernels once: bash tools/hy4/install_strix.sh (HY4_ALLOW_SLOW=1 starts on the slow path anyway).")+ for flag, path, what in (("HY4_PF_SPARSE", sp, "sparse prefill attention (Triton fallback)"), ("HY4_PF_CK", ck, "CK latent attention (slower fallback)")):+ if os.environ.get(flag, "0") == "1" and not os.path.isfile(path):+ print(f"hy4 serve: WARNING {path} is missing: {what}. Build it with: bash tools/hy4/install_strix.sh", file=sys.stderr, flush=True)++def apply_env(ctx: int) -> None:for k, v in SHIPPED_ENV.items():os.environ.setdefault(k, v)@@ -355,6 +382,7 @@ def main(argv=None):ap.add_argument("--sched-chunk", type=int, default=1024, help="prefill rows per scheduler turn with --slots > 1 (a decode round of the other sessions runs between chunks)")args = ap.parse_args(argv)apply_env(args.max_ctx)+ check_kernels()st = State(args)app = build_app(st)