#!/usr/bin/env bash set -uo pipefail # ───────────────────────────────────────────────────────────────────────────── # run_af_one_ckpt_fast.sh — method-A (single-process batch) version of # run_af_one_ckpt.sh. Starts ONE GR00T server for the ckpt, then runs # groot_full_factor_batch.py once per seed (200 cells in one process → no # per-cell cold start). Output identical layout, only faster. # # Usage: run_af_one_ckpt_fast.sh # Env: SEEDS_OVERRIDE ("40" / "40 41 42"), SAMPLE_N (200), TOTAL_EPISODES (200), # SIM_BACKEND (gpu), RENDER_BACKEND (gpu) # ───────────────────────────────────────────────────────────────────────────── ROOT=/workspace/groot_eval HARNESS="${ROOT}/harness" CKPT="${1:?ckpt_name}" GPU="${2:?gpu}" PORT="${3:?port}" SEEDS=(${SEEDS_OVERRIDE:-40 41 42}) SAMPLE_N="${SAMPLE_N:-200}" TOTAL_EPISODES="${TOTAL_EPISODES:-200}" SIM_BACKEND="${SIM_BACKEND:-gpu}" RENDER_BACKEND="${RENDER_BACKEND:-gpu}" NO_DISTRACTOR_PROB="${NO_DISTRACTOR_PROB:-0.70}" # Auto-detect ckpt layout: either /checkpoint-10000/ or / directly (HF layout) MODEL_PATH="${ROOT}/gr00t_af_ckpts/${CKPT}/checkpoint-10000" [[ -d "${MODEL_PATH}" ]] || MODEL_PATH="${ROOT}/gr00t_af_ckpts/${CKPT}" OUT_DIR="${RESULTS_ROOT:-${ROOT}/results_af}/${CKPT}" LOG_DIR="${ROOT}/logs/gr00t_af" mkdir -p "${OUT_DIR}" "${LOG_DIR}" slog="${LOG_DIR}/server_fast_${CKPT}_gpu${GPU}.log" [[ -d "${MODEL_PATH}" ]] || { echo "[${CKPT}] MODEL_PATH not found: ${MODEL_PATH}"; exit 1; } ls "${MODEL_PATH}"/*.safetensors >/dev/null 2>&1 || { echo "[${CKPT}] no safetensors in ${MODEL_PATH}"; exit 1; } echo "[$(date +%H:%M:%S)] ${CKPT}: start GR00T server gpu=${GPU} port=${PORT}" ( cd "${ROOT}/gr00t_repo/codebase" && CUDA_VISIBLE_DEVICES="${GPU}" \ HF_HOME="${ROOT}/.hf_cache" HF_TOKEN="$(cat ${ROOT}/.hf_token)" \ NO_ALBUMENTATIONS_UPDATE=1 TOKENIZERS_PARALLELISM=false \ "${ROOT}/.venv_groot/bin/python" -m gr00t.eval.run_gr00t_server \ --model-path "${MODEL_PATH}" \ --embodiment-tag new_embodiment --device cuda:0 \ --host 127.0.0.1 --port "${PORT}" ) > "${slog}" 2>&1 & spid=$! ok=0 for _ in $(seq 1 300); do kill -0 "${spid}" 2>/dev/null || { echo "[${CKPT}] SERVER DIED during load"; break; } grep -q "Server ready\|Server is ready" "${slog}" 2>/dev/null && { ok=1; break; } sleep 3 done [[ "${ok}" == "1" ]] || { echo "[${CKPT}] server not ready"; tail -n 25 "${slog}"; kill "${spid}" 2>/dev/null; exit 1; } echo "[$(date +%H:%M:%S)] ${CKPT}: server ready (pid ${spid})" _MS_TORCH_LIB="$("${ROOT}/.venv_ms/bin/python" -c 'import torch,os;print(os.path.join(os.path.dirname(torch.__file__),"lib"))' 2>/dev/null || true)" export LD_LIBRARY_PATH="${_MS_TORCH_LIB}:${LD_LIBRARY_PATH:-}" export MANISKILL_CONFLICT_ROOT="${MANISKILL_CONFLICT_ROOT:-${ROOT}/genie_repo/maniskill_conflict}" rc_all=0 for sb in "${SEEDS[@]}"; do rt="${OUT_DIR}/full_factor_${CKPT}_seed${sb}.txt" echo "[$(date +%H:%M:%S)] ${CKPT}: seed_base=${sb} → ${rt}" CUDA_VISIBLE_DEVICES="${GPU}" \ "${ROOT}/.venv_ms/bin/python" "${HARNESS}/groot_full_factor_batch.py" \ --host 127.0.0.1 --port "${PORT}" \ --results-txt "${rt}" \ --video-root "${OUT_DIR}/videos_seed${sb}" \ --sample-n "${SAMPLE_N}" --sample-seed 42 --seed-base "${sb}" \ --total-episodes "${TOTAL_EPISODES}" --max-episode-steps 500 \ --no-distractor-prob "${NO_DISTRACTOR_PROB}" --replan-steps 5 \ --sim-backend "${SIM_BACKEND}" --render-backend "${RENDER_BACKEND}" \ > "${LOG_DIR}/client_fast_${CKPT}_seed${sb}.log" 2>&1 src=$? [[ "${src}" -ne 0 ]] && rc_all=1 grep -E "^overall_success" "${rt}" 2>/dev/null || echo "[${CKPT} seed${sb}] no overall_ line" done kill "${spid}" 2>/dev/null; wait "${spid}" 2>/dev/null python3 - "${OUT_DIR}" "${CKPT}" "${SEEDS[@]}" > "${OUT_DIR}/SUMMARY.txt" <<'PY' import re, sys from pathlib import Path out_dir, ckpt, *seeds = sys.argv[1:] rates, line = [], [] for sb in seeds: p = Path(out_dir) / f"full_factor_{ckpt}_seed{sb}.txt" if not p.exists(): line.append(f"seed{sb}: MISSING"); continue m = re.search(r"overall_success=(\d+)/(\d+) \(([\d.]+)%\)", p.read_text()) if m: s, n, r = int(m.group(1)), int(m.group(2)), float(m.group(3)) rates.append(r); line.append(f"seed{sb}: {s}/{n} ({r:.1f}%)") else: line.append(f"seed{sb}: PARSE_FAILED") avg = sum(rates)/len(rates) if rates else 0.0 print(f"# {ckpt} — full-factor TASK-aligned, single-process batch " f"(sample_n=200 seed=42, 200 eps, max_steps=500, no_distractor=0.70, " f"default difficulty, sim=gpu)") for l in line: print(l) print(f"AVG over {len(rates)} seed(s): {avg:.1f}%") PY echo "[$(date +%H:%M:%S)] ${CKPT}: DONE rc=${rc_all}" cat "${OUT_DIR}/SUMMARY.txt" exit ${rc_all}