#!/usr/bin/env bash set -uo pipefail # Resume an OOM-truncated genie experiment WITHOUT redoing completed runs. # Job index is deterministic (seed 42) so a run with index K is the same job # regardless of which attempt produced it. We pool every completed ood_ # dir across all experiments_partial_*/ + current experiments/, then run ONLY # the missing indices in a FRESH low-memory process (won't hit the ~step280 OOM # ceiling because it only does the ~70-150 missing runs). # # Usage: resume_genie.sh ROOT=/workspace/groot_eval GENIE="${ROOT}/genie_repo/genie_envisioner" CONDA=/opt/miniforge3/condabin/conda ENV=genie_envisioner exp="${1:?experiment}"; gpu="${2:?gpu}" SEED=42; TOTAL=200; SEED_BASE=0; THIRD_SEED=42 EXPDIR="${ROOT}/results_genie/${exp}/experiments" RESULTS_TXT="${ROOT}/results_genie/${exp}/genie_${exp}_ood_seed${SEED}.txt" LOG="${ROOT}/logs/genie/resume_${exp}.log" WEIGHT="${ROOT}/genie_ckpts/${exp}"; LTX="${ROOT}/LTX-Video" case "${EXPDIR}" in "${ROOT}/results_genie/"*) : ;; *) echo REFUSING; exit 2;; esac mkdir -p "${EXPDIR}" # 1) Consolidate: bring one dir per index from every partial backup into EXPDIR for bk in "${ROOT}/results_genie/${exp}"/experiments_partial_*/; do [ -d "$bk" ] || continue for d in "$bk"ood_*/; do [ -d "$d" ] || continue idx=$(basename "$d" | grep -oE '^ood_[0-9]+') ls -d "${EXPDIR}/${idx}_"*/ >/dev/null 2>&1 || cp -r "$d" "${EXPDIR}/" done done # 2) Full deterministic 400-job list python - "$exp" "$SEED" "$TOTAL" "$SEED_BASE" "$THIRD_SEED" > /tmp/jobs_${exp}_full.json <<'PY' import random, sys, json, math experiment=sys.argv[1]; seed=int(sys.argv[2]); n_episodes=int(sys.argv[3]) seed_base=int(sys.argv[4]); third_seed=int(sys.argv[5]) rng=random.Random(seed) def _ss(n): p=[] for a,b in ((0,1),(2,3),(4,5)): if a /tmp/jobs_${exp}_missing.json <<'PY' import sys, json, os, glob, re exp=sys.argv[1]; expdir=sys.argv[2] full=json.load(open(f"/tmp/jobs_{exp}_full.json")) done=set() for d in glob.glob(os.path.join(expdir,"ood_*/")): m=re.match(r"ood_(\d+)", os.path.basename(d.rstrip("/"))) if m: done.add(int(m.group(1))) missing=[j for j in full if j["index"] not in done] json.dump(missing, open(f"/tmp/jobs_{exp}_missing.json","w")) print(f"done={len(done)} missing={len(missing)} total={len(full)}", file=sys.stderr) PY nmiss=$(python -c "import json;print(len(json.load(open('/tmp/jobs_${exp}_missing.json'))))") echo "[$(date +%H:%M:%S)] ${exp}: consolidated done; MISSING=${nmiss}/400 -> resuming on gpu=${gpu}" if [ "${nmiss}" -eq 0 ]; then echo "${exp}: already complete (400/400)"; exit 0; fi # 4) Run ONLY missing jobs in a fresh process (hardened cpu config) CUDA_VISIBLE_DEVICES="${gpu}" \ PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True,garbage_collection_threshold:0.6,max_split_size_mb:64 \ HF_HOME="${ROOT}/.hf_cache" HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 \ TOKENIZERS_PARALLELISM=false NO_ALBUMENTATIONS_UPDATE=1 \ "${CONDA}" run -n "${ENV}" --no-capture-output \ python "${GENIE}/main.py" \ --experiment "${exp}" --weight "${WEIGHT}" \ --pretrained-model-name-or-path "${LTX}" \ --domain-name conflict --num-inference-steps 5 --replan-steps 5 \ --max-episode-steps 300 --sim-backend cpu \ --experiment-root "${EXPDIR}" \ --batch-jobs-file /tmp/jobs_${exp}_missing.json \ --batch-results-txt "${RESULTS_TXT}" \ >> "${LOG}" 2>&1 rc=$? fin=$(ls -d "${EXPDIR}"/ood_*/ 2>/dev/null | grep -oE 'ood_[0-9]+' | sort -u | wc -l) echo "[$(date +%H:%M:%S)] ${exp}: resume rc=${rc} total unique indices now=${fin}/400" exit ${rc}