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/tests/omegallm/bf16-inference.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 / tests / omegallm / bf16-inference.py` 102 lines ยท 5382 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """External BF16 decode oracle. Requires an already authorized GPU window.""" 3 import argparse 4 import hashlib 5 import json 6 import os 7 from pathlib import Path 8 import re 9 import struct 10 import subprocess 11 12 p = argparse.ArgumentParser(description=__doc__) 13 p.add_argument('--candidate', type=Path, required=True) 14 p.add_argument('--baseline', type=Path, required=True) 15 p.add_argument('--compiler', type=Path, required=True) 16 p.add_argument('--source', type=Path, required=True, help='candidate concatenated build source') 17 p.add_argument('--checkpoint', type=Path, action='append', required=True) 18 p.add_argument('--merges', type=Path, required=True) 19 p.add_argument('--output', type=Path, required=True) 20 a = p.parse_args() 21 a.output.mkdir(parents=True, exist_ok=False) 22 assert os.environ.get('SPARK_WINDOW'), 'authorized SPARK_WINDOW required' 23 sha = lambda x: hashlib.sha256(x.read_bytes()).hexdigest() 24 inputs = [a.candidate, a.baseline, a.compiler, a.source, a.merges] + a.checkpoint 25 report = {'window': os.environ['SPARK_WINDOW'], 'verdict': 'RUNNING', 26 'inputs': {str(x.resolve()): sha(x) for x in inputs}, 'checks': []} 27 def save(): 28 (a.output/'result.json').write_text(json.dumps(report, indent=2)+'\n') 29 save() 30 def run(tag, binary, args, expected=0, data=None): 31 cmd = [str(binary.resolve()), *map(str,args)] 32 r = subprocess.run(cmd, input=data, capture_output=True, timeout=300) 33 (a.output/(tag+'.stdout')).write_bytes(r.stdout) 34 (a.output/(tag+'.stderr')).write_bytes(r.stderr) 35 report['checks'].append({'tag': tag, 'argv': cmd, 'exit': r.returncode, 36 'stdout_sha256': hashlib.sha256(r.stdout).hexdigest(), 37 'stderr_sha256': hashlib.sha256(r.stderr).hexdigest()}) 38 save() 39 assert r.returncode in (expected if isinstance(expected, tuple) else (expected,)), (tag, r.returncode, expected) 40 return r.stdout 41 def compare(tag, ck, prompt, mode, binary=None, expected=0): 42 out = run(tag, binary or a.candidate, ['gdbench',ck,250,prompt,a.merges,mode],expected) 43 lines = out.decode().splitlines() 44 points = [list(map(int,x.split()[1:])) for x in lines if x.startswith('GQ ')] 45 total = [list(map(int,x.split()[1:])) for x in lines if x.startswith('GDQ ')] 46 assert len(points) == 250 and len(total) == 1, ('incomplete-comparison',tag) 47 assert [x[0] for x in points] == list(range(250)), ('step-sequence',tag) 48 assert total[0][0] == 250 49 assert total[0][1] == sum(x[4] for x in points), ('difference-count',tag) 50 assert total[0][2] == max(x[5] for x in points), ('maximum-error',tag) 51 assert total[0][3] == sum(x[2]!=x[3] and x[6]>`500000000` for x in points), ('divergence-count',tag) 52 if mode == 8: 53 assert total[0][2] <= `250000000` and total[0][3] == 0, ('BF16-accuracy',tag) 54 if mode == 2: 55 assert total[0][1:] == [0,0,0], ('f32-regression',tag) 56 return out 57 def profile(tag, binary, ck): 58 out = run(tag,binary,['gdbench',ck,1,'Once upon a time',a.merges,7]) 59 ids = [int(x.split()[1]) for x in out.decode().splitlines() if x.startswith('GP ')] 60 assert ids, ('missing-profile',tag) 61 return sum(27 <= i <= 36 for i in ids) 62 try: 63 prompts = ['The Omega compiler reads a program and', 64 'Once upon a time, a small fox found a red ball.', 65 '1 2 3 4 5. The answer is', 66 'fn main to int ret 0 end. '+('The moon and stars were bright. '*45)] 67 for i,ck in enumerate(a.checkpoint): 68 for j,prompt in enumerate(prompts): 69 compare(f'bf16-{i}-{j}',ck,prompt,8) 70 compare(f'f32-{i}',ck,prompts[0],2) 71 layers = struct.unpack_from('