"""Frozen matched training contrast and one ensemble replacement; no Test.""" import csv import json from pathlib import Path import sys ROOT=Path('/marimo/storage/road');sys.path.insert(0,str(ROOT)) from visual_preference import policy,digest,write_json,RUN from lighton_completed_gate_oct2 import BUNDLE,ORDER,table,compare,rover,drop_runaways def main(): freeze,split,source,fit_ids=policy();ids=split['val_ids'] run=json.loads((RUN/'run_config.json').read_text()) assert run['fit_ids']==fit_ids and run['val_ids']==ids and run['validation_contaminated'] is False assert run['training_source_sha256']==digest(ROOT/'visual_preference.py') marker=json.loads((RUN/'final/SAVE_COMPLETE').read_text()) assert marker['step']==freeze['configuration']['steps'] assert marker['weight_sha256']==digest(RUN/'final/adapter_model.safetensors') assert marker['manifest_sha256']==digest(RUN/'final/run_config.json') for kind in ['initial','final']: sidecar=json.loads((ROOT/f'preds_val_visual_preference_{kind}_oct2.manifest.json').read_text()) assert sidecar['ids']==ids and sidecar['freeze_sha256']==digest(ROOT/'visual_preference_oct2.freeze.json') assert sidecar['source_sha256']==digest(ROOT/'visual_preference.py') expected=freeze['initialization']['weight_sha256'] if kind=='initial' else marker['weight_sha256'] assert sidecar['adapter_sha256']==expected for i,sha in sidecar['image_sha256'].items():assert digest(ROOT/'images'/(i+'.jpg'))==sha initial=ROOT/'preds_val_visual_preference_initial_oct2.csv' final=ROOT/'preds_val_visual_preference_final_oct2.csv' matched=compare(initial,final,BUNDLE/'Train.csv',BUNDLE/'split_manifest.json',10000,20261002) tables={name:table(BUNDLE/('m_'+name+'.csv'),ids) for name in ORDER} tables['preference']=table(final,ids) scratch=ROOT/'visual_preference_gate_oct2';scratch.mkdir(exist_ok=True) for name,members in [('control',ORDER),('replace_r64',ORDER[:1]+['preference']+ORDER[2:])]: with (scratch/(name+'.csv')).open('w',newline='') as f: w=csv.writer(f);w.writerow(['ID','raw']) for i in ids:w.writerow([i,rover(drop_runaways([tables[m][i] for m in members if tables[m][i]]))]) report=compare(scratch/'control.csv',scratch/'replace_r64.csv',BUNDLE/'Train.csv',BUNDLE/'split_manifest.json',10000,20261002) assert abs(report['sqrt_weighted_raw']['baseline']-.9318177934195226)<1e-12 def passed(r): w=r['sqrt_weighted_raw'];return w['delta']>=.001 and w['paired_delta_ci95'][0]>0 and r['arithmetic_raw']['delta']>0 report.update(matched_training=matched,decision='eligible_for_artifact_review' if passed(report) and passed(matched) else 'do_not_promote', final_model_sha256=marker['weight_sha256'],freeze_sha256=digest(ROOT/'visual_preference_oct2.freeze.json'), eligible_preference_pairs=run['eligible_preference_pairs'],test_queued=False,submission_attempted=False, limitations='Repeated holdout; matched training and one fixed ensemble arm. Production artifact gaps still require review.') write_json(ROOT/'visual_preference_completed_gate_oct2.json',report);print(json.dumps(report),flush=True) if __name__=='__main__':main()