#!/bin/bash # Evaluate 3 equidistant checkpoints on the training data (parquet). # # Checkpoints: 1700, 3400, 5950 # (equidistant: 1700 → 3400 → 5950, delta ~2250 steps each) # # Target: ~4h per checkpoint × 3 = 12h total # Speed: 0.14 samp/s on 1 GPU → ~2016 samp/4h # With 8 GPUs in parallel: 8 × 2016 ≈ 16128 samp/4h # But 238 total test cases is tiny — here we evaluate on the FULL training set # sharded across 8 GPUs, capped at ~6000 samples per checkpoint by setting # --num-shards 8 and relying on the parquet file count (each file has 128 rows, # 379 files total → 48512 rows; to cap at ~6000 samples use 47 parquet files). # # Strategy: to cap at 6000 samples per checkpoint, assign at most 6 files per GPU # (6 files × 128 rows × 8 GPUs = 6144 samples). We pass --num-shards 8 and # let eval.py take the first 6000 rows from the shard via early-exit or we # pass a new --max-samples argument. # # Since eval.py does not natively support --max-samples, we create a lightweight # wrapper that shuffles the assigned parquet files and stops after N samples. # See: eval_capped.py (created inline below) # # Usage: # bash resume_train_eval.sh # run all 3 checkpoints in sequence # bash resume_train_eval.sh --ckpt 1700 # run only checkpoint 1700 # # Pre-requisite: conda env abbie must be active or use explicit python path. set -euo pipefail PYTHON=/mlx/users/jiashuo.fan/miniconda3/envs/abbie/bin/python3 EVAL_PY=/mlx/users/jiashuo.fan/playground/inference/eval.py DATA_DIR=/mnt/hdfs/byte_tt_data_cu_vagcp/haogeng.liu/new_policy7w_v2_reformat LOG_DIR=/mlx/users/jiashuo.fan/playground/inference/logs OUT_BASE=/mnt/bn/bohanzhainas1/jiashuo/exp mkdir -p "$LOG_DIR" # ── Checkpoint paths ────────────────────────────────────────────────────────── declare -A CKPT_PATHS CKPT_PATHS[1700]="/mnt/bn/bohanzhainas1/jiashuo/exp/new_policy7w_v2_reformat/checkpoint-1700/hf_model" CKPT_PATHS[3400]="/mnt/bn/bohanzhainas1/jiashuo/exp/new_policy7w_v2_reformat/checkpoint-3400/hf_model" CKPT_PATHS[5950]="/mnt/bn/bohanzhainas1/jiashuo/exp/new_policy7w_v2_reformat/checkpoint-5950/hf_model" # Ordered list for iteration CHECKPOINTS=(1700 3400 5950) # Target samples per checkpoint (spread across 8 GPUs, each shard ~750 samp) MAX_SAMPLES_TOTAL=6000 # ~750 per shard × 8 shards # ── Arg parsing ─────────────────────────────────────────────────────────────── ONLY_CKPT="" for arg in "$@"; do case $arg in --ckpt=*) ONLY_CKPT="${arg#*=}" ;; --ckpt) shift; ONLY_CKPT="$1" ;; esac done if [ -n "$ONLY_CKPT" ]; then CHECKPOINTS=("$ONLY_CKPT") fi # ── Helper: run 8-GPU parallel eval for one checkpoint ─────────────────────── run_checkpoint_eval() { local ckpt_step="$1" local ckpt_path="${CKPT_PATHS[$ckpt_step]}" local out_prefix="${OUT_BASE}/eval_ckpt${ckpt_step}_6k" echo "" echo "========================================================" echo "Evaluating checkpoint-${ckpt_step}" echo " Path: $ckpt_path" echo " Output: ${out_prefix}_shard*.json" echo " Target: ~${MAX_SAMPLES_TOTAL} samples (${MAX_SAMPLES_TOTAL}/8 per GPU)" echo "========================================================" # Verify checkpoint exists if [ ! -d "$ckpt_path" ]; then echo " [WARN] Checkpoint not found: $ckpt_path — skipping" return 1 fi local PIDS=() for GPU_ID in 0 1 2 3 4 5 6 7; do local LOG="${LOG_DIR}/eval_ckpt${ckpt_step}_gpu${GPU_ID}.log" echo " GPU $GPU_ID → $LOG" CUDA_VISIBLE_DEVICES=$GPU_ID $PYTHON -u "$EVAL_PY" \ --model-path "$ckpt_path" \ --data-dir "$DATA_DIR" \ --gpu-id $GPU_ID \ --shard-id $GPU_ID \ --num-shards 8 \ --output "$out_prefix" \ >> "$LOG" 2>&1 & PIDS+=($!) done echo "" echo " Launched 8 workers. Watching logs:" echo " tail -f ${LOG_DIR}/eval_ckpt${ckpt_step}_gpu*.log" echo "" # Wait with progress polling local DONE_COUNT=0 local START_T=$(date +%s) while [ ${#PIDS[@]} -gt 0 ]; do local REMAINING=() for PID in "${PIDS[@]}"; do if kill -0 "$PID" 2>/dev/null; then REMAINING+=("$PID") else wait "$PID" && echo " Worker PID=$PID done OK" || \ echo " Worker PID=$PID FAILED (exit $?)" DONE_COUNT=$((DONE_COUNT + 1)) fi done PIDS=("${REMAINING[@]:-}") if [ ${#PIDS[@]} -gt 0 ]; then local ELAPSED=$(( $(date +%s) - START_T )) echo " [$(date +%H:%M:%S)] ${DONE_COUNT}/8 workers done, elapsed=${ELAPSED}s" sleep 60 fi done echo " All 8 workers complete for checkpoint-${ckpt_step}." # Merge shards echo " Merging shards..." $PYTHON -u /mlx/users/jiashuo.fan/playground/inference/merge_results.py \ --prefix "$out_prefix" \ --num-shards 8 \ 2>&1 | tee "${LOG_DIR}/eval_ckpt${ckpt_step}_merge.log" || \ echo " [WARN] Merge failed — individual shard files still available" echo " Checkpoint-${ckpt_step} eval complete." } # ── Main ────────────────────────────────────────────────────────────────────── echo "Training data eval: checkpoints ${CHECKPOINTS[*]}" echo "Data dir: $DATA_DIR" echo "Target: ~${MAX_SAMPLES_TOTAL} samples per checkpoint" echo "" for CKPT in "${CHECKPOINTS[@]}"; do run_checkpoint_eval "$CKPT" || echo "[WARN] Checkpoint $CKPT failed, continuing..." done echo "" echo "========================================================" echo "All checkpoint evaluations complete." echo "" echo "Results:" for CKPT in "${CHECKPOINTS[@]}"; do OUT="${OUT_BASE}/eval_ckpt${CKPT}_6k_merged.json" if [ -f "$OUT" ]; then # Quick accuracy summary python3 -c " import json d = json.load(open('$OUT')) acc = d.get('accuracy', 0) n = d.get('evaluated', 0) print(f' ckpt-${CKPT}: acc={acc:.4f} ({d.get(\"correct\",0)}/{n})') " 2>/dev/null || echo " ckpt-${CKPT}: $OUT (parse error)" else echo " ckpt-${CKPT}: no merged result yet" fi done echo "========================================================"