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++
serve: a request handed from a batch slot back to the solo path keeps the slot leg's decode time and tokens (#1869); timings.prompt_n is what the engine read, the rest is cache_n (#1870)
Niko12210636c4642f29
diff --git a/serve/server.py b/serve/server.pyindex a9deb0adc..92fb783fa 100644--- a/serve/server.py+++ b/serve/server.py@@ -1255,6 +1255,7 @@ class StrataEngine:pending: list[int] = []prompt, left = list(ids), int(max_new)reused0 = None # the first read's reused tokens: a continued leg's count includes this request's own output+ carry = {} # #1869: the figures of the legs that ended in a hand-back to the solo path (the final DONE adds to them)ok = yield from self._take_control(cancel, len(prompt))if not ok:return@@ -1453,6 +1454,7 @@ class StrataEngine:and not (out and out[-1] in EOS_IDS)):# the solo path continues it: the engine copies the slot's sessions back (all but the# last token are in them) and decodes with MTP drafts again+ carry_leg(carry, self.last) # #1869: the solo path's DONE replaces these figuresself.slot_live[slot] = Noneself.slot_used[slot] = time.time()with self.slot_cv:@@ -1486,6 +1488,8 @@ class StrataEngine:passif reused0 is not None and isinstance(self.last, dict):self.last = {**self.last, "reused": reused0}+ if carry and isinstance(self.last, dict):+ self.last = add_carry(carry, self.last)if holding:self.ctl.release()if admit_wait:@@ -4036,6 +4040,27 @@ def prompt_tokens_seen(prompt_tokens: int, last: dict) -> int:return min(prompt_tokens, int(last.get("reused") or 0) + int(read))+def carry_leg(carry: dict, leg: dict) -> None:+ """#1869: a request that decoded in a batch slot and went back to the solo path ends with the solo path's DONE, which+ replaces the engine's figures: keep the slot leg's decode time, tokens and prompt figures to add to it."""+ carry["decode_ms"] = carry.get("decode_ms", 0.0) + float(leg.get("decode_ms") or 0.0)+ carry["generated"] = carry.get("generated", 0) + int(leg.get("generated") or 0)+ carry.setdefault("prompt_ms", float(leg.get("prompt_ms") or 0.0))+ if leg.get("prompt_read") is not None:+ carry.setdefault("prompt_read", int(leg["prompt_read"]))+++def add_carry(carry: dict, last: dict) -> dict:+ """The request's totals: the earlier legs' decode time and tokens plus the final one's; the prompt figures of the leg+ that read the prompt (the solo continuation reads next to nothing)."""+ out = {**last, "decode_ms": float(last.get("decode_ms") or 0.0) + carry.get("decode_ms", 0.0),+ "generated": int(last.get("generated") or 0) + carry.get("generated", 0),+ "prompt_ms": max(float(last.get("prompt_ms") or 0.0), carry.get("prompt_ms", 0.0))}+ if "prompt_read" in carry:+ out["prompt_read"] = carry["prompt_read"]+ return out++def request_timings(prompt_tokens: int, generated: int, last: dict) -> dict | None:"""One request's `timings` in llama.cpp's names (what its clients show as speed), from the engine's own clock(StrataEngine.last): prompt_n is what was read, cache_n what the conversation cache already held. None when the@@ -4043,6 +4068,10 @@ def request_timings(prompt_tokens: int, generated: int, last: dict) -> dict | Noif last.get("prompt_ms") is None:return Nonecache_n = int(last.get("reused") or 0)+ if last.get("prompt_read") is not None and last.get("finish") != "cancel":+ # #1870: the engine says how many prompt tokens it read: the slot's own session may have held the rest+ # (not the conversation cache), so the rate is not made of tokens it never read+ cache_n = max(cache_n, max(0, prompt_tokens - int(last["prompt_read"])))prompt_n, prompt_ms, decode_ms = max(0, prompt_tokens - cache_n), float(last["prompt_ms"]), float(last.get("decode_ms") or 0)decoded = int(last.get("generated") or generated) # the engine's count gives its rate, as /metrics doesreturn {"cache_n": cache_n, "prompt_n": prompt_n, "prompt_ms": round(prompt_ms, 1),diff --git a/serve/test_request_accounting.py b/serve/test_request_accounting.pyindex 70fe868dd..145fdd560 100644--- a/serve/test_request_accounting.py+++ b/serve/test_request_accounting.py@@ -9,7 +9,7 @@ import urllib.requestfrom pathlib import Pathfrom serve.frontend import ChatTemplate-from serve.server import ByteTokenizer, EngineDied, Service, serve+from serve.server import ByteTokenizer, EngineDied, Service, add_carry, carry_leg, request_timings, servefrom serve.test_server import ThinkingEngine@@ -180,5 +180,46 @@ class RequestAccounting(unittest.TestCase):self.assertEqual((metrics["totals"]["drafts_offered"], metrics["totals"]["drafts_accepted"]), (18, 8))+class SlotLegAccounting(unittest.TestCase):+ """#1869: a request that decoded in a batch slot and finished on the solo path keeps the slot leg's decode time and+ tokens (the solo DONE alone said 1 token in 18 ms); #1870: prompt_n is what the engine read."""++ def test_solo_leg_adds_to_the_slot_leg(self):+ carry = {}+ slot_leg = {"generated": 134, "decode_ms": 2900.0, "prompt_ms": 3794.7, "prompt_read": 2052, "finish": "cancel"}+ carry_leg(carry, slot_leg)+ solo_done = {"generated": 1, "decode_ms": 18.4, "prompt_ms": 2.0, "prompt_read": 1, "finish": "stop", "reused": 0}+ total = add_carry(carry, solo_done)+ self.assertEqual((total["generated"], total["decode_ms"]), (135, 2918.4))+ self.assertEqual((total["prompt_ms"], total["prompt_read"], total["finish"]), (3794.7, 2052, "stop"))+ timings = request_timings(2052, 135, total)+ self.assertEqual(timings["predicted_ms"], 2918.4)+ self.assertAlmostEqual(timings["predicted_per_second"], 46.3, places=1)++ def test_two_hand_backs_sum(self):+ carry = {}+ carry_leg(carry, {"generated": 10, "decode_ms": 100.0, "prompt_ms": 50.0})+ carry_leg(carry, {"generated": 20, "decode_ms": 300.0, "prompt_ms": 1.0})+ total = add_carry(carry, {"generated": 5, "decode_ms": 50.0, "prompt_ms": 1.0})+ self.assertEqual((total["generated"], total["decode_ms"], total["prompt_ms"]), (35, 450.0, 50.0))+ self.assertNotIn("prompt_read", total)++ def test_prompt_n_is_what_was_read(self):+ # the slot already held the whole prompt: 1 token read, the conversation cache off (reused 0)+ last = {"prompt_ms": 563.5, "decode_ms": 700.0, "generated": 30, "reused": 0, "prompt_read": 1, "finish": "stop"}+ t = request_timings(43086, 30, last)+ self.assertEqual((t["prompt_n"], t["cache_n"]), (1, 43085))+ self.assertEqual(t["prompt_n"] + t["cache_n"], 43086)+ self.assertLess(t["prompt_per_second"], 10)+ # a cold read, and an older engine without the field: unchanged+ cold = request_timings(2052, 10, {**last, "prompt_read": 2052})+ self.assertEqual((cold["prompt_n"], cold["cache_n"]), (2052, 0))+ old = request_timings(2052, 10, {k: v for k, v in last.items() if k != "prompt_read"})+ self.assertEqual((old["prompt_n"], old["cache_n"]), (2052, 0))+ # the conversation cache's own count still counts when larger+ both = request_timings(1000, 10, {**last, "reused": 900, "prompt_read": 100})+ self.assertEqual((both["prompt_n"], both["cache_n"]), (100, 900))++if __name__ == "__main__":unittest.main()