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
GLM server: load the MTP eh_proj sidecar from the model folder (mtp_eh_proj.st) by default
YanissAmzdf5c2be1c037
diff --git a/README.md b/README.mdindex 71bb661..f52ef8c 100644--- a/README.md+++ b/README.md@@ -42,7 +42,7 @@ First GLM launch: the server tunes its dense GEMM kernels before it opens the poGLM reasons at maximum effort by default. With a small `max_tokens`, the reasoning can use the whole budget: `content` is then empty and `finish_reason` is `length`. Send `"reasoning_effort": "low"` in the request (or start the server with `--default-reasoning-effort low`), or allow at least 1000 tokens. The server defaults to greedy sampling when a request gives no temperature; set the sampling values of the model card in your client, or with `--default-temperature` and `--default-top-p`.-Optional for GLM: an unquantized MTP `eh_proj` sidecar raises draft acceptance (about +5 % decode). The pack does not ship it and the server starts without it (one log line). To add it, see "Optional MTP sidecar" in `tools/glm/SERVE.md`.+GLM: the pack ships `mtp_eh_proj.st`, an unquantized MTP `eh_proj` (64 MiB). The server loads it automatically from the model folder; it raises draft acceptance and decode speed (26.7 -> 31.6 tok/s greedy on the card protocol). Details in `tools/glm/SERVE.md`.Memory: GLM at `-c 131072` leaves about 10 GiB free on a 128 GB machine. Close browsers and other large processes first, or use a smaller `-c`.diff --git a/tools/glm/SERVE.md b/tools/glm/SERVE.mdindex a8318b5..1ab7b42 100644--- a/tools/glm/SERVE.md+++ b/tools/glm/SERVE.md@@ -36,23 +36,27 @@ wins): `EXL3_MOE_UNION_V2=1`, `EXL3_MOE_CFG=2`, `EXL3_HIP_PREFILL_MIN_ROWS=2`,`Generator.MTP_FUSE_CATCHUP = 2`. There is no `--temperature`/seed handling beyond therequest body.-### Optional MTP sidecar (higher draft acceptance)+### MTP sidecar (higher draft acceptance)-The published pack stores the MTP `eh_proj` at 2 bits. An unquantized copy raises draft-acceptance (about +0.08) and decode speed (about +5 %), but the pack does not ship it and-the server runs fine without it. If `EXL3_MTP_EH_FP16` is not set, the server uses-`~/models/glm53-mtp-eh-proj-bf16.safetensors` when that file exists and otherwise starts-without it, with one log line. To add it, extract it once from the official GLM-5.3-checkpoint (BF16 `eh_proj`, about 64 MiB), then point the server at it:+The pack stores the MTP `eh_proj` at 2 bits. The pack also ships an unquantized copy,+`mtp_eh_proj.st` (BF16, 64 MiB), and the server loads it automatically: no flag, no variable.+It is a normal safetensors file with a `.st` extension, so no weight loader indexes it as+model weights. It only changes the draft; target token ids stay equal. Measured on the card+protocol (3 prompts, 400 tokens, greedy, Ryzen AI Max+ 395, MTP 2): 26.7 -> 31.6 tok/s.++Source order, one log line says which one was used:++1. `EXL3_MTP_EH_FP16=<path>` (a path that does not exist stops the load with an error; `0` turns the sidecar off)+2. `mtp_eh_proj.st` in the folder given by `--model`+3. `~/models/glm53-mtp-eh-proj-bf16.safetensors` (older location)+4. none: the server runs without it, with lower draft acceptance (one log line)++To build it yourself from the official GLM-5.3 checkpoint:```bash-python tools/glm/mtp_eh_sidecar.py <official GLM-5.3 checkpoint dir> ~/models/glm53-mtp-eh-proj-bf16.safetensors-# or any path, with: EXL3_MTP_EH_FP16=<path> python tools/glm/serve.py ...+python tools/glm/mtp_eh_sidecar.py <official GLM-5.3 checkpoint dir> <model folder>/mtp_eh_proj.st```-An explicit `EXL3_MTP_EH_FP16=<path>` that does not exist stops the load with an error;-`EXL3_MTP_EH_FP16=0` turns the sidecar off.-## Endpoints### `GET /v1/models`diff --git a/tools/glm/serve.py b/tools/glm/serve.pyindex 4026e12..1423b38 100644--- a/tools/glm/serve.py+++ b/tools/glm/serve.py@@ -21,6 +21,9 @@ from jinja2.sandbox import ImmutableSandboxedEnvironmentDEFAULT_MODEL = "~/models/glm53-exl3-td205"EH_SIDECAR_DEFAULT = "~/models/glm53-mtp-eh-proj-bf16.safetensors"+# Name inside the model folder. Not *.safetensors, so the weight loader never indexes it as model weights+# (same layout trick as uncensor_direction.st); the file is a normal safetensors file.+EH_SIDECAR_IN_PACK = "mtp_eh_proj.st"SPEED_ENV = {"EXL3_MOE_CFG": "2","EXL3_HIP_PREFILL_MIN_ROWS": "2",@@ -36,7 +39,7 @@ SPEED_ENV = {"EXL3_PREFILL_BIG_CHUNK_MAXPOS": "32768", # mem512k1: plain chunks beyond 32K depth, lower peak memory at 512K ctx# 27/09 acceptaudit2 WIN: unquantized MTP eh_proj (td205 stores it at 2 bpw, cos 0.79):# served accept +0.077 +- 0.008 (n=24), target ids 24/24 equal, serve_accept decode +4.8 %.- # The published pack does not ship the sidecar: it is optional (see apply_eh_sidecar_default()).+ # The pack ships the sidecar as mtp_eh_proj.st; loaded by default (see apply_eh_sidecar_default()).# 27/09 verifyfuse1 WIN: R-row verify linears in one launch (Hadamards in-kernel):# served R=2 round -3.04 +- 0.20 ms, +6.7 % t/s; R=1 bitwise, R=2 greedy 64/64."EXL3_VERIFY_FUSE": "1",@@ -70,23 +73,31 @@ SPEED_ENV = {"EXL3_PF_SKIP": "1",}-def apply_eh_sidecar_default() -> str:- """Use the optional unquantized MTP eh_proj sidecar only when it exists.+def apply_eh_sidecar_default(model_dir: str | None = None) -> str:+ """Pick the optional unquantized MTP eh_proj sidecar and log which source is used.- An explicit EXL3_MTP_EH_FP16 is never touched (a wrong path still fails loudly at load).- Otherwise the default path is used if the file is there, and the server starts without it- (one log line) if not: the sidecar only raises draft acceptance, it is not needed to run.- Returns the outcome: "explicit", "default" or "absent".+ Order: explicit EXL3_MTP_EH_FP16 (never touched; "0" = off; a wrong path still fails loudly at load)+ > EH_SIDECAR_IN_PACK inside the model folder > the old default path under ~/models > absent.+ The sidecar only raises draft acceptance, the server runs without it.+ Returns the source: "explicit", "pack", "default" or "absent"."""if "EXL3_MTP_EH_FP16" in os.environ:+ print(f"serve: MTP eh_proj sidecar: EXL3_MTP_EH_FP16={os.environ['EXL3_MTP_EH_FP16']} (explicit)", flush=True)return "explicit"+ if model_dir:+ path = Path(model_dir).expanduser() / EH_SIDECAR_IN_PACK+ if path.is_file():+ os.environ["EXL3_MTP_EH_FP16"] = str(path)+ print(f"serve: MTP eh_proj sidecar: {path} (model folder)", flush=True)+ return "pack"path = os.path.expanduser(EH_SIDECAR_DEFAULT)if os.path.isfile(path):os.environ["EXL3_MTP_EH_FP16"] = path+ print(f"serve: MTP eh_proj sidecar: {path} (default path)", flush=True)return "default"- print(f"serve: no MTP eh_proj sidecar at {EH_SIDECAR_DEFAULT}: running without it "- "(draft acceptance is a little lower). To add it: python tools/glm/mtp_eh_sidecar.py "- "<official GLM-5.3 checkpoint dir> <out.safetensors>, then set EXL3_MTP_EH_FP16=<out.safetensors>.",+ print(f"serve: MTP eh_proj sidecar: none ({EH_SIDECAR_IN_PACK} not in the model folder, nothing at "+ f"{EH_SIDECAR_DEFAULT}): running without it, draft acceptance is lower. To add it: python "+ "tools/glm/mtp_eh_sidecar.py <official GLM-5.3 checkpoint dir> <model folder>/" + EH_SIDECAR_IN_PACK,flush=True)return "absent"@@ -713,7 +724,7 @@ def main() -> None:for key, value in SPEED_ENV.items():os.environ.setdefault(key, value)os.environ.setdefault("EXL3_MOE_UNION_V2", "1")- apply_eh_sidecar_default()+ apply_eh_sidecar_default(args.model)engine = ResidentEngine(args.model, max_history=args.max_history or args.num_draft, max_ctx=args.max_ctx, num_draft=args.num_draft)template = Path(args.chat_template or Path(args.model) / "chat_template.jinja").expanduser().read_text(encoding="utf-8")print(mem_line("loaded"), flush=True)diff --git a/tools/glm/test_serve.py b/tools/glm/test_serve.pyindex dd0de16..c17a5e5 100644--- a/tools/glm/test_serve.py+++ b/tools/glm/test_serve.py@@ -33,26 +33,35 @@ def run(coro):class ServeTests(unittest.TestCase):template = "{% for m in messages %}<|im_start|>{{ m.role }}: {{ m.content }}<|im_end|>{% endfor %}{% if tools %}TOOLS={{ tools|length }}{% endif %}"- def test_eh_sidecar_default_is_optional(self):+ def test_eh_sidecar_source_order(self):import os, tempfilefrom unittest import mockwith tempfile.TemporaryDirectory() as home:+ pack = Path(home) / "pack"+ pack.mkdir()with mock.patch.dict(os.environ, {"HOME": home}):os.environ.pop("EXL3_MTP_EH_FP16", None)- # fresh install: no file -> variable stays unset, no FileNotFoundError at load- self.assertEqual(serve.apply_eh_sidecar_default(), "absent")+ # nothing anywhere: variable stays unset, no FileNotFoundError at load+ self.assertEqual(serve.apply_eh_sidecar_default(str(pack)), "absent")self.assertNotIn("EXL3_MTP_EH_FP16", os.environ)- # file present at the default path -> used- path = Path(home) / "models" / "glm53-mtp-eh-proj-bf16.safetensors"- path.parent.mkdir()- path.write_bytes(b"x")- self.assertEqual(serve.apply_eh_sidecar_default(), "default")- self.assertEqual(os.environ["EXL3_MTP_EH_FP16"], str(path))- # explicit value (even a missing file) is never touched- os.environ["EXL3_MTP_EH_FP16"] = "/nope/x.safetensors"- self.assertEqual(serve.apply_eh_sidecar_default(), "explicit")- self.assertEqual(os.environ["EXL3_MTP_EH_FP16"], "/nope/x.safetensors")+ # old default path only+ old = Path(home) / "models" / "glm53-mtp-eh-proj-bf16.safetensors"+ old.parent.mkdir()+ old.write_bytes(b"x")+ self.assertEqual(serve.apply_eh_sidecar_default(str(pack)), "default")+ self.assertEqual(os.environ["EXL3_MTP_EH_FP16"], str(old))+ # file in the model folder wins over the old path+ os.environ.pop("EXL3_MTP_EH_FP16")+ (pack / serve.EH_SIDECAR_IN_PACK).write_bytes(b"x")+ self.assertEqual(serve.apply_eh_sidecar_default(str(pack)), "pack")+ self.assertEqual(os.environ["EXL3_MTP_EH_FP16"], str(pack / "mtp_eh_proj.st"))+ # explicit value (even a missing file, even "0") is never touched+ for value in ("/nope/x.safetensors", "0"):+ os.environ["EXL3_MTP_EH_FP16"] = value+ self.assertEqual(serve.apply_eh_sidecar_default(str(pack)), "explicit")+ self.assertEqual(os.environ["EXL3_MTP_EH_FP16"], value)self.assertNotIn("EXL3_MTP_EH_FP16", serve.SPEED_ENV)+ self.assertFalse(serve.EH_SIDECAR_IN_PACK.endswith(".safetensors"))def test_stream_engine_error_still_ends_with_finish_reason(self):from aiohttp.test_utils import TestClient, TestServer