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.

Merge main into feature/health-progress

YanissAmz59edc80a5667
diff --cc tools/qwen/SERVE.md
index a14a3dc,716ff6e..3357c36
--- a/tools/qwen/SERVE.md
+++ b/tools/qwen/SERVE.md
@@@ -80,41 -81,8 +81,41 @@@ environment wins. The engine modules re
template, one prompt, one choice (`n`, `best_of`, `echo` answer 400). The slot routes are CPU-tested only.
- Debug extensions (all optional): `"speculative": false` decodes plain for that request, `"cache_prompt": false`
forgets the prompt cache first (cold run), `"return_token_ids": true` adds the generated ids. Switching
- speculative mode or `cache_prompt: false` rebuilds the Generator and so drops the prompt cache.
+ speculative mode or `cache_prompt: false` rebuilds the Generator and so drops the prompt cache (400 with `--sessions` > 1).
+## 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 4)", "progress": 0.31, "stage": "target weights", "stage_index": 1, "stage_count": 5,
+ "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: target weights, drafter weights, vision tower, engine setup, warm-up (the vision stage is absent with `--no-vision`, the drafter with `--draft-policy off`). `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-qwen.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: 300 # seconds; a first start tunes kernels
+models:
+ "qwen":
+ proxy: http://127.0.0.1:${PORT}
+ checkEndpoint: /health
+ cmd: python tools/qwen/serve.py --port ${PORT}
+```
+
## Prompt cache between turns
The Generator keeps KV pages (256 tokens) and GDN recurrent checkpoints in RAM (4 GiB, about 111 MiB each). A follow-up
diff --cc tools/qwen/serve.py
index 5ad2b68,30ab5b0..05e7476
--- a/tools/qwen/serve.py
+++ b/tools/qwen/serve.py
@@@ -1510,27 -1673,6 +1679,27 @@@ def create_app(engine: Any, model_id: s
# ---------------------------------------------------------------------------- main
+def load_all(args: argparse.Namespace):
+ """Everything before the port opens: template, defaults, engine, slot store, warm-up."""
+ model_dir = str(Path(args.model).expanduser())
+ template = (Path(model_dir) / "chat_template.jinja").read_text(encoding="utf-8")
+ defaults = load_defaults(model_dir, args)
+ t0 = time.time()
- print(f"qserve: starting, model={model_dir} ctx={args.ctx} draft_policy={args.draft_policy} "
++ print(f"qserve: starting, model={model_dir} ctx={args.ctx} sessions={args.sessions} draft_policy={args.draft_policy} "
+ f"defaults={ {k: v for k, v in defaults.items() if v is not None} }", flush=True)
+ engine = QwenEngine(model_dir, args.ctx, ndt=args.ndt, draft_policy=args.draft_policy, vision=not args.no_vision,
- cache_bits=args.cache_bits)
++ cache_bits=args.cache_bits, sessions=args.sessions)
+ env = {k: v for k, v in sorted(os.environ.items()) if k.startswith(("EXL3_", "MPW"))}
+ print(f"qserve: effective env {env}", flush=True)
+ from exllamav3.generator.slot_store import SlotStore
+ engine.slot_store = SlotStore(engine.generator, [c for c in (engine.cache, engine.draft_cache) if c is not None],
+ args.slot_save_path, args.model_id)
+ startup_health.stage("warm-up")
+ with Heartbeat("warm-up (first decode steps)"):
+ engine.warmup()
+ return engine, template, defaults, model_dir, t0
+
+
def main() -> None:
parser = argparse.ArgumentParser(allow_abbrev=False, description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
@@@ -1573,10 -1736,8 +1757,10 @@@
async def serve() -> None:
runner = web.AppRunner(app)
await runner.setup()
- await web.TCPSite(runner, args.host, args.port).start()
+ sock = startup_health.finish() # the early listener's open socket: no refused connection
+ site = web.SockSite(runner, sock) if sock is not None else web.TCPSite(runner, args.host, args.port)
+ await site.start()
- print(f"qserve: READY on http://{args.host}:{args.port} model={args.model_id} ctx={args.ctx} "
+ print(f"qserve: READY on http://{args.host}:{args.port} model={args.model_id} ctx={args.ctx} sessions={args.sessions} "
f"speculative={engine.spec_on} vision={engine.supports_vision} (start-up {time.time() - t0:.0f} s)",
flush=True)
await asyncio.Event().wait()