omega-tool-model
First-party Omega tool-use model source, serving harnesses, and verification records
Brought by drakestapleton
omega-tool-model / pilot / run.py
| 1 | import os |
| 2 | """External experiment instrument; all training and inference execute in Omega.""" |
| 3 | from pathlib import Path |
| 4 | import hashlib,json,os,re,shutil,subprocess,time |
| 5 | |
| 6 | R=Path(__file__).parent |
| 7 | GPU=Path('/tmp/gk/r10/ollm-gb10') |
| 8 | CPU=(Path(os.path.expanduser('~')) / '/handoffs/weight-tuning-20261104/build/ollm'.lstrip('/')) |
| 9 | BASE=Path('/tmp/gk/r10/run/ck60000.bin') |
| 10 | MERGES=(Path(os.path.expanduser('~')) / '/handoffs/omega-llm-20261101/v1-data/merges4096.bin'.lstrip('/')) |
| 11 | assert os.environ.get('SPARK_WINDOW') |
| 12 | commands=[] |
| 13 | def sha(p): |
| 14 | with p.open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest() |
| 15 | initial=sha(BASE) |
| 16 | assert initial=='a53ced7265818c8f6197449315e9ca4082721665022fec4f81d4538e8d6c2d0f' |
| 17 | assert sha(GPU)=='54fb8233c62a13c0b3bac13a38dd5b583943e9e9097342baaa57fc22db2ceb49' |
| 18 | assert (R/'receipts/baseline-sample.txt').read_bytes()==(R/'receipts/baseline-gpu-sample.txt').read_bytes() |
| 19 | def run(label,args,timeout=1200): |
| 20 | t=time.time();p=R/f'receipts/{label}.log' |
| 21 | with p.open('w') as f:q=subprocess.run([str(x) for x in args],stdout=f,stderr=subprocess.STDOUT,timeout=timeout) |
| 22 | commands.append({'label':label,'argv':[str(x) for x in args],'rc':q.returncode,'start':t,'end':time.time()}) |
| 23 | (R/'commands.json').write_text(json.dumps(commands,indent=2)+'\n') |
| 24 | assert q.returncode==0,(label,q.returncode) |
| 25 | return p.read_text() |
| 26 | def score(label,ck,data,w=None): |
| 27 | if w is None:w=(data.stat().st_size//2-1)//256 |
| 28 | s=run(label,[GPU,'geval',ck,data,w,MERGES]) |
| 29 | m=re.findall(r'^E (\d+) (\d+) (\d+) (\d+)$',s,re.M) |
| 30 | assert len(m)==1 and int(m[0][1])==w |
| 31 | d={'label':label,'checkpoint':str(ck),'loss_micronats':int(m[0][2]),'windows':w} |
| 32 | print(json.dumps(d),flush=True);return d |
| 33 | |
| 34 | dev=R/'data/dev.tok';final=R/'data/test.tok' |
| 35 | trials=[score('dev-baseline',BASE,dev)] |
| 36 | current=R/'checkpoints/start.ck' |
| 37 | for steps in [250,500,1000]: |
| 38 | nxt=R/f'checkpoints/step{steps}.ck';assert not nxt.exists();shutil.copyfile(current,nxt) |
| 39 | run(f'train-{steps}',[GPU,'gtrainb',nxt,R/'data/mixed.tok',steps,50]) |
| 40 | trials.append(score(f'dev-{steps}',nxt,dev));current=nxt |
| 41 | (R/'progress.json').write_text(json.dumps(trials,indent=2)) |
| 42 | best=min(trials,key=lambda x:x['loss_micronats']) |
| 43 | selected=Path(best['checkpoint']) |
| 44 | (R/'selection.json').write_text(json.dumps({'trials':trials,'selected':best,'sha256':sha(selected),'selected_before_final':True},indent=2)) |
| 45 | finalscores=[score('test-baseline',BASE,final),score('test-selected',selected,final)] |
| 46 | stories=MERGES.parent/'held.tok' |
| 47 | storyscores=[score('stories-baseline',BASE,stories,64),score('stories-selected',selected,stories,64)] |
| 48 | probes=[] |
| 49 | seen=set() |
| 50 | for row in json.loads((R/'data/test.json').read_text()): |
| 51 | if row['kind'] in seen:continue |
| 52 | seen.add(row['kind']);probes.append(row) |
| 53 | (R/'probes.json').write_text(json.dumps(probes,indent=2)) |
| 54 | for label,ck in [('baseline',BASE),('selected',selected)]: |
| 55 | for row in probes: |
| 56 | run(f"sample-{label}-{row['kind']}",[R/'build/sample',ck,128,row['prompt'],MERGES],300) |
| 57 | print('sample '+label+' '+row['kind']+' complete',flush=True) |
| 58 | # Independent CPU replay of a trained output prefix, before behavioral conclusions. |
| 59 | probe=next(x for x in probes if x['kind']=='add') |
| 60 | cpu=run('selected-cpu-prefix',[CPU,'sample',selected,1,20,0,probe['prompt'],MERGES],300) |
| 61 | gpu=run('selected-gpu-prefix',[R/'build/sample',selected,20,probe['prompt'],MERGES],120) |
| 62 | assert cpu==gpu,'CPU and GPU trained output disagree' |
| 63 | assert sha(BASE)==initial |
| 64 | summary={'final_scores':finalscores,'story_scores':storyscores,'selected':best,'selected_sha256':sha(selected),'original_unchanged':True,'cpu_gpu_prefix_parity':True,'window':os.environ['SPARK_WINDOW']} |
| 65 | (R/'results.json').write_text(json.dumps(summary,indent=2)+'\n') |
| 66 | print('TRAINING AND GENERATION COMPLETE',flush=True) |