| #!/usr/bin/env bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| 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 |
|
|
| |
| 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" |
|
|
| |
| 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_TAGS[@]} -gt 0 ]]; then |
| for t in "${ONLY_TAGS[@]}"; do |
| [[ "$t" == "$tag" ]] && return 0 |
| done |
| return 1 |
| fi |
| |
| for t in "${SKIP_TAGS[@]}"; do |
| [[ "$t" == "$tag" ]] && return 1 |
| done |
| return 0 |
| } |
|
|
| |
| log() { |
| local msg="[$(date '+%H:%M:%S')] $1" |
| echo "$msg" | tee -a "$LOG_FILE" |
| } |
|
|
| section() { |
| log "" |
| log "==============================================" |
| log "$1" |
| log "==============================================" |
| } |
|
|
| |
| 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) |
| |
| |
| 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" |
| } |
|
|
| |
| 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) |
|
|
| |
| |
| run_phase "baselines" \ |
| "Sampling-strategy baselines (silver_bullet vs failed_only vs random)" \ |
| "~90 min" \ |
| "bash ${PROJECT_DIR}/run_baselines.sh" |
|
|
| |
| |
| 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" |
|
|
| |
| |
| 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 |
|
|
| |
| |
| 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" |
|
|
| |
| |
| run_phase "prompt_prefix" \ |
| "Prompt-prefix injection sweep (k = 0..4)" \ |
| "~80 min" \ |
| "bash ${PROJECT_DIR}/run_prompt_prefix.sh" |
|
|
| |
| |
| run_phase "scale_up" \ |
| "14B scale-up experiment" \ |
| "~90 min" \ |
| "bash ${PROJECT_DIR}/run_scale_up.sh" |
|
|
| |
| |
| |
| 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" |
|
|
| |
| 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 <tag>" |
| 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." |
|
|