Files
MeltMind/tools/phase3_item_b_shared_common.py
T

96 lines
4.5 KiB
Python

"""Item b immutable scope, assignments and conservative total-cost projection."""
import json
import math
import statistics
from pathlib import Path
from phase2_h1_worker_v2 import checked, sha
from phase2_home_freeze_io import verify
from phase3_seed1_v2_common import fold_view
from phase3_item_b_shared_budget import RULING, USER_CAP, full_fold_bound, project
ROOT = Path('/home/frank14f/MeltMind-runs/phase3-item-b-shared-2026-11-19')
def read(p):
return json.loads(Path(p).read_text())
def config(root):
if root.resolve() != ROOT:
raise PermissionError('Sole shared-mode b root')
c = read(root/'contract.json')
verify(root, 'implementation')
expected = dict(approval='1795011607.907609', seed=0, epochs=200, new_fits=5, shared_budget_ruling=RULING,
postfit_gpu_reserve=7200, postfit_cpu_cap=3600,
phase3_gpu_cap=720000, no_retry=True)
if any(c.get(k) != v for k,v in expected.items()):
raise PermissionError('Fixed item_b scope/budgets')
for p,h in {**c['source_sha256'], **c['code_sha256']}.items():
checked(p,h)
bounds = read(c['shared_budget_evidence'])
if bounds['ruling'] != RULING or c['phase_reservations'] != bounds['phase_reservations']:
raise ValueError('Fixed shared budget identity')
full_bounds = []
for job, row in zip(c['jobs'], bounds['folds'], strict=True):
epoch = row['max_train_epoch_seconds']
full = full_fold_bound(epoch, job['validation_seconds_bound'])
if (job['id'] != row['fold'] or job['shared_epoch_seconds_bound'] != epoch
or job['full_training_gpu_seconds_bound'] != full):
raise ValueError('Fixed fold timing bounds')
full_bounds.append(full)
cap = math.ceil(c['preparation_charge_gpu_seconds'] + c['postfit_gpu_reserve']
+ sum(full_bounds) + max(full_bounds))
if (c['gpu_cap'] != cap or c['phase_reservations']['b'] != cap or cap > USER_CAP
or sum(c['phase_reservations'].values()) > c['phase3_gpu_cap']
or c['phase_reservations']['item1b'] != bounds['parked_1b_actual_including_tail']):
raise ValueError('User or phase 3 reservation exceeded')
pilot = read(c['pilot_contract'])
import numpy as np
import torch
if np.__version__ != pilot['versions']['numpy'] or torch.__version__ != pilot['versions']['torch']:
raise ValueError('Original environment versions')
if [j['id'] for j in c['jobs']] != list(range(5)):
raise ValueError('Exactly five folds')
tests = []
for job in c['jobs']:
f = fold_view(pilot, job['id'])['folds'][0]
tests.extend(f['test'])
if job['target_steps'] != 200*len(f['learning']):
raise ValueError('Full fixed epochs')
for k in ('learning','validation','test','c','clock_sha256','learning_nodes'):
if job[k] != f[k]:
raise ValueError('Original fold identity changed')
if len(tests) != 552 or len(set(tests)) != 552:
raise ValueError('Original552 roster')
rows=read(c['query_roster_contract'])['rows']
if len(rows)!=552 or {r['case'] for r in rows}!=set(tests) or len({r['component_id'] for r in rows})!=204:
raise ValueError('552 parts /204 components query roster')
for r in rows:
p=pilot['parts'][r['case']]
if r['v5_cache']['output_sha256']!=p['output_sha256'] or r['nodes']!=p['nodes'] or r['component_id']!=p['clock_group']:
raise ValueError('Learning query/geometry/cache identity')
if c['inputs']!=22 or c['added_parameters']!=384 or c['budget_approval']!='1795007580.895539' or not c['decision_requires_seed_reference']:
raise PermissionError('Fixed regional context scope')
checked(c['comparison_contract'], c['comparison_contract_sha256'])
return c,pilot
def assignment(root,c,index,digest):
a = read(checked(root/'jobs'/str(index)/'assignment.json',digest))
if a['id'] != index or a['contract_sha256'] != sha(root/'contract.json'):
raise PermissionError('Assignment identity')
return dict(c['jobs'][index], **{k:a[k] for k in ('gpu_uuid','worker_cpus','token','queue_identity')})
def first_epoch_release(root,index):
if (root/'global-stop.json').exists():
raise RuntimeError('Global stop')
p = root/'jobs'/str(index)/'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 gate not passed')
return True