okami.mom/strata

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

Yasei-no-otokobench: report Coder IQ1_M on Threadripper 3990X and RX 6900 XT (#628)cc86ad90d

main
2.7 KiB55 linesraw
1"""One bounded coding smoke check, separate from throughput measurements."""
2import argparse
3import ast
4import json
5import re
6import urllib.request
7from pathlib import Path
8
9parser = argparse.ArgumentParser(description=__doc__)
10parser.add_argument("--url", default="http://127.0.0.1:8080")
11args = parser.parse_args()
12
13request = {
14    "model": "strata",
15    "messages": [{"role": "user", "content":
16        "Write only Python code defining clamp_score(value: int) -> int. "
17        "Return value clamped to the inclusive range 0 through 100. "
18        "No imports, no markdown, no tests, no extra text."}],
19    "max_tokens": 256, "temperature": 0, "reasoning_effort": "none",
20}
21wire = urllib.request.Request(
22    args.url.rstrip("/") + "/v1/chat/completions",
23    data=json.dumps(request).encode(), headers={"Content-Type": "application/json"})
24with urllib.request.urlopen(wire, timeout=300) as response:
25    result = json.load(response)
26code = result["choices"][0]["message"]["content"].strip()
27code = re.sub(r"^```(?:python)?\s*\n|\n```$", "", code)
28tree = ast.parse(code)
29allowed_nodes = (ast.Module, ast.FunctionDef, ast.arguments, ast.arg, ast.Return,
30                 ast.If, ast.Compare, ast.Lt, ast.LtE, ast.Gt, ast.GtE, ast.Eq,
31                 ast.Call, ast.Name, ast.Load, ast.Constant, ast.UnaryOp, ast.USub,
32                 ast.Expr)
33allowed_names = {"clamp_score", "value", "int", "min", "max"}
34if len(tree.body) != 1 or not isinstance(tree.body[0], ast.FunctionDef):
35    raise ValueError("Expected one function definition")
36if tree.body[0].name != "clamp_score" or tree.body[0].decorator_list:
37    raise ValueError("Unexpected function name or decorator")
38for node in ast.walk(tree):
39    if not isinstance(node, allowed_nodes):
40        raise ValueError(f"Unsupported generated syntax: {type(node).__name__}")
41    if isinstance(node, ast.Name) and node.id not in allowed_names:
42        raise ValueError(f"Unexpected generated name: {node.id}")
43namespace = {"__builtins__": {"int": int, "min": min, "max": max}}
44exec(compile(tree, "generated-clamp-score", "exec"), namespace)
45failures = []
46for value in range(-1000, 1001):
47    actual = namespace["clamp_score"](value)
48    if actual != min(100, max(0, value)):
49        failures.append({"input": value, "actual": actual})
50report = {"url": args.url, "request": request, "response": result, "generated_code": code,
51          "cases": 2001, "failures": failures, "passed": not failures,
52          "scope": "One simple function only; not a general coding-quality benchmark."}
53Path(__file__).with_name("coding-smoke-check.json").write_text(
54    json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
55print(json.dumps({"cases": 2001, "passed": not failures, "code": code}))