CausalGrok / code /scripts /run_spurious.sh
nileshsarkar-ai's picture
Upload code/scripts
42c0d23 verified
#!/usr/bin/env bash
# scripts/run_spurious.sh
#
# Outcome-C variant: inject a colored-corner spurious feature at
# correlation rho into PneumoniaMNIST and run standard vs. grokking
# in parallel. Both detached under nohup.
#
# Defaults:
# GPU_STD=0 GPU_GROK=0 (single-GPU box; both share GPU 0)
# N_TRAIN=500 SEED=42
# RHO=0.8 (val plateau ceiling for the shortcut)
# WD_GROK=5e-3 (elevated WD; Goldilocks zone fix β€”
# previous run showed β€–Wβ€– climbing instead
# of decreasing, so wd=1e-3 was too weak)
# WANDB_MODE=offline (logs to disk; sync later)
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "${ROOT}"
GPU_STD="${GPU_STD:-0}"
GPU_GROK="${GPU_GROK:-0}"
N_TRAIN="${N_TRAIN:-500}"
SEED="${SEED:-42}"
RHO="${RHO:-0.8}"
WD_GROK="${WD_GROK:-5e-3}"
export WANDB_MODE="${WANDB_MODE:-offline}"
echo "Spurious-feature variant β€” rho=${RHO}, n_train=${N_TRAIN}, seed=${SEED}"
echo " standard run on GPU ${GPU_STD} (default WD)"
echo " grokking run on GPU ${GPU_GROK} (WD=${WD_GROK})"
# RUN_TAG slug (e.g. 0.8 β†’ "spurious08", 0.95 β†’ "spurious095") so the
# run_dir clearly identifies the spurious variant on disk.
RHO_SLUG="spurious$(echo "${RHO}" | tr -d '.')"
EXTRA_ARGS="--spurious_rho ${RHO}" \
RUN_TAG="${RHO_SLUG}" \
bash scripts/launch.sh standard "${N_TRAIN}" "${SEED}" "${GPU_STD}"
EXTRA_ARGS="--spurious_rho ${RHO} --weight_decay ${WD_GROK}" \
RUN_TAG="${RHO_SLUG}" \
bash scripts/launch.sh grokking "${N_TRAIN}" "${SEED}" "${GPU_GROK}"
echo
echo "Both spurious runs detached. Watch with:"
echo " bash scripts/list_runs.sh"
echo " tail -f experiments/runs/<run_id>/logs/train.log"
echo
echo "Decision numbers will be in summary.json when each finishes."