okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

zimuhuan-codeCommunity benchmark: 2× RTX 3060 12 GB, Qwen3.8-Flash-Next IQ3_S (three prompt sizes, 3 runs each) (#721)eb4e0c4b4

main
2.6 KiB52 linesraw
1#!/usr/bin/env python3
2"""复现并诊断 needle_bench 的 512k 档失败(HTTP 400),同时兼作重跑。
3失败时打印**响应体**(官方工具只打印 "Bad Request",看不到原因)。
4"""
5import json
6import os
7import sys
8import time
9import urllib.error
10import urllib.request
11
12sys.path.insert(0, os.environ.get("STRATA_TOOLS", "tools"))   # run from the repository root
13import needle_bench as nb  # noqa: E402
14
15URL = os.environ.get("STRATA_URL", "http://127.0.0.1:8081").rstrip("/") + "/v1/chat/completions"
16KEY = os.environ.get("STRATA_KEY", "")
17TARGET = int(512 * 1024 * 0.98)          # 工具的口径:512k × 0.98
18# ⚠️ 官方工具按 CHARS_PER_TOKEN=3.2 估算**偏乐观**:512k 档目标 513,802 tok 实造 1,644,166 字符,
19#    服务端实测 **524,392 tokens**(真实比率 ≈3.135)⇒ prompt+40 > 524,288,被 **400 拒**(never truncated)。
20#    ⇒ 这里再打 0.98 折(≈1,611,000 字符),预计落到 ~515K tokens,才是名副其实的「512K 档」。
21CHARS = int(TARGET * nb.CHARS_PER_TOKEN * 0.98)
22WORD = "harbor-velvet-512"
23
24text = nb.haystack(CHARS)
25cut = text.rfind("\n", 0, len(text) // 2) + 1
26needle = f"\nThe secret code word for this text is: {WORD}. Remember it.\n"
27prompt = (text[:cut] + needle + text[cut:] +
28          "\n\nWhat is the secret code word mentioned in the text above? Reply with the code word only.")
29print(f"目标 {TARGET:,} tok · haystack {CHARS:,} 字符 · 实际 prompt {len(prompt):,} 字符", flush=True)
30
31body = {"model": "strata", "max_tokens": 40, "temperature": 0,
32        "chat_template_kwargs": {"enable_thinking": False},
33        "messages": [{"role": "user", "content": prompt}]}
34data = json.dumps(body).encode()
35print(f"请求体 {len(data):,} 字节", flush=True)
36req = urllib.request.Request(URL, data=data,
37                             headers={"Content-Type": "application/json", "Authorization": "Bearer " + KEY})
38t0 = time.time()
39try:
40    with urllib.request.urlopen(req, timeout=1800) as r:
41        out = json.loads(r.read())
42    dt = time.time() - t0
43    ans = (out["choices"][0]["message"].get("content") or "")
44    tim = out.get("timings") or {}
45    print(f"✅ HTTP 200 · {dt:.0f} s · prompt_tokens={out['usage']['prompt_tokens']:,} "
46          f"· prompt_tok_s={tim.get('prompt_per_second')}")
47    print(f"   {'FOUND' if WORD in ans else 'MISSED'}  answer={ans.strip()[:80]!r}")
48except urllib.error.HTTPError as e:
49    print(f"❌ HTTP {e.code} · {time.time()-t0:.1f} s")
50    print("响应体:", e.read().decode("utf-8", "replace")[:1000])
51except Exception as e:
52    print(f"❌ {type(e).__name__}: {e}")