awbench 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- awbench/__init__.py +38 -0
- awbench/__main__.py +10 -0
- awbench/_doctor.py +205 -0
- awbench/_selftest.py +249 -0
- awbench/artifact.py +346 -0
- awbench/bench.py +1543 -0
- awbench/cli.py +239 -0
- awbench/doctor_local.py +47 -0
- awbench/driver.py +195 -0
- awbench-0.1.0.dist-info/METADATA +190 -0
- awbench-0.1.0.dist-info/RECORD +15 -0
- awbench-0.1.0.dist-info/WHEEL +5 -0
- awbench-0.1.0.dist-info/entry_points.txt +2 -0
- awbench-0.1.0.dist-info/licenses/LICENSE +202 -0
- awbench-0.1.0.dist-info/top_level.txt +1 -0
awbench/__init__.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""awbench -- a hard-oracle benchmark for a served model.
|
|
2
|
+
|
|
3
|
+
Every item is scored by exact match, set membership or an ordering predicate.
|
|
4
|
+
There is no LLM judge anywhere: a judge is a model, and a benchmark whose
|
|
5
|
+
verdict comes from a model cannot tell you the model is wrong.
|
|
6
|
+
|
|
7
|
+
Two results are comparable only when they scored the SAME items. A run records
|
|
8
|
+
an item-set fingerprint (over the scored item ids) and a content digest (over
|
|
9
|
+
what each item sends); `compare` refuses a pair whose fingerprints or digests
|
|
10
|
+
differ, and it never compares a run that has no score.
|
|
11
|
+
|
|
12
|
+
from awbench import ITEMS, DIMENSIONS, run, comparable_runs
|
|
13
|
+
result = run(turn_fn) # turn_fn(messages) -> text | (text, finish)
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from awbench.bench import (
|
|
17
|
+
DIMENSIONS,
|
|
18
|
+
ITEMS,
|
|
19
|
+
BenchItem,
|
|
20
|
+
UnjudgeableError,
|
|
21
|
+
comparable_runs,
|
|
22
|
+
judge_response,
|
|
23
|
+
regression_report,
|
|
24
|
+
run,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"DIMENSIONS",
|
|
29
|
+
"ITEMS",
|
|
30
|
+
"BenchItem",
|
|
31
|
+
"UnjudgeableError",
|
|
32
|
+
"comparable_runs",
|
|
33
|
+
"judge_response",
|
|
34
|
+
"regression_report",
|
|
35
|
+
"run",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
__version__ = "0.1.0"
|
awbench/__main__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""`python -m awbench` -- a way in that does not depend on the console shim.
|
|
2
|
+
|
|
3
|
+
A blocked or missing `awbench` script on PATH must not leave the tool
|
|
4
|
+
unreachable; this entry point exists before that outage, not after it.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from awbench.cli import main
|
|
8
|
+
|
|
9
|
+
if __name__ == "__main__":
|
|
10
|
+
raise SystemExit(main())
|
awbench/_doctor.py
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"""Stack-aware `doctor` for awbench.
|
|
2
|
+
|
|
3
|
+
GENERATED BY gen_aw_doctor.py -- DO NOT EDIT.
|
|
4
|
+
Regenerate it with the generator named above; a hand-edit here is reverted by
|
|
5
|
+
the next run and fails the parity gate.
|
|
6
|
+
|
|
7
|
+
Why a doctor exists at all: the aw* bricks are designed to COMPOSE, so the
|
|
8
|
+
interesting failures live BETWEEN them. "awbench is installed" is not the useful
|
|
9
|
+
fact -- "awbench is installed and the thing it pairs with is not" is. This reports
|
|
10
|
+
the whole stack, not just itself.
|
|
11
|
+
|
|
12
|
+
stdlib only, on purpose: a diagnostic that cannot run because a dependency is
|
|
13
|
+
missing is worthless precisely when you need it.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import importlib.util
|
|
18
|
+
import os
|
|
19
|
+
import shutil
|
|
20
|
+
import sys
|
|
21
|
+
|
|
22
|
+
SELF = 'awbench'
|
|
23
|
+
#: Frozen from the Aither World registry at generation time. A shipped
|
|
24
|
+
#: package cannot read the registry, and a doctor that guessed at the family
|
|
25
|
+
#: would go stale in silence. Regenerate to update.
|
|
26
|
+
FAMILY = [
|
|
27
|
+
'awask', 'awavatar', 'awbac', 'awbrain', 'awbrowse', 'awcams', 'awcap', 'awclassify', 'awcrowd',
|
|
28
|
+
'awdecide', 'awdeck', 'awdelphi', 'awdiscord', 'awdit', 'awedgerunner', 'awembed', 'awevolve',
|
|
29
|
+
'awexpress', 'awfind', 'awflow', 'awfocus', 'awgather', 'awgit', 'awgov', 'awgraph', 'awgym',
|
|
30
|
+
'awiam', 'awindex', 'awkno', 'awm', 'awmail', 'awmine', 'awnboard', 'awnest', 'awnet', 'awnode',
|
|
31
|
+
'awpermit', 'awplay', 'awpool', 'awpredict', 'awprism', 'awprove', 'awreason', 'awrecover',
|
|
32
|
+
'awrecurse', 'awrelay', 'awrena', 'awrepl', 'awreport', 'awresearch', 'awrise', 'awrouter',
|
|
33
|
+
'awrtifact', 'awrun', 'awscope', 'awscreen', 'awseal', 'awsettings', 'awshare', 'awsprite',
|
|
34
|
+
'awstorage', 'awsuite', 'awswarm', 'awtax', 'awtoll', 'awtunnel', 'awvision', 'awvoice',
|
|
35
|
+
'awwall', 'gawbbonet',
|
|
36
|
+
]
|
|
37
|
+
FAMILY_ERROR = None
|
|
38
|
+
PAIRS_WITH = ['adk', 'awevolve', 'awrun']
|
|
39
|
+
|
|
40
|
+
#: This brick's OWN config, read out of its source at generation time.
|
|
41
|
+
#: ENV_REQUIRED is `os.environ["X"]` -- absent, that is a KeyError the moment
|
|
42
|
+
#: the line runs. ENV_OPTIONAL is `os.getenv("X")`, which returns None and lets
|
|
43
|
+
#: the caller cope. Only this brick's namespace is listed: reporting the
|
|
44
|
+
#: platform-wide vars it also touches would be noise, and a doctor that floods
|
|
45
|
+
#: gets ignored.
|
|
46
|
+
ENV_REQUIRED = []
|
|
47
|
+
ENV_OPTIONAL = []
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _installed(mod: str) -> "str | None":
|
|
51
|
+
"""Version if importable, else None. Never raises -- a broken sibling must
|
|
52
|
+
not take the diagnostic down with it."""
|
|
53
|
+
try:
|
|
54
|
+
if importlib.util.find_spec(mod) is None:
|
|
55
|
+
return None
|
|
56
|
+
except (ImportError, ValueError):
|
|
57
|
+
return None
|
|
58
|
+
try:
|
|
59
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
60
|
+
try:
|
|
61
|
+
return version(mod)
|
|
62
|
+
except PackageNotFoundError:
|
|
63
|
+
return "installed"
|
|
64
|
+
except Exception:
|
|
65
|
+
return "installed"
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def report(out=None) -> int:
|
|
69
|
+
"""Print the stack picture. 0 = this brick and its pairs are present."""
|
|
70
|
+
out = out or sys.stdout
|
|
71
|
+
print(f"{SELF} doctor", file=out)
|
|
72
|
+
|
|
73
|
+
mine = _installed(SELF)
|
|
74
|
+
print(f" self {SELF} {mine or 'NOT IMPORTABLE'}", file=out)
|
|
75
|
+
shim = shutil.which(SELF)
|
|
76
|
+
print(f" command {shim or 'not on PATH'}", file=out)
|
|
77
|
+
if FAMILY_ERROR:
|
|
78
|
+
# Never an empty stack: "0/0 installed" reads as a clean machine.
|
|
79
|
+
print(f"\nverdict: UNJUDGED -- {FAMILY_ERROR}", file=out)
|
|
80
|
+
return 2
|
|
81
|
+
|
|
82
|
+
# The stack. Siblings this brick pairs with are called out separately,
|
|
83
|
+
# because a missing pair is a REASON, while a missing unrelated brick is
|
|
84
|
+
# just a fact about your machine.
|
|
85
|
+
missing_pairs, present = [], []
|
|
86
|
+
for name in FAMILY:
|
|
87
|
+
v = _installed(name)
|
|
88
|
+
if v:
|
|
89
|
+
present.append(name)
|
|
90
|
+
elif name in PAIRS_WITH:
|
|
91
|
+
missing_pairs.append(name)
|
|
92
|
+
print(f" stack {len(present)}/{len(FAMILY)} aw* packages installed",
|
|
93
|
+
file=out)
|
|
94
|
+
if present:
|
|
95
|
+
print(f" {' '.join(sorted(present))}", file=out)
|
|
96
|
+
|
|
97
|
+
missing_req = [v for v in ENV_REQUIRED if not os.environ.get(v)]
|
|
98
|
+
if ENV_REQUIRED or ENV_OPTIONAL:
|
|
99
|
+
have = sum(1 for v in ENV_REQUIRED + ENV_OPTIONAL if os.environ.get(v))
|
|
100
|
+
total = len(ENV_REQUIRED) + len(ENV_OPTIONAL)
|
|
101
|
+
print(f" config {have}/{total} of this brick's own vars set", file=out)
|
|
102
|
+
if missing_req:
|
|
103
|
+
# Not a preference. os.environ[...] raises the moment it runs.
|
|
104
|
+
print(f" MISSING REQUIRED: {' '.join(missing_req)}", file=out)
|
|
105
|
+
|
|
106
|
+
local = _local_checks()
|
|
107
|
+
for line in local:
|
|
108
|
+
print(f" {line}", file=out)
|
|
109
|
+
problems, unjudged = _local_verdict()
|
|
110
|
+
|
|
111
|
+
if mine is None:
|
|
112
|
+
print(f"\nverdict: {SELF} itself is not importable. Reinstall it before "
|
|
113
|
+
f"anything else here means much.", file=out)
|
|
114
|
+
return 1
|
|
115
|
+
if missing_req:
|
|
116
|
+
print(f"\nverdict: {SELF} is missing required config "
|
|
117
|
+
f"({', '.join(missing_req)}). Those are read with os.environ[...], "
|
|
118
|
+
f"so the code path that needs them raises rather than degrades.",
|
|
119
|
+
file=out)
|
|
120
|
+
return 1
|
|
121
|
+
# A measured NO outranks a missing optional pair: awrise printed
|
|
122
|
+
# "nothing wakes run-due" and still exited 0 because the missing-pairs
|
|
123
|
+
# branch returned first (measured 2026-09-20).
|
|
124
|
+
if problems:
|
|
125
|
+
for p in problems:
|
|
126
|
+
print(f"\nverdict: {p}", file=out)
|
|
127
|
+
return 1
|
|
128
|
+
if unjudged:
|
|
129
|
+
for u in unjudged:
|
|
130
|
+
print(f"\nverdict: UNJUDGED -- could not judge: {u}", file=out)
|
|
131
|
+
return 2
|
|
132
|
+
if missing_pairs:
|
|
133
|
+
print(f"\nverdict: {SELF} works, but pairs with "
|
|
134
|
+
f"{', '.join(sorted(missing_pairs))} which "
|
|
135
|
+
f"{'is' if len(missing_pairs) == 1 else 'are'} not installed. "
|
|
136
|
+
f"That is a capability you are missing, not an error.", file=out)
|
|
137
|
+
return 0
|
|
138
|
+
print(f"\nverdict: {SELF} and everything it pairs with are present.", file=out)
|
|
139
|
+
return 0
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _local_verdict() -> tuple:
|
|
143
|
+
"""The brick's OWN verdict, folded into the exit code.
|
|
144
|
+
|
|
145
|
+
Without this the local lines are DECORATION. Measured 2026-09-20: awrise
|
|
146
|
+
printed "hostclock NOT INSTALLED -- nothing wakes run-due" and "last tick
|
|
147
|
+
never", then exited 0 -- teaching an operator that a doctor exit code
|
|
148
|
+
carries no information. A brick opts in with `_doctor_local_verdict()`
|
|
149
|
+
returning (problems, unjudged); a brick without one is unaffected.
|
|
150
|
+
"""
|
|
151
|
+
try:
|
|
152
|
+
mod = importlib.import_module(f"{SELF}.doctor_local")
|
|
153
|
+
problems, unjudged = mod._doctor_local_verdict()
|
|
154
|
+
except Exception: # noqa: BLE001
|
|
155
|
+
return [], []
|
|
156
|
+
return list(problems or []), list(unjudged or [])
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _local_checks() -> "list[str]":
|
|
160
|
+
"""Per-brick checks, if this package defines them.
|
|
161
|
+
|
|
162
|
+
Kept as a HOOK rather than generated guesses: the generator knows the family
|
|
163
|
+
from the registry, but it does not know what awbench needs at runtime, and a
|
|
164
|
+
doctor that invented config requirements would be confidently wrong. A
|
|
165
|
+
package supplies `_doctor_local()` returning display lines; absent, the
|
|
166
|
+
stack picture above still stands on its own.
|
|
167
|
+
"""
|
|
168
|
+
try:
|
|
169
|
+
mod = importlib.import_module(f"{SELF}.doctor_local")
|
|
170
|
+
except Exception:
|
|
171
|
+
return []
|
|
172
|
+
try:
|
|
173
|
+
return list(mod._doctor_local())
|
|
174
|
+
except Exception as exc: # noqa: BLE001
|
|
175
|
+
return [f"local checks raised {type(exc).__name__}: {exc}"]
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def main(argv: "list[str] | None" = None) -> int:
|
|
179
|
+
# --self-test delegates to a SIBLING module when one exists.
|
|
180
|
+
#
|
|
181
|
+
# This file is generated and a fresh run replaces it, so a self-test
|
|
182
|
+
# written HERE is deleted by the next regeneration. awdelphi learned that
|
|
183
|
+
# the expensive way: 125 lines exercising four real failure paths --
|
|
184
|
+
# convergence, roster anonymization, resume, gateway-down -- lived in this
|
|
185
|
+
# file and were destroyed by a routine regeneration, silently, leaving a
|
|
186
|
+
# --self-test flag that reported PASS while asserting nothing.
|
|
187
|
+
#
|
|
188
|
+
# So the seam is a separate module the generator never writes. A package
|
|
189
|
+
# with real machinery to prove puts it in _selftest.py; everything else
|
|
190
|
+
# keeps the honest answer below rather than a self-test that only ever
|
|
191
|
+
# passes.
|
|
192
|
+
argv = list(argv if argv is not None else __import__("sys").argv[1:])
|
|
193
|
+
if "--self-test" in argv:
|
|
194
|
+
try:
|
|
195
|
+
from . import _selftest as _st
|
|
196
|
+
except Exception:
|
|
197
|
+
print("no _selftest module: this doctor reports the stack, and has",
|
|
198
|
+
"no machinery of its own to prove")
|
|
199
|
+
return 0
|
|
200
|
+
return int(_st.run())
|
|
201
|
+
return report()
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
if __name__ == "__main__":
|
|
205
|
+
raise SystemExit(main())
|
awbench/_selftest.py
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"""`awbench --self-test`: exit 0 only after PROVING each guard can fail.
|
|
2
|
+
|
|
3
|
+
A benchmark's self-test that only shows the happy path is the failure it
|
|
4
|
+
exists to prevent: a ruler that cannot fail reads every model as good. So each
|
|
5
|
+
arm below drives a guard with the input it guards against and asserts it trips,
|
|
6
|
+
next to the input it must let through:
|
|
7
|
+
|
|
8
|
+
scorers the engine's own proofs (every scorer fails the trap answer)
|
|
9
|
+
oracle a synthetic model answering from KEY scores 1.0 on every item --
|
|
10
|
+
so no item is unpassable -- and a constant "Yes." model does not
|
|
11
|
+
no score a silent model and a dead transport judge NOTHING, and the run
|
|
12
|
+
carries no score rather than a zero
|
|
13
|
+
refusals mismatched item sets, a result with no fingerprint, edited prompts
|
|
14
|
+
under unchanged ids, and a missing score are all refused by compare
|
|
15
|
+
round trip an artifact written to disk loads and compares to itself cleanly
|
|
16
|
+
redaction a key in the endpoint URL never reaches the artifact
|
|
17
|
+
|
|
18
|
+
It never touches the network. A check list that ran zero checks is a failure.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import contextlib
|
|
24
|
+
import io
|
|
25
|
+
import json
|
|
26
|
+
import tempfile
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
from typing import Any, Callable, Dict, List, Tuple
|
|
29
|
+
|
|
30
|
+
from awbench import __version__, artifact, bench, driver
|
|
31
|
+
|
|
32
|
+
#: A correct final answer for every item, checked against the item's own scorer.
|
|
33
|
+
#: Adding an item without adding its key fails the self-test on purpose: it is
|
|
34
|
+
#: the proof that the new item CAN be passed, which a typo in a scorer would
|
|
35
|
+
#: silently make impossible.
|
|
36
|
+
KEY: Dict[str, str] = {
|
|
37
|
+
"ef_status": "1",
|
|
38
|
+
"ef_rename": "4",
|
|
39
|
+
"ef_architecture": "8",
|
|
40
|
+
"ef_trap_long_easy": "1",
|
|
41
|
+
"rm_vision": "gemma4-12b",
|
|
42
|
+
"rm_cheap": "deepseek-v4-flash",
|
|
43
|
+
"rm_hard": "deepseek-v4-pro",
|
|
44
|
+
"rm_trap_offline_device": "bonsai-27b",
|
|
45
|
+
"pl_order": "backup\nmigrate\ndeploy\nverify",
|
|
46
|
+
"pl_impossible": "IMPOSSIBLE: the second step -- the restore has already overwritten "
|
|
47
|
+
"the state from before it.",
|
|
48
|
+
"pl_parallel": "Run A and B in parallel, then C.",
|
|
49
|
+
"pl_rollback": "stop-traffic\nrollback\ndiagnose\nredeploy",
|
|
50
|
+
"pl_prereq_missing": "WRONG: create the service account first, then grant it access.",
|
|
51
|
+
"pl_irreversible": "B first: verify the new bucket serves every object, because the "
|
|
52
|
+
"delete cannot be undone.",
|
|
53
|
+
"pl_no_op_step": "3",
|
|
54
|
+
"es_exceeds": "I escalate it to deepseek-v4-pro.",
|
|
55
|
+
"es_dont_escalate": "I answer it directly myself.",
|
|
56
|
+
"wf_follow": "I follow the runbook as written: stop traffic first.",
|
|
57
|
+
"wf_procedure_gap": "I flag the gap and update the runbook.",
|
|
58
|
+
"lh_remaining": "No: three remain -- search is in progress, mail and reports are "
|
|
59
|
+
"not started.",
|
|
60
|
+
"lh_stale_goal": "Re-read the goal before acting on step 3.",
|
|
61
|
+
"cx_crystallise": "Checkpoint: summarise the state and persist it first.",
|
|
62
|
+
"cx_keep_drop": "b",
|
|
63
|
+
"of_use_result": "I pick one of the fixes and apply it as the next step.",
|
|
64
|
+
"of_when": "Offload.",
|
|
65
|
+
"lt_bat_ball": "50",
|
|
66
|
+
"lt_negation": "No: a restart has other causes, such as a deploy or a reboot.",
|
|
67
|
+
"lt_absence": "We cannot know: the shipper was down, so the empty search proves "
|
|
68
|
+
"nothing.",
|
|
69
|
+
"lt_rate": "80 minutes: each GPU loads a shard twice as large.",
|
|
70
|
+
"gk_basic": "Compute Unified Device Architecture.",
|
|
71
|
+
"gk_decline": "I cannot know that; I have no access to those metrics.",
|
|
72
|
+
"dc_dead_not_pass": "Unknown: it checked zero files, so the run is dead, not a pass.",
|
|
73
|
+
"dc_health_not_working": "No: without a token it cannot reach the API.",
|
|
74
|
+
"dc_floor": "No: it scores below its own majority-lookup floor.",
|
|
75
|
+
"dc_partial_fix": "Not necessarily: the second cause is still there.",
|
|
76
|
+
"rp_locate": "Search the repository to locate the backoff function.",
|
|
77
|
+
"rp_provenance": "I would query the op log for that commit before answering.",
|
|
78
|
+
"rp_predict_before_act": "Predict the resulting state with the model first.",
|
|
79
|
+
"rp_no_lookup_needed": "No, I can compute it directly.",
|
|
80
|
+
"se_volatile_status": "Check it live with a probe.",
|
|
81
|
+
"se_stable_math": "Answer directly: I can compute it myself.",
|
|
82
|
+
"se_changed_since_training": "Look it up: it postdates my training cutoff.",
|
|
83
|
+
"se_stable_definition": "Answer from memory; it is a stable definition.",
|
|
84
|
+
"se_needs_search": "Look it up: prices change.",
|
|
85
|
+
"se_no_search": "Answer from memory; it is a stable fact.",
|
|
86
|
+
"mt_carry_number": "16",
|
|
87
|
+
"mt_revise_constraint": "test\nbuild\nship",
|
|
88
|
+
"mt_correction": "Max",
|
|
89
|
+
"mt_stale_fact": "9090",
|
|
90
|
+
"mt_cancelled_task": "backup, notify",
|
|
91
|
+
"mt_standing_format": "6 DONE",
|
|
92
|
+
"mt_unit_carry": "750",
|
|
93
|
+
"mt_code_revision": "name=combine result=12",
|
|
94
|
+
"tr_code_not_web": "awgraph",
|
|
95
|
+
"tr_web_not_code": "awfind",
|
|
96
|
+
"tr_durable_not_relay": "awm",
|
|
97
|
+
"tr_relay_not_durable": "awrelay",
|
|
98
|
+
"tr_predict_before_fleet_action": "awpredict",
|
|
99
|
+
"tr_recurse_oversized_context": "awrecurse",
|
|
100
|
+
"tr_repl_state_survives": "awrepl",
|
|
101
|
+
"tr_reason_keeps_chain": "awreason",
|
|
102
|
+
"tr_recall_before_hypothesis": "recall",
|
|
103
|
+
"tr_lease_before_shared_edit": "awgit lease acquire on the file",
|
|
104
|
+
"tr_no_tool_needed": "None: I compute it directly.",
|
|
105
|
+
"tr_rg_before_graph": "rg",
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
Messages = List[Dict[str, str]]
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _first_user(messages: Messages) -> str:
|
|
112
|
+
return next((m["content"] for m in messages if m.get("role") == "user"), "")
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def oracle_turn_fn() -> Callable[[Messages], Tuple[str, str]]:
|
|
116
|
+
"""A synthetic model that answers every item from KEY.
|
|
117
|
+
|
|
118
|
+
It identifies the item by its first user turn and returns the keyed answer on
|
|
119
|
+
every turn of a thread; only the final reply is scored, and the replayed
|
|
120
|
+
intermediate replies are plain text, so a thread never has a hole.
|
|
121
|
+
"""
|
|
122
|
+
by_prompt = {i.prompt: i.id for i in bench.ITEMS}
|
|
123
|
+
|
|
124
|
+
def turn_fn(messages: Messages) -> Tuple[str, str]:
|
|
125
|
+
item_id = by_prompt.get(_first_user(messages), "")
|
|
126
|
+
return (KEY.get(item_id, ""), "stop")
|
|
127
|
+
|
|
128
|
+
return turn_fn
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _quiet(fn: Callable[[], Any]) -> Tuple[Any, str]:
|
|
132
|
+
buf = io.StringIO()
|
|
133
|
+
with contextlib.redirect_stdout(buf):
|
|
134
|
+
value = fn()
|
|
135
|
+
return value, buf.getvalue()
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _doc(result: Dict[str, Any], model: str = "synthetic") -> Dict[str, Any]:
|
|
139
|
+
return artifact.build(model, "http://127.0.0.1/v1", result, version=__version__,
|
|
140
|
+
started_at="", finished_at="", served_models=[model],
|
|
141
|
+
params={"max_tokens": 64, "temperature": 0})
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def run() -> int:
|
|
145
|
+
"""Run every arm; 0 only when each check ran and held."""
|
|
146
|
+
results: List[Tuple[bool, str]] = []
|
|
147
|
+
|
|
148
|
+
def ck(cond: bool, what: str) -> None:
|
|
149
|
+
results.append((bool(cond), what))
|
|
150
|
+
|
|
151
|
+
# -- scorers: the engine's own proofs --------------------------------------
|
|
152
|
+
rc, out = _quiet(bench.self_test)
|
|
153
|
+
ck(rc == 0, "engine scorer self-test passes"
|
|
154
|
+
+ ("" if rc == 0 else " | " + out.strip().splitlines()[-1][:120]))
|
|
155
|
+
|
|
156
|
+
# -- oracle: every item is passable, and a constant answer is not ---------
|
|
157
|
+
missing = sorted({i.id for i in bench.ITEMS} - set(KEY))
|
|
158
|
+
stale = sorted(set(KEY) - {i.id for i in bench.ITEMS})
|
|
159
|
+
ck(not missing and not stale,
|
|
160
|
+
f"the answer key covers exactly the item set (missing {missing[:4]}, stale {stale[:4]})")
|
|
161
|
+
oracle = bench.run(oracle_turn_fn())
|
|
162
|
+
failed = [d["id"] for d in oracle["detail"] if d.get("score") != 1.0]
|
|
163
|
+
ck(not failed, f"a synthetic model answering from the key scores 1.0 on every item "
|
|
164
|
+
f"(below 1.0: {failed[:6]})")
|
|
165
|
+
ck(oracle["overall"] == 1.0 and oracle["comparable"] is True
|
|
166
|
+
and oracle["n_judged"] == len(bench.ITEMS),
|
|
167
|
+
f"...so the run is comparable with overall 1.0 (got {oracle['overall']})")
|
|
168
|
+
yes = bench.run(lambda _m: ("Yes.", "stop"))
|
|
169
|
+
ck(yes["comparable"] is True and yes["overall"] is not None and yes["overall"] < 0.5,
|
|
170
|
+
f"a constant 'Yes.' model is judged on every item and scores below 0.5 "
|
|
171
|
+
f"(got {yes['overall']}) -- the scorers can fail end to end")
|
|
172
|
+
|
|
173
|
+
# -- no judged items -> no score --------------------------------------------
|
|
174
|
+
silent = bench.run(lambda _m: ("", "stop"))
|
|
175
|
+
ck(silent["n_judged"] == 0 and silent["overall"] is None
|
|
176
|
+
and silent["comparable"] is False and silent["dimensions"] == {},
|
|
177
|
+
"a silent model judges NOTHING and carries no score, not a zero")
|
|
178
|
+
|
|
179
|
+
def dead(_m: Messages) -> Tuple[str, str]:
|
|
180
|
+
raise ConnectionError("connection refused")
|
|
181
|
+
|
|
182
|
+
gone = bench.run(dead)
|
|
183
|
+
ck(gone["overall"] is None and gone["n_judged"] == 0
|
|
184
|
+
and all(u["why"].startswith("transport error") for u in gone["unjudged"]),
|
|
185
|
+
"a dead endpoint is UNJUDGED on every item -- never scored as a wrong answer")
|
|
186
|
+
cut = bench.run(lambda _m: ("I would first consider", "length"))
|
|
187
|
+
ck(cut["overall"] is None and cut["n_judged"] == 0,
|
|
188
|
+
"a reply truncated at max_tokens is unjudged, not scored")
|
|
189
|
+
|
|
190
|
+
# -- refusals ----------------------------------------------------------------
|
|
191
|
+
doc_o, doc_y, doc_s = _doc(oracle), _doc(yes), _doc(silent)
|
|
192
|
+
same = artifact.compare(doc_o, _doc(oracle))
|
|
193
|
+
ck(not same.refused and same.exit_code() == 0
|
|
194
|
+
and same.verdict.startswith("NO EFFECT"),
|
|
195
|
+
f"a run compared with itself: no effect, exit 0 (got {same.refused or same.verdict})")
|
|
196
|
+
worse = artifact.compare(doc_o, doc_y)
|
|
197
|
+
ck(not worse.refused and worse.exit_code() == 1 and bool(worse.losses),
|
|
198
|
+
"a worse candidate on the same item set is compared and REJECTED (exit 1)")
|
|
199
|
+
subset = bench.run(oracle_turn_fn(), dimensions=["logic_traps", "doctrine"])
|
|
200
|
+
mixed = artifact.compare(doc_o, _doc(subset))
|
|
201
|
+
ck(mixed.refused.startswith("REFUSING: different item sets") and mixed.exit_code() == 2,
|
|
202
|
+
"two runs over DIFFERENT item sets are refused, whatever their scores")
|
|
203
|
+
legacy = {"model": "old", "endpoint": "", "result": dict(oracle, item_set={})}
|
|
204
|
+
unknown = artifact.compare(legacy, doc_o)
|
|
205
|
+
ck(unknown.refused.startswith("UNKNOWN") and unknown.exit_code() == 2,
|
|
206
|
+
"a result with no fingerprint is UNKNOWN and refused, never assumed compatible")
|
|
207
|
+
edited = json.loads(json.dumps(doc_o))
|
|
208
|
+
edited["awbench"]["content_sha256"] = "0" * 16
|
|
209
|
+
drift = artifact.compare(doc_o, edited)
|
|
210
|
+
ck("different item CONTENT" in drift.refused and drift.exit_code() == 2,
|
|
211
|
+
"same ids with edited prompts are refused on the content digest")
|
|
212
|
+
noscore = artifact.compare(doc_s, doc_o)
|
|
213
|
+
ck(noscore.refused.startswith("REFUSING: a missing score") and noscore.exit_code() == 2,
|
|
214
|
+
"a run with no score is never compared -- not even as a zero")
|
|
215
|
+
|
|
216
|
+
# -- round trip ----------------------------------------------------------------
|
|
217
|
+
with tempfile.TemporaryDirectory() as td:
|
|
218
|
+
path = Path(td) / "run.json"
|
|
219
|
+
path.write_text(json.dumps(doc_o), encoding="utf-8")
|
|
220
|
+
loaded = artifact.load(str(path))
|
|
221
|
+
again = artifact.compare(loaded, loaded)
|
|
222
|
+
ck(loaded["awbench"]["content_sha256"] == doc_o["awbench"]["content_sha256"]
|
|
223
|
+
and again.exit_code() == 0,
|
|
224
|
+
"an artifact written to disk loads and compares to itself cleanly")
|
|
225
|
+
bad = Path(td) / "bad.json"
|
|
226
|
+
bad.write_text("{not json", encoding="utf-8")
|
|
227
|
+
try:
|
|
228
|
+
artifact.load(str(bad))
|
|
229
|
+
ck(False, "an unreadable artifact raises instead of loading as empty")
|
|
230
|
+
except artifact.ArtifactError:
|
|
231
|
+
ck(True, "an unreadable artifact raises instead of loading as empty")
|
|
232
|
+
|
|
233
|
+
# -- redaction -----------------------------------------------------------------
|
|
234
|
+
red = driver.redact_endpoint("https://user:secret@example.test:8443/v1?api_key=k#x")
|
|
235
|
+
ck(red == "https://example.test:8443/v1" and "secret" not in red,
|
|
236
|
+
f"a credential in the endpoint URL never reaches the artifact (got {red})")
|
|
237
|
+
ck(driver.chat_completions_url("http://h:8000/v1/") == "http://h:8000/v1/chat/completions"
|
|
238
|
+
and driver.chat_completions_url("http://h:8000") == "http://h:8000/v1/chat/completions",
|
|
239
|
+
"a /v1 base and a bare server root resolve to the same chat-completions URL")
|
|
240
|
+
|
|
241
|
+
for ok, what in results:
|
|
242
|
+
print(f" {'ok ' if ok else 'FAIL'} {what}")
|
|
243
|
+
bad_n = sum(1 for ok, _ in results if not ok)
|
|
244
|
+
if not results:
|
|
245
|
+
print("self-test: ran ZERO checks -- that is not a pass")
|
|
246
|
+
return 1
|
|
247
|
+
print(f"\nawbench self-test: {'PASSED' if not bad_n else 'FAILED'} "
|
|
248
|
+
f"({len(results)} checks, {bad_n} failure(s))")
|
|
249
|
+
return 1 if bad_n else 0
|