Dashboard: a reasoning chooser, offering only what the model accepts
Reasoning effort isn't a backend flag -- vLLM's --reasoning-parser only parses
the output. It's a chat-template kwarg read per request, and the models differ:
Qwen3.8 27B's template takes enable_thinking plus reasoning_effort in
('low','medium','xhigh') and raises on anything else, while Ornith 1.5 9B takes
only enable_thinking. Note 'xhigh', not OpenAI's 'high'.
So the chooser is built from what the loaded model's own template actually reads
(hfcache.template_controls), with the level names from the catalog, which is the
part that can't be inferred -- a level the template doesn't know would make it
raise, so an undeclared or unreadable one is never offered or sent.
The proxy injects the setting into chat completions, with a key the client set
itself always winning, the same precedence mlx_lm gives its own
--chat-template-kwargs. Reading it from config per request (mtime-cached) means
the dashboard changes it with no restart, so the model stays loaded -- the
startup flag would have cost a full reload per change.
vLLM gets no control: llm-host runs it without a proxy, so there is nothing in
the path to inject the kwarg. The panel hides itself rather than pretend.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
944eda06cc
commit
623d093b81
6 changed files with 395 additions and 44 deletions
|
|
@ -22,10 +22,25 @@ import time
|
|||
from collections import deque
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
|
||||
from .. import paths
|
||||
from .. import hfcache, paths, plan
|
||||
|
||||
RECENT_RUNS = 50 # completed requests kept for the dashboard's summary
|
||||
|
||||
_cfg_cache = {"mtime": None, "cfg": {}}
|
||||
|
||||
|
||||
def live_cfg():
|
||||
"""config.json, re-read when it changes. The reasoning setting is edited from the
|
||||
dashboard while this process runs, and it must take effect without a restart --
|
||||
a restart would unload the model, which is the whole thing we're avoiding."""
|
||||
try:
|
||||
mtime = paths.CONFIG_FILE.stat().st_mtime
|
||||
except OSError:
|
||||
return _cfg_cache["cfg"]
|
||||
if mtime != _cfg_cache["mtime"]:
|
||||
_cfg_cache["mtime"], _cfg_cache["cfg"] = mtime, paths.load_config()
|
||||
return _cfg_cache["cfg"]
|
||||
|
||||
VENV = paths.DATA / "venv-mlx"
|
||||
PY = VENV / "bin/python"
|
||||
|
||||
|
|
@ -148,7 +163,7 @@ def _uncached(usage):
|
|||
return max(n - int(cached), 0)
|
||||
|
||||
|
||||
def make_handler(inner_port, served_name, context, key, stats, aliases=()):
|
||||
def make_handler(inner_port, served_name, context, key, stats, aliases=(), reasoning=None):
|
||||
# Names a client may call the loaded model: its llm-host name and its repo id.
|
||||
accepted = {served_name.lower(), *(a.lower() for a in aliases if a)}
|
||||
|
||||
|
|
@ -226,6 +241,17 @@ def make_handler(inner_port, served_name, context, key, stats, aliases=()):
|
|||
if isinstance(body, dict):
|
||||
if self.path.startswith("/v1/") and not self._model_ok(body):
|
||||
return
|
||||
# Server-side reasoning default. Only chat completions go through a
|
||||
# chat template, and a key the client set itself always wins -- the
|
||||
# same precedence mlx_lm applies to its own --chat-template-kwargs.
|
||||
if reasoning and "chat/completions" in self.path:
|
||||
kw = reasoning()
|
||||
if kw:
|
||||
mine = dict(kw)
|
||||
theirs = body.get("chat_template_kwargs")
|
||||
if isinstance(theirs, dict):
|
||||
mine.update(theirs)
|
||||
body["chat_template_kwargs"] = mine
|
||||
# Force the preloaded model: mlx_lm would otherwise try to load a
|
||||
# model matching the name it's given.
|
||||
body["model"] = "default_model"
|
||||
|
|
@ -401,10 +427,19 @@ def run_server(cfg, entry, choice, args):
|
|||
inner = port + 1
|
||||
# Claim the public port first: if it's taken, fail before starting (and orphaning) a child.
|
||||
stats = Stats()
|
||||
# The template is fixed for this process, so read its knobs once; the chosen level is
|
||||
# read per request, since the dashboard can change it while we run.
|
||||
controls = hfcache.template_controls(choice["repo"])
|
||||
|
||||
def reasoning():
|
||||
value = (live_cfg().get("reasoning") or {}).get(entry["name"])
|
||||
return plan.reasoning_kwargs(value, entry, controls)
|
||||
|
||||
try:
|
||||
srv = ThreadingHTTPServer(("0.0.0.0", port),
|
||||
make_handler(inner, entry["name"], choice.get("est_context", entry["context"]),
|
||||
paths.api_key(), stats, aliases=(choice.get("repo"),)))
|
||||
paths.api_key(), stats, aliases=(choice.get("repo"),),
|
||||
reasoning=reasoning))
|
||||
except OSError as e:
|
||||
print(f"llm-host: can't listen on port {port} ({e.strerror}). Another program is using it; "
|
||||
f"pick a free port with: llmhost setup --api-port <port>", flush=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue