71 lines
4.7 KiB
Python
71 lines
4.7 KiB
Python
"""Item1 frozen roles, schedules and costs. No model execution or target access."""
|
|
import json,math
|
|
from pathlib import Path
|
|
from phase2_fixed_io import BASE
|
|
from phase2_h1_worker_v2 import checked,sha
|
|
from phase2_home_freeze_io import verify
|
|
|
|
def read(p):return json.loads(Path(p).read_text())
|
|
def lr_step(step,total=64000,warmup=3200):
|
|
if not 1<=step<=total or not 1<warmup<total:raise ValueError('1-based fixed update domain')
|
|
if step<=warmup:return 1e-4+(step-1)*9e-4/(warmup-1)
|
|
return 1e-5+(1e-3-1e-5)*(1+math.cos(math.pi*(step-warmup)/(total-warmup)))/2
|
|
|
|
def execution_command(args):
|
|
return any(Path(x).name in {'phase3_data_sufficiency_v2_queue.py','phase3_data_sufficiency_v2_guard.py','phase3_data_sufficiency_v2_worker.py'} for x in args)
|
|
|
|
def config(root):
|
|
c=read(root/'contract.json');verify(root,'implementation')
|
|
if c['approval']!='1794948643.973609' or c['new_fits']!=6 or c['item_gpu_cap']!=120000 or c['budget_approval']!='1794948710.366709' or c['phase3_gpu_cap']!=612000 or c['train_gpu_cap']+c['postfit_gpu_reserve']!=c['item_gpu_cap']:raise PermissionError('Frozen item1 scope')
|
|
if c['U']!=32000 or c['delta']!=.001 or c['seed']!=0 or c['fold']!=0 or not c['no_retry']:raise ValueError('Frozen science identity')
|
|
for p,h in {**c['source_sha256'],**c['code_sha256']}.items():checked(p,h)
|
|
pilot=read(c['pilot_contract'])
|
|
import torch,numpy as np
|
|
if torch.__version__!=pilot['versions']['torch'] or np.__version__!=pilot['versions']['numpy']:raise ValueError('Original library identity')
|
|
if len({j['gpu_uuid'] for j in c['jobs']})!=4 or sum(j['gpu_seconds'] for j in c['jobs'])!=c['train_gpu_cap']:raise ValueError('Job resources')
|
|
pools=c['pools'];sets=[set(pools[str(p)]['learning']) for p in [25,50,100]]
|
|
if not sets[0]<sets[1]<sets[2] or sets[2]!=set(pilot['folds'][0]['learning']):raise ValueError('Original nested roles')
|
|
for p in [25,50,100]:
|
|
q=pools[str(p)]
|
|
if set(q['learning'])&(set(q['validation'])|set(q['test'])) or q['validation']!=pilot['folds'][0]['validation'] or q['test']!=pilot['folds'][0]['test']:raise ValueError('Role separation')
|
|
if read(q['clock_path'])['parts']!=q['learning'] or q['learning_nodes']!=sum(pilot['parts'][x]['nodes'] for x in q['learning']):raise ValueError('Learning clock/node identity')
|
|
for j in c['jobs']:
|
|
q=pools[str(j['pool'])];target=200*len(q['learning']) if j['mode']=='epoch' else j['step_budget']
|
|
if j['target_steps']!=target or j['learning_parts']!=len(q['learning']) or j['learning_nodes']!=q['learning_nodes']:raise ValueError('Cell identity')
|
|
return c,pilot
|
|
|
|
def view_for(c,pilot,job):return dict(pilot,folds=[c['pools'][str(job['pool'])]])
|
|
|
|
def project_cell(job,observation):
|
|
v=observation;steps=v['steps'];per=v['max_epoch_seconds']/job['learning_parts'];val=max(v['max_validation_seconds'],job['validation_seconds_bound'])
|
|
if not 0<steps<=job['target_steps'] or not all(math.isfinite(x) and x>=0 for x in [per,val,v['charged']]) or per<=0:raise ValueError('Invalid cost evidence')
|
|
checks=20 if job['mode']=='epoch' else job['target_steps']//3200
|
|
future=1.25*((job['target_steps']-steps)*per+checks*val)+120
|
|
return dict(id=job['id'],pool=job['pool'],mode=job['mode'],projected_gpu_seconds=v['charged']+future,job_cap=job['gpu_seconds'],within_cap=v['charged']+future<=job['gpu_seconds'])
|
|
|
|
def project_total(c,estimates,terminal):
|
|
if any(i not in range(6) for i in estimates) or any(i not in range(6) for i in terminal):raise ValueError('Unknown cell')
|
|
total=c['postfit_gpu_reserve'];rows=[]
|
|
for j in c['jobs']:
|
|
i=j['id'];cost=terminal[i]['gpu_seconds_charged'] if i in terminal else estimates.get(i,{}).get('projected_gpu_seconds',j['prelaunch_projected_gpu_seconds'])
|
|
if not math.isfinite(cost) or cost<0:raise ValueError('Invalid ledger')
|
|
rows.append(dict(id=i,projected_gpu_seconds=cost,within_cap=cost<=j['gpu_seconds']));total+=cost
|
|
return dict(status='PASS' if total<=c['item_gpu_cap'] and all(x['within_cap'] for x in rows) else 'STOP_BUDGET_PROJECTION',rows=rows,projected_item_gpu_seconds=total,postfit_reserve=c['postfit_gpu_reserve'],phase3_cap=c['phase3_gpu_cap'])
|
|
|
|
def first_epoch_release(root,jobid):
|
|
if (root/'global-stop.json').exists():raise RuntimeError('Global item1 stop')
|
|
p=root/'jobs'/str(jobid)/'first-epoch-projection.json'
|
|
if not p.exists():return False
|
|
d=read(p)
|
|
if d['status']!='PASS' or d['contract_sha256']!=sha(root/'contract.json'):raise RuntimeError('First-epoch projection rejected')
|
|
return True
|
|
|
|
def dispatchable(pending,active_jobs,limit=4):
|
|
occupied={j['gpu_uuid'] for j in active_jobs};slots=limit-len(active_jobs);selected=[]
|
|
if slots<0 or len(occupied)!=len(active_jobs):raise ValueError('Active GPU collision/cap')
|
|
for j in pending:
|
|
if not slots:break
|
|
if j['gpu_uuid'] in occupied:continue
|
|
selected.append(j);occupied.add(j['gpu_uuid']);slots-=1
|
|
return selected
|