Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
sycl: OpenAI logprobs on /v1/chat/completions (engine LP lines + server_intel)
maxfridbe835d30b186ac
diff --git a/docs/INTEL.md b/docs/INTEL.mdindex f29eb4a68..72bb6d1b0 100644--- a/docs/INTEL.md+++ b/docs/INTEL.md@@ -344,6 +344,15 @@ with `--stream-experts` there is no host copy of the experts, so any expert leftand computed on the CPU whenever it is routed. At 1,536 MiB the cache came up 128 experts short and decode fell to5-10 tok/s; 1,024 MiB fits all 12,288 with 2 GB of VRAM still free.+**Logprobs (2026-10-02).** `/v1/chat/completions` takes OpenAI's `"logprobs": true` and `"top_logprobs": 0..20`,+streamed or not, through `sycl/serve/server_intel.py`; the reply carries `choices[0].logprobs.content[]` (`token`,+`logprob`, `bytes`, `top_logprobs`), and with thinking on the thinking tokens under `reasoning_content`. The engine+(the port only) gets `logprobs=K` on its GEN line and writes an `LP logprob id:logprob ...` line after each `T`+line, from the verify window's head logits - the distribution the token was taken from, before temperature,+penalties and sampling. Upstream's server ignores the lines, and an engine never asked writes none. Each token+costs one 1 MB logits row copy when asked. Measured (IQ2_XS, "capital of France"): "Paris" at -0.0019 (p 0.998), the+same answer and no measurable time without it. Not on `/v1/completions` or the Anthropic endpoint yet.+**The Monitor tab on Intel.** `sycl/serve/server_intel.py` is `serve/server.py` with two additions made at runtime:diff --git a/sycl/serve/server_intel.py b/sycl/serve/server_intel.pyindex 819a5c2c4..7a4c7cc5d 100644--- a/sycl/serve/server_intel.py+++ b/sycl/serve/server_intel.py@@ -8,10 +8,15 @@ upstream merges stay clean); this wrapper adds, at run time:- the Monitor tab's GPU readings on an Intel Arc (sycl/serve/xe_telemetry.py) when no NVIDIA card answers;- a model menu in the web app's header, for a host that swaps models on one GPU: the config names the RPC thatdoes the swap as "model_switcher" (it takes {"mode": m} and answers {"mode", "up", "starting", "choices",- "urls"}); the menu offers the models served on this server's port. Without that key nothing changes.+ "urls"}); the menu offers the models served on this server's port. Without that key nothing changes;+ - OpenAI `logprobs` / `top_logprobs` on /v1/chat/completions (streamed or not): the engine (the SYCL port,+ `logprobs=K` on its GEN line) writes an `LP` line after each `T` line, which upstream's server would ignore.+ The values are the model's log-probabilities from the verify window's logits, before sampling, temperature and+ penalties; with thinking on, the thinking tokens are listed too (in order, under `reasoning_content`)."""from __future__ import annotations+import collectionsimport jsonimport sysimport urllib.parse@@ -126,7 +131,112 @@ def install_switcher(argv):S.make_handler = make+def install_logprobs():+ """`LP` lines next to their tokens, the request's `logprobs` to the engine, OpenAI's `logprobs` in the reply."""+ Eng = S.StrataEngine++ def _pump(self): # serve/server.py's StrataEngine._pump, plus: an LP line goes beside its token, not in the queue+ proc, lines = self.proc, self.lines+ lp = self.__dict__.setdefault("lp_lines", collections.deque())+ last_t = None+ for line in proc.stdout:+ if line.startswith("LP "):+ lp.append((last_t, line))+ continue+ if line.startswith("T "):+ try:+ last_t = int(line[2:])+ except ValueError:+ last_t = None+ lines.put(line)+ if self.proc is proc:+ self.ended = True+ lines.put(None)+ Eng._pump = _pump++ keys = Eng.sampling_keys++ def sampling_keys(sampling):+ k = top_logprobs(sampling or {})+ return keys(sampling) + (f" logprobs={k}" if k is not None else "")+ Eng.sampling_keys = staticmethod(sampling_keys)++ generate = Eng.generate++ def gen(self, *a, **kw):+ self.__dict__.setdefault("lp_lines", collections.deque()).clear() # this request's lines only+ return generate(self, *a, **kw)+ Eng.generate = gen++ def entry(tok, t, line):+ f = line.split()+ if len(f) < 2 or f[1] == "nan":+ return None++ def item(i, lp):+ b = tok.token_bytes(i) if hasattr(tok, "token_bytes") else tok.decode([i]).encode()+ return {"token": b.decode("utf-8", "replace"), "logprob": lp, "bytes": list(b)}+ e = item(t, float(f[1])) if t is not None else {"token": "", "logprob": float(f[1]), "bytes": []}+ e["top_logprobs"] = [item(int(i), float(v)) for i, _, v in (x.partition(":") for x in f[2:])]+ return e++ chunks = S.openai_chunks++ def openai_chunks(svc, req, *a, **kw):+ if top_logprobs(req) is None:+ yield from chunks(svc, req, *a, **kw)+ return+ eng = svc.engine+ for c in chunks(svc, req, *a, **kw):+ lp = getattr(eng, "lp_lines", None)+ if c and c.get("choices") and lp:+ got = []+ while lp:+ t, line = lp.popleft()+ if t in svc.stop_ids: # the stop token ends the reply; OpenAI does not list it+ continue+ e = entry(svc.tok, t, line)+ if e is not None:+ got.append(e)+ if got:+ d = c["choices"][0].get("delta") or {}+ key = "reasoning_content" if d.get("reasoning_content") and not d.get("content") else "content"+ c["choices"][0]["logprobs"] = {key: got}+ yield c+ S.openai_chunks = openai_chunks++ collect = S.openai_collect++ def openai_collect(cs):+ merged = {"content": [], "reasoning_content": []}++ def tap():+ for c in cs:+ if c and c.get("choices") and c["choices"][0].get("logprobs"):+ for k, v in c["choices"][0]["logprobs"].items():+ merged[k].extend(v)+ yield c+ out = collect(tap())+ if merged["content"] or merged["reasoning_content"]:+ out["choices"][0]["logprobs"] = {k: v for k, v in merged.items() if v} | {"content": merged["content"]}+ return out+ S.openai_collect = openai_collect+++def top_logprobs(req: dict):+ """The K for the engine's logprobs=K, or None when the request did not ask (OpenAI: logprobs=true, top_logprobs+ 0..20; the legacy completions form, logprobs=N, is taken as N)."""+ lp = req.get("logprobs")+ if lp is True:+ k = req.get("top_logprobs")+ return max(0, min(20, int(k))) if isinstance(k, int) and not isinstance(k, bool) else 0+ if isinstance(lp, int) and not isinstance(lp, bool) and lp >= 0:+ return min(20, lp)+ return None++if __name__ == "__main__":install_xe_reader()install_switcher(sys.argv[1:])+ install_logprobs()sys.exit(S.main())diff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cppindex 9f3389091..b683d3693 100644--- a/sycl/src/program/generate.cpp+++ b/sycl/src/program/generate.cpp@@ -5421,6 +5421,10 @@ int main(int argc, char **argv) try {float req_min_p = 0.0f, req_penalty_repeat = 1.0f, req_penalty_freq = 0.0f, req_penalty_present = 0.0f;int req_penalty_last_n = 0;int req_cvec = 1; // cvec=0|1: a loaded control vector for this request (on when absent)+ // SYCL port: logprobs=K (0..20) - after each "T id" an "LP logprob id:logprob ..." line with the token's+ // log-probability and the K most likely tokens', from the verify window's head logits (before sampling,+ // penalties and temperature). -1 (absent): no LP lines; a server that does not ask never sees one.+ int req_logprobs = -1;// tuning keys (setup's calibration measures settings without restarting the engine): the PCIe share of// the missed experts and the draft-probability floor, for this request onlydouble req_pcie_frac = o.pcie_frac, req_spec_min_p = o.spec_min_p;@@ -5446,6 +5450,7 @@ int main(int argc, char **argv) try {else if (key == "penalty_freq") req_penalty_freq = fv;else if (key == "penalty_present") req_penalty_present = fv;else if (key == "seed") req_seed = std::strtoull(tok.c_str() + eq + 1, nullptr, 10);+ else if (key == "logprobs") req_logprobs = std::clamp(std::atoi(tok.c_str() + eq + 1), -1, 20);else if (key == "pcie_frac") req_pcie_frac = std::clamp((double) fv, 0.0, 1.0);else if (key == "spec_min_p") req_spec_min_p = std::clamp((double) fv, 0.0, 1.0);// unknown keys are skipped: the ids start at the first token without '='@@ -6144,6 +6149,30 @@ int main(int argc, char **argv) try {bool eos = false;for (int i = 0; i <= a && produced_n < max_new && !eos; ++i) {std::printf("T %d\n", (int) outv[(size_t) i]);+ if (req_logprobs >= 0) { // row i of this window's head logits is the distribution token i came from+ static std::vector<float> lrow;+ static std::vector<int32_t> lord;+ lrow.resize((size_t) ver.vocab());+ if (!ver.copy_logits(i, lrow.data())) {+ std::printf("LP nan\n");+ } else {+ float mx = -INFINITY;+ for (const float v : lrow) mx = std::max(mx, v);+ double se = 0.0;+ for (const float v : lrow) se += std::exp((double) v - mx);+ const double lse = (double) mx + std::log(se);+ std::printf("LP %.6f", (double) lrow[(size_t) outv[(size_t) i]] - lse);+ if (req_logprobs > 0) {+ lord.resize(lrow.size());+ for (size_t v = 0; v < lrow.size(); ++v) lord[v] = (int32_t) v;+ std::partial_sort(lord.begin(), lord.begin() + req_logprobs, lord.end(),+ [&](int32_t x1, int32_t x2) { return lrow[(size_t) x1] > lrow[(size_t) x2]; });+ for (int j = 0; j < req_logprobs; ++j)+ std::printf(" %d:%.6f", lord[(size_t) j], (double) lrow[(size_t) lord[(size_t) j]] - lse);+ }+ std::printf("\n");+ }+ }strata::core::progress_beat();++produced_n;if (o.suffix_draft > 0) sfx.append(outv[(size_t) i]);