"""Freeze a delay stage plan with short (held-out training-scene) and long (earlier-env, n via seeds) sources. Runs on the pod.""" import argparse, hashlib, json, sys, time from pathlib import Path import h5py E = Path('/data/robo_ttt/robocasa_memory_20261103/evaluation-ck30000-20261108') OLD = E/'cotrain-ck3000-20261114' N = E/'cotrain-delay-n10-20261115' sys.path.insert(0, str(OLD/'code')) from experiments.robocasa_memory.evaluation.memory_conditions import native_full_video CONDS = ('checkpoint100', 'full_history') def digest(p): with open(p, 'rb') as f: return hashlib.file_digest(f, 'sha256').hexdigest() def mem(config, cond, h, budget): return None if cond == 'checkpoint100' else native_full_video(config, h+budget, spatial_policy='fixed_256') def main(): p = argparse.ArgumentParser(); p.add_argument('--stage', required=True); p.add_argument('--label-minutes', type=int, required=True) p.add_argument('--short', action='append', default=[], help='case=source_dir (held-out training-scene clean-handoff source)') p.add_argument('--long', action='append', default=[], help='cell=source_dir=frame_cache_hdf5[=seed:seed:...] (earlier env, one scene; per-cell seeds override --long-seeds)') p.add_argument('--long-seeds', default='', help='comma-separated policy seeds for each long cell') p.add_argument('--conditions', default=','.join(CONDS), help='comma-separated memory conditions to freeze into the plan') p.add_argument('--conditions-note', default='', help='why the condition set differs from the default, recorded in the plan'); a = p.parse_args() conds = tuple(x for x in a.conditions.split(',') if x); assert conds and set(conds) <= set(CONDS) stage = N/a.stage; stage.mkdir(parents=True, exist_ok=True); assert not (stage/'plan.json').exists() old = json.loads((OLD/'evaluation-plan.json').read_text()) hist = {c['case']: c for c in old['cases'] if c['condition'] == 'history'} immediate = {r['trial_id']: r for r in json.loads((OLD/'summary.json').read_text())['results']} config = json.loads((OLD/'checkpoint/model/config.json').read_text()) cases = [] for item in a.short: name, src = item.split('='); src = Path(src); g = json.loads((src/'result.json').read_text()); c = hist[name] assert g['status'] == 'verified' and g['case'] == name and g['training_sha256'] == c['hdf5_sha256'] assert g['storage_steps'] == c['storage_frames'] and g['scenario']['group'] == c['group'] assert g['model_instruction_as_in_training'] == c['instruction'] assert g['concealed_every_step_after_storage'] and g['replay_concealed_every_step'] and not g['first_choice_made'] assert not g['session_violations'] and g['gripper_clear_at_handoff'] and g['independent_replay_max_error'] <= 1e-8 assert digest(src/'trajectory.hdf5') == g['trajectory_sha256'] h = g['handoff_step']; budget = c['max_policy_steps'] for cond in conds: cases.append(dict(trial_id=f'{name}-{a.stage}-{cond}', case=name, family=c['family'], condition=cond, source_kind='short', source_dir=str(src), source_trajectory_sha256=g['trajectory_sha256'], training_hdf5_sha256=c['hdf5_sha256'], training_source_dir=g['source'], generator_version=g['generator_version'], storage_steps=g['storage_steps'], storage_complete_event_step=g['storage_complete_event_step'], handoff_step=h, chores=g['chores'], post_storage_seconds_from_event=g['post_storage_seconds_from_event'], post_storage_seconds_from_immediate_handoff=g['post_storage_seconds_from_immediate_handoff'], handoff_residual={k: g['handoff_residual'][k] for k in ('base_xy_m', 'base_yaw_rad', 'eef_pos_m', 'eef_rot_rad', 'model_state_max_abs')}, instruction=c['instruction'], policy_seed=c['policy_seed'], max_policy_steps=budget, expert_retrieval_seconds=c['retrieval_actions']/20, paired_immediate_trial=c['trial_id'], paired_immediate_success=immediate[c['trial_id']]['task_success'], paired_immediate_first_choice_correct=immediate[c['trial_id']].get('first_choice_correct'), memory_condition=mem(config, cond, h, budget))) seeds = [int(x) for x in a.long_seeds.split(',') if x] for item in a.long: parts = item.split('='); cell, src, cache = parts[:3]; src = Path(src) cell_seeds = [int(x) for x in parts[3].split(':')] if len(parts) > 3 else seeds; g = json.loads((src/'result.json').read_text()); family = cell.split('-')[0] assert g['status'] == 'verified' and g['cell'] == cell and digest(src/'trajectory.hdf5') == g['trajectory_sha256'] assert g['independent_replay_max_error'] == 0 and g['replay_concealed_every_step_from_first'] and not g['replay_violations'] assert g['replay_gripper_clear_at_handoff'] and g['replay_phase_at_handoff'] == 'resume_original_request' with h5py.File(src/'trajectory.hdf5') as f: h = int(f.attrs['handoff_step']); b = int(f.attrs['storage_end_step']); bnd = int(f.attrs['side_neutral_boundary_step']) ref = f.attrs['reference'] with h5py.File(ref) as f: ref_steps = len(f['data/demo_0/actions']) with h5py.File(cache) as f: assert int(f.attrs['handoff_step']) == h and f.attrs['renderer'] == 'nvidia_egl' assert h == g['handoff_step'] and len(cell_seeds) == 10 # Pre-declared rule of the original delay plan (fixed before inference): max(immediate family budget, # 1.25 x expert side-specific retrieval steps rounded up to the next 100). Reproduces every earlier budget. family_budget = 600 if family == 'spice' else 1800 budget = max(family_budget, -(-int(1.25*(ref_steps-bnd))//100)*100) for k, seed in enumerate(cell_seeds): for cond in conds: cases.append(dict(trial_id=f'{cell}-s{k:02d}-{a.stage}-{cond}', case=f'{cell}-s{k:02d}', family=family, condition=cond, source_kind='long', source_dir=str(src), source_trajectory_sha256=g['trajectory_sha256'], frame_cache=str(cache), env_minutes=int(cell.split('-')[1][:2]), storage_steps=b, storage_complete_event_step=b, handoff_step=h, chores=None, post_storage_seconds_from_event=g['post_storage_seconds_at_handoff'], post_storage_seconds_from_immediate_handoff=None, handoff_residual=g['handoff_residual'], instruction=g['instruction'], policy_seed=seed, max_policy_steps=budget, expert_retrieval_seconds=(ref_steps-bnd)/20, expert_recall_total_seconds=(ref_steps-g['recall_request_step'])/20, long_cell_seeds=cell_seeds, paired_immediate_trial=None, paired_immediate_success=None, paired_immediate_first_choice_correct=None, family_budget_steps=family_budget, budget_rule='max(family budget, ceil100(1.25 x expert side-specific steps))', memory_condition=mem(config, cond, h, budget))) plan = dict(schema='cotrain_clean_handoff_delay_v2', stage=a.stage, label_minutes=a.label_minutes, frozen_unix=time.time(), model=dict(repo='namhokaist/simplememvla-robocasa-spice-cup-storage-cotrain-ck3000', revision=old['model']['revision'], checkpoint=str(OLD/'checkpoint/model')), execute_steps=8, action_horizon=16, num_denoising_steps=10, evaluator='evaluate_delayed_v2.py', long_cell_seeds=seeds, conditions=list(conds), conditions_note=a.conditions_note or None, count=len(cases), cases=cases, model_weights_changed=False, old_results_pooled=False, label_note='Stage label is nominal; report actual post-storage seconds per case.') (stage/'plan.json').write_text(json.dumps(plan, indent=2)+'\n') print(json.dumps(dict(stage=str(stage), count=len(cases), sha256=digest(stage/'plan.json')))) if __name__ == '__main__': main()