evaluation_all / code /run_full_factor_groot.sh
yqi19's picture
Upload folder using huggingface_hub
8aa2acf verified
Raw
History Blame Contribute Delete
7.14 kB
#!/usr/bin/env bash
set -uo pipefail
# ─────────────────────────────────────────────────────────────────────────────
# run_full_factor_groot.sh — GR00T N1.7 full-factor sweep.
#
# Cell sampling, instruction format, header and the per-cell / overall result
# format are COPIED VERBATIM from
# eval_pi0_5/examples/maniskill_full_factor/run_full_factor_inference.sh
# so the produced full_factor_<ckpt>_seed<NN>.txt files are directly comparable
# to the pi0.5 ones. Only the per-cell python call drives a GR00T zmq server
# (groot_full_factor_main.py) instead of the openpi websocket policy.
#
# A GR00T inference server must already be reachable at ${HOST}:${PORT}.
#
# Usage:
# bash run_full_factor_groot.sh [total_episodes] [results_txt_path] [sample_n]
#
# Env overrides: HOST PORT SIM_BACKEND RENDER_BACKEND MAX_EPISODE_STEPS
# SEED_BASE NO_DISTRACTOR_PROB SAMPLE_SEED REPLAN_STEPS
# MS_PY GROOT_FF_MAIN VIDEO_ROOT MANISKILL_CONFLICT_ROOT
# pi0.5 protocol values: sample_n=200 sample_seed=42 total_episodes=200
# max_episode_steps=500 no_distractor_prob=0.70
# sim/render=cpu seed_base ∈ {40,41,42}
# ─────────────────────────────────────────────────────────────────────────────
TOTAL_EPISODES_TARGET="${1:-200}"
RESULTS_TXT_PATH="${2:-}"
SAMPLE_N="${3:-200}"
HOST="${HOST:-127.0.0.1}"
PORT="${PORT:-5555}"
SIM_BACKEND="${SIM_BACKEND:-cpu}"
RENDER_BACKEND="${RENDER_BACKEND:-cpu}"
MAX_EPISODE_STEPS="${MAX_EPISODE_STEPS:-500}"
SEED_BASE="${SEED_BASE:-40}"
NO_DISTRACTOR_PROB="${NO_DISTRACTOR_PROB:-0.70}"
SAMPLE_SEED="${SAMPLE_SEED:-42}"
REPLAN_STEPS="${REPLAN_STEPS:-5}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MS_PY="${MS_PY:-/workspace/groot_eval/.venv_ms/bin/python}"
GROOT_FF_MAIN="${GROOT_FF_MAIN:-${SCRIPT_DIR}/groot_full_factor_main.py}"
if [[ -z "${RESULTS_TXT_PATH}" ]]; then
ts="$(date +%Y%m%d_%H%M%S)"
RESULTS_TXT_PATH="/workspace/groot_eval/results_af/full_factor_ep${TOTAL_EPISODES_TARGET}_sample${SAMPLE_N}_${ts}.txt"
fi
mkdir -p "$(dirname "${RESULTS_TXT_PATH}")"
VIDEO_ROOT="${VIDEO_ROOT:-$(dirname "${RESULTS_TXT_PATH}")/videos_seed${SEED_BASE}}"
# ── Generate task list: all 4320 or a random subset of sample_n ──
# (VERBATIM from pi0.5 run_full_factor_inference.sh)
mapfile -t TASK_LINES < <(python3 - "${SAMPLE_N}" "${SAMPLE_SEED}" <<'PY'
import itertools, random, sys
VERBS = ["lift","grasp","push","pull","rotate","slide"]
COLORS = ["red","yellow","blue","orange","green","black"]
SHAPES = ["cube","sphere","cup","car","pyramid","star"]
SPATIALS = ["left","right","middle","front","behind"]
SIZES = ["small","large","smaller","larger"]
all_tasks = list(itertools.product(VERBS, COLORS, SHAPES, SPATIALS, SIZES))
n = int(sys.argv[1])
seed = int(sys.argv[2])
if n > 0:
rng = random.Random(seed)
rng.shuffle(all_tasks)
all_tasks = all_tasks[:n]
for t in all_tasks:
print(" ".join(t))
PY
)
TOTAL_CELLS="${#TASK_LINES[@]}"
NUM_EPISODES="$(python3 -c "import math; print(math.ceil(${TOTAL_EPISODES_TARGET} / ${TOTAL_CELLS}))")"
echo "sample_n=${SAMPLE_N}${TOTAL_CELLS} cells, ${NUM_EPISODES} episodes/cell (target ${TOTAL_EPISODES_TARGET} total)"
{
echo "# Full-factor inference (GR00T N1.7)"
echo "sample_n=${SAMPLE_N} sample_seed=${SAMPLE_SEED} total_cells=${TOTAL_CELLS}"
echo "total_episodes_target=${TOTAL_EPISODES_TARGET} num_episodes_per_cell=${NUM_EPISODES}"
echo "total_episodes_actual=$((TOTAL_CELLS * NUM_EPISODES))"
echo "host=${HOST} port=${PORT}"
echo "sim_backend=${SIM_BACKEND} render_backend=${RENDER_BACKEND}"
echo "max_episode_steps=${MAX_EPISODE_STEPS} seed_base=${SEED_BASE}"
echo "no_distractor_prob=${NO_DISTRACTOR_PROB} replan_steps=${REPLAN_STEPS}"
echo
echo "index verb color shape spatial size prompt successes/total"
} > "${RESULTS_TXT_PATH}"
# ManiSkill C-extensions link libtorch.so — make ms-venv torch libs findable.
_MS_TORCH_LIB="$("${MS_PY}" -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:-/workspace/groot_eval/genie_repo/maniskill_conflict}"
total_success=0
total_episodes_done=0
i=0
for line in "${TASK_LINES[@]}"; do
read -r verb color shape spatial size <<<"${line}"
i=$((i + 1))
verb_cap="${verb^}"
case "${spatial}" in
left) phrase="on the left" ;;
right) phrase="on the right" ;;
middle) phrase="in the middle" ;;
front) phrase="in front" ;;
behind) phrase="at the back" ;;
esac
prompt="${verb_cap} the ${size} ${color} ${shape} ${phrase}."
seed=$((SEED_BASE + i))
echo "[${i}/${TOTAL_CELLS}] ${prompt}"
run_log="$(mktemp)"
"${MS_PY}" "${GROOT_FF_MAIN}" \
--host "${HOST}" \
--port "${PORT}" \
--verb "${verb}" \
--color "${color}" \
--shape "${shape}" \
--spatial "${spatial}" \
--size "${size}" \
--num-episodes "${NUM_EPISODES}" \
--max-episode-steps "${MAX_EPISODE_STEPS}" \
--sim-backend "${SIM_BACKEND}" \
--render-backend "${RENDER_BACKEND}" \
--replan-steps "${REPLAN_STEPS}" \
--no-distractor-prob "${NO_DISTRACTOR_PROB}" \
--seed "${seed}" \
--video-out-path "${VIDEO_ROOT}/${verb}_${size}_${color}_${shape}_${spatial}" \
2>&1 | tee "${run_log}"
py_status="${PIPESTATUS[0]}"
if [[ "${py_status}" -ne 0 ]]; then
echo "${i} ${verb} ${color} ${shape} ${spatial} ${size} ERROR" >> "${RESULTS_TXT_PATH}"
rm -f "${run_log}"
echo "Task ${i}/${TOTAL_CELLS} failed. Partial results: ${RESULTS_TXT_PATH}"
exit "${py_status}"
fi
success_info="$(python3 - "${run_log}" <<'PY'
import re, sys
from pathlib import Path
txt = Path(sys.argv[1]).read_text(encoding="utf-8", errors="ignore")
m = re.search(r"Success rate:\s*(\d+)\s*/\s*(\d+)", txt)
print(f"{m.group(1)} {m.group(2)}" if m else "NA NA")
PY
)"
rm -f "${run_log}"
read -r ep_succ ep_total <<<"${success_info}"
if [[ "${ep_succ}" == "NA" ]]; then
cell_result="NA"
else
total_success=$((total_success + ep_succ))
total_episodes_done=$((total_episodes_done + ep_total))
cell_result="${ep_succ}/${ep_total}"
fi
echo "${i} ${verb} ${color} ${shape} ${spatial} ${size} \"${prompt}\" ${cell_result}" >> "${RESULTS_TXT_PATH}"
done
overall_rate="$(python3 -c "
s, n = ${total_success}, ${total_episodes_done}
print(f'{100.0*s/n:.1f}' if n > 0 else '0.0')
")"
{
echo
echo "overall_success=${total_success}/${total_episodes_done} (${overall_rate}%)"
} >> "${RESULTS_TXT_PATH}"
echo ""
echo "Done: ${total_episodes_done} episodes across ${TOTAL_CELLS} cells"
echo "Overall: ${total_success}/${total_episodes_done} (${overall_rate}%)"
echo "Results: ${RESULTS_TXT_PATH}"