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
|
|
@ -13,7 +13,7 @@ from collections import deque
|
|||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
from pathlib import Path
|
||||
|
||||
from .. import hfcache, hw, opencode, paths, service
|
||||
from .. import hfcache, hw, opencode, paths, plan, service
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
SAMPLE_SECONDS = 2
|
||||
|
|
@ -223,6 +223,7 @@ class Sampler:
|
|||
|
||||
dl = self.downloaded()
|
||||
models = [{**m, "downloaded": dl.get(m["repo"], False)} for m in cfg.get("models", [])]
|
||||
reasoning = self.reasoning_state(cfg, active)
|
||||
|
||||
with self.lock:
|
||||
self.history.append(point)
|
||||
|
|
@ -256,6 +257,7 @@ class Sampler:
|
|||
"hardware": cfg.get("hardware_name"), "budget_gib": cfg.get("budget_gib"),
|
||||
"active": active, "served_models": served, "models": models,
|
||||
"excluded": cfg.get("excluded", []), "gpu": gpu, "last_log": last_log,
|
||||
"reasoning": reasoning,
|
||||
"action": self.action,
|
||||
"metrics": {
|
||||
"running": metrics.get("running"), "waiting": metrics.get("waiting"),
|
||||
|
|
@ -277,6 +279,42 @@ class Sampler:
|
|||
"runs": list(self.runs)[::-1],
|
||||
}
|
||||
|
||||
def reasoning_state(self, cfg, active):
|
||||
"""What the active model can be told about reasoning, and what it's set to.
|
||||
Only MLX: on vLLM llm-host has no proxy in front, so nothing here could inject
|
||||
the kwarg into a client's request."""
|
||||
choice = next((m for m in cfg.get("models", []) if m["name"] == active), None)
|
||||
if not choice or cfg.get("backend") != "mlx":
|
||||
return {"options": [], "value": plan.DEFAULT, "why": "" if choice else None}
|
||||
entry = next((m for m in paths.load_catalog()["models"] if m["name"] == active), None)
|
||||
if not entry:
|
||||
return {"options": [], "value": plan.DEFAULT, "why": None}
|
||||
if not hfcache.repo_dir(choice["repo"]).exists():
|
||||
return {"options": [], "value": plan.DEFAULT,
|
||||
"why": "the model isn't downloaded yet, so its chat template can't be read"}
|
||||
controls = hfcache.template_controls(choice["repo"])
|
||||
opts = plan.reasoning_options(entry, choice, controls)
|
||||
value = (cfg.get("reasoning") or {}).get(active) or plan.DEFAULT
|
||||
if value not in [v for v, _ in opts]:
|
||||
value = plan.DEFAULT
|
||||
why = "" if opts else "this model's chat template exposes no reasoning controls"
|
||||
return {"options": [{"value": v, "label": l} for v, l in opts], "value": value, "why": why}
|
||||
|
||||
def set_reasoning(self, value):
|
||||
"""Takes effect on the next request -- no restart, so the model stays loaded."""
|
||||
cfg = paths.load_config()
|
||||
active = cfg.get("active")
|
||||
allowed = [o["value"] for o in self.reasoning_state(cfg, active)["options"]]
|
||||
if value not in allowed:
|
||||
return False, allowed
|
||||
cfg.setdefault("reasoning", {})[active] = value
|
||||
paths.save_config(cfg)
|
||||
self.cfg = cfg
|
||||
with self.lock:
|
||||
if self.state.get("reasoning"):
|
||||
self.state["reasoning"]["value"] = value
|
||||
return True, allowed
|
||||
|
||||
def snapshot(self):
|
||||
with self.lock:
|
||||
s = dict(self.state)
|
||||
|
|
@ -360,6 +398,12 @@ def make_handler(sampler, key):
|
|||
return self.send_json(400, {"error": f"unknown model {name!r}"})
|
||||
sampler.control("switch", name)
|
||||
return self.send_json(202, {"ok": True, "model": name})
|
||||
if path == "/api/reasoning":
|
||||
ok, allowed = sampler.set_reasoning(str(data.get("value", "")))
|
||||
if not ok:
|
||||
return self.send_json(400, {"error": "unsupported value for this model",
|
||||
"allowed": allowed})
|
||||
return self.send_json(200, {"ok": True, "value": data.get("value")})
|
||||
if path in ("/api/stop", "/api/start", "/api/restart"):
|
||||
sampler.control(path.rsplit("/", 1)[1])
|
||||
return self.send_json(202, {"ok": True})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue