unparallelled commited on
Commit
76469ee
·
verified ·
1 Parent(s): b50ee6a

Upload scripts/lenbucket_experiment.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/lenbucket_experiment.sh +181 -0
scripts/lenbucket_experiment.sh ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # =============================================================================
3
+ # lenbucket_experiment.sh -- does TRAINING DOCUMENT LENGTH change 16k retrieval?
4
+ #
5
+ # THE QUESTION
6
+ # The 2026-09-03 result left retrieval at 27% at the full 16,384 window. One
7
+ # standing hypothesis for the ceiling is the training corpus: flux documents
8
+ # have median 826 tokens, p90 2,721, and only 0.27% reach 16k -- so almost no
9
+ # training example ever required attending across the window. This tests it by
10
+ # holding everything else fixed and changing only document length.
11
+ #
12
+ # THREE ARMS, one variable
13
+ # armA_c flux plain text median 826, p90 2,721 tok ALREADY TRAINED (run 28)
14
+ # L1 b1_4096_8192 docs in [4096, 8192) trained here
15
+ # L2 b2_8192_16384 docs in [8192, 16384) trained here
16
+ # All three: 400 steps, global batch 524,288, from run7' (run 6 step 750),
17
+ # YARN_ORIG_MAXPOS=4096 matched, Muon+ZeRO-1, bf16. Only the data differs.
18
+ #
19
+ # WHY armA_c IS RE-EVALUATED HERE rather than reusing its published numbers:
20
+ # those were measured with the flux val shard as NIAH filler, and flux is not
21
+ # on this box (nor in the HF model repo). A different haystack is a different
22
+ # test, so all three arms are re-scored against ONE haystack instead.
23
+ #
24
+ # HAYSTACK CHOICE: b3_16384_32768 val shard -- documents of 16-32k tokens, held
25
+ # out from every arm above. b1's or b2's own val shard would be in-distribution
26
+ # for exactly one arm and would flatter it.
27
+ #
28
+ # MEMORY: the H200 runs used CP_B=4 and 108 GB/GPU. These are 80 GB H100s, so
29
+ # CP_B=2 with grad_accum 16 holds the global batch at 524,288 while roughly
30
+ # halving activation memory. If step 0 OOMs, the run retries at CP_B=1/accum 32
31
+ # -- same global batch, same optimizer trajectory, just slower.
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
+ EXE=./build/bluscriptCP_exec
42
+ CK=checkpoints_bluscriptcp/rank_0
43
+ LOG=lenbucket_logs; mkdir -p "$LOG"
44
+ M="$LOG/master.log"
45
+
46
+ # stderr, never stdout: train_one()'s stdout is its return value.
47
+ say(){ echo "[$(date -u +%H:%M:%S)] $*" | tee -a "$M" >&2; }
48
+ die(){ say "FATAL: $*"; exit 1; }
49
+
50
+ T=16384; NP=4; GPUS=0,1,2,3; ORIG=4096
51
+ ARCH="CP_N_EMBD=1536 CP_N_LAYER=36 CP_N_HEAD=12 CP_N_KVHEAD=4 CP_FFN=4096 CP_WEIGHT_TYING=0"
52
+ COMMON="CP_SIZE=$NP CP_ATTN_MODE=ring CP_ATTN_FUSION=split CP_T=$T \
53
+ YARN_SCALE=4 YARN_ORIG_MAXPOS=$ORIG \
54
+ CP_ZERO=1 CP_ZERO_V2=1 CP_ZERO_SYMMETRIC=1 CP_BF16=1 CP_OPTIMIZER=muon \
55
+ CP_MAX_LR=1e-3 CP_MIN_LR=1e-4 CP_WARMUP=1 \
56
+ CP_CKPT=1 CP_CKPT_KEEP=1 CP_CKPT_NEW_RUN=1"
57
+
58
+ PARENT="$CK/blumodelcp_run6_step_750.ckpt" # run7'
59
+ HAY_ABS="$PWD/lendata/haystack/b3val_haystack.bin"
60
+ LENS="1024 2048 4096 8192 16360"
61
+ N=${N:-100}
62
+ TASKS="niah_single val_backward"
63
+
64
+ [ -x "$EXE" ] || die "$EXE not built"
65
+ [ -f "$PARENT" ] || die "parent run7' missing: $PARENT"
66
+ [ -f "$HAY_ABS" ] || die "haystack missing: $HAY_ABS"
67
+
68
+ say "=== length-bucket experiment ==="
69
+ say "free disk $(df -BG --output=avail /root | tail -1 | tr -dc '0-9')G"
70
+
71
+ # ---------------------------------------------------------------------------
72
+ train_one(){ # $1 = arm label (l1/l2) $2 = data dir
73
+ local A="$1"
74
+ local DD="$2"
75
+ local lf="$LOG/${A}.log"
76
+ if [ -f "$LOG/${A}.ckpt" ] && [ -f "$(cat "$LOG/${A}.ckpt")" ]; then
77
+ say "$A already trained -> $(cat "$LOG/${A}.ckpt")"; return 0
78
+ fi
79
+ [ -d "$DD" ] || { say "$A: data dir $DD missing -- SKIP"; return 1; }
80
+ local ntr; ntr=$(ls "$DD"/*train*.bin 2>/dev/null | wc -l)
81
+ local nva; nva=$(ls "$DD"/*val*.bin 2>/dev/null | wc -l)
82
+ say "$A: $ntr train shards, $nva val shards in $DD"
83
+ [ "$ntr" -ge 1 ] && [ "$nva" -ge 1 ] || { say "$A: need >=1 train and >=1 val shard"; return 1; }
84
+
85
+ # CP_B x grad_accum must hold global batch at 524,288 to match armA_c exactly.
86
+ local B ACC
87
+ for cfg in "2 16" "1 32"; do
88
+ B=${cfg% *}; ACC=${cfg#* }
89
+ say "$A: attempting CP_B=$B (grad_accum=$ACC, global 524288)"
90
+ env $ARCH $COMMON CP_INIT_FROM="$PWD/$PARENT" CP_DATA_ROOT="$PWD/$DD" \
91
+ CP_B=$B CP_GLOBAL_BATCH=524288 CP_MAX_STEPS=400 \
92
+ CP_REWARMUP=100 CP_REWARMUP_PEAK=0.3 CP_CKPT_FREQ=200 \
93
+ CUDA_VISIBLE_DEVICES=$GPUS mpirun --allow-run-as-root -np $NP "$EXE" \
94
+ > "$lf" 2>&1
95
+ if grep -qaiE 'out of memory|CUDA error: out of memory|bad_alloc' "$lf"; then
96
+ say "$A: OOM at CP_B=$B -- retrying smaller"; continue
97
+ fi
98
+ break
99
+ done
100
+
101
+ local RN; RN=$(grep -aoE 'CP_Training_log[0-9]+' "$lf" | head -1 | grep -oE '[0-9]+')
102
+ [ -n "$RN" ] || { say "$A: no run number in $lf -- FAILED"; return 1; }
103
+ local CKF; CKF=$(ls -t $CK/blumodelcp_run${RN}_step_*.ckpt 2>/dev/null | head -1)
104
+ [ -n "$CKF" ] || { say "$A: run $RN wrote NO checkpoint -- FAILED"; return 1; }
105
+ # all four ZeRO-1 shards or the load is silently partial
106
+ local bn n; bn=$(basename "$CKF")
107
+ n=$(ls checkpoints_bluscriptcp/rank_*/"$bn" 2>/dev/null | wc -l)
108
+ [ "$n" -ge 4 ] || { say "$A: only $n/4 rank shards for $bn -- FAILED"; return 1; }
109
+ echo "$CKF" > "$LOG/${A}.ckpt"
110
+ say "$A -> run $RN, $bn, B=$B, final loss $(grep -aE '^step ' "$lf" | tail -1 | grep -oE 'loss: [0-9.]+')"
111
+ say "$A peak mem $(grep -aoE 'mem: [0-9]+MB' "$lf" | tail -1)"
112
+ return 0
113
+ }
114
+
115
+ train_one l1 lendata/b1_4096_8192 || say "L1 incomplete -- continuing"
116
+ train_one l2 lendata/b2_8192_16384 || say "L2 incomplete -- continuing"
117
+
118
+ # ---------------------------------------------------------------------------
119
+ # evaluate all three arms against ONE haystack
120
+ # ---------------------------------------------------------------------------
121
+ EXTRA=""
122
+ [ -f "$CK/blumodelcp_run28_step_400.ckpt" ] && EXTRA="armA_c=blumodelcp_run28_step_400.ckpt"
123
+ for A in l1 l2; do
124
+ f="$LOG/${A}.ckpt"; [ -f "$f" ] || continue
125
+ p=$(cat "$f"); [ -f "$p" ] || continue
126
+ EXTRA="$EXTRA ${A}=$(basename "$p")"
127
+ done
128
+ [ -n "$EXTRA" ] || die "no checkpoints to evaluate"
129
+ MODELS=$(echo $EXTRA | tr ' ' '\n' | cut -d= -f1 | tr '\n' ' ')
130
+ say "eval models: $MODELS"
131
+ say "haystack: $HAY_ABS ($(stat -Lc%s "$HAY_ABS") B)"
132
+
133
+ for LEN in $LENS; do
134
+ say "eval PROMPT_LEN=$LEN N=$N"
135
+ # GEN_DATA_ROOT: generation never reads training data, but bluscriptCP builds
136
+ # the DataLoader before reaching the CP_GENERATE branch, and this box has no
137
+ # Data_Loader/Data (no flux). Any dir with a *train*.bin and a *val*.bin works.
138
+ GEN_DATA_ROOT=lendata/b1_4096_8192 \
139
+ HAY="$HAY_ABS" PY=$PY OUT=lenb_len_$LEN TASKS="$TASKS" CKPTS="$MODELS" N=$N \
140
+ PROMPT_LEN=$LEN MAX_NEW=24 T=$T DEPTHS="0.0,0.25,0.5,0.75,1.0" \
141
+ YARN_ORIG=$ORIG GPUS=0,1,2,3 JOBS_PER_GPU=2 BF16=1 GREEDY=1 \
142
+ CKPT_EXTRA="$EXTRA" ./run_longeval.sh >> "$LOG/eval_$LEN.log" 2>&1 \
143
+ || say " WARN: eval at $LEN returned nonzero"
144
+ [ -f "lenb_len_$LEN/summary.csv" ] && say " -> $(sed -n 2p lenb_len_$LEN/summary.csv)"
145
+ done
146
+ say "eval done"
147
+
148
+ # ---------------------------------------------------------------------------
149
+ {
150
+ echo "# Training document length vs 16k retrieval -- $(date -u +%Y-%m-%d)"
151
+ echo
152
+ echo "All arms: 400 steps, global batch 524,288, from run7' (run 6 step 750),"
153
+ echo "YARN_ORIG_MAXPOS=4096 matched, Muon+ZeRO-1 bf16, 4xH100."
154
+ echo "Only the training data differs. NIAH scored generatively (substring match),"
155
+ echo "greedy, N=$N per cell, one shared haystack held out from every arm."
156
+ echo
157
+ echo "| arm | training docs |"
158
+ echo "|---|---|"
159
+ echo "| armA_c | flux plain text, median 826 / p90 2,721 tok |"
160
+ echo "| l1 | b1_4096_8192, docs in [4096, 8192) |"
161
+ echo "| l2 | b2_8192_16384, docs in [8192, 16384) |"
162
+ echo
163
+ for LEN in $LENS; do
164
+ echo "## PROMPT_LEN=$LEN"; echo '```'
165
+ cat "lenb_len_$LEN/summary.csv" 2>/dev/null || echo "(missing)"
166
+ echo '```'; echo
167
+ done
168
+ echo "## Training losses"; echo '```'
169
+ for A in l1 l2; do
170
+ [ -f "$LOG/${A}.log" ] && \
171
+ echo "$A: $(grep -aE '^step ' "$LOG/${A}.log" | tail -1 | grep -oE 'loss: [0-9.]+')"
172
+ done
173
+ echo '```'
174
+ echo
175
+ echo "NOTE: losses are NOT comparable across arms -- each is measured on its own"
176
+ echo "data distribution. Longer documents are a different prediction problem, so"
177
+ echo "a higher loss on b2 than on flux says nothing about model quality. Only the"
178
+ echo "retrieval numbers compare."
179
+ } > "$LOG/RESULTS.md"
180
+ say "wrote $LOG/RESULTS.md"
181
+ say "=== LENBUCKET DONE ==="