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
|
|
@ -63,6 +63,15 @@ h1 span { color: var(--muted); font-weight: 500; }
|
|||
}
|
||||
.loadline b { color: var(--warn); font-family: system-ui, sans-serif; margin-right: 6px; }
|
||||
.btns { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
|
||||
.effort { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
|
||||
.effort .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
|
||||
.effort .row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
|
||||
.effort select {
|
||||
background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
|
||||
padding: 6px 10px; font: inherit; font-size: 13px; min-width: 150px;
|
||||
}
|
||||
.effort select:disabled { color: var(--muted); }
|
||||
.effort .s { color: var(--muted); font-size: 12px; margin-top: 7px; line-height: 1.45; }
|
||||
button {
|
||||
font: inherit; font-size: 13px; font-weight: 550; padding: 7px 13px; border-radius: 8px; cursor: pointer;
|
||||
border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
|
||||
|
|
@ -171,6 +180,15 @@ pre {
|
|||
<div class="repo" id="cur-repo"></div>
|
||||
<div class="hwline" id="hwline"></div>
|
||||
<div class="loadline" id="loadline"><b id="load-title">Loading</b><span id="load-text"></span></div>
|
||||
<div class="effort" id="effort" hidden>
|
||||
<div class="k">Reasoning</div>
|
||||
<div class="row">
|
||||
<select id="effort-sel"></select>
|
||||
<span class="meta" id="effort-state"></span>
|
||||
</div>
|
||||
<div class="s" id="effort-note"></div>
|
||||
</div>
|
||||
|
||||
<div class="btns">
|
||||
<button id="btn-restart">Restart</button>
|
||||
<button id="btn-stop" class="danger">Stop</button>
|
||||
|
|
@ -411,8 +429,58 @@ function render(s) {
|
|||
chart("c-power", h.map((p) => p.power), "var(--c5)", plim, (v) => Math.round(v) + " W");
|
||||
}
|
||||
renderRuns(s);
|
||||
renderEffort(s);
|
||||
}
|
||||
|
||||
let effortBusy = false;
|
||||
|
||||
function renderEffort(s) {
|
||||
const r = s.reasoning || {}, box = $("effort"), sel = $("effort-sel");
|
||||
const opts = r.options || [];
|
||||
// Hidden rather than disabled when there is nothing to choose: on vLLM there's no proxy
|
||||
// to inject the kwarg, and a model whose template has no switches has nothing to offer.
|
||||
box.hidden = !opts.length && !r.why;
|
||||
if (!opts.length) {
|
||||
sel.innerHTML = "";
|
||||
sel.disabled = true;
|
||||
$("effort-state").textContent = "";
|
||||
$("effort-note").textContent = r.why || "";
|
||||
return;
|
||||
}
|
||||
if (effortBusy) return;
|
||||
const want = opts.map((o) => o.value).join("|");
|
||||
if (sel.dataset.sig !== want) {
|
||||
sel.dataset.sig = want;
|
||||
sel.innerHTML = "";
|
||||
for (const o of opts) {
|
||||
const el = document.createElement("option");
|
||||
el.value = o.value;
|
||||
el.textContent = o.label;
|
||||
sel.append(el);
|
||||
}
|
||||
}
|
||||
sel.value = r.value || "default";
|
||||
sel.disabled = s.phase !== "ready";
|
||||
$("effort-state").textContent = s.phase === "ready" ? "" : "available once the model is ready";
|
||||
$("effort-note").textContent = "Applies to requests that don't set their own; takes effect "
|
||||
+ "on the next request, with no reload.";
|
||||
}
|
||||
|
||||
$("effort-sel").onchange = async (e) => {
|
||||
const value = e.target.value;
|
||||
effortBusy = true;
|
||||
try {
|
||||
await api("/api/reasoning", { method: "POST", body: JSON.stringify({ value }) });
|
||||
const opt = e.target.selectedOptions[0];
|
||||
toast(`Reasoning: ${opt ? opt.textContent : value}`);
|
||||
} catch (err) {
|
||||
toast("Couldn't change reasoning");
|
||||
} finally {
|
||||
effortBusy = false;
|
||||
poll();
|
||||
}
|
||||
};
|
||||
|
||||
function renderRuns(s) {
|
||||
const runs = s.runs || [], body = $("runs-body"), foot = $("runs-foot");
|
||||
$("runs-empty").hidden = runs.length > 0;
|
||||
|
|
|
|||
|
|
@ -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