#!/usr/bin/env bash # scripts/launch.sh — launch a single training run, detached via nohup. # # Usage: # bash scripts/launch.sh [condition] [n_train] [seed] [gpu] # # Defaults: # condition = grokking # n_train = 500 # seed = 42 # gpu = 0 # # Survives SSH disconnects. All artifacts in experiments/runs//. set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "${ROOT}" source "${ROOT}/scripts/lib/nohup_runner.sh" source "${ROOT}/scripts/lib/env.sh" resolve_python CONDITION="${1:-grokking}" N_TRAIN="${2:-500}" SEED="${3:-42}" GPU="${4:-0}" WANDB_MODE_ARG="${WANDB_MODE:-online}" # online|offline|disabled EXTRA_ARGS="${EXTRA_ARGS:-}" # extra trainer flags pass-through # e.g. EXTRA_ARGS="--spurious_rho 0.8 --weight_decay 5e-3" RUN_TAG="${RUN_TAG:-}" # extra slug inserted into the run_id between # and n. Caller-controlled because # the launcher pre-creates the run_dir before the # trainer can self-tag. # e.g. RUN_TAG=spurious08 RUN_TAG=spurious095_ps10 STAMP="$(date -u +%Y%m%d-%H%M%S)" TAG_INFIX="" [[ -n "${RUN_TAG}" ]] && TAG_INFIX="_${RUN_TAG}" RUN_ID="${STAMP}_${CONDITION}${TAG_INFIX}_n${N_TRAIN}_s${SEED}" RUN_DIR="experiments/runs/${RUN_ID}" mkdir -p "${RUN_DIR}"/{logs,results,checkpoints,figures} echo "Launching CausalGrok run" echo " condition : ${CONDITION}" echo " n_train : ${N_TRAIN}" echo " seed : ${SEED}" echo " GPU : ${GPU}" echo " run_id : ${RUN_ID}" # Build the trainer argv. EXTRA_ARGS is intentionally unquoted so it # word-splits into individual flags (env vars cannot carry arrays). read -r -a _extra <<<"${EXTRA_ARGS}" CUDA_VISIBLE_DEVICES="${GPU}" launch_detached "${RUN_DIR}" \ "${PYTHON}" -u -m experiments.causalgrok_baseline \ --condition "${CONDITION}" \ --n_train "${N_TRAIN}" \ --seed "${SEED}" \ --run_dir "${RUN_DIR}" \ --wandb_project causalgrok \ --wandb_mode "${WANDB_MODE_ARG}" \ "${_extra[@]}"