Files
MeltMind/tools/prepare_phase3_item1b.py
T

95 lines
7.4 KiB
Python

"""Metadata-only item1b training preparation; no new fits or screen/test reads."""
from pathlib import Path
import time
from phase2_h1_worker_v2 import checked,sha,save
from phase3_item1b_common import ROOT,read
from phase2_home_freeze_io import verify
from phase2_gate_outcome_review import validate_review
from track_a_h2_prepare import local_code_closure
from phase3_shared_capacity import PHASE_RESERVES
B=Path(__file__).resolve().parents[1]
H=Path('/home/frank14f/MeltMind-runs')
def main():
start=time.process_time()
if ROOT.exists():raise FileExistsError('Sole item1b root already exists')
croot=H/'phase3-item-c-2026-11-18';validate_review(croot);verify(croot,'implementation')
cc=read(croot/'contract.json');pilot=read(cc['pilot_contract'])
source=dict(cc['source_sha256'])
spec=B/'references/2026-11-18/phase3-item-1b/mold-short-schedule-spec.md'
checked(spec,'55ffc6f9320f6b6f03244acd8548d5037a6efa43d3ce8c48f1b89bb0cb4b5e58')
for p in [spec,croot/'contract.json',croot/'review.json',croot/'expected-review-binding.json',croot/'implementation-review-git-freeze.json',croot/'implementation-review-authorization.json']:
source[str(p)]=sha(p)
baseline=[];jobs=[]
for f in pilot['folds']:
i=f['fold']
w=B/'artifacts/phase2-h2-s1-2026-11-17/worker' if i==0 else H/'phase2-h2-s2-2026-11-17/folds'/str(i)/'worker'
result=read(w/'result.json')
if i==0:
original_contract=w.parent/'contract.json';original=read(original_contract)
if original['fold']!=0 or original['seed']!=0 or original['epochs']!=200:
raise ValueError('Original S1 fold0 contract')
source[str(original_contract)]=sha(original_contract)
elif result['fold']!=i:
raise ValueError('Original S2 fold identity')
if result['completed_epochs']!=200 or result['optimizer_steps']!=200*len(f['learning']):
raise ValueError('Original200epoch same-fold model identity')
stats=read(w/'standardization.json')
if stats['parts']!=f['learning'] or stats['nodes']!=f['learning_nodes']:
raise ValueError('Paired original normalization learning role')
checked(result['checkpoint'],result['checkpoint_sha256'])
for p in [w/'result.json',w/'standardization.json',Path(result['checkpoint'])]:source[str(p)]=sha(p)
histories=[w/'history'/f'{e:03d}.json' for e in range(10,201,10)]
for p in histories:source[str(p)]=sha(p)
val=max(read(p)['validation_seconds'] for p in histories)
baseline.append(dict(fold=i,checkpoint=result['checkpoint'],checkpoint_sha256=result['checkpoint_sha256'],
result=str(w/'result.json'),result_sha256=sha(w/'result.json'),standardization=str(w/'standardization.json'),standardization_sha256=sha(w/'standardization.json'),completed_epochs=200,seed=0))
jobs.append({k:f[k] for k in ('learning','validation','test','c','clock_sha256','learning_nodes')}|
dict(id=i,target_steps=100*len(f['learning']),cpu_seconds=30000,validation_seconds_bound=val,
rss_bytes=4*2**30,recorded_vram_bytes=2*2**30,process_vram_bytes=4*2**30,disk_bytes=8*2**30))
files=sorted(B.glob('tools/phase3_item1b_*.py'))+[Path(__file__).resolve(),B/'tools/test_phase3_item1b.py']
codes=local_code_closure(files+sorted((B/'tools/s2_models').glob('*.py')))
for p,h in cc['code_sha256'].items():codes.setdefault(p,h)
for p,h in {**source,**codes}.items():checked(p,h)
comparison=dict(version='item1b-training-v1',spec_sha256=sha(spec),scheduling_ruling='1795010666.724069',
scheduling_change='all five folds may train before screen; screen still gates any test postfit',
folds=pilot['folds'],roster_parts=552,components=204,seed=0,epochs=100,inputs=19,
recipe='original H2; paired seed0 initialization and original epoch-derived part order; unchanged MSE/optimizer/decay/clipping',
schedule='epochs1..5:1e-4+(e-1)*(1e-3-1e-4)/4;6..100:1e-5+(1e-3-1e-5)*(1+cos(pi*(e-5)/95))/2',
interpretation='joint update-budget and complete-schedule change; not200epoch midpoint; no separate causal claim',
checkpoint='last-epoch100.pt only',validation_diagnostics='original full-node MSE every10epochs, never selection or screen',
baseline_models=baseline,seed1_root=str(H/'phase3-seed1-v2-2026-11-18'),
screen=dict(fold=1,domain='same matched validation query domain',metric='component-equal relativeL2',
delta_short_at_most=-.001,absolute_effect_strictly_above_absolute_seed1_minus_seed0=True,
missing_reference='WAIT_NO_EXTRA_SEED',fail='ARCHIVE_ALL_FIVE_NO_TEST_READ'),
test=dict(requires_screen_PASS=True,requires_separate_pre_score_review=True,parts=552,components=204,
upper_delta_relativeL2_strictly_below=-.001,absolute_effect_strictly_above_absolute_pooled_seed_difference=True,
bootstrap=2000,bootstrap_seed=2026111408,paired_components=True,confidence=.95,
report=['signed means','CI','seed difference','per-fold','hard last-point/Rg','tau','negative predictions','E_tail if available']),
postfit='separately bound validation screen; test inference/score only after screenPASS and actual pre-score review; no postfit launch in training queue',
limitations=['one seed difference is not full training randomness','development-contaminated restricted benchmark, not fresh-family confirmation'])
ROOT.mkdir();save(ROOT/'comparison-contract.json',comparison)
c=dict(version='phase3-item1b-v1',approval='1795010666.724069',entry_approval='1795010507.291259',budget_approval='1795007580.895539',
seed=0,epochs=100,new_fits=5,no_retry=True,gpu_cap=88560,postfit_gpu_reserve=7200,postfit_cpu_cap=3600,
phase3_gpu_cap=720000,phase_reservations=PHASE_RESERVES,preparation_charge_gpu_seconds=600,preparation_cpu_cap=600,
runaway_gpu_seconds=30000,screen_fold=1,test_requires_screen_pass=True,dispatch_order=[1,0,2,3,4],
waiting_charge='all5 from queue start to own terminal; includes pending never-dispatched waits/failures;60s setup per fold',
projection='actual+1.5 remaining100epoch training and10 diagnostic validations+120 cleanup; total gate, no per-fold projection stop',
validation_targets_read='diagnostic_only_every10_epochs_after_reviewed_launch; not selection or screen',test_targets_read=False,
screen_started=False,postfit_started=False,track_a_ledger='separate',
shared_rule_module='phase3_shared_capacity.py unchanged reviewed2ddecef3/e30612ea',
capacity_adapter='item1b key/cap and GPU0..2 only; original shared admission/registry/lease operations unchanged',
jobs=jobs,pilot_contract=cc['pilot_contract'],query_roster_contract=cc['query_roster_contract'],
baseline_models=baseline,source_sha256=source,code_sha256=codes,
comparison_contract=str(ROOT/'comparison-contract.json'),comparison_contract_sha256=sha(ROOT/'comparison-contract.json'))
save(ROOT/'contract.json',c)
save(ROOT/'preparation-audit.json',dict(status='PREPARED_PENDING_ASSIST_REVIEW',contract_sha256=sha(ROOT/'contract.json'),
code_files=len(codes),source_files=len(source),baseline_models=5,opaque_model_hashes_only=True,
metadata_cpu_seconds=time.process_time()-start,labels_decoded=False,arrays_decoded=False,models_loaded=False,new_fits_started=False))
print(read(ROOT/'preparation-audit.json'))
if __name__=='__main__':main()