Download scripts/runpod_train.sh from Kolgrim/hades: direct link, hf CLI and curl.
- Browser
- Download file 3.08 kB
-
https://huggingface.co/Kolgrim/hades/resolve/main/scripts/runpod_train.sh
- Command line
-
hf download hf://Kolgrim/hades/scripts/runpod_train.sh
-
curl -L -o runpod_train.sh https://huggingface.co/Kolgrim/hades/resolve/main/scripts/runpod_train.sh
3.08 kB
| # RunPod runner for HADES `small` pretraining (Task 19, RunPod instead of Kaggle). | |
| # | |
| # The corpus and code live in the private HF dataset $CORPUS_REPO (zstd shards + manifest + code tarball); | |
| # checkpoints are mirrored to the private HF model repo $CKPT_REPO, so any pod (any data center) can resume. | |
| # | |
| # Usage on the pod (HF_TOKEN must be set): | |
| # bash runpod_train.sh setup # fetch code + corpus, verify shard sha256 against the manifest | |
| # bash runpod_train.sh bench # 50 steps to measure tokens/s (separate run dir, not mirrored) | |
| # bash runpod_train.sh full # full run with --resume auto; mirrors checkpoints every 15 min | |
| set -euo pipefail | |
| MODE=${1:?usage: runpod_train.sh setup|bench|full} | |
| : "${HF_TOKEN:?HF_TOKEN is required}" | |
| CORPUS_REPO=${CORPUS_REPO:-Kolgrim/hades-corpus-v1} | |
| CKPT_REPO=${CKPT_REPO:-Kolgrim/hades-small-ckpt} | |
| CONFIG=${HADES_CONFIG:-configs/small.yaml} | |
| W=${WORKSPACE:-/workspace} | |
| REPO=$W/hades | |
| DATA=$W/corpus | |
| RUN=$W/runs/small | |
| hf_cli() { hf "$@"; } | |
| setup() { | |
| pip install -q -U "huggingface_hub[hf_xet]" zstandard >/dev/null | |
| apt-get -qq update >/dev/null && apt-get -qq install -y zstd >/dev/null || true | |
| hf_cli download "$CORPUS_REPO" --repo-type dataset --local-dir "$W/hf-corpus" >/dev/null | |
| mkdir -p "$REPO" && tar -xzf "$W"/hf-corpus/code/hades-*.tar.gz -C "$REPO" | |
| pip install -q -e "$REPO" >/dev/null | |
| mkdir -p "$DATA" | |
| cp "$W/hf-corpus/manifest.json" "$DATA/" | |
| for f in "$W"/hf-corpus/*/*.bin.zst; do | |
| g=$(basename "$(dirname "$f")"); mkdir -p "$DATA/$g" | |
| out="$DATA/$g/$(basename "$f" .zst)" | |
| [ -f "$out" ] || zstd -q -d --long=27 "$f" -o "$out" | |
| done | |
| python - "$DATA" <<'PY' | |
| import hashlib, json, sys | |
| from pathlib import Path | |
| d = Path(sys.argv[1]); m = json.loads((d / "manifest.json").read_text()); bad = 0; n = 0 | |
| for g, splits in m["groups"].items(): | |
| for s in splits.values(): | |
| for sh in s["shards"]: | |
| p = d / g / Path(sh["path"]).name; n += 1 | |
| if hashlib.sha256(p.read_bytes()).hexdigest() != sh["sha256"]: | |
| print("SHA MISMATCH", p); bad += 1 | |
| print(f"verified {n - bad}/{n} shards against manifest") | |
| sys.exit(1 if bad else 0) | |
| PY | |
| } | |
| pretrain() { | |
| cd "$REPO" | |
| python -m hades.train.pretrain --config "$CONFIG" --out "$1" --data-dir "$DATA" --resume auto "${@:2}" | |
| } | |
| mirror() { hf_cli upload "$CKPT_REPO" "$RUN" . --repo-type model --private --delete "step_*.pt" >/dev/null || echo "mirror failed (will retry)"; } | |
| case "$MODE" in | |
| setup) setup ;; | |
| bench) | |
| rm -rf "$W/runs/bench" | |
| pretrain "$W/runs/bench" --max-steps 50 | |
| tail -3 "$W/runs/bench/log.jsonl" ;; | |
| full) | |
| mkdir -p "$RUN" | |
| if ! ls "$RUN"/step_*.pt >/dev/null 2>&1; then | |
| hf_cli download "$CKPT_REPO" --repo-type model --local-dir "$RUN" >/dev/null 2>&1 && echo "resuming from mirror" || echo "fresh run" | |
| fi | |
| ( while sleep 900; do mirror; done ) & MIRROR=$! | |
| trap 'kill $MIRROR 2>/dev/null || true' EXIT | |
| pretrain "$RUN" "${@:2}" | |
| mirror | |
| echo "DONE: $(tail -1 "$RUN/log.jsonl")" ;; | |
| *) echo "unknown mode $MODE" >&2; exit 2 ;; | |
| esac | |