omega-tool-model
First-party Omega tool-use model source, serving harnesses, and verification records
Brought by drakestapleton
omega-tool-model / deployment / build.py
| 1 | import os |
| 2 | """External build/preparation instrument; installed execution is native Omega.""" |
| 3 | from pathlib import Path |
| 4 | import hashlib, json, shutil, subprocess, difflib |
| 5 | |
| 6 | R = Path(__file__).resolve().parent |
| 7 | P = R.parent / 'tool-omega-20261104' |
| 8 | D = (Path(os.path.expanduser('~')) / '/.local/share/omega-tool-model/round40'.lstrip('/')) |
| 9 | C = R.parent / 'omega-llm-20261101/omega-mv/seed/out/omc' |
| 10 | def sha(p): return hashlib.sha256(p.read_bytes()).hexdigest() |
| 11 | assert sha(C) == '2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f' |
| 12 | latest = json.loads((P/'LATEST.json').read_text()) |
| 13 | assert latest['round'] == 40 and latest['accepted'] and latest['audit_pass'] |
| 14 | ck = Path(latest['checkpoint']) |
| 15 | assert sha(ck) == latest['sha256'] == '7c7b5b5260f2d9453b6076b64e7f23e88341d96498584f2dfaa229c31ad2e346' |
| 16 | assert sha(P/'build/sample') == 'c13cce93f117dd413417009bb34340f59e3265a7c4bb9486fdc6dc6e856d4269' |
| 17 | merges = R.parent/'omega-llm-20261101/v1-data/merges4096.bin' |
| 18 | for src, name in ((ck,'model.ck'), (merges,'merges.bin')): |
| 19 | dest = D/name |
| 20 | if not dest.exists(): |
| 21 | shutil.copyfile(src, dest) |
| 22 | assert sha(src) == sha(dest) |
| 23 | dest.chmod(0o444) |
| 24 | |
| 25 | jobs = json.loads((P/'round40/final-selected.json').read_text()) |
| 26 | demo = jobs[0]['turns'][0]['prompt'] |
| 27 | (D/'example.prompt').write_text(demo) |
| 28 | def literal(s): return json.dumps(s, ensure_ascii=False) |
| 29 | entry = '\n'.join([ |
| 30 | 'text imodel '+literal(str(D/'model.ck')), |
| 31 | 'text imerges '+literal(str(D/'merges.bin')), |
| 32 | 'text example '+literal(demo), |
| 33 | (R/'entry.om').read_text(), |
| 34 | ]) |
| 35 | src = (P/'build/sample-all.om').read_text() |
| 36 | out = src |
| 37 | old = 'ret argread i oarg 0 4096' |
| 38 | assert out.count(old) == 1 |
| 39 | out = out.replace(old, 'ret installedargs i') |
| 40 | old = '''fn main to int |
| 41 | if ne oargc 5 |
| 42 | ret 2 |
| 43 | end |
| 44 | nn = oargu 2 |
| 45 | if or eq nn 0 gt nn 256 |
| 46 | ret 2 |
| 47 | end''' |
| 48 | assert out.count(old) == 1 |
| 49 | out = out.replace(old, 'fn main to int\niread\nnn = ulong 160') |
| 50 | old = 'np = obprompt 3\nfor i ulong np' |
| 51 | assert out.count(old) == 1 |
| 52 | out = out.replace(old, 'np = obprompt 3\nif ge np get og 1\nret 3\nend\nfor i ulong np') |
| 53 | out = out+'\n'+entry |
| 54 | (R/'installed-all.om').write_text(out) |
| 55 | (R/'sampler.diff').write_text(''.join(difflib.unified_diff(src.splitlines(True), out.splitlines(True), fromfile='qualified-sampler', tofile='installed-sampler'))) |
| 56 | assert src[src.index('fn gsforward'):src.index('fn main to int')] == out[out.index('fn gsforward'):out.index('fn main to int')] |
| 57 | # Every byte of the original GPU unit precedes gsforward and is unchanged. |
| 58 | start = src.index('text nvctl ') |
| 59 | end = src.index('fn gsforward') |
| 60 | assert src[start:end] == out[out.index('text nvctl '):out.index('fn gsforward')] |
| 61 | q = subprocess.run([str(C)],input=out.encode(),capture_output=True,timeout=60) |
| 62 | (R/'compile.stderr').write_bytes(q.stderr) |
| 63 | assert q.returncode == 0, (q.returncode,q.stderr.decode()) |
| 64 | (D/'omega-tool-model').write_bytes(q.stdout) |
| 65 | (D/'omega-tool-model').chmod(0o555) |
| 66 | shutil.copyfile(R/'installed-all.om',D/'source.om') |
| 67 | pins = {str(x):sha(x) for x in (C,ck,merges,P/'build/sample',P/'build/sample-all.om',R/'entry.om',R/'installed-all.om',D/'model.ck',D/'merges.bin',D/'omega-tool-model')} |
| 68 | (R/'build-receipt.json').write_text(json.dumps(dict(compile_rc=q.returncode,pins=pins,kernel_source_unchanged=True,model_math_unchanged=True),indent=2)+'\n') |
| 69 | print('Native build passed; copied weights verified; model math and GPU source unchanged.') |