Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-train/blob/main/eval/omegese45/oe_en.py # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-train / eval / omegese45 / oe_en.py` 126 lines ยท 6442 bytes Raw Blame History 1 """Eval-owned parser of the rep2en English response (aien-train #45). 2 3 The sentence shapes are transcribed from the translator's documented 4 fixed templates: docs/omegese45/TRANSLATOR.md section "rep2en" (tables 5 "Templates" and "Plain words") at feat/45-chat-translator `cdd1a4b9`. This 6 module does not 7 import or run translator code. It parses one response into the facts it 8 states, then checks every stated fact against the runtime facts.tsv rows and 9 the episode, which check-demo has already bound to the signed artifacts. 10 11 Shapes (numbers are decimal without leading zeros; hashes are 64 lowercase 12 hex digits; one line, final LF): 13 OK mm: Completed and verified: one matmul_u32 job multiplying a M by K 14 matrix by a K by N matrix with seed S; job 1 dag_id D mjr1_sha256 H. 15 OK pair: Completed and verified: two matmul_u32 jobs, each multiplying a M 16 by K matrix by a K by N matrix, with seeds S and T; job 1 dag_id D1 17 mjr1_sha256 H1; job 2 dag_id D2 mjr1_sha256 H2. 18 bound: Not completed: refused before dispatch (code bound): the goal asks 19 for a M by K by N matmul and a dimension is outside the admitted 20 range 1 to 256; nothing was dispatched. 21 stop: Not completed: job J was refused (code C): REASON. 22 Not completed: job J failed (code C): REASON. 23 """ 24 25 import re 26 27 NUM = r"(0|[1-9][0-9]*)" 28 HEX = r"([0-9a-f]{64})" 29 JOBREF = r"job %s dag_id %s mjr1_sha256 %s" % (NUM, HEX, HEX) 30 DIMS = r"a %s by %s matrix by a %s by %s matrix" % (NUM, NUM, NUM, NUM) 31 32 RE_MM = re.compile(r"Completed and verified: one matmul_u32 job multiplying %s with seed %s; %s\.\n\Z" 33 % (DIMS, NUM, JOBREF)) 34 RE_PAIR = re.compile(r"Completed and verified: two matmul_u32 jobs, each multiplying %s, with seeds %s and %s; %s; %s\.\n\Z" 35 % (DIMS, NUM, NUM, JOBREF, JOBREF)) 36 RE_BOUND = re.compile(r"Not completed: refused before dispatch \(code bound\): the goal asks for a %s by %s by %s matmul" 37 r" and a dimension is outside the admitted range 1 to 256; nothing was dispatched\.\n\Z" 38 % (NUM, NUM, NUM)) 39 RE_STOP = re.compile(r"Not completed: job %s (was refused|failed) \(code ([a-z]+)\): ([a-z ]+)\.\n\Z" % NUM) 40 41 # Reason phrase that each code's sentence must carry (one phrase per code; a 42 # phrase naming a different failure than the code is UNFAITHFUL). 43 REASON = { 44 "replay": "the worker refused a replay of an already executed job", 45 "budget": "the job was refused for budget or fuel", 46 "worker": "the worker refused the job", 47 "transport": "the connection to the worker failed", 48 "receipt": "the verifier refused the worker receipt", 49 "recomp": "the verifier recompute failed", 50 "verdict": "the recomputed result did not match the worker result", 51 "io": "a local input or output error occurred", 52 } 53 CLASS_OF_VERB = {"was refused": "refused", "failed": "fail"} 54 55 56 def parse(text): 57 """English -> claim dict, or None when no documented shape matches.""" 58 m = RE_MM.match(text) 59 if m: 60 g = m.groups() 61 return {"shape": "ok", "kind": "mm", "dims": (int(g[0]), int(g[1]), int(g[3])), 62 "k2": int(g[2]), "seeds": (int(g[4]),), "jobs": [(int(g[5]), g[6], g[7])]} 63 m = RE_PAIR.match(text) 64 if m: 65 g = m.groups() 66 return {"shape": "ok", "kind": "pair", "dims": (int(g[0]), int(g[1]), int(g[3])), 67 "k2": int(g[2]), "seeds": (int(g[4]), int(g[5])), 68 "jobs": [(int(g[6]), g[7], g[8]), (int(g[9]), g[10], g[11])]} 69 m = RE_BOUND.match(text) 70 if m: 71 return {"shape": "bound", "dims": tuple(int(x) for x in m.groups())} 72 m = RE_STOP.match(text) 73 if m: 74 return {"shape": "stop", "job": int(m.group(1)), "cls": CLASS_OF_VERB[m.group(2)], 75 "code": m.group(3), "reason": m.group(4)} 76 return None 77 78 79 def last_row(rows, job): 80 got = [r for r in rows if r["job"] == job] 81 return got[-1] if got else None 82 83 84 def check_response(text, msgs, rows): 85 """Yield (name, status, detail) checks of the English against facts and episode.""" 86 out = [] 87 88 def rec(name, ok, detail=""): 89 out.append((name, "PASS" if ok else "FAIL", detail)) 90 91 claim = parse(text) 92 if claim is None: 93 rec("english.parse", False, "no documented shape: %r" % text[:120]) 94 return out 95 rec("english.parse", True, claim["shape"]) 96 goal, rep = msgs[0], msgs[-1] 97 gdims = tuple(goal.dims) 98 if claim["shape"] == "ok": 99 rec("english.kind", claim["kind"] == goal.jk and rep.cls == "ok" and rep.jk == goal.jk 100 and rep.dims == goal.dims and rep.seeds == goal.seeds, 101 "english=%s goal=%s report=%s" % (claim["kind"], goal.jk, rep.text)) 102 rec("english.dims", claim["dims"] == gdims and claim["k2"] == gdims[1], 103 "english=%s k2=%d goal=%s" % (claim["dims"], claim["k2"], gdims)) 104 rec("english.seeds", claim["seeds"] == tuple(goal.seeds), 105 "english=%s goal=%s" % (claim["seeds"], tuple(goal.seeds))) 106 want_jobs = len(goal.seeds) 107 rec("english.job_count", [j for j, _, _ in claim["jobs"]] == list(range(1, want_jobs + 1))) 108 for j, dag, sha in claim["jobs"]: 109 r = last_row(rows, j) 110 ok = (r is not None and r["exit"] == 0 and r["class"] == "ok" 111 and r["dag_id"] == dag and r["mjr1_sha256"] == sha 112 and (r["m"], r["k"], r["n"]) == claim["dims"] and r["seed"] == claim["seeds"][j - 1]) 113 rec("english.job%d_receipt" % j, ok, "dag_id=%s mjr1_sha256=%s" % (dag, sha)) 114 elif claim["shape"] == "bound": 115 rec("english.dims", claim["dims"] == gdims, "english=%s goal=%s" % (claim["dims"], gdims)) 116 rec("english.bound_true", any(not (1 <= d <= 256) for d in gdims), "goal=%s" % (gdims,)) 117 rec("english.nothing_dispatched", not rows, "rows=%d" % len(rows)) 118 rec("english.report", rep.text == "rep refused bound end", rep.text) 119 else: 120 r = rows[-1] if rows else None 121 rec("english.stop_row", r is not None and r["job"] == claim["job"] 122 and r["class"] == claim["cls"] and r["code"] == claim["code"], 123 "english job=%d %s %s" % (claim["job"], claim["cls"], claim["code"])) 124 rec("english.reason", REASON.get(claim["code"]) == claim["reason"], claim["reason"]) 125 rec("english.report", rep.cls == claim["cls"] and rep.code == claim["code"], rep.text) 126 return out