#!/usr/bin/env bash ############################################################################### # StepProbe — Master driver for all follow-up experiments. # # Runs the six GPU-gated experiment scripts in their priority order (the # tallest reviewer-risk items first), then regenerates every paper figure # and LaTeX table so the paper source is up to date. # # Every step is skip-if-exists, so if you Ctrl-C mid-run, just re-run and # it resumes from where it stopped. A single failure halts the master # script (set -e), but individual sub-scripts tolerate resumption. # # Total runtime if everything runs from scratch: ~10-12 hours on one 3090 Ti. # Re-runs after partial completion are proportionally shorter. # # Usage: # bash run_all_experiments.sh # run the default priority order # bash run_all_experiments.sh --dry-run # print the plan, run nothing # bash run_all_experiments.sh --skip baselines multi_seed # skip by tag # bash run_all_experiments.sh --only prompt_prefix # run one phase # OPENAI_API_KEY=sk-... bash run_all_experiments.sh # include A3 validation # # Phase tags (for --skip / --only): # baselines — sampling-strategy baselines (A4) # multi_seed — 3-seed robustness on primary cell (A1) # classifier — LLM-judge classifier validation (A3) — API KEY REQUIRED # llama_lr — Llama LR sensitivity sweep (A5) # prompt_prefix — training-free intervention (B2-a) # scale_up — 14B scale-up experiment (B1) # paper — regenerate figures + tables (always runs at the end) ############################################################################### set -euo pipefail PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)" cd "$PROJECT_DIR" export CUDA_VISIBLE_DEVICES="${CUDA_VISIBLE_DEVICES:-1}" export HF_HUB_DOWNLOAD_TIMEOUT=300 # ========================== CONFIG ========================================= LOG_DIR="${PROJECT_DIR}/logs" TIMESTAMP=$(date +%Y%m%d_%H%M%S) LOG_FILE="${LOG_DIR}/run_all_experiments_${TIMESTAMP}.log" PY="${PY:-python}" GPU_MEM="${GPU_MEM:-0.55}" mkdir -p "$LOG_DIR" # ========================== ARG PARSING ==================================== DRY_RUN=false CONTINUE_ON_ERROR=false ONLY_TAGS=() SKIP_TAGS=() while [[ $# -gt 0 ]]; do case $1 in --dry-run) DRY_RUN=true; shift ;; --continue-on-error) CONTINUE_ON_ERROR=true; shift ;; --skip) shift; while [[ $# -gt 0 && "$1" != --* ]]; do SKIP_TAGS+=("$1"); shift; done ;; --only) shift; while [[ $# -gt 0 && "$1" != --* ]]; do ONLY_TAGS+=("$1"); shift; done ;; --help|-h) grep -E "^#( |$)" "$0" | sed 's/^# \?//' | head -40 exit 0 ;; *) echo "Unknown option: $1"; exit 1 ;; esac done FAILED_TAGS=() should_run() { local tag=$1 # If --only was passed, only those tags run. if [[ ${#ONLY_TAGS[@]} -gt 0 ]]; then for t in "${ONLY_TAGS[@]}"; do [[ "$t" == "$tag" ]] && return 0 done return 1 fi # Otherwise, skip tags listed in --skip. for t in "${SKIP_TAGS[@]}"; do [[ "$t" == "$tag" ]] && return 1 done return 0 } # ========================== LOGGING ======================================== log() { local msg="[$(date '+%H:%M:%S')] $1" echo "$msg" | tee -a "$LOG_FILE" } section() { log "" log "==============================================" log "$1" log "==============================================" } # Run one phase. $1 = tag, $2 = description, $3 = runtime estimate, $4 = command. run_phase() { local tag=$1 desc=$2 eta=$3 cmd=$4 if ! should_run "$tag"; then log "[skip $tag] $desc" return 0 fi section "PHASE: $desc [tag=$tag, ETA $eta]" if $DRY_RUN; then log " [DRY-RUN] $cmd" return 0 fi local phase_start=$(date +%s) # Disable `set -e` around the eval so a non-zero exit doesn't kill us; # we want to check the status ourselves. Restore immediately after. set +e eval "$cmd" 2>&1 | tee -a "$LOG_FILE" local rc=${PIPESTATUS[0]} set -e local phase_end=$(date +%s) local dur=$((phase_end - phase_start)) if [[ $rc -ne 0 ]]; then log "FAILED [$tag] after $((dur / 60))m $((dur % 60))s — exit=$rc" FAILED_TAGS+=("$tag") if $CONTINUE_ON_ERROR; then log " continuing to next phase (--continue-on-error set)" return 0 fi log " Resume with: bash $0 --only $tag" log " Or skip and continue the remaining queue: bash $0 --continue-on-error --skip $tag" log " (Individual scripts are skip-if-exists so restart is cheap.)" exit 1 fi log "PHASE COMPLETE [$tag] in $((dur / 60))m $((dur % 60))s" } # ========================== PREFLIGHT ====================================== section "StepProbe — full follow-up experiment sweep" log " Project dir: $PROJECT_DIR" log " Log file: $LOG_FILE" log " GPU: $(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -1 || echo 'unknown')" log " CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES" if [[ ${#ONLY_TAGS[@]} -gt 0 ]]; then log " Running ONLY: ${ONLY_TAGS[*]}" elif [[ ${#SKIP_TAGS[@]} -gt 0 ]]; then log " Skipping: ${SKIP_TAGS[*]}" fi if $DRY_RUN; then log " Mode: DRY-RUN" fi OVERALL_START=$(date +%s) # ========================== PHASE 1 — BASELINES (A4) ====================== # Tallest reviewer-risk: if silver_bullet ≈ random, the novelty claim collapses. run_phase "baselines" \ "Sampling-strategy baselines (silver_bullet vs failed_only vs random)" \ "~90 min" \ "bash ${PROJECT_DIR}/run_baselines.sh" # ========================== PHASE 2 — MULTI-SEED (A1) ===================== # Reviewer-rigor blocker for NeurIPS-tier submission. run_phase "multi_seed" \ "Multi-seed robustness (3 seeds at T=0.6 on primary cell)" \ "~2 h" \ "bash ${PROJECT_DIR}/run_multi_seed.sh" # ========================== PHASE 3 — CLASSIFIER (A3) ===================== # LLM-judge validation. Requires OPENAI_API_KEY or ANTHROPIC_API_KEY. if [[ -n "${OPENAI_API_KEY:-}" ]]; then run_phase "classifier" \ "Error-type classifier validation (OpenAI judge, gpt-4o)" \ "~5 min + API cost" \ "$PY ${PROJECT_DIR}/scripts/validate_classifier.py \ --judge openai --judge-model gpt-4o --n-samples 200" elif [[ -n "${ANTHROPIC_API_KEY:-}" ]]; then run_phase "classifier" \ "Error-type classifier validation (Anthropic judge, claude-3-5-sonnet)" \ "~5 min + API cost" \ "$PY ${PROJECT_DIR}/scripts/validate_classifier.py \ --judge anthropic --judge-model claude-3-5-sonnet-latest --n-samples 200" elif should_run "classifier"; then log "[skip classifier] set OPENAI_API_KEY or ANTHROPIC_API_KEY to include LLM-judge validation" fi # ========================== PHASE 4 — LLAMA LR SWEEP (A5) ================= # Converts the §8 regression discussion into evidence-backed narrative. run_phase "llama_lr" \ "Llama-family learning-rate sweep (5e-5, 1e-4, 2e-4)" \ "~2.5 h" \ "bash ${PROJECT_DIR}/run_llama_lr_sweep.sh" # ========================== PHASE 5 — PROMPT PREFIX (B2-a) ================ # Headline figure for the reframed paper: training-free intervention. run_phase "prompt_prefix" \ "Prompt-prefix injection sweep (k = 0..4)" \ "~80 min" \ "bash ${PROJECT_DIR}/run_prompt_prefix.sh" # ========================== PHASE 6 — 14B SCALE-UP (B1) =================== # Answers the inevitable "does it scale?" reviewer question. run_phase "scale_up" \ "14B scale-up experiment" \ "~90 min" \ "bash ${PROJECT_DIR}/run_scale_up.sh" # ========================== PHASE 7 — PAPER ARTIFACTS ===================== # Always regenerate — this is cheap and ensures every figure/table reflects # whatever new experiments succeeded above. run_phase "paper" \ "Regenerate paper figures + LaTeX tables" \ "~1 min" \ "$PY ${PROJECT_DIR}/scripts/compute_ci.py \ --diagnosis ${PROJECT_DIR}/results/diagnosis \ --output ${PROJECT_DIR}/results/metrics --n-boot 5000 && \ $PY ${PROJECT_DIR}/scripts/make_paper_figures.py \ --metrics ${PROJECT_DIR}/results/metrics \ --diagnosis ${PROJECT_DIR}/results/diagnosis \ --segmented ${PROJECT_DIR}/results/segmented \ --output ${PROJECT_DIR}/figures/paper && \ $PY ${PROJECT_DIR}/scripts/make_tables.py \ --metrics-dir ${PROJECT_DIR}/results/metrics \ --output-dir ${PROJECT_DIR}/figures/paper" # ========================== DONE =========================================== OVERALL_END=$(date +%s) TOTAL=$((OVERALL_END - OVERALL_START)) if [[ ${#FAILED_TAGS[@]} -gt 0 ]]; then section "RUN FINISHED WITH FAILURES" log " Failed phases: ${FAILED_TAGS[*]}" log " Resume any of them with: bash $0 --only " else section "ALL EXPERIMENTS COMPLETE" fi log " Total time: $((TOTAL / 3600))h $(((TOTAL % 3600) / 60))m" log " Log file: $LOG_FILE" log "" log " Next:" log " 1. Open figures/paper/ to review all figures and tables." log " 2. Recompile paper/: cd paper && make (or upload to Overleaf)." log " 3. Read §6.3 (baselines), §7 (interventions), §8 (limitations) first" log " — those are the sections whose content depends on these runs."