abidlabs HF Staff commited on
Commit
a93e5a1
·
verified ·
1 Parent(s): 92d63d4

Add hf-jobs launcher for Hugging Face Jobs

Browse files
Files changed (1) hide show
  1. hf-jobs/launch.sh +101 -0
hf-jobs/launch.sh ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Launch nanochat pipeline stages on Hugging Face Jobs (https://huggingface.co/docs/hub/jobs).
3
+ #
4
+ # This script runs INSIDE a job. Typical submission from your own machine:
5
+ #
6
+ # hf jobs run --flavor a10g-small --timeout 45m -s HF_TOKEN \
7
+ # -v hf://buckets/ML-Intern-lab/nanochat-cache:/root/.cache/nanochat \
8
+ # python:3.12 -- \
9
+ # bash -lc "git clone https://huggingface.co/ML-Intern-lab/nanochat && cd nanochat && bash hf-jobs/launch.sh smoke"
10
+ #
11
+ # Stages: smoke | dataset | tok | base | base_eval | sft | eval | chat | speedrun
12
+ # Stage behavior is tuned via env vars, e.g. NANOCHAT_SHARDS, NANOCHAT_BASE_ARGS, NANOCHAT_SFT_ARGS.
13
+ #
14
+ # Checkpoints/data persist under NANOCHAT_BASE_DIR (default ~/.cache/nanochat) —
15
+ # mount a bucket volume there if you want artifacts to survive the job or be
16
+ # shared between stage jobs.
17
+
18
+ set -euxo pipefail
19
+
20
+ STAGE="${1:-smoke}"
21
+ REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
22
+ cd "$REPO_DIR"
23
+
24
+ export OMP_NUM_THREADS=1
25
+ export NANOCHAT_BASE_DIR="${NANOCHAT_BASE_DIR:-$HOME/.cache/nanochat}"
26
+ mkdir -p "$NANOCHAT_BASE_DIR"
27
+ export WANDB_RUN="${WANDB_RUN:-dummy}" # 'dummy' disables wandb logging
28
+ # Optional live metrics: sitecustomize.py bridges nanochat's DummyWandb into trackio
29
+ export PYTHONPATH="$(pwd)/hf-jobs${PYTHONPATH:+:$PYTHONPATH}"
30
+ export NANOCHAT_TRACKIO_PROJECT="${NANOCHAT_TRACKIO_PROJECT:-nanochat-hf-jobs}"
31
+ export NANOCHAT_TRACKIO_SPACE_ID="${NANOCHAT_TRACKIO_SPACE_ID:-ML-Intern-lab/nanochat-hf-jobs-trackio}"
32
+
33
+ # --- dependencies (uv, same as runs/speedrun.sh) ---
34
+ command -v uv &>/dev/null || curl -LsSf https://astral.sh/uv/install.sh | sh
35
+ export PATH="$HOME/.local/bin:$PATH"
36
+ [ -d .venv ] || uv venv
37
+ uv sync --extra gpu
38
+ source .venv/bin/activate
39
+
40
+ # number of GPUs for torchrun stages (1 on single-GPU jobs)
41
+ if command -v nvidia-smi &>/dev/null; then
42
+ GPUS="${NANOCHAT_GPUS:-$(nvidia-smi -L | wc -l)}"
43
+ else
44
+ GPUS=1
45
+ fi
46
+ echo "launch.sh: stage=$STAGE gpus=$GPUS base_dir=$NANOCHAT_BASE_DIR"
47
+
48
+ case "$STAGE" in
49
+ smoke)
50
+ # Tiny end-to-end pipeline proving the whole launch path on a single GPU.
51
+ # 1 training shard (~250M chars) + the pinned validation shard.
52
+ python -m nanochat.dataset -n 1
53
+ python -m scripts.tok_train --max-chars=200000000
54
+ python -m scripts.tok_eval
55
+ python -m scripts.base_train -- \
56
+ --depth=6 --head-dim=64 --window-pattern=L --max-seq-len=512 \
57
+ --device-batch-size=16 --total-batch-size=16384 \
58
+ --num-iterations=50 --eval-every=25 --eval-tokens=524288 \
59
+ --core-metric-every=-1 --sample-every=-1 --run=dummy
60
+ python -m scripts.chat_sft -- \
61
+ --num-iterations=30 --total-batch-size=32768 \
62
+ --eval-every=15 --eval-tokens=524288 \
63
+ --chatcore-every=-1 --run=dummy
64
+ python -m scripts.chat_cli -p "Why is the sky blue?"
65
+ ;;
66
+ dataset)
67
+ python -m nanochat.dataset -n "${NANOCHAT_SHARDS:-170}"
68
+ ;;
69
+ tok)
70
+ python -m scripts.tok_train --max-chars="${NANOCHAT_TOK_MAX_CHARS:-2000000000}"
71
+ python -m scripts.tok_eval
72
+ ;;
73
+ base)
74
+ # Default mirrors runs/speedrun.sh (8xH100, d24). Override with NANOCHAT_BASE_ARGS.
75
+ torchrun --standalone --nproc_per_node="$GPUS" -m scripts.base_train -- \
76
+ ${NANOCHAT_BASE_ARGS:---depth=24 --target-param-data-ratio=8 --device-batch-size=16 --fp8}
77
+ ;;
78
+ base_eval)
79
+ torchrun --standalone --nproc_per_node="$GPUS" -m scripts.base_eval -- \
80
+ ${NANOCHAT_BASE_EVAL_ARGS:---device-batch-size=16}
81
+ ;;
82
+ sft)
83
+ torchrun --standalone --nproc_per_node="$GPUS" -m scripts.chat_sft -- \
84
+ ${NANOCHAT_SFT_ARGS:-}
85
+ ;;
86
+ eval)
87
+ torchrun --standalone --nproc_per_node="$GPUS" -m scripts.chat_eval -- \
88
+ ${NANOCHAT_EVAL_ARGS:--i sft}
89
+ ;;
90
+ chat)
91
+ python -m scripts.chat_cli -p "${NANOCHAT_PROMPT:-Why is the sky blue?}"
92
+ ;;
93
+ speedrun)
94
+ bash runs/speedrun.sh
95
+ ;;
96
+ *)
97
+ echo "Unknown stage: $STAGE (expected smoke|dataset|tok|base|base_eval|sft|eval|chat|speedrun)" >&2
98
+ exit 1
99
+ ;;
100
+ esac
101
+ echo "launch.sh: stage $STAGE done"