evaluation_all / code /resume_genie.sh
yqi19's picture
Upload folder using huggingface_hub
8aa2acf verified
Raw
History Blame Contribute Delete
4.99 kB
#!/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_<idx>
# 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 <experiment> <gpu>
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<n and b<n: p+=[(a,b),(b,a)]
return p
_SZ={"verb_size","size_object","color_size"}
_SP={"verb_spatial","color_spatial","spatial_size","spatial_object"}
if experiment in _SZ: all_pairs=_ss(6)
elif experiment=="spatial_size": all_pairs=_ss(5)
elif experiment in _SP: n=5; all_pairs=[(i,j) for i in range(n) for j in range(n) if i!=j]
else: n=6; all_pairs=[(i,j) for i in range(n) for j in range(n) if i!=j]
_rt={"verb_color":("verb","color"),"verb_object":("verb","shape"),"verb_size":("verb","size"),
"verb_spatial":("verb","spatial"),"color_object":("color","shape"),"size_object":("size","shape"),
"color_size":("color","size"),"color_spatial":("color","spatial"),"spatial_size":("spatial","size"),
"spatial_object":("spatial","shape")}
first,second=_rt[experiment]
raw=[]
for ep in range(n_episodes):
i,j=rng.choice(all_pairs); raw.append((i,j,first,ep)); raw.append((i,j,second,ep))
total=len(raw); num_ep=math.ceil(n_episodes/total)
jobs=[]
for k,(i,j,rt,ep) in enumerate(raw):
idx=k+1; rn=f"ood_{idx:03d}_{experiment}_{i}_{j}_{rt}"
if experiment=="verb_object": rs=seed_base+ep; ets=ep
else: rs=seed_base+idx; ets=third_seed
jobs.append({"index":idx,"pair_i":i,"pair_j":j,"run_type":rt,"seed":rs,
"third_seed":ets,"num_episodes":num_ep,"experiment_name":rn})
print(json.dumps(jobs))
PY
# 3) Filter to MISSING indices only
python - "$exp" "$EXPDIR" > /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}