#!/bin/bash # Runs ON a RunPod pod. Generates one clone shard, uploads it to HF, self-terminates. # Durability rule (gpu-runbook): the pod owns its own result delivery -- a Mac-side watcher # can be reaped, so nothing may depend on one. Incremental saves + HF upload + self-kill. set -x SHARD=$1; N_SHARDS=$2; N_SEQS=$3; HARVEST=$4; THIN=$5; CHUNK=$6; ORDER=${7:-9} case "$ORDER" in 3) NL=2;; 9) NL=4;; 33) NL=6;; *) echo "bad order"; exit 1;; esac cd /root apt-get update -qq && apt-get install -y -qq tmux git >/dev/null 2>&1 pip install -q huggingface_hub numpy python - "$NL" <<'PY' import os from huggingface_hub import hf_hub_download os.makedirs("/root/results/nlp_cp", exist_ok=True) import sys for f in [f"factored{sys.argv[1]}.pt", "train.npy", "test.npy"]: p = hf_hub_download("bgradowhite/rende-nlp-fig1", f"results/{f}", repo_type="dataset", local_dir="/root/dl") os.replace(p, f"/root/results/nlp_cp/{f}") print("data ready") PY # GPU health before investing (gpu-runbook non-negotiable) nvidia-smi --query-gpu=name,memory.total,ecc.errors.uncorrected.volatile.total --format=csv python -c "import torch;assert torch.cuda.is_available();print('cuda OK',torch.cuda.get_device_name(0))" || { echo "GPU UNUSABLE - self-terminating"; runpodctl remove pod "$RUNPOD_POD_ID"; exit 1; } tmux new-session -d -s clone "cd /root && PYTHONUNBUFFERED=1 python -u nlp_cp_sweep.py clones \ --shard $SHARD --n-shards $N_SHARDS --n-seqs $N_SEQS --harvest $HARVEST --thin $THIN \ --chunk $CHUNK --order $ORDER --outdir /root/results/nlp_cp 2>&1 | tee /root/shard$SHARD.log; \ echo EXIT=\$? >> /root/shard$SHARD.log" while tmux has-session -t clone 2>/dev/null; do sleep 60; done python - <