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
Merge public main b394b58
YanissAmz4f81d0bb6e33
diff --cc tools/glm/serve.pyindex 018d0f5,91e69d8..0c3d47c--- a/tools/glm/serve.py+++ b/tools/glm/serve.py@@@ -19,8 -19,8 +19,10 @@@ import aiohttfrom aiohttp import webfrom jinja2.sandbox import ImmutableSandboxedEnvironment+sys.path.append(str(Path(__file__).resolve().parent.parent))+import startup_health # noqa: E402 (GET /health with load progress while the model loads)+ # serve_metrics.py is a symlink to the shared tools/strix_halo/serve_metrics.py+ from serve_metrics import MetricsDEFAULT_MODEL = "~/models/glm53-exl3-td205"EH_SIDECAR_DEFAULT = "~/models/glm53-mtp-eh-proj-bf16.safetensors"@@@ -460,14 -456,26 +462,29 @@@ def prime_dense_tune(budget_s: float =def create_app(engine: Any, model_id: str, template: str) -> web.Application:"""Build the HTTP layer around a resident engine (also accepts a fake engine in tests)."""- queue: asyncio.Queue[tuple[dict[str, Any], asyncio.Queue]] = asyncio.Queue()+ queue: asyncio.Queue[tuple[dict[str, Any], asyncio.Queue, dict[str, Any]]] = asyncio.Queue()lock = asyncio.Lock() # serializes generation with slot save/restore+ processing = 0 # admitted requests; closure, app config is immutable after startupapp = web.Application(client_max_size=16 * 1024**2)- app.update(engine=engine, model_id=model_id, template=template, queue=queue)+ app.update(engine=engine, model_id=model_id, template=template, queue=queue, metrics=Metrics())++ def observe(st: dict[str, Any], prompt_tokens: int) -> None:+ # The MTP window is a fixed num_draft_tokens per round, so rounds = proposed / window+ # (exact except for a final window truncated by max_new_tokens). No generator -> no rounds.+ num_draft = int(getattr(getattr(engine, "greedy_generator", None), "num_draft_tokens", 0) or 0)+ accepted = int(st.get("accepted_draft_tokens", 0))+ rejected = int(st.get("rejected_draft_tokens", 0))+ proposed = accepted + rejected+ app["metrics"].observe(+ prompt_tokens=prompt_tokens, cached=int(st.get("cached_tokens", 0)),+ predicted=int(st.get("new_tokens", 0)),+ prefill_s=float(st.get("time_prefill") or 0.0), generate_s=float(st.get("time_generate") or 0.0),+ drafts=proposed // num_draft if proposed and num_draft else 0,+ draft_tokens=proposed, accepted=accepted)+ async def health(_: web.Request) -> web.Response:+ return web.json_response({"status": "ok", "source": "kyojin", "model": model_id})+async def models(_: web.Request) -> web.Response:return web.json_response({"object": "list", "data": [{"id": model_id, "object": "model", "created": 0, "owned_by": "local"}]})@@@ -767,8 -799,8 +808,9 @@@if getattr(engine, "slot_store", None) is not None:app.router.add_get("/slots", slots)app.router.add_post("/slots/{id}", slot_action)+ app.router.add_get("/health", health)app.router.add_get("/v1/models", models)+ app.router.add_get("/metrics", metrics_view)app.router.add_post("/v1/chat/completions", completions)app.router.add_post("/apply-template", apply_template)app.router.add_post("/completion", completion)diff --cc tools/mimo/SERVE.mdindex 7b8ed74,05d2d76..f9c2316--- a/tools/mimo/SERVE.md+++ b/tools/mimo/SERVE.md@@@ -40,43 -40,16 +40,49 @@@ top-level config does not carry `max_po`stop` (string or list), `temperature`, `top_p`, `max_completion_tokens` or `max_tokens` (the first wins; default 4096). A reply cut by the limit reports `finish_reason: "length"`. An engine failure mid-stream ends with an `error` frame, `finish_reason: "error"` and `[DONE]`. Tool calls are emitted onlyonce the XML block closes, so a client never sees half a JSON payload.- `GET /v1/models` — one entry, `MiMo-2.6-EXL3`.-- `GET /health` — `{"status","model","generator","spec_gate"}`; with the gate on, `spec_gate`+- `GET /health` — `{"status","model","generator","spec_gate"}` once ready (load progress while starting: see below); with the gate on, `spec_gate`carries the live counters `n_spec n_plain n_off n_shadow n_probe_fail t_plain t_spectok_round`. Useful while tuning.+ - `GET /metrics` — Prometheus text (llama.cpp `llamacpp:*` names) for scraping. Counters+ accumulate when a request completes; `requests_processing`, `requests_deferred` and+ `kv_cache_usage_ratio` are read live. `spec_decode_num_drafts_total` counts the engine's+ decode steps (one verification round each while speculating), an upper bound when+ `--spec-gate` falls back to plain. A request cancelled mid-stream is not counted in this+ first version.+## Start-up progress on `/health`++The port answers from the first second, while the model is still loading. `GET /health` returns `200 {"status":"ok","source":"kyojin"}`+(plus the fields listed above) when the server is ready, and while it loads:++```json+503 {"status": "loading", "source": "kyojin", "message": "Target weights, 40 % (stage 1 of 3)", "progress": 0.31, "stage": "target weights", "stage_index": 1, "stage_count": 3,+ "stage_progress": 0.4, "elapsed_s": 52.1, "eta_s": null, "progress_basis": "stages"}+```++Every `/health` reply carries `"source": "kyojin"` (a hint for parsers). While `status` is `loading`, `message` is one plain line for a UI, built from the other fields: stage, percent, "stage x of y", and "about N s left" when an ETA exists.++Stages here: drafter weights, target weights, engine setup (no drafter stage with `--no-dflash`). `stage_progress` is the share of modules loaded (or kernel keys tuned) and is `null` when a+stage cannot count its work. `progress` counts finished stages plus that share, with equal weights+(`progress_basis: "stages"`); once one start has completed, its stage durations are kept in+`~/.cache/kyojin/startup-mimo.json` (`KYOJIN_HEALTH_DIR` changes the folder) and later starts weigh the stages by+them (`"history"`) and report `eta_s`. Without a history `eta_s` is `null`: no estimate is made up. A failed load+answers `500 {"status":"error","message":...}` for a few seconds before the process exits. Every other path answers+`503 {"error":{"message":"Loading model",...}}` during the load, like llama.cpp. Nothing changes after READY, and+the `READY` line is the same. The helper is `tools/startup_health.py`, shared by the three servers.++llama-swap polls `checkEndpoint` (default `/health`, HTTP 200 = ready) until `healthCheckTimeout` runs out, so give it+room for a first start:++```yaml+healthCheckTimeout: 600 # seconds; a first start tunes kernels+models:+ "mimo":+ proxy: http://127.0.0.1:${PORT}+ checkEndpoint: /health+ cmd: python tools/mimo/serve.py --port ${PORT}+```+## SpecGate across mixed requests — decision**Kept, not reset per request** (the default). The gate holds no prompt content: only smootheddiff --cc tools/mimo/serve.pyindex f2f3503,d3e870e..b014699--- a/tools/mimo/serve.py+++ b/tools/mimo/serve.py@@@ -29,8 -28,8 +29,10 @@@ import aiohttfrom aiohttp import webfrom jinja2.sandbox import ImmutableSandboxedEnvironment+sys.path.append(str(Path(__file__).resolve().parent.parent))+import startup_health # noqa: E402 (GET /health with load progress while the model loads)+ # serve_metrics.py is a symlink to the shared tools/strix_halo/serve_metrics.py+ from serve_metrics import MetricsDEFAULT_MODEL = os.path.expanduser("~/models/mimo26-exl3")DEFAULT_MODEL_ID = "MiMo-2.6-EXL3"