interplane.Get Omega
Read in your language

omega-tool-model

First-party Omega tool-use model source, serving harnesses, and verification records

Brought by drakestapleton

branch main Branches Tags History

omega-tool-model / deployment / fast / build.py

80 lines · 3642 bytes Raw Blame History
1import os
2"""External build instrument. Both shipped programs are native Omega."""
3from pathlib import Path
4import hashlib,json,subprocess,difflib
5R=Path(__file__).resolve().parent
6D=(Path(os.path.expanduser('~')) / '/.local/share/omega-tool-model/round40'.lstrip('/'))
7C=(Path(os.path.expanduser('~')) / '/handoffs/omega-llm-20261101/omega-mv/seed/out/omc'.lstrip('/'))
8def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest()
9assert sha(C)=='2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f'
10manifest=json.loads((D/'DEPLOYED.json').read_text())
11assert sha(D/'model.ck')==manifest['checkpoint_sha256']
12assert sha(D/'omega-tool-model')==manifest['runtime_sha256']
13src=(D/'source.om').read_text()
14mainstart=src.index('fn main to int\niread')
15mainend=src.index('text imodel ',mainstart)
16base=src[:mainstart]+src[mainend:]
17entry=src[mainend:]
18cliententry=entry[:entry.index('note Preserve the sampler')]
19cliententry=cliententry.replace('No tools are executed. No chat service is started.', 'Streams from the resident local model. No tools are executed.')
20flushstart=base.index('fn oflush to void')
21flushend=base.index('\nnote v1 checkpoint',flushstart)
22flush='''fn oflush to void
23n = get oon 0
24if eq n 0
25ret
26end
27if lt get nfd 0 0
28r = write 2 oout 0 n
29put oon 0 0
30ret
31end
32nheader n
33for i ulong n
34put nbuf add i 2 get oout i
35end
36if not nsend 0 add n 2
37put nerr 0 1
38end
39put oon 0 0
40end
41'''
42base=base[:flushstart]+flush+base[flushend:]
43transport=(R/'transport.om').read_text()
44server=(R/'server.om').read_text().replace('r = umask 63','put nfd 0 -1\nr = umask 63')
45resident=transport+'\n'+base+'\n'+server
46client=transport+'\n'+cliententry+'\n'+(R/'client-entry.om').read_text()
47head='''
48note Only the 32-row tile containing the last context position needs vocabulary scores.
49note Keep the original kernel, K reduction order, full allocated stride and output row offset.
50fn gglast x ulong w ulong c ulong to void
51row = mul div sub get og 9 1 32 32
52k4 = uint mul get og 2 4
53n4 = uint mul get og 0 4
54xx = add x mul row ulong k4
55cc = add c mul row ulong n4
56gkopa 0 xx k4 4 0 0
57gkopa 1 w k4 4 0 0
58gkopc cc n4 4 0 0 f32 1.0f64
59ggmm 32 get og 0 get og 2 1 1 false
60end
61'''
62old='ggxwt z w x get og 0 d false\nend\nfn gsnext'
63assert resident.count(old)==1
64optimized=resident.replace(old,'gglast z w x\nend\nfn gsnext')+head
65sources={'server-base':resident,'server-head':optimized,'client':client}
66receipts={}
67for name,source in sources.items():
68 path=R/(name+'.om');path.write_text(source)
69 p=subprocess.run([str(C)],input=source.encode(),capture_output=True,timeout=60)
70 (R/(name+'.stderr')).write_bytes(p.stderr)
71 assert p.returncode==0,(name,p.returncode,p.stderr.decode())
72 (R/name).write_bytes(p.stdout);(R/name).chmod(0o700)
73 receipts[name]=dict(source_sha256=sha(path),binary_sha256=sha(R/name),compile_rc=p.returncode)
74(R/'resident.diff').write_text(''.join(difflib.unified_diff(src.splitlines(True),resident.splitlines(True),fromfile='installed',tofile='resident')))
75(R/'projection.diff').write_text(''.join(difflib.unified_diff(resident.splitlines(True),optimized.splitlines(True),fromfile='resident',tofile='last-tile')))
76start=src.index('text nvctl ');end=src.index('fn gsforward')
77for name in ('server-base','server-head'):
78 s=sources[name];assert src[start:end]==s[s.index('text nvctl '):s.index('fn gsforward')]
79(R/'build.json').write_text(json.dumps(dict(builds=receipts,kernel_source_unchanged=True,pins={str(p):sha(p) for p in (C,D/'source.om',D/'omega-tool-model',D/'model.ck',D/'merges.bin')}),indent=2)+'\n')
80print('Built native resident baseline, last-tile candidate and streaming client; kernel source unchanged.')