OpenExpDatasets / experiments /learnability /run_bestfirst_eval_gold.sh
ayush1801's picture
Upload folder using huggingface_hub
0a351ee verified
Raw
History Blame Contribute Delete
2.84 kB
#!/bin/bash
# =============================================================================
# Best-first eval driver for the POLICY-ONLY GOLD checkpoints.
# Sibling of run_bestfirst_eval.sh; evaluates only the gold finetuned models
# (base 0/1.pt are already covered by run_bestfirst_eval.sh).
#
# eval set: every policy-only-gold epoch_2.pt (final) + epoch_1.pt (mid)
# under train_policy_only_gold/.
# eval: bestfirst_search.py, extrinsic-95, --max-pops 4000, --timeout 600.
# Action cap OFF (faithful to MCTS).
#
# Uses all 4 GPUs, one eval per GPU at a time.
# =============================================================================
set -u
LEARN=/datadrive/ayush/home/minimoX/learning
cd "$LEARN" || exit 1
source "$(conda info --base)/etc/profile.d/conda.sh"
conda activate minimo_new
export WANDB_MODE=offline
TRAIN_BASE=$LEARN/experiments/learnability/train_policy_only_gold
BF_EVAL=$LEARN/experiments/learnability/bestfirst_eval_gold
mkdir -p "$BF_EVAL"
PROBLEMSET=extrinsic-95
BF_MAXPOPS=4000
BF_WORKERS=6
BF_TIMEOUT=600
GPUS=(0 1 2 3)
NGPU=${#GPUS[@]}
LOG=$BF_EVAL/eval_driver.log
ts() { date +"%Y-%m-%d %H:%M:%S"; }
log() { echo "[$(ts)] $*" | tee -a "$LOG"; }
E_CKPT=(); E_JSON=(); E_LOG=(); E_LABEL=()
add_eval() { E_CKPT+=("$1"); E_JSON+=("$2"); E_LOG+=("$3"); E_LABEL+=("$4"); }
for CKPT_NAME in epoch_2.pt epoch_1.pt; do
TAG=$([[ $CKPT_NAME == epoch_2.pt ]] && echo final || echo mid)
while IFS= read -r ckpt; do
[[ -z "$ckpt" ]] && continue
ckpt=$(realpath "$ckpt")
label=$(echo "$ckpt" | sed "s#.*train_policy_only_gold/##; s#/updates.*##")
add_eval "$ckpt" \
"$(dirname "$ckpt")/bf_${PROBLEMSET}_${TAG}.json" \
"$(dirname "$ckpt")/bf_${PROBLEMSET}_${TAG}.log" \
"$TAG/$label"
done < <(find "$TRAIN_BASE" -name "$CKPT_NAME" -path "*updates_*" 2>/dev/null | sort)
done
NJOBS=${#E_CKPT[@]}
log "===== START: $NJOBS gold best-first evals (max_pops=${BF_MAXPOPS} timeout=${BF_TIMEOUT}s) on GPUs ${GPUS[*]} ====="
k=0
for ((j=0; j<NJOBS; j++)); do
gpu=${GPUS[$((k % NGPU))]}
log "EVAL [$k/$NJOBS] ${E_LABEL[$j]} -> gpu $gpu"
(
CUDA_VISIBLE_DEVICES=$gpu python -u bestfirst_search.py \
--agent "${E_CKPT[$j]}" \
--problemset "$PROBLEMSET" \
--max-pops "$BF_MAXPOPS" \
--workers "$BF_WORKERS" \
--timeout "$BF_TIMEOUT" \
--output "${E_JSON[$j]}" \
> "${E_LOG[$j]}" 2>&1
echo "[$(ts)] EVAL DONE ${E_LABEL[$j]}" >> "$LOG"
) &
k=$((k + 1))
if (( k % NGPU == 0 )); then wait; fi
done
wait
log "--- All gold best-first evals complete ---"
for f in $(find "$TRAIN_BASE" -name "bf_${PROBLEMSET}_*.json" 2>/dev/null | sort); do
python -c "import json;d=json.load(open('$f'));print(d['num_solved'],'/',d['num_problems'],'$f')" 2>/dev/null | tee -a "$LOG"
done