Files
leleka/engine/strata/tools/early_close_test.py
T
Pavlo RatushnyiandClaude Sonnet 5.5 87e2633afe engine/strata: bring the Strata subtree to upstream 41cf05a0 (engine 0.1.50) with the local patches re-applied
Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree
(570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base =
the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main).

Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR
experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details,
conflict table and left-out files are in docs/upstream.md.

Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61),
docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out.

scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run").
Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR
macros on. No GPU run, no quality gate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:49:15 +01:00

48 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""A client that stops reading a streamed answer early must not leave its tokens to the next request.
STRATA_KEY=... python3 tools/early_close_test.py http://127.0.0.1:8090
"""
import json, os, sys, threading, urllib.request
URL = sys.argv[1].rstrip("/") + "/v1/chat/completions"
KEY = os.environ.get("STRATA_KEY", "")
def req(content, stream, max_tokens=300):
body = json.dumps({"model": "m", "max_tokens": max_tokens, "temperature": 0, "stream": stream,
"messages": [{"role": "user", "content": content}],
"chat_template_kwargs": {"enable_thinking": False}}).encode()
return urllib.request.Request(URL, data=body, headers={"Content-Type": "application/json",
"Authorization": f"Bearer {KEY}"})
def early_close(content, keep_lines=5):
r = urllib.request.urlopen(req(content, True), timeout=600)
for _ in range(keep_lines):
r.readline()
r.close() # the client goes away mid-answer
def answer(content):
with urllib.request.urlopen(req(content, False, 60), timeout=600) as r:
m = json.load(r)["choices"][0]["message"]
return (m.get("content") or "") + " " + (m.get("reasoning_content") or m.get("reasoning") or "")
ok = True
# alone (solo path), then the same with a second request running (batch slots)
for label, background in (("solo", False), ("batch", True)):
bg = None
if background:
bg = threading.Thread(target=answer, args=("Count slowly from 1 to 60, one number per line.",))
bg.start()
early_close("Describe the weather in Montpellier in great detail, at length.")
a = answer("Reply with exactly one word: the color of the sky on a clear day.")
good = "blue" in a.lower() and "montpellier" not in a.lower()
ok &= good
print(f"{label}: {'OK' if good else 'STALE'} -> {a[:120]!r}", flush=True)
if bg:
bg.join()
sys.exit(0 if ok else 1)