evaluation_all / code /run_af_one_ckpt.sh
yqi19's picture
Upload folder using huggingface_hub
8aa2acf verified
#!/usr/bin/env bash
set -uo pipefail
# ─────────────────────────────────────────────────────────────────────────────
# run_af_one_ckpt.sh — evaluate ONE GR00T all-factor checkpoint, 3 seeds,
# aligned 1:1 with the pi0.5 full-factor protocol, on ONE dedicated GPU.
#
# Starts a dedicated GR00T zmq server pinned to <gpu> for the given checkpoint,
# runs run_full_factor_groot.sh for seed_base ∈ {40,41,42} (sample_n=200,
# sample_seed=42, 200 episodes, max_episode_steps=500, no_distractor_prob=0.70,
# cpu sim/render, default difficulty), then stops the server and writes a
# 3-seed-averaged SUMMARY.txt.
#
# Output is written ONLY under results_af/<ckpt>/ — it never touches results/
# (GR00T conflict) or results_genie/.
#
# Usage: run_af_one_ckpt.sh <ckpt_name> <gpu> <port>
# ckpt_name e.g. all_factor_Lrandom_f50_n400
# ─────────────────────────────────────────────────────────────────────────────
ROOT=/workspace/groot_eval
HARNESS="${ROOT}/harness"
CKPT="${1:?ckpt_name (dir under gr00t_af_ckpts)}"
GPU="${2:?gpu}"
PORT="${3:?port}"
SEEDS=(${SEEDS_OVERRIDE:-40 41 42})
SAMPLE_N="${SAMPLE_N:-200}"
TOTAL_EPISODES="${TOTAL_EPISODES:-200}"
MODEL_PATH="${ROOT}/gr00t_af_ckpts/${CKPT}/checkpoint-10000"
OUT_DIR="${ROOT}/results_af/${CKPT}"
LOG_DIR="${ROOT}/logs/gr00t_af"
mkdir -p "${OUT_DIR}" "${LOG_DIR}"
slog="${LOG_DIR}/server_${CKPT}.log"
if [[ ! -d "${MODEL_PATH}" ]]; then
echo "[${CKPT}] MODEL_PATH not found: ${MODEL_PATH}" ; exit 1
fi
echo "[$(date +%H:%M:%S)] ${CKPT}: starting 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 and listening" "${slog}" 2>/dev/null && { ok=1; break; }
sleep 3
done
if [ "${ok}" != "1" ]; then
echo "[${CKPT}] server not ready; tail server log:"; tail -n 30 "${slog}"
kill "${spid}" 2>/dev/null; wait "${spid}" 2>/dev/null
exit 1
fi
echo "[$(date +%H:%M:%S)] ${CKPT}: server ready (pid ${spid})"
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}"
HOST=127.0.0.1 PORT="${PORT}" SEED_BASE="${sb}" SAMPLE_SEED=42 \
SIM_BACKEND="${SIM_BACKEND:-gpu}" RENDER_BACKEND="${RENDER_BACKEND:-gpu}" MAX_EPISODE_STEPS=500 \
NO_DISTRACTOR_PROB=0.70 REPLAN_STEPS=5 \
CUDA_VISIBLE_DEVICES="${GPU}" \
VIDEO_ROOT="${OUT_DIR}/videos_seed${sb}" \
MS_PY="${ROOT}/.venv_ms/bin/python" \
bash "${HARNESS}/run_full_factor_groot.sh" "${TOTAL_EPISODES}" "${rt}" "${SAMPLE_N}" \
> "${LOG_DIR}/client_${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
# ── 3-seed average ──
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 (sample_n=200 seed=42, 200 eps, "
f"max_steps=500, no_distractor=0.70, default difficulty); "
f"sim_backend=gpu → 任务/采样/prompt/success 与 pi0.5 一致,但数值非 1:1 可比")
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}