BHARGAV REDDY commited on
Commit
5296727
Β·
verified Β·
1 Parent(s): ea58023

Upload run_cloud_300m.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. run_cloud_300m.sh +137 -0
run_cloud_300m.sh ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # =============================================================================
3
+ # LUNA 300M β€” Cloud Smoke Test + Full Training (Single Command)
4
+ #
5
+ # Paste this ONE command into any cloud GPU terminal:
6
+ #
7
+ # export HF_TOKEN=hf_xxx && \
8
+ # git clone https://huggingface.co/spaces/ASTERIZER/LUNA /workspace/LUNA && \
9
+ # cd /workspace/LUNA && bash run_cloud_300m.sh
10
+ #
11
+ # What it does:
12
+ # 1. Installs all dependencies
13
+ # 2. Downloads the 4.5B token dataset from HuggingFace
14
+ # 3. Runs a 2-step smoke test to verify everything works
15
+ # 4. If smoke test passes, starts the full 300M pretraining
16
+ # 5. Uploads all checkpoints to HuggingFace when done
17
+ #
18
+ # The smoke test catches ALL issues (model init, data loading, forward/backward,
19
+ # tokenizer, checkpoint saving, text generation) BEFORE burning GPU hours.
20
+ # =============================================================================
21
+
22
+ set -e
23
+
24
+ DATA_DIR="/workspace/data/litdata_pretrain_final"
25
+ OUT_DIR="/workspace/out/pretrain/luna-300m"
26
+ HF_DATASET="ASTERIZER/Luna_Dataset"
27
+ MAX_TOKENS="${1:-4515286950}"
28
+
29
+ echo ""
30
+ echo "============================================================"
31
+ echo " LUNA 300M β€” Cloud Pipeline"
32
+ echo " Dataset : $HF_DATASET -> $DATA_DIR"
33
+ echo " Output : $OUT_DIR"
34
+ echo " Tokens : $MAX_TOKENS"
35
+ echo "============================================================"
36
+
37
+ # ── 1. Dependencies ──────────────────────────────────────────────────────────
38
+ echo ""
39
+ echo "[1/5] Installing dependencies..."
40
+ pip install -q --upgrade pip 2>/dev/null
41
+ pip install -q \
42
+ torch torchvision \
43
+ psutil \
44
+ pyyaml \
45
+ huggingface_hub \
46
+ transformers \
47
+ datasets \
48
+ pyarrow \
49
+ gdown \
50
+ tensorboard 2>/dev/null || true
51
+ echo " Done."
52
+
53
+ # ── 2. Download Dataset ──────────────────────────────────────────────────────
54
+ echo ""
55
+ echo "[2/5] Fetching dataset from HuggingFace..."
56
+ if [ -f "$DATA_DIR/index.json" ]; then
57
+ echo " Dataset already exists at $DATA_DIR, skipping download."
58
+ else
59
+ HF_TOKEN="${HF_TOKEN:-}"
60
+ python fetch_data.py \
61
+ --source huggingface \
62
+ --hf_repo "$HF_DATASET" \
63
+ --out_dir "$DATA_DIR" \
64
+ --hf_token "$HF_TOKEN"
65
+ fi
66
+
67
+ # Quick verify
68
+ DATA_DIR_ENV="$DATA_DIR" python - <<'PYEOF'
69
+ import json, os
70
+ from pathlib import Path
71
+ data_dir = Path(os.environ["DATA_DIR_ENV"])
72
+ idx_path = data_dir / "index.json"
73
+ if not idx_path.exists():
74
+ print(f"FATAL: No index.json at {data_dir}")
75
+ raise SystemExit(1)
76
+ with open(idx_path) as f:
77
+ idx = json.load(f)
78
+ chunks = idx.get("chunks", [])
79
+ total = sum(c.get("dim", 0) for c in chunks)
80
+ present = sum(1 for c in chunks if (data_dir / c["filename"]).exists())
81
+ missing = len(chunks) - present
82
+ print(f" Dataset: {len(chunks)} chunks, {total:,} tokens, {missing} missing")
83
+ if missing > 0:
84
+ print("FATAL: Missing chunks!")
85
+ raise SystemExit(1)
86
+ PYEOF
87
+ echo " Dataset verified."
88
+
89
+ # ── 3. Smoke Test ─────────────────────────────────────────────────────────────
90
+ echo ""
91
+ echo "[3/5] Running 2-step smoke test..."
92
+ echo " (This verifies model + data + training + generation BEFORE full run)"
93
+ echo ""
94
+
95
+ python smoke_test_300m.py \
96
+ --data_path "$DATA_DIR" \
97
+ --steps 2
98
+
99
+ SMOKE_EXIT=$?
100
+ if [ $SMOKE_EXIT -ne 0 ]; then
101
+ echo ""
102
+ echo "============================================================"
103
+ echo " SMOKE TEST FAILED β€” aborting full training."
104
+ echo " Fix the issues above and retry."
105
+ echo "============================================================"
106
+ exit 1
107
+ fi
108
+
109
+ echo ""
110
+ echo " Smoke test passed! Starting full training..."
111
+
112
+ # ── 4. Full Training ─────────────────────────────────────────────────────────
113
+ echo ""
114
+ echo "[4/5] Starting LUNA 300M full pretraining..."
115
+ echo " - Validation: every 100 steps (10 generation prompts)"
116
+ echo " - Checkpoints: every 1000 steps"
117
+ echo " - Auto VRAM probe for max batch size"
118
+ echo ""
119
+
120
+ python train_300m.py \
121
+ --config train_config_300m.yaml \
122
+ --data_path "$DATA_DIR" \
123
+ --out_dir "$OUT_DIR" \
124
+ --max_tokens "$MAX_TOKENS"
125
+
126
+ # ── 5. Done ──────────────────────────────────────────────────────────────────
127
+ echo ""
128
+ echo "============================================================"
129
+ echo " LUNA 300M β€” COMPLETE"
130
+ echo " Output : $OUT_DIR"
131
+ echo " Final model : $OUT_DIR/final/lit_model.pth"
132
+ if [ -n "$HF_TOKEN" ]; then
133
+ echo " HF Upload : https://huggingface.co/ASTERIZER/LUNA-300M"
134
+ else
135
+ echo " HF Upload : SKIPPED (set HF_TOKEN)"
136
+ fi
137
+ echo "============================================================"