unparallelled commited on
Commit
4820f78
·
verified ·
1 Parent(s): 1e44574

Upload scripts/finish_all.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/finish_all.sh +247 -0
scripts/finish_all.sh ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # =============================================================================
3
+ # finish_all.sh -- run the rest of the 2026-09-03 plan UNATTENDED:
4
+ #
5
+ # arm C' -> arm A' -> eval both -> rebuild notebook -> upload to HF -> ready
6
+ #
7
+ # Detached with nohup, so it survives the chat session closing.
8
+ #
9
+ # ALREADY DONE before this script starts (do not redo):
10
+ # run7' (run 6, step 750) corrected-cache 16k base
11
+ # arm B' (run 7, step 400) IN2 needle at distance 0
12
+ # eval of base_c + armB_c at 1024/2048/4096/8192/16360, N=100
13
+ # cache_fix_results.ipynb run7' vs run7 comparison
14
+ #
15
+ # RUN NUMBERING: bluscriptCP picks run_number as the first free
16
+ # CP_BluScreipt_Training_logs/CP_Training_log<N>.csv. Logs 1-26 exist, so arm C
17
+ # takes 27 and arm A takes 28. Neither collides with the run6/7/8 checkpoints --
18
+ # which matters, because exactly that collision (arm B taking run 7 while an old
19
+ # run7_step_750 sat in rank_0) let CP_CKPT_KEEP=1 prune arm B's step-200 shard on
20
+ # rank_0 and made it unresumable.
21
+ #
22
+ # EVERY checkpoint is verified across ALL FOUR ZeRO-1 rank shards. A zero exit
23
+ # code is not proof: bluscriptCP catches a failed save and only prints [WARN],
24
+ # and a 3-of-4 shard set loads silently wrong.
25
+ #
26
+ # THE EVAL REUSES the existing newck_len_* dirs on purpose. run_longeval.sh's
27
+ # prompt signature covers N, length, depths, seed and haystack -- NOT the model
28
+ # set -- so adding armC_c/armA_c to CKPT_EXTRA reuses the prompts, skips the
29
+ # finished base_c/armB_c cells, and rebuilds summary.csv with all four models.
30
+ # DO NOT change PROMPT_LEN/N/DEPTHS here or the signature flips and every
31
+ # completed cell is wiped.
32
+ # =============================================================================
33
+ set -uo pipefail
34
+ cd "$(dirname "$0")"
35
+
36
+ ROOT="$(cd ../.. && pwd)"
37
+ export LD_LIBRARY_PATH="$ROOT/Tensor-Implementations/lib:$ROOT/Profiler/lib:${LD_LIBRARY_PATH:-}"
38
+ export OMPI_ALLOW_RUN_AS_ROOT=1 OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1
39
+
40
+ PY=${PY:-/root/Adhi/BluTrain/envv/bin/python}
41
+ HFCLI=/root/Adhi/BluTrain/envv/bin/hf
42
+ EXE=./build/bluscriptCP_exec
43
+ CK=checkpoints_bluscriptcp/rank_0
44
+ LOG=finish_logs; mkdir -p "$LOG"
45
+ M="$LOG/finish.log"
46
+ REPO=unparallelled/BluScriptCP
47
+
48
+ say(){ echo "[$(date -u +%H:%M:%S)] $*" | tee -a "$M" >&2; }
49
+ die(){ say "FATAL: $*"; exit 1; }
50
+
51
+ T=16384; YARN=4; ORIG=4096; NP=4; GPUS=0,1,2,3
52
+ ARCH="CP_N_EMBD=1536 CP_N_LAYER=36 CP_N_HEAD=12 CP_N_KVHEAD=4 CP_FFN=4096 CP_WEIGHT_TYING=0"
53
+ COMMON="CP_SIZE=$NP CP_ATTN_MODE=ring CP_ATTN_FUSION=split CP_T=$T \
54
+ YARN_SCALE=$YARN YARN_ORIG_MAXPOS=$ORIG \
55
+ CP_ZERO=1 CP_ZERO_V2=1 CP_ZERO_SYMMETRIC=1 CP_BF16=1 CP_OPTIMIZER=muon \
56
+ CP_MAX_LR=1e-3 CP_MIN_LR=1e-4 CP_WARMUP=1 \
57
+ CP_CKPT=1 CP_CKPT_KEEP=1 CP_CKPT_NEW_RUN=1"
58
+
59
+ R7="$CK/blumodelcp_run6_step_750.ckpt" # run7', every arm's parent
60
+ LENS="1024 2048 4096 8192 16360"
61
+ N=100
62
+ TASKS="niah_single val_backward"
63
+
64
+ [ -x "$EXE" ] || die "$EXE missing"
65
+ [ -f "$R7" ] || die "run7' parent checkpoint missing: $R7"
66
+
67
+ say "=== finish_all.sh start ==="
68
+ say "free disk $(df -BG --output=avail /root | tail -1 | tr -dc '0-9')G"
69
+
70
+ # Warn about the HF token UP FRONT rather than 2 hours later at the upload step.
71
+ if [ -z "${HF_TOKEN:-}" ] && [ ! -f "$HOME/.cache/huggingface/token" ] && [ ! -f hf_token.txt ]; then
72
+ say "WARNING: no HF token found. Training and eval will proceed; the UPLOAD"
73
+ say " step will wait for one. Provide it either way:"
74
+ say " echo '<token>' > $(pwd)/hf_token.txt"
75
+ say " or: export HF_TOKEN=<token> (only helps if set before this script)"
76
+ fi
77
+
78
+ # ---------------------------------------------------------------------------
79
+ # train one arm and verify it landed on all four ranks
80
+ # ---------------------------------------------------------------------------
81
+ train_arm(){ # $1 = arm letter
82
+ # Separate statements: in `local A=$1 lf="...${A}..."` bash expands every word
83
+ # BEFORE the local builtin runs, so ${A} is still unset and `set -u` aborts.
84
+ local A="$1"
85
+ local lf="$LOG/arm_${A}.log"
86
+ if [ -f "$LOG/arm_${A}.ckpt" ] && [ -f "$(cat "$LOG/arm_${A}.ckpt")" ]; then
87
+ say "arm $A already done -> $(cat "$LOG/arm_${A}.ckpt")"; return 0
88
+ fi
89
+ [ -d "in2_data/arm_$A" ] || { say "arm $A: no in2_data/arm_$A -- SKIPPING"; return 1; }
90
+ say "training arm $A' (400 steps from run7')"
91
+ env $ARCH $COMMON CP_INIT_FROM="$PWD/$R7" CP_DATA_ROOT="$PWD/in2_data/arm_$A" \
92
+ CP_B=4 CP_GLOBAL_BATCH=524288 CP_MAX_STEPS=400 \
93
+ CP_REWARMUP=100 CP_REWARMUP_PEAK=0.3 CP_CKPT_FREQ=200 \
94
+ CUDA_VISIBLE_DEVICES=$GPUS mpirun --allow-run-as-root -np $NP "$EXE" \
95
+ > "$lf" 2>&1
96
+ local rc=$?
97
+ local RN; RN=$(grep -aoE 'CP_Training_log[0-9]+' "$lf" | head -1 | grep -oE '[0-9]+')
98
+ [ -n "$RN" ] || { say "arm $A: no run number in $lf (rc=$rc) -- FAILED"; return 1; }
99
+ local CKF; CKF=$(ls -t $CK/blumodelcp_run${RN}_step_*.ckpt 2>/dev/null | head -1)
100
+ [ -n "$CKF" ] || { say "arm $A: run $RN wrote NO checkpoint (rc=$rc) -- FAILED"; return 1; }
101
+ # all four ZeRO-1 shards, or the load is silently partial
102
+ local base n; base=$(basename "$CKF")
103
+ n=$(ls checkpoints_bluscriptcp/rank_*/"$base" 2>/dev/null | wc -l)
104
+ [ "$n" -ge 4 ] || { say "arm $A: only $n/4 rank shards for $base -- FAILED"; return 1; }
105
+ grep -qa 'checkpoint save.*failed' "$lf" && { say "arm $A: a checkpoint save FAILED"; return 1; }
106
+ echo "$CKF" > "$LOG/arm_${A}.ckpt"
107
+ say "arm $A' -> run $RN, $base, final loss $(grep -aE '^step ' "$lf" | tail -1 | grep -oE 'loss: [0-9.]+')"
108
+ return 0
109
+ }
110
+
111
+ train_arm c || say "arm C did not complete -- continuing with whatever exists"
112
+ train_arm a || say "arm A did not complete -- continuing with whatever exists"
113
+
114
+ # ---------------------------------------------------------------------------
115
+ # evaluate every model that exists, matched cache (YARN_ORIG=4096)
116
+ # ---------------------------------------------------------------------------
117
+ EXTRA="base_c=blumodelcp_run6_step_750.ckpt"
118
+ B=$(ls -t $CK/blumodelcp_run7_step_400.ckpt 2>/dev/null | head -1)
119
+ [ -n "$B" ] && EXTRA="$EXTRA armB_c=$(basename "$B")"
120
+ for A in c a; do
121
+ f="$LOG/arm_${A}.ckpt"
122
+ [ -f "$f" ] || continue
123
+ p=$(cat "$f"); [ -f "$p" ] || continue
124
+ EXTRA="$EXTRA arm$(echo $A | tr a-z A-Z)_c=$(basename "$p")"
125
+ done
126
+ MODELS=$(echo $EXTRA | tr ' ' '\n' | cut -d= -f1 | tr '\n' ' ')
127
+ say "eval models: $MODELS"
128
+
129
+ for LEN in $LENS; do
130
+ say "eval PROMPT_LEN=$LEN (finished cells are skipped)"
131
+ PY=$PY OUT=newck_len_$LEN TASKS="$TASKS" CKPTS="$MODELS" N=$N \
132
+ PROMPT_LEN=$LEN MAX_NEW=24 T=$T DEPTHS="0.0,0.25,0.5,0.75,1.0" \
133
+ YARN_ORIG=$ORIG GPUS=0,1,2,3 JOBS_PER_GPU=2 BF16=1 GREEDY=1 \
134
+ CKPT_EXTRA="$EXTRA" ./run_longeval.sh >> "$LOG/eval_$LEN.log" 2>&1 \
135
+ || say " WARN: eval at $LEN returned nonzero"
136
+ [ -f "newck_len_$LEN/summary.csv" ] && say " -> $(head -1 newck_len_$LEN/summary.csv)"
137
+ done
138
+ say "eval done"
139
+
140
+ # ---------------------------------------------------------------------------
141
+ # rebuild the notebook and the markdown report with all four models
142
+ # ---------------------------------------------------------------------------
143
+ $PY Tests/bluscriptcp/mk_cache_notebook.py --out cache_fix_results.ipynb \
144
+ >> "$LOG/notebook.log" 2>&1 \
145
+ && say "notebook rebuilt: cache_fix_results.ipynb" \
146
+ || say "WARN: notebook rebuild failed -- see $LOG/notebook.log"
147
+
148
+ {
149
+ echo "# Corrected-cache retrain results -- 2026-09-03"
150
+ echo
151
+ echo "Models: run7' (base_c), arm B' (armB_c), arm C' (armC_c), arm A' (armA_c),"
152
+ echo "all trained under YARN_ORIG_MAXPOS=4096 and evaluated under the same."
153
+ echo "Generative substring-match scoring, greedy, bf16, N=$N per cell."
154
+ echo
155
+ for LEN in $LENS; do
156
+ echo "## PROMPT_LEN=$LEN"; echo '```'
157
+ cat "newck_len_$LEN/summary.csv" 2>/dev/null || echo "(missing)"
158
+ echo '```'; echo
159
+ done
160
+ echo "## Training losses"; echo '```'
161
+ echo "run7' (run 6, step 750): $(grep -aE '^step ' retrain_logs/run7c.log | tail -1 | grep -oE 'loss: [0-9.]+')"
162
+ echo "arm B' (run 7, step 400): $(grep -aE '^step ' retrain_logs/arm_b.log | tail -1 | grep -oE 'loss: [0-9.]+')"
163
+ for A in c a; do
164
+ [ -f "$LOG/arm_${A}.log" ] && \
165
+ echo "arm ${A}' : $(grep -aE '^step ' "$LOG/arm_${A}.log" | tail -1 | grep -oE 'loss: [0-9.]+')"
166
+ done
167
+ echo '```'
168
+ } > "$LOG/RESULTS.md"
169
+ say "wrote $LOG/RESULTS.md"
170
+
171
+ # ---------------------------------------------------------------------------
172
+ # upload. Waits up to 2 h for a token so the chat can supply one late.
173
+ # ---------------------------------------------------------------------------
174
+ for i in $(seq 1 120); do
175
+ if [ -f hf_token.txt ]; then export HF_TOKEN=$(tr -d ' \n' < hf_token.txt); fi
176
+ [ -n "${HF_TOKEN:-}" ] && break
177
+ [ -f "$HOME/.cache/huggingface/token" ] && break
178
+ [ "$i" = 1 ] && say "waiting for an HF token (checking hf_token.txt every 60s, up to 2h)"
179
+ sleep 60
180
+ done
181
+
182
+ if [ -z "${HF_TOKEN:-}" ] && [ ! -f "$HOME/.cache/huggingface/token" ]; then
183
+ say "UPLOAD SKIPPED: no HF token after 2h."
184
+ cat > TEARDOWN_BLOCKED.txt <<EOF
185
+ NOT SAFE TO TEAR DOWN -- nothing was uploaded.
186
+
187
+ Everything below exists only on this box. Provide a token and re-run the upload:
188
+
189
+ echo '<hf-token>' > $(pwd)/hf_token.txt
190
+ ./finish_all.sh # training/eval are idempotent, it jumps to upload
191
+
192
+ What still needs uploading:
193
+ cache_fix_results.ipynb the results notebook
194
+ newck_len_*/ corrected-cache eval data
195
+ $LOG/ arm C'/arm A' training logs + RESULTS.md
196
+ retrain_logs/ run7'/arm B' training logs
197
+ checkpoints_bluscriptcp/rank_0/ run6 (run7'), run7 (arm B'), run27, run28
198
+ checkpoints_old_run7/ yesterday's buggy-cache run7 base
199
+ EOF
200
+ say "wrote TEARDOWN_BLOCKED.txt"
201
+ exit 1
202
+ fi
203
+
204
+ say "uploading to $REPO"
205
+ up(){ # $1=local $2=remote
206
+ [ -e "$1" ] || { say " skip $1 (absent)"; return 0; }
207
+ if $HFCLI upload "$REPO" "$1" "$2" >>"$LOG/upload.log" 2>&1; then
208
+ say " ok $1 -> $2"
209
+ else
210
+ say " FAIL $1 -> $2 (see $LOG/upload.log)"; UPFAIL=1
211
+ fi
212
+ }
213
+ UPFAIL=0
214
+ up cache_fix_results.ipynb docs/cache_fix_results_2026-09-03.ipynb
215
+ up "$LOG/RESULTS.md" docs/RETRAIN_RESULTS_2026-09-03.md
216
+ up EVAL_COMPARISON.md docs/EVAL_COMPARISON_2026-09-02.md
217
+ for LEN in $LENS; do up "newck_len_$LEN" "logs/newck_len_$LEN/"; done
218
+ up retrain_logs logs/retrain_corrected_cache/
219
+ up "$LOG" logs/finish_all/
220
+ up eval_logs logs/eval_run7c/
221
+ up eval_run7c.sh scripts/eval_run7c.sh
222
+ up finish_all.sh scripts/finish_all.sh
223
+ up retrain_corrected_cache.sh scripts/retrain_corrected_cache.sh
224
+ up Tests/bluscriptcp/mk_cache_notebook.py scripts/mk_cache_notebook.py
225
+ up Tests/bluscriptcp/longeval_gen.py scripts/longeval_gen.py
226
+ up Tests/bluscriptcp/longeval_score.py scripts/longeval_score.py
227
+ up run_longeval.sh scripts/run_longeval.sh
228
+
229
+ # checkpoints last: biggest, and least useful if something above failed
230
+ for f in $CK/blumodelcp_run6_step_750.ckpt $CK/blumodelcp_run7_step_400.ckpt; do
231
+ [ -f "$f" ] && up "$f" "checkpoints/$(basename "$f")"
232
+ done
233
+ for A in c a; do
234
+ [ -f "$LOG/arm_${A}.ckpt" ] && { p=$(cat "$LOG/arm_${A}.ckpt"); up "$p" "checkpoints/$(basename "$p")"; }
235
+ done
236
+
237
+ if [ "$UPFAIL" = 0 ]; then
238
+ { echo "TEARDOWN READY -- $(date -u +'%Y-%m-%d %H:%M:%S UTC')"
239
+ echo "All results, logs, scripts and checkpoints uploaded to $REPO."
240
+ echo "Verify with: $HFCLI repo-files $REPO list | grep -E 'newck_len|cache_fix'"; } > TEARDOWN_READY.txt
241
+ rm -f TEARDOWN_BLOCKED.txt
242
+ say "=== TEARDOWN READY ==="
243
+ else
244
+ say "=== SOME UPLOADS FAILED -- NOT safe to tear down (see $LOG/upload.log) ==="
245
+ echo "Some uploads FAILED -- see $LOG/upload.log" > TEARDOWN_BLOCKED.txt
246
+ exit 1
247
+ fi