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
Serve: no fixed reply budget by default, a reply may use the free context
YanissAmz10139091ff8f
diff --git a/tools/glm/SERVE.md b/tools/glm/SERVE.mdindex 212412a..2fe526a 100644--- a/tools/glm/SERVE.md+++ b/tools/glm/SERVE.md@@ -81,7 +81,7 @@ Honored:because the GLM template iterates them as a dict.- `tools` — passed to the template verbatim (no server-side validation).- `stream` (bool) — SSE or a single JSON body.-- `max_completion_tokens` or `max_tokens` (the first wins; default **32768**, thinking included; `--default-max-tokens`), `temperature` and+- `max_completion_tokens` or `max_tokens` (the first wins; default: all the free context, thinking included; `--default-max-tokens` sets a limit), `temperature` and`top_p` (default: the pack's `generation_config.json`, 1.0 and 0.95), `stop` (string or array; also fed to EXL3 as stop conditions).- `model` — must equal `--model-id` if present, else 400.- `clear_thinking` — forwarded to the template as a Jinja variable.diff --git a/tools/glm/serve.py b/tools/glm/serve.pyindex ca564fb..256615f 100644--- a/tools/glm/serve.py+++ b/tools/glm/serve.py@@ -116,7 +116,7 @@ TOOL_CLOSE = "</tool_call>"# The engine's own default stays greedy; the lane passes the model card's sampling.# Used when a request omits the field. main() replaces the sampling values with the pack's# generation_config.json (the model card's recommendation); command-line flags win over both.-SERVE_DEFAULTS: dict[str, Any] = {"temperature": 1.0, "top_p": 0.95, "reasoning_effort": "medium", "max_tokens": 32768}+SERVE_DEFAULTS: dict[str, Any] = {"temperature": 1.0, "top_p": 0.95, "reasoning_effort": "medium", "max_tokens": None}# The model's template (levels low, high, max) with a medium level added: the model's "high" plus one instruction line.DEFAULT_TEMPLATE = Path(__file__).resolve().parent.parent / "lanes" / "assets" / "glm53-template-medium.jinja"@@ -230,7 +230,7 @@ def token_limit(body: dict[str, Any], default: int | None = None) -> int:value = body.get(key)if isinstance(value, int) and not isinstance(value, bool) and value >= 1:return min(value, body.get("_room") or value)- default = default or SERVE_DEFAULTS["max_tokens"]+ default = default or SERVE_DEFAULTS["max_tokens"] or body.get("_room") or 32768 # unset: all the free contextreturn min(default, body.get("_room") or default)@@ -858,7 +858,7 @@ def main() -> None:parser.add_argument("--default-top-p", type=float, default=None,help="used when a request omits top_p (default: generation_config.json)")parser.add_argument("--default-max-tokens", type=int, default=None,- help="reply budget when a request omits max_tokens, thinking included (default 32768)")+ help="reply budget when a request omits max_tokens, thinking included (default: all the free context)")parser.add_argument("--default-reasoning-effort", choices=("low", "medium", "high", "max"), default=None,help="thinking effort when a request omits it (default: medium)")args = parser.parse_args()diff --git a/tools/mimo/SERVE.md b/tools/mimo/SERVE.mdindex c54de80..8c7e9c8 100644--- a/tools/mimo/SERVE.md+++ b/tools/mimo/SERVE.md@@ -39,7 +39,7 @@ top-level config does not carry `max_position_embeddings` — the GLM fix.- `POST /v1/chat/completions` — `stream: true` (SSE `chat.completion.chunk`) and `false`.`tools` / `tool_calls` / `tool` role messages, `reasoning_content` for `<think>` blocks,- `stop` (string or list), `temperature`, `top_p`, `max_completion_tokens` or `max_tokens` (the first wins; default 32768, thinking included; `--default-max-tokens`). 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 only+ `stop` (string or list), `temperature`, `top_p`, `max_completion_tokens` or `max_tokens` (the first wins; default: all the free context, thinking included; `--default-max-tokens` sets a limit). 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"}` once ready (load progress while starting: see below); with the gate on, `spec_gate`diff --git a/tools/mimo/serve.py b/tools/mimo/serve.pyindex 6c1ba24..0e5d6f7 100644--- a/tools/mimo/serve.py+++ b/tools/mimo/serve.py@@ -41,7 +41,7 @@ DEFAULT_NDT = 7# Used when a request omits the field. Agent clients often send no sampling at all, and plain greedy# makes the model loop: main() takes the values of the pack's generation_config.json (the model# card's recommendation); command-line flags win over both.-SERVE_DEFAULTS: dict[str, Any] = {"temperature": 1.0, "top_p": 0.95, "reasoning_effort": "medium", "max_tokens": 32768}+SERVE_DEFAULTS: dict[str, Any] = {"temperature": 1.0, "top_p": 0.95, "reasoning_effort": "medium", "max_tokens": None}# The model's own template plus a medium effort level (the model defines none).DEFAULT_TEMPLATE = Path(__file__).with_name("chat_template.jinja")@@ -217,7 +217,7 @@ def token_limit(body: dict[str, Any], default: int | None = None) -> int:value = body.get(key)if isinstance(value, int) and not isinstance(value, bool) and value >= 1:return min(value, body.get("_room") or value)- default = default or SERVE_DEFAULTS["max_tokens"]+ default = default or SERVE_DEFAULTS["max_tokens"] or body.get("_room") or 32768 # unset: all the free contextreturn min(default, body.get("_room") or default)@@ -810,7 +810,7 @@ def main() -> None:parser.add_argument("--default-top-p", type=float, default=None,help="used when a request omits top_p (default: generation_config.json)")parser.add_argument("--default-max-tokens", type=int, default=None,- help="reply budget when a request omits max_tokens, thinking included (default 32768)")+ help="reply budget when a request omits max_tokens, thinking included (default: all the free context)")parser.add_argument("--default-reasoning-effort", choices=("medium", "none"), default=None,help="medium (default) adds one effort instruction to the prompt; none leaves the model's own prompt")args = parser.parse_args()diff --git a/tools/qwen/SERVE.md b/tools/qwen/SERVE.mdindex 7eb071d..82fe624 100644--- a/tools/qwen/SERVE.md+++ b/tools/qwen/SERVE.md@@ -44,7 +44,7 @@ Quick test:| `--default-reasoning-effort` | `medium` | `low`, `medium` or `xhigh` || `--chat-template` | `tools/qwen/chat_template.jinja` | the model's template with a `medium` effort instruction added (the model's own leaves medium empty); `<model>/chat_template.jinja` is the unchanged one || `--no-thinking` | off | thinking off unless a request turns it on |-| `--default-max-tokens` | 32768 | when a request omits `max_tokens` (always clipped to the free context) |+| `--default-max-tokens` | free context | reply budget when a request omits `max_tokens`; unset, a reply may use all the context left || `--slot-save-path` | `~/cache/llama-slots` | directory for slot files || `--sessions` | 1 | requests decoded together; see below |diff --git a/tools/qwen/serve.py b/tools/qwen/serve.pyindex 1ffd6a1..e2f6276 100644--- a/tools/qwen/serve.py+++ b/tools/qwen/serve.py@@ -63,6 +63,7 @@ FALLBACK_DEFAULTS: dict[str, Any] = {"temperature": 1.0, "top_p": 0.95, "top_k":# Thinking effort when a request names none. The model's own template defines xhigh and low only;# chat_template.jinja next to this file is that template plus a medium level.DEFAULT_EFFORT = "medium"+NO_CTX_REPLY = 32768 # reply budget when the engine reports no context lengthDEFAULT_TEMPLATE = Path(__file__).with_name("chat_template.jinja")# OpenAI effort names -> the Qwen template names (xhigh, medium, low).EFFORT_ALIASES = {"high": "xhigh", "minimal": "low"}@@ -1172,7 +1173,7 @@ ROUTES = {"/health": ("GET",), "/v1/models": ("GET",), "/slots": ("GET",), "/v1/def create_app(engine: Any, model_id: str, template: str, defaults: dict[str, Any] | None = None,- default_max_tokens: int = 32768) -> web.Application:+ default_max_tokens: int | None = None) -> web.Application:"""HTTP layer around a resident engine (also accepts a fake engine in tests)."""defaults = defaults or load_defaults("/nonexistent")queue: asyncio.Queue = asyncio.Queue()@@ -1279,10 +1280,10 @@ def create_app(engine: Any, model_id: str, template: str, defaults: dict[str, Anmax_tokens = body.get("max_tokens")if max_tokens is not None and (not isinstance(max_tokens, int) or isinstance(max_tokens, bool) or max_tokens < 1):raise BadRequest("max_tokens must be a positive integer")- room = reply_room(ctx, prompt_tokens, draft_window(engine, body.get("speculative", True) is not False)) if ctx else default_max_tokens+ room = reply_room(ctx, prompt_tokens, draft_window(engine, body.get("speculative", True) is not False)) if ctx else (default_max_tokens or NO_CTX_REPLY)if room < 1:raise BadRequest(f"context length exceeded: prompt is {prompt_tokens} tokens, the server context is {ctx}")- max_tokens = min(max_tokens or default_max_tokens, room)+ max_tokens = min(max_tokens or default_max_tokens or room, room)seed = body.get("seed")if seed is not None and (not isinstance(seed, int) or isinstance(seed, bool)):raise BadRequest("seed must be an integer")@@ -1744,7 +1745,8 @@ def main() -> None:parser.add_argument("--default-reasoning-effort", choices=("low", "medium", "xhigh"), default=None,help=f"thinking effort when a request omits it (default: {DEFAULT_EFFORT})")parser.add_argument("--no-thinking", action="store_true", help="thinking off unless a request turns it on")- parser.add_argument("--default-max-tokens", type=int, default=32768, help="when a request omits max_tokens")+ parser.add_argument("--default-max-tokens", type=int, default=None,+ help="reply budget when a request omits max_tokens (default: all the free context)")parser.add_argument("--slot-save-path", default="~/cache/llama-slots")parser.add_argument("--sessions", type=int, default=1,help="requests decoded together (default 1: one at a time, in order). Every session reserves the "