interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / tests / omegallm / pre-review.py

78 lines · 3951 bytes Raw Blame History
1#!/usr/bin/env python3
2"""Pre-review checks supplementing the Omega LLM behavior gates."""
3import ast
4import os
5from pathlib import Path
6import re
7import subprocess
8import sys
9import tempfile
10
11root = Path(sys.argv[1]).resolve() if len(sys.argv) == 2 else Path(__file__).resolve().parents[2]
12referee = root / "tests/omegallm/serve-check.py"
13wrapper = root / "tests/omegallm/serve-check.sh"
14
15
16def kv_check():
17 """e993f179's KV-cached decode (model.om okvlcp, okvkv) against the guarded path: tests/omegallm/kv-check.py."""
18 p = subprocess.run([sys.executable, str(root / "tests/omegallm/kv-check.py")], capture_output=True, text=True)
19 sys.stdout.write(p.stdout)
20 sys.stderr.write(p.stderr)
21 if p.returncode != 0:
22 print(f"PRE_REVIEW FAIL: tests/omegallm/kv-check.py exit {p.returncode}")
23 sys.exit(1)
24
25
26tree = ast.parse(referee.read_text())
27samplers = []
28for node in ast.walk(tree):
29 if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute):
30 if isinstance(node.func.value, ast.Name) and node.func.value.id == "subprocess" and node.func.attr == "run":
31 if node.args and isinstance(node.args[0], ast.List):
32 args = node.args[0].elts
33 if len(args) > 1 and isinstance(args[0], ast.Name) and args[0].id == "OLLM":
34 samplers.append(args[1])
35assert samplers, "No sampler call found; update this check for the new referee structure"
36configurable = any(isinstance(x, ast.Name) and x.id == "SAMPLE_VERB" for x in samplers)
37if not configurable:
38 assert all(isinstance(x, ast.Constant) and x.value == "sample" for x in samplers)
39 print("PRE_REVIEW PASS: referee sampler is hardcoded to sample; environment cannot select it")
40 kv_check()
41 sys.exit(0)
42assert all(isinstance(x, ast.Name) and x.id == "SAMPLE_VERB" for x in samplers)
43assert any(isinstance(x, ast.Call) and len(x.args) == 2
44 and isinstance(x.args[0], ast.Constant) and x.args[0].value == "SAMPLE_VERB"
45 and isinstance(x.args[1], ast.Constant) and x.args[1].value == "sample"
46 for x in ast.walk(tree)), "Inspect changed sampler default"
47text = wrapper.read_text()
48assert text.count("\npids=") == 1, "Wrapper setup boundary changed; inspect before updating check"
49prefix = text.split("\npids=", 1)[0]
50with tempfile.TemporaryDirectory(prefix="omega-review-") as tmp:
51 fixture = Path(tmp) / "fixture"
52 fixture.write_bytes(b"pre-review fixture\n")
53 def selected(setup, verb, inherited):
54 env = {"PATH": os.environ.get("PATH", "/usr/bin:/bin"),
55 "OLLM": str(fixture), "CK": str(fixture), "MERGES": str(fixture),
56 "OUT": tmp, "ALLEN": str(Path(tmp) / "absent"), "VERB": verb}
57 if inherited is not None:
58 env["SAMPLE_VERB"] = inherited
59 script = setup + '\nprintf "SELECTED=%s\\n" "${SAMPLE_VERB-UNSET}"\n'
60 p = subprocess.run(["sh", "-c", script, str(wrapper)], env=env,
61 capture_output=True, text=True, timeout=10)
62 assert p.returncode == 0, p.stderr
63 lines = [s for s in p.stdout.splitlines() if s.startswith("SELECTED=")]
64 assert len(lines) == 1, p.stdout
65 value = lines[0].split("=", 1)[1]
66 return "sample" if value == "UNSET" else value
67 count = 0
68 for verb in ["serve", "gserve", "gserveb"]:
69 expected = "gsampb" if verb == "gserveb" else "sample"
70 for inherited in [None, "sample", "gsample", "gsampb", "invalid"]:
71 got = selected(prefix, verb, inherited)
72 assert got == expected, (verb, inherited, got, expected)
73 count += 1
74 mutant, changed = re.subn(r"SAMPLE_VERB=(?:gsampb|sample)", ":", prefix)
75 assert changed, "No sampler assignments found"
76 assert selected(mutant, "serve", "gsampb") != "sample", "Control did not expose inherited sampler"
77 print(f"PRE_REVIEW PASS: sampler environments={count}, unprotected control caught")
78kv_check()