#!/usr/bin/env bash set -uo pipefail # ───────────────────────────────────────────────────────────────────────────── # run_all_groot.sh — evaluate ALL 10 GR00T conflict checkpoints. # # One checkpoint per GPU: for each category we start a dedicated GR00T zmq # inference server (gr00t venv) pinned to one GPU, then run the ManiSkill OOD # sweep (ms venv) on the SAME GPU for GPU physics+render, then stop the server. # Up to NUM_GPUS checkpoints run concurrently (processed in waves). # # Each checkpoint is evaluated on its OWN conflict experiment (category name). # Every episode video is saved under # ${OUT_ROOT}//experiments//video/ep000{,_wrist}.mp4 # # Usage: # bash run_all_groot.sh [seed] [total_episodes] # Defaults: seed=42 total_episodes=200 (→ 400 runs per checkpoint) # Override episode count: bash run_all_groot.sh 42 20 # ───────────────────────────────────────────────────────────────────────────── SEED="${1:-42}" TOTAL_EPISODES="${2:-200}" ROOT=/workspace/groot_eval HARNESS="${ROOT}/harness" CKPT_ROOT="${ROOT}/checkpoints" OUT_ROOT="${OUT_ROOT:-${ROOT}/results}" LOG_DIR="${ROOT}/logs/run_$(date +%Y%m%d_%H%M%S)" GROOT_VENV_PY="${ROOT}/gr00t_repo/codebase/.venv/bin/python" GROOT_CODE="${ROOT}/gr00t_repo/codebase" MS_PY="${ROOT}/.venv_ms/bin/python" NUM_GPUS="${NUM_GPUS:-8}" SIM_BACKEND="${SIM_BACKEND:-gpu}" BASE_PORT="${BASE_PORT:-5600}" CATEGORIES=( color_object color_size color_spatial size_object spatial_object spatial_size verb_color verb_object verb_size verb_spatial ) mkdir -p "${LOG_DIR}" "${OUT_ROOT}" echo "seed=${SEED} total_episodes=${TOTAL_EPISODES} sim_backend=${SIM_BACKEND}" echo "logs: ${LOG_DIR}" echo "results/videos: ${OUT_ROOT}" run_one() { local cat="$1" gpu="$2" port="$3" local ckpt="${CKPT_ROOT}/${cat}" local slog="${LOG_DIR}/server_${cat}.log" local clog="${LOG_DIR}/client_${cat}.log" local exp_root="${OUT_ROOT}/${cat}/experiments" local results_txt="${OUT_ROOT}/${cat}/${cat}_ood_seed${SEED}.txt" mkdir -p "${exp_root}" "$(dirname "${results_txt}")" echo "[$(date +%H:%M:%S)] START ${cat} gpu=${gpu} port=${port}" # ── Start GR00T inference server on this GPU ── ( cd "${GROOT_CODE}" && CUDA_VISIBLE_DEVICES="${gpu}" \ HF_HOME="${ROOT}/.hf_cache" HF_TOKEN="$(cat ${ROOT}/.hf_token)" \ NO_ALBUMENTATIONS_UPDATE=1 TOKENIZERS_PARALLELISM=false \ "${GROOT_VENV_PY}" -m gr00t.eval.run_gr00t_server \ --model-path "${ckpt}" \ --embodiment-tag new_embodiment \ --device cuda:0 \ --host 127.0.0.1 \ --port "${port}" ) > "${slog}" 2>&1 & local server_pid=$! # ── Wait until the server is listening (model load can take ~1-2 min) ── local ready=0 for _ in $(seq 1 180); do if ! kill -0 "${server_pid}" 2>/dev/null; then echo "[${cat}] SERVER DIED during startup — see ${slog}" break fi if grep -q "Server ready\|Server is ready and listening" "${slog}" 2>/dev/null; then ready=1; break fi sleep 3 done if [[ "${ready}" -ne 1 ]]; then echo "[${cat}] server not ready; killing. tail server log:" tail -n 20 "${slog}" || true kill "${server_pid}" 2>/dev/null || true wait "${server_pid}" 2>/dev/null || true return 1 fi echo "[$(date +%H:%M:%S)] [${cat}] server ready (pid ${server_pid}), starting sweep" # ── Run the OOD sweep on the SAME GPU (ManiSkill GPU physics+render) ── CUDA_VISIBLE_DEVICES="${gpu}" \ HOST=127.0.0.1 PORT="${port}" SIM_BACKEND="${SIM_BACKEND}" \ EXPERIMENT_ROOT="${exp_root}" GROOT_MAIN="${HARNESS}/groot_main.py" MS_PY="${MS_PY}" \ bash "${HARNESS}/run_ood_groot_inference.sh" \ "${cat}" "${SEED}" "${TOTAL_EPISODES}" "${results_txt}" \ > "${clog}" 2>&1 local rc=$? # ── Stop the server ── kill "${server_pid}" 2>/dev/null || true wait "${server_pid}" 2>/dev/null || true echo "[$(date +%H:%M:%S)] DONE ${cat} rc=${rc} results=${results_txt}" return ${rc} } # ── Process in waves of NUM_GPUS (one checkpoint per GPU) ── launched=0 pids=() for idx in "${!CATEGORIES[@]}"; do cat="${CATEGORIES[$idx]}" gpu=$(( launched % NUM_GPUS )) port=$(( BASE_PORT + gpu )) run_one "${cat}" "${gpu}" "${port}" & pids+=($!) launched=$(( launched + 1 )) if (( launched % NUM_GPUS == 0 )); then echo "[$(date +%H:%M:%S)] --- waiting for wave to finish ---" for p in "${pids[@]}"; do wait "${p}" || true; done pids=() fi done for p in "${pids[@]}"; do wait "${p}" || true; done echo echo "================ ALL DONE ================" for cat in "${CATEGORIES[@]}"; do rt="${OUT_ROOT}/${cat}/${cat}_ood_seed${SEED}.txt" if [[ -f "${rt}" ]]; then echo "### ${cat}" grep -E "^overall_" "${rt}" 2>/dev/null || echo " (no overall_ line — check logs)" else echo "### ${cat}: MISSING ${rt}" fi done echo "Videos under: ${OUT_ROOT}//experiments//video/"