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 / grow-gate.py

78 lines · 3305 bytes Raw Blame History
1#!/usr/bin/env python3
2"""Compile every build.sh target, then check growth on the native host binary.
3
4External verification only. Usage: grow-gate.py COMPILERS.json OUTPUT --core N
5The JSON object maps each build.sh target name to its pinned compiler's path.
6The a64efi compiler keeps its existing ../a64efi/efirt.om companion.
7"""
8import argparse
9import hashlib
10import json
11import os
12from pathlib import Path
13import re
14import subprocess
15import sys
16
17
18def targets(script):
19 start = 'case "$TARGET" in\n'
20 if script.count(start) != 1:
21 raise ValueError('build.sh must have exactly one target case')
22 case = script.split(start, 1)[1].split('\nesac', 1)[0]
23 labels = re.findall(r'^\s+([^\n)]+)\)', case, flags=re.M)
24 names = []
25 for label in labels:
26 if label == '*':
27 continue
28 if not re.fullmatch(r'[a-z0-9]+(?:\|[a-z0-9]+)*', label):
29 raise ValueError('unrecognized target label: ' + label)
30 names.extend(label.split('|'))
31 if not names or len(names) != len(set(names)):
32 raise ValueError('empty or duplicate build target inventory')
33 return names
34
35
36def main():
37 p = argparse.ArgumentParser(description=__doc__)
38 p.add_argument('compilers', type=Path)
39 p.add_argument('output', type=Path)
40 p.add_argument('--core', required=True, type=int)
41 args = p.parse_args()
42 build = Path(__file__).resolve().with_name('build.sh')
43 names = targets(build.read_text())
44 compilers = json.loads(args.compilers.read_text())
45 if not isinstance(compilers, dict) or set(compilers) != set(names):
46 raise ValueError('compiler map must cover exactly these targets: ' + ', '.join(names))
47 output = args.output.resolve()
48 output.mkdir(parents=True, exist_ok=True)
49 failed = False
50 for name in names:
51 compiler = Path(compilers[name]).expanduser().resolve()
52 env = dict(os.environ, TARGET=name, OMC=str(compiler),
53 OUT=str(output / name), CORE=str(args.core))
54 print('compiler', name, hashlib.sha256(compiler.read_bytes()).hexdigest(), flush=True)
55 result = subprocess.run(['sh', str(build)], env=env, capture_output=True, timeout=120)
56 (output / (name + '.log')).write_bytes(result.stdout + result.stderr)
57 print(result.stdout.decode(errors='replace'), end='')
58 print(result.stderr.decode(errors='replace'), end='')
59 print('BUILD_TARGET', name, 'rc=' + str(result.returncode), flush=True)
60 failed |= result.returncode != 0
61 if failed:
62 raise SystemExit(1)
63 print('ALL_TARGET_BUILDS_PASS', len(names), flush=True)
64 command = ['taskset', '-c', str(args.core), 'nice', '-n', '19', sys.executable, '-B',
65 str(build.with_name('grow-check.py')), str(output / 'aarch64'),
66 str(Path(compilers['aarch64']).expanduser().resolve())]
67 result = subprocess.run(command, capture_output=True, timeout=120)
68 (output / 'host-growth.log').write_bytes(result.stdout + result.stderr)
69 print(result.stdout.decode(errors='replace'), end='')
70 print(result.stderr.decode(errors='replace'), end='')
71 print('HOST_GROWTH rc=' + str(result.returncode), flush=True)
72 if result.returncode != 0:
73 raise SystemExit(1)
74 print('GROW_GATE_PASS')
75
76
77if __name__ == '__main__':
78 main()