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.

Add contributor guide, issue and pull request templates, and a one-command benchmark

YanissAmz296f958c241c
diff --git a/.github/ISSUE_TEMPLATE/benchmark_report.yml b/.github/ISSUE_TEMPLATE/benchmark_report.yml
new file mode 100644
index 0000000..5e9b060
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/benchmark_report.yml
@@ -0,0 +1,34 @@
+name: Benchmark report
+description: Share the numbers from `tools/bench.sh` on your machine
+labels: ["benchmark"]
+body:
+ - type: markdown
+ attributes:
+ value: |
+ Start the server from the README quickstart, then run `tools/bench.sh` and paste its output below. Thank you for sharing.
+ - type: textarea
+ id: result
+ attributes:
+ label: Output of tools/bench.sh
+ description: Paste the whole markdown block.
+ validations:
+ required: true
+ - type: input
+ id: hardware
+ attributes:
+ label: Machine
+ description: Product name, RAM size and speed, cooling or power mode if you changed it.
+ validations:
+ required: true
+ - type: input
+ id: command
+ attributes:
+ label: Server command
+ description: The command that started the server, with flags and environment variables.
+ validations:
+ required: true
+ - type: textarea
+ id: notes
+ attributes:
+ label: Notes
+ description: Anything unusual (other load on the machine, changed kernel parameters, first launch or warm cache).
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
new file mode 100644
index 0000000..0705dad
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -0,0 +1,61 @@
+name: Bug report
+description: Something does not build, load, serve or run correctly
+labels: ["bug"]
+body:
+ - type: textarea
+ id: hardware
+ attributes:
+ label: Hardware
+ description: CPU / APU, GPU, RAM size, BIOS memory split if you changed it.
+ placeholder: "Ryzen AI Max+ 395, Radeon 8060S (gfx1151), 128 GB"
+ validations:
+ required: true
+ - type: input
+ id: kernel
+ attributes:
+ label: Linux distribution and kernel
+ description: Output of `uname -r` and the distribution name.
+ validations:
+ required: true
+ - type: input
+ id: rocm
+ attributes:
+ label: ROCm and PyTorch versions
+ description: Output of `bash tools/strix_halo/env.sh --check`, or `rocm-sdk version` and `python -c "import torch; print(torch.__version__)"`.
+ validations:
+ required: true
+ - type: input
+ id: version
+ attributes:
+ label: Kyojin version
+ description: Release tag or commit (`git rev-parse --short HEAD`).
+ validations:
+ required: true
+ - type: input
+ id: model
+ attributes:
+ label: Model
+ description: Model pack and size.
+ placeholder: "yamz-labs/GLM-5.3-Flash-EXL3-Yamz"
+ - type: textarea
+ id: command
+ attributes:
+ label: Command
+ description: The exact command you ran, with all flags and environment variables.
+ render: shell
+ validations:
+ required: true
+ - type: textarea
+ id: expected
+ attributes:
+ label: What happened and what you expected
+ validations:
+ required: true
+ - type: textarea
+ id: log
+ attributes:
+ label: Log
+ description: The server or build log, from the start through the error. Remove anything private.
+ render: text
+ validations:
+ required: true
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
new file mode 100644
index 0000000..66292fe
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,5 @@
+blank_issues_enabled: true
+contact_links:
+ - name: Changes to ExLlamaV3 itself
+ url: https://github.com/turboderp-org/exllamav3/issues
+ about: Problems that also happen on upstream ExLlamaV3 belong in the upstream repository.
diff --git a/.github/ISSUE_TEMPLATE/model_request.yml b/.github/ISSUE_TEMPLATE/model_request.yml
new file mode 100644
index 0000000..1821abf
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/model_request.yml
@@ -0,0 +1,30 @@
+name: Model request
+description: Ask for support for another model
+labels: ["model request"]
+body:
+ - type: input
+ id: model
+ attributes:
+ label: Model
+ description: Link to the model page.
+ validations:
+ required: true
+ - type: input
+ id: size
+ attributes:
+ label: Architecture and size
+ description: Architecture family, parameter count, expected size on disk after quantisation.
+ validations:
+ required: true
+ - type: textarea
+ id: why
+ attributes:
+ label: Why this model
+ description: What you want to run and what you tried (for example, whether upstream ExLlamaV3 already supports it).
+ validations:
+ required: true
+ - type: input
+ id: licence
+ attributes:
+ label: Licence
+ description: Licence of the weights.
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 0000000..d8beffc
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,7 @@
+## What this changes
+
+## How you checked it
+<!-- CPU tests, GPU tests, `tools/bench.sh` before and after. Say what you did not run. -->
+
+## Notes
+<!-- Hardware and ROCm version if the change touches kernels. Anything a reviewer should know. -->
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..4fe4ec4
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,57 @@
+# Contributing to Kyojin
+
+Thank you for helping. Kyojin is the Yamz inference engine for AMD Strix Halo, built on [ExLlamaV3](https://github.com/turboderp-org/exllamav3). Issues and pull requests are welcome.
+
+## Most wanted
+
+- **Benchmarks from other gfx1151 machines** (Ryzen AI Max+ 395 and 390, other vendors, other RAM sizes). Run `tools/bench.sh` and post the output with the benchmark report template.
+- **Other ROCm GPUs.** Other GPUs are untested. Reports of what builds, what runs and what fails are useful even when the answer is "it does not work".
+- **Bug reports with logs.** Use the bug report template: hardware, kernel, ROCm version, exact command, and the server log.
+- **Documentation.** Install problems you hit, missing steps, unclear wording.
+
+## Build
+
+Follow the Quickstart in `README.md`. In short:
+
+```bash
+python3 -m venv .venv && source .venv/bin/activate
+pip install --pre torch rocm-sdk-devel --index-url https://rocm.nightlies.amd.com/v2/gfx1151/
+pip install -r requirements.txt
+rocm-sdk init
+export EXL3_ROCM_SDK=$(rocm-sdk path --root)
+source tools/strix_halo/env.sh # from the repository root, in every new shell
+./build.sh
+```
+
+## Run the CPU tests
+
+These need no GPU and no built extension. Run each file separately, because two files share the name `test_serve.py`:
+
+```bash
+pip install pytest
+for t in tests/test_ablit_runtime_cpu.py tests/test_uncensor_bundled_cpu.py tools/glm/test_serve.py tools/mimo/test_serve.py tools/mimo/test_toolcalls.py; do PYTHONPATH=. pytest -q $t; done
+```
+
+`tools/glm/test_serve.py` takes a few minutes. If it hangs, look for a stale lock file at `~/.cache/torch_extensions/*/exllamav3_ext/lock` and remove it. GPU tests under `tests/` need a built extension and a free GPU; say in the pull request whether you ran them.
+
+## Pull requests
+
+- Keep a pull request to one change. Explain what it fixes and how you checked it.
+- For speed changes, include before and after numbers from `tools/bench.sh` on the same machine, and the command you used.
+- Do not add new dependencies without a reason in the description.
+- Do not commit model weights, secrets, local paths or personal data.
+
+## Code and commit conventions
+
+- Python: follow the style of the file you edit. Keep functions small and name things for what they do.
+- Environment switches use the `EXL3_` prefix (for example `EXL3_ABLIT_RUNTIME`). Document each new switch next to the code that reads it.
+- Commit subjects are short, in English, in the imperative, with no prefix and no trailing period (for example: `Fix union MoE RM=8 kernels: process rows in groups of 4`). Add a body when the reason is not obvious.
+- Make normal commits. Do not rewrite history on a branch others use.
+
+## Upstream
+
+Kyojin is built on ExLlamaV3 by turboderp. A change that belongs to ExLlamaV3 itself (general quantisation, the CUDA path, the tokenizer, shared generator logic) should go to [turboderp-org/exllamav3](https://github.com/turboderp-org/exllamav3) first. Send to this repository what is specific to gfx1151, ROCm, the Strix Halo serving tools or the supported models.
+
+## Licence
+
+Contributions are under the MIT licence of the repository.
diff --git a/README.md b/README.md
index bca6e96..7ec35d5 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ Weights: [Yamz on Hugging Face](https://huggingface.co/yamz-labs) - `yamz-labs/G
Requirements: Linux (Ubuntu/Debian tested), a gfx1151 machine with 128 GB, Python 3.12, `gcc`, a ROCm 7 `libhsa-runtime64.so.1` (the PyTorch copy segfaults on gfx1151 and Ubuntu's own `libhsa-runtime64-1` is ROCm 5.7, too old; `tools/strix_halo/env.sh` finds the one inside the SDK wheel below first, then /opt/rocm, or take `EXL3_HSA_LIB=<path>`), ROCm 7.0 or newer (ROCm 6.4 has no gfx1151 code), a ROCm build of PyTorch for gfx1151, and a ROCm SDK devel tree with the `hipsparse/` and `thrust/` headers (the `rocm-sdk-devel` wheel).
```bash
-git clone https://github.com/Yamz-Labs/kyojin Yamz-Labs/kyojin kyojin && cd kyojinYamz-Labs/kyojin kyojin && cd kyojin cd kyojin
+git clone https://github.com/Yamz-Labs/kyojin && cd kyojin
python3 -m venv .venv && source .venv/bin/activate
# 1. ROCm torch + SDK first (AMD gfx1151 wheels; plain `pip install torch` gives a CUDA/CPU build that cannot run here):
pip install --pre torch rocm-sdk-devel --index-url https://rocm.nightlies.amd.com/v2/gfx1151/
@@ -56,6 +56,10 @@ llama.cpp (ROCm, UD-IQ1_S 1.56 bpw, `-fa 1 -ub 2048`, no MTP), same machine: pp4
Quality against the official FP8 weights (129 held-out rows): see the model cards.
+## Share your numbers
+Start a server from the quickstart, then run `tools/bench.sh` (standard library only, `--base` and `--model` select the server). It measures prefill on a prompt of about 3.5K tokens and decode on prose, chat and code with the prompts behind the table above, and prints one Markdown block with your hardware and versions.
+Paste it into a [benchmark report](https://github.com/Yamz-Labs/kyojin/issues/new?template=benchmark_report.yml). Results from other gfx1151 machines and other ROCm GPUs are the most useful contribution. See `CONTRIBUTING.md`.
+
## Optional refusal hook
The engine can project one fixed direction out of the residual stream at run time. It edits no weights and no quantised data. Off unless `EXL3_ABLIT_RUNTIME=/path/to/spec.json` is set or the model folder contains `uncensor_spec.json`.
- Bundled spec: if `<model_dir>/uncensor_spec.json` exists (with `uncensor_direction.st` next to it, or `uncensor_spec.safetensors`), the engine applies it at load and logs ` -- ablit runtime: spec <path> active (bundled in the model directory)`. An explicit `EXL3_ABLIT_RUNTIME=<path>` wins. `EXL3_ABLIT_RUNTIME=off` or `--no-uncensor` (GLM and MiMo servers) disables it. A missing or malformed spec stops the load with an error that names the file.
diff --git a/tools/bench.py b/tools/bench.py
new file mode 100755
index 0000000..718e348
--- /dev/null
+++ b/tools/bench.py
@@ -0,0 +1,230 @@
+#!/usr/bin/env python3
+"""One-command benchmark against a running Kyojin server (OpenAI-style API).
+
+ python tools/bench.py # http://localhost:8000/v1, model taken from /v1/models
+ python tools/bench.py --base http://localhost:8000/v1 --reps 3
+
+Standard library only. Method and decode prompts are the ones behind the numbers in README.md:
+
+ prefill tok/s = prompt_tokens / wall time (max_tokens=1, temperature 0, a unique prompt each run)
+ decode tok/s = (completion_tokens - 1) / (last streamed chunk - first streamed chunk)
+ 128 new tokens, temperature 0, three different prompts each for prose, chat and code
+
+The prefill prompt is about 3.5K tokens of English text taken from the Markdown files of this
+repository (the published figures used a WikiText-2 slice; pass --corpus <file> to use any text
+file). Each request starts with a unique tag so no prompt cache can answer it. The first request
+after a build or a first launch is slow while the kernels tune: a short warm-up runs first, and
+you should run the script twice on a fresh install.
+
+Prints one Markdown block to paste into a benchmark report issue.
+"""
+import argparse
+import json
+import platform
+import random
+import re
+import shutil
+import statistics
+import subprocess
+import sys
+import time
+import urllib.request
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parent.parent
+
+DECODE_PROMPTS = {
+ "prose": [
+ "Write a 300-word story about a lighthouse.",
+ "Write a 300-word story about a lighthouse. Use a different keeper and a different coast.",
+ "Tell a 300-word story set in a lighthouse during a winter storm, with a different ending.",
+ ],
+ "chat": [
+ "Explain how a hash map works, with its time complexity, in about 300 words.",
+ "Explain how a hash map works and where it degrades, in about 300 words.",
+ "Explain hash maps to a backend engineer: buckets, collisions, resizing. About 300 words.",
+ ],
+ "code": [
+ "Write a Python function that parses an ISO-8601 duration string into seconds, with tests.",
+ "Write a Python function that parses an ISO-8601 duration into seconds, handling negative "
+ "durations, with unit tests.",
+ "Write a Python function parsing ISO-8601 durations (P[n]Y[n]M[n]DT[n]H[n]M[n]S) into a "
+ "timedelta, with tests for every unit.",
+ ],
+}
+PREFILL_TARGET_TOKENS = 3500
+
+
+def post(base, body, timeout=3600):
+ req = urllib.request.Request(base + "/chat/completions", json.dumps(body).encode(),
+ {"content-type": "application/json"})
+ return urllib.request.urlopen(req, timeout=timeout)
+
+
+def chat(prompt):
+ return [{"role": "user", "content": prompt}]
+
+
+def prefill(base, model, text):
+ t0 = time.perf_counter()
+ d = json.load(post(base, {"model": model, "messages": chat(text), "max_tokens": 1, "temperature": 0}))
+ wall = time.perf_counter() - t0
+ n = d["usage"]["prompt_tokens"]
+ return n, n / wall
+
+
+def decode(base, model, prompt, max_tokens):
+ body = {"model": model, "messages": chat(prompt), "max_tokens": max_tokens, "temperature": 0,
+ "stream": True, "stream_options": {"include_usage": True}}
+ first = last = None
+ n_chunks = 0
+ usage = None
+ for raw in post(base, body):
+ line = raw.decode().strip()
+ if not line.startswith("data: {"):
+ continue
+ d = json.loads(line[6:])
+ usage = d.get("usage") or usage
+ delta = (d.get("choices") or [{}])[0].get("delta") or {}
+ if delta.get("content") or delta.get("reasoning_content"):
+ now = time.perf_counter()
+ first = first or now
+ last = now
+ n_chunks += 1
+ toks = (usage or {}).get("completion_tokens") or n_chunks
+ if not last or last <= first or toks < 2:
+ return None
+ return (toks - 1) / (last - first)
+
+
+def load_words(corpus):
+ files = [Path(corpus)] if corpus else sorted(ROOT.rglob("*.md"))
+ words = []
+ for f in files:
+ if any(p in f.parts for p in (".venv", ".git", "node_modules")):
+ continue
+ words += f.read_text(encoding="utf-8", errors="ignore").split()
+ return words
+
+
+def sh(cmd):
+ try:
+ return subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=20).stdout.strip()
+ except Exception:
+ return ""
+
+
+def cpu_name():
+ try:
+ for line in Path("/proc/cpuinfo").read_text().splitlines():
+ if line.startswith("model name"):
+ return line.split(":", 1)[1].strip()
+ except OSError:
+ pass
+ return platform.processor() or "unknown"
+
+
+def ram_gib():
+ try:
+ for line in Path("/proc/meminfo").read_text().splitlines():
+ if line.startswith("MemTotal"):
+ return f"{int(line.split()[1]) / 1048576:.0f} GiB"
+ except OSError:
+ pass
+ return "unknown"
+
+
+def rocm_version():
+ for f in ("/opt/rocm/.info/version", "/opt/rocm/.info/version-dev"):
+ if Path(f).is_file():
+ return Path(f).read_text().strip()
+ for cmd in ("rocm-sdk version", "hipconfig --version"):
+ if shutil.which(cmd.split()[0]):
+ out = sh(cmd)
+ if out:
+ return out.splitlines()[0]
+ out = sh(f"{sys.executable} -c 'import torch; print(torch.version.hip or \"\")'")
+ return f"HIP {out} (PyTorch)" if out else "unknown"
+
+
+def gpu_name():
+ out = sh("rocminfo 2>/dev/null | grep -m1 -o 'gfx[0-9a-z]*'")
+ return out or "unknown"
+
+
+def main():
+ ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
+ ap.add_argument("--base", default="http://localhost:8000/v1", help="OpenAI-style base URL")
+ ap.add_argument("--model", help="model id (default: first id from /models)")
+ ap.add_argument("--reps", type=int, default=3, help="runs per measurement (default 3)")
+ ap.add_argument("--max-tokens", type=int, default=128)
+ ap.add_argument("--corpus", help="text file for the prefill prompt (default: Markdown files of this repository)")
+ a = ap.parse_args()
+ base = a.base.rstrip("/")
+ reps = max(1, min(a.reps, 3))
+
+ model = a.model
+ if not model:
+ try:
+ model = json.load(urllib.request.urlopen(base + "/models", timeout=30))["data"][0]["id"]
+ except Exception as e:
+ sys.exit(f"cannot reach {base}/models ({e}). Start the server first (see the README quickstart).")
+
+ words = load_words(a.corpus)
+ if len(words) < 8000:
+ sys.exit("not enough text for the prefill prompt: pass --corpus <file> with at least 8000 words")
+ rng = random.Random(1234)
+ tag = f"{int(time.time())}"
+
+ def slice_text(n_words, salt):
+ s = rng.randrange(0, len(words) - n_words)
+ return f"[{salt}] " + " ".join(words[s:s + n_words]) + "\nSummarize in one word."
+
+ print(f"warm-up on {model} at {base} ...", file=sys.stderr)
+ n, _ = prefill(base, model, slice_text(300, f"{tag}-warm"))
+ decode(base, model, DECODE_PROMPTS["chat"][0], 32)
+ ratio = n / 300.0 # tokens per word on this text
+ n_words = max(500, min(len(words) - 1, int(PREFILL_TARGET_TOKENS / ratio)))
+
+ pf = []
+ for i in range(reps):
+ print(f"prefill {i + 1}/{reps}", file=sys.stderr)
+ pf.append(prefill(base, model, slice_text(n_words, f"{tag}-{i}")))
+ dec = {}
+ for i in range(reps): # categories interleaved
+ for cat, prompts in DECODE_PROMPTS.items():
+ print(f"decode {cat} {i + 1}/{reps}", file=sys.stderr)
+ v = decode(base, model, prompts[i], a.max_tokens)
+ if v is not None:
+ dec.setdefault(cat, []).append(v)
+
+ def med(xs):
+ return f"{statistics.median(xs):.1f}" if xs else "n/a"
+
+ ptok = int(statistics.median(n for n, _ in pf))
+ lines = [
+ "### Kyojin benchmark",
+ "",
+ f"- Model: `{model}`",
+ f"- CPU: {cpu_name()}",
+ f"- RAM: {ram_gib()}",
+ f"- GPU target: {gpu_name()}",
+ f"- Kernel: {platform.release()}",
+ f"- ROCm: {rocm_version()}",
+ f"- Server: {base}",
+ f"- Date: {time.strftime('%Y-%m-%d')}",
+ "",
+ "| Measurement | Result |",
+ "|---|---|",
+ f"| Prefill, ~{ptok} tokens (median of {len(pf)}) | {med([t for _, t in pf])} tok/s |",
+ ]
+ for cat in DECODE_PROMPTS:
+ xs = dec.get(cat, [])
+ lines.append(f"| Decode, {cat}, {a.max_tokens} tokens, temperature 0 (median of {len(xs)}) | {med(xs)} tok/s |")
+ lines += ["", "Method: prefill = prompt tokens / wall time (1 output token); decode = (tokens - 1) / streaming time. "
+ "Same prompts as the numbers in the README."]
+ print("\n".join(lines))
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tools/bench.sh b/tools/bench.sh
new file mode 100755
index 0000000..3709294
--- /dev/null
+++ b/tools/bench.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+# One-command benchmark against a running server: tools/bench.sh [--base URL] [--model ID] [--reps N]
+exec python3 "$(dirname "$(readlink -f "$0")")/bench.py" "$@"