unparallelled commited on
Commit
7fc2e13
·
verified ·
1 Parent(s): 6e0358e

Upload scripts/b4_continue.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/b4_continue.sh +139 -0
scripts/b4_continue.sh ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # =============================================================================
3
+ # b4_continue.sh -- CONTINUE ext32k through the rest of b4 at a 32k window.
4
+ #
5
+ # ext32k already trained 750 steps = 0.393 B tokens = 34% of b4's train split.
6
+ # This runs steps 750 -> 2227, the remaining 1,477 steps = 0.775 B tokens,
7
+ # finishing exactly one pass over b4 (1.168 B of 1.171 B available, no wrap).
8
+ #
9
+ # WHY CP_CKPT_RESUME AND NOT CP_INIT_FROM:
10
+ # CP_INIT_FROM loads WEIGHTS ONLY and starts at step 0, so the DataLoader would
11
+ # restart at token 0 and replay the 0.393 B ext32k already saw. CP_CKPT_RESUME
12
+ # restores start_step=750, and bluscriptCP.cpp:2084 then calls
13
+ # skip_batches(750 * 16 = 12,000) to fast-forward the stream to 0.393 B. That
14
+ # is what makes this a true continuation of the epoch rather than a replay.
15
+ #
16
+ # KNOWN DEGRADATION -- the ZeRO optimizer sidecar is missing.
17
+ # Yesterday's teardown uploaded the two .ckpt files but NOT the .zero_g1
18
+ # sidecar, and that box is gone. Per bluscriptCP.cpp:2032, "without the sidecar
19
+ # a bf16 run resumes with group 1's Adam m/v at zero -- it trains on, so the
20
+ # loss curve only looks slightly wrong." Weights and group-0 optimizer state
21
+ # restore normally; group 1's momentum rebuilds over tens of steps. Expect a
22
+ # small loss transient right after step 750 that is an artifact, not a signal.
23
+ #
24
+ # LEARNING RATE -- CP_MAX_LR / CP_MIN_LR DO NOT EXIST.
25
+ # bluscriptCP.cpp hardcodes max_lr=6e-4 (line 131) and min_lr=6e-5 (line 132),
26
+ # and the env-parsing block never reads CP_MAX_LR or CP_MIN_LR -- there is not
27
+ # even a float env helper. Every script in this project passed them as a no-op.
28
+ # So the real schedule is 6e-4 * CP_REWARMUP_PEAK(0.3) = 1.8e-4 peak, 6e-5 floor.
29
+ # ext32k's first 750 steps ran at exactly that (verified from its log: 1.8000e-04
30
+ # at steps 99..649, 6.0030e-05 at 749), so this continuation MUST keep the same
31
+ # values or it would not be a continuation. Do not "fix" the LR here.
32
+ #
33
+ # SCHEDULE: re-warm 100 steps from 750 back to 1.8e-4, flat to 2027, then a
34
+ # 200-step decay tail. decay_start = 750+100+1177 = 2027. The guard at
35
+ # bluscriptCP.cpp:1006 needs CP_WARMUP+CP_STABLE < CP_MAX_STEPS-1:
36
+ # 100+1177 = 1277 < 2226. This is a SECOND schedule on top of ext32k's
37
+ # completed one, so "ext32k@750 vs this" is not a steps-only contrast.
38
+ # =============================================================================
39
+ set -uo pipefail
40
+ cd "$(dirname "$0")"
41
+ ROOT="$(cd ../.. && pwd)"
42
+ export LD_LIBRARY_PATH="$ROOT/Tensor-Implementations/lib:$ROOT/Profiler/lib:${LD_LIBRARY_PATH:-}"
43
+ export OMPI_ALLOW_RUN_AS_ROOT=1 OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1
44
+
45
+ PY=/root/Adhi/BluTrain/envv/bin/python
46
+ EXE=./build/bluscriptCP_exec
47
+ CK=checkpoints_bluscriptcp/rank_0
48
+ LOG=b4cont_logs; mkdir -p "$LOG"
49
+ M="$LOG/master.log"
50
+ say(){ echo "[$(date -u +%H:%M:%S)] $*" | tee -a "$M" >&2; }
51
+ die(){ say "FATAL: $*"; exit 1; }
52
+
53
+ T=32768; NP=2; GPUS=0,1; ORIG=16384; SCALE=2
54
+ RUN=2; START=750; STEPS=2227; WARM=100; STABLE=1177; FREQ=50; KEEP=2
55
+ EVALS="1100 1650 2227" # 750 is already evaluated (the ext32k result)
56
+ DATA=lendata/b4_32768_65536
57
+ HAY="$PWD/lendata/haystack/b2val_haystack.bin"
58
+ ARCH="CP_N_EMBD=1536 CP_N_LAYER=36 CP_N_HEAD=12 CP_N_KVHEAD=4 CP_FFN=4096 CP_WEIGHT_TYING=0"
59
+ BASE="CP_SIZE=$NP CP_ATTN_MODE=ring CP_ATTN_FUSION=split CP_T=$T \
60
+ YARN_SCALE=$SCALE YARN_ORIG_MAXPOS=$ORIG \
61
+ CP_ZERO=1 CP_ZERO_V2=1 CP_ZERO_SYMMETRIC=1 CP_BF16=1 CP_OPTIMIZER=muon \
62
+ CP_WARMUP=$WARM CP_REWARMUP=$WARM \
63
+ CP_REWARMUP_PEAK=0.3 CP_REWARMUP_ANCHOR=$START CP_STABLE=$STABLE \
64
+ CP_CKPT=1 CP_CKPT_FREQ=$FREQ CP_CKPT_KEEP=$KEEP"
65
+
66
+ $PY -c "import tiktoken" 2>/dev/null || die "tiktoken missing"
67
+ [ -x "$EXE" ] || die "not built"
68
+ for r in 0 1; do
69
+ [ -f "checkpoints_bluscriptcp/rank_$r/blumodelcp_run${RUN}_step_${START}.ckpt" ] || \
70
+ die "rank_$r ext32k step-$START checkpoint missing"
71
+ done
72
+ [ $((SCALE*ORIG)) -eq $T ] || die "YaRN invariant"
73
+ say "=== CONTINUE ext32k through the rest of b4 ==="
74
+ say "resume run $RUN at step $START -> $STEPS ($((STEPS-START)) new steps, $(echo "scale=3; ($STEPS-$START)*524288/1000000000" | bc) B tokens)"
75
+ say "loader fast-forwards $((START*16)) batches = $(echo "scale=3; $START*524288/1000000000" | bc) B; reads to $(echo "scale=3; $STEPS*524288/1000000000" | bc) B of 1.171 B -- no wrap"
76
+ say "WARNING: .zero_g1 sidecar absent -- group 1 Adam moments start at zero (small transient)"
77
+ say "eval points: $EVALS"
78
+
79
+ run_seg(){
80
+ local TGT="$1"
81
+ [ -f "$LOG/seg_${TGT}.done" ] && { say "segment to $TGT done"; return 0; }
82
+ say "training to step $TGT"
83
+ ( for i in $(seq 1 6000); do
84
+ n=$(ls checkpoints_bluscriptcp/rank_*/blumodelcp_run${RUN}_step_${TGT}.ckpt 2>/dev/null | wc -l)
85
+ if [ "$n" -ge "$NP" ]; then
86
+ sleep 5
87
+ for p in $(pgrep -f 'mpirun.*bluscriptCP_exec') $(pgrep -f 'build/bluscriptCP_exec'); do kill "$p" 2>/dev/null; done
88
+ exit 0
89
+ fi
90
+ sleep 20
91
+ done ) &
92
+ local WPID=$!
93
+ env $ARCH $BASE CP_CKPT_RESUME=$RUN CP_DATA_ROOT="$PWD/$DATA" \
94
+ CP_B=1 CP_GLOBAL_BATCH=524288 CP_MAX_STEPS=$STEPS \
95
+ CUDA_VISIBLE_DEVICES=$GPUS mpirun --allow-run-as-root -np $NP "$EXE" \
96
+ >> "$LOG/train.log" 2>&1
97
+ kill $WPID 2>/dev/null; wait $WPID 2>/dev/null
98
+ grep -qaiE 'out of memory|bad_alloc' "$LOG/train.log" && die "OOM"
99
+ local SRC="blumodelcp_run${RUN}_step_${TGT}.ckpt"
100
+ local n; n=$(ls checkpoints_bluscriptcp/rank_*/"$SRC" 2>/dev/null | wc -l)
101
+ [ "$n" -ge "$NP" ] || die "step $TGT checkpoint missing ($n/$NP)"
102
+ local SAFE="b4c${TGT}_${SRC}"
103
+ for r in 0 1; do
104
+ [ -f "checkpoints_bluscriptcp/rank_$r/$SAFE" ] || \
105
+ cp "checkpoints_bluscriptcp/rank_$r/$SRC" "checkpoints_bluscriptcp/rank_$r/$SAFE"
106
+ done
107
+ echo "$SAFE" > "$LOG/seg_${TGT}.ckpt"; touch "$LOG/seg_${TGT}.done"
108
+ say "step $TGT reached, preserved $SAFE, loss $(grep -aE '^step ' "$LOG/train.log" | tail -1 | grep -oE 'loss: [0-9.]+')"
109
+ }
110
+
111
+ eval_seg(){
112
+ local TGT="$1"
113
+ [ -f "$LOG/eval_${TGT}.done" ] && return 0
114
+ local SAFE; SAFE=$(cat "$LOG/seg_${TGT}.ckpt")
115
+ say "EVAL @ step $TGT"
116
+ for LEN in 8192 16360 32744; do
117
+ GEN_DATA_ROOT=$DATA HAY="$HAY" PY=$PY OUT=b4c_${TGT}_len_$LEN TASKS="niah_single" \
118
+ CKPTS="b4c$TGT" N=100 PROMPT_LEN=$LEN MAX_NEW=24 T=$T \
119
+ DEPTHS="0.0,0.25,0.5,0.75,1.0" YARN_ORIG=$ORIG YARN=$SCALE \
120
+ GPUS=0,1 JOBS_PER_GPU=1 BF16=1 GREEDY=1 \
121
+ CKPT_EXTRA="b4c$TGT=$SAFE" ./run_longeval.sh >> "$LOG/eval_${TGT}_${LEN}.log" 2>&1 \
122
+ || say " WARN eval @$TGT len $LEN"
123
+ [ -s "b4c_${TGT}_len_$LEN/summary.csv" ] && \
124
+ say " step $TGT len $LEN -> $(sed -n 2p b4c_${TGT}_len_$LEN/summary.csv)"
125
+ done
126
+ touch "$LOG/eval_${TGT}.done"
127
+ }
128
+
129
+ for TGT in $EVALS; do run_seg "$TGT" || die "segment $TGT failed"; eval_seg "$TGT"; done
130
+ say "=== B4 CONTINUATION DONE ==="
131
+ say "progression vs ext32k@750 (niah_single):"
132
+ for LEN in 8192 16360 32744; do
133
+ line=" len $LEN: 750=(see ext32k)"
134
+ for TGT in $EVALS; do
135
+ v=$(sed -n 2p "b4c_${TGT}_len_$LEN/summary.csv" 2>/dev/null | cut -d, -f2)
136
+ line="$line ${TGT}=${v:-?}"
137
+ done
138
+ say "$line"
139
+ done