unparallelled commited on
Commit
14ea6ec
·
verified ·
1 Parent(s): 33ee427

Upload scripts/ext_32k.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/ext_32k.sh +130 -0
scripts/ext_32k.sh ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # =============================================================================
3
+ # ext_32k.sh -- YaRN-extend the best 16k model to 32k, then evaluate.
4
+ #
5
+ # WHY THIS RUN EXISTS
6
+ # The length ladder ended in a tie: l3 (b3, 16-32k docs TRUNCATED to the 16k
7
+ # window) matched l2 (b2, 8-16k docs that FIT) to the decimal at 16,360 --
8
+ # 35.0 vs 35.0, and -6.0/+2.0/+0.0 pp across 4k/8k/16k, none resolvable.
9
+ # Conclusion: document length helps only while documents fit inside the window.
10
+ # So widen the window first, THEN feed b3, whose documents now fit.
11
+ #
12
+ # PARENT: l2, the best 16k arm, not run7'. l2 is where the 16k ladder topped out.
13
+ #
14
+ # THE YaRN INVARIANT that cost 27pp when it was wrong:
15
+ # YARN_SCALE * YARN_ORIG_MAXPOS must equal CP_T EXACTLY, and ORIG_MAXPOS must
16
+ # be the length the weights were ACTUALLY trained at (16384 here, not the
17
+ # 1024 default at YARNOps.cpp:57).
18
+ # 2 * 16384 = 32768 == CP_T OK
19
+ #
20
+ # MEMORY -- 2 GPUS IS TIGHT. cp cannot exceed the GPU count, so cp=2 puts
21
+ # T/2 = 16,384 tokens on each rank:
22
+ # projected 130.8 GB/GPU = 91.4% of an H200's 143 GB
23
+ # That is close enough that fragmentation may still OOM, so STEP 1 is a 3-step
24
+ # probe and the script aborts rather than wasting hours. This does NOT fit an
25
+ # 80 GB H100 (measured: it OOMs).
26
+ #
27
+ # TOKEN BUDGET: 750 steps x 1,048,576 = 786 M tokens, matching run7's original
28
+ # 4k->16k extension exactly, so the two extension stages are comparable.
29
+ #
30
+ # GATE ON SHORT CONTEXT, NOT PERPLEXITY. The 2026-09-02 mismatch condition
31
+ # IMPROVED 16k (0 -> 14-17%) while COLLAPSING 4k from 74% to 16%. Perplexity at
32
+ # the new length would have looked fine. The eval therefore spans 1k..32k and a
33
+ # regression at 1k/4k is a failure even if 32k improves.
34
+ # =============================================================================
35
+ set -uo pipefail
36
+ cd "$(dirname "$0")"
37
+ ROOT="$(cd ../.. && pwd)"
38
+ export LD_LIBRARY_PATH="$ROOT/Tensor-Implementations/lib:$ROOT/Profiler/lib:${LD_LIBRARY_PATH:-}"
39
+ export OMPI_ALLOW_RUN_AS_ROOT=1 OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1
40
+
41
+ PY=/root/Adhi/BluTrain/envv/bin/python
42
+ EXE=./build/bluscriptCP_exec
43
+ CK=checkpoints_bluscriptcp/rank_0
44
+ LOG=ext32k_logs; mkdir -p "$LOG"
45
+ M="$LOG/master.log"
46
+ say(){ echo "[$(date -u +%H:%M:%S)] $*" | tee -a "$M" >&2; }
47
+ die(){ say "FATAL: $*"; exit 1; }
48
+
49
+ T=32768; NP=${NP:-2}; GPUS=${GPUS:-0,1}
50
+ ORIG=16384; SCALE=2
51
+ STEPS=${STEPS:-750}
52
+ PARENT="$CK/lenbucket_l2_blumodelcp_run2_step_400.ckpt"
53
+ DATA=lendata/b3_16384_32768
54
+ ARCH="CP_N_EMBD=1536 CP_N_LAYER=36 CP_N_HEAD=12 CP_N_KVHEAD=4 CP_FFN=4096 CP_WEIGHT_TYING=0"
55
+
56
+ [ $(( SCALE * ORIG )) -eq $T ] || die "YaRN invariant broken: $SCALE * $ORIG != $T"
57
+ $PY -c "import tiktoken" 2>/dev/null || die "tiktoken missing: $PY -m pip install tiktoken"
58
+ [ -x "$EXE" ] || die "$EXE not built (make libtensor SM_ARCH=90 && make CP_FUSED_ROPE=1 CP_ATTN_SPLIT=1 SM_ARCH=90 bluscript-cp)"
59
+ [ -f "$PARENT" ] || die "parent l2 missing: $PARENT"
60
+ [ -d "$DATA" ] || die "b3 data missing: $DATA"
61
+
62
+ say "=== 16k -> 32k YaRN extension ==="
63
+ say "CP_T=$T YARN_SCALE=$SCALE YARN_ORIG_MAXPOS=$ORIG (product $(( SCALE*ORIG )) == $T)"
64
+ say "parent $(basename $PARENT), data $DATA, cp=$NP, $STEPS steps x 1,048,576 = 786 M tokens"
65
+
66
+ COMMON="CP_SIZE=$NP CP_ATTN_MODE=ring CP_ATTN_FUSION=split CP_T=$T \
67
+ YARN_SCALE=$SCALE YARN_ORIG_MAXPOS=$ORIG \
68
+ CP_ZERO=1 CP_ZERO_V2=1 CP_ZERO_SYMMETRIC=1 CP_BF16=1 CP_OPTIMIZER=muon \
69
+ CP_MAX_LR=1e-3 CP_MIN_LR=1e-4"
70
+
71
+ # ---- STEP 1: 3-step memory probe -------------------------------------------
72
+ if [ ! -f "$LOG/probe.ok" ]; then
73
+ say "probe: 3 steps at T=$T to confirm it fits before committing hours"
74
+ env $ARCH $COMMON CP_REWARMUP=1 CP_REWARMUP_PEAK=0.3 CP_CKPT=0 \
75
+ CP_INIT_FROM="$PWD/$PARENT" CP_DATA_ROOT="$PWD/$DATA" \
76
+ CP_B=1 CP_GLOBAL_BATCH=65536 CP_MAX_STEPS=3 \
77
+ CUDA_VISIBLE_DEVICES=$GPUS mpirun --allow-run-as-root -np $NP "$EXE" \
78
+ > "$LOG/probe.log" 2>&1
79
+ if grep -qaiE 'out of memory|bad_alloc' "$LOG/probe.log"; then
80
+ say "PROBE OOM at T=$T with cp=$NP. Projected 130.8 GB/GPU."
81
+ say " This needs more ranks: cp=4 -> 67.5 GB/GPU. Not runnable on $NP GPUs."
82
+ exit 1
83
+ fi
84
+ grep -aE '^step +[0-9]+ \|' "$LOG/probe.log" | tail -1 | sed 's/^/ probe: /' | tee -a "$M"
85
+ say "probe peak mem: $(grep -aoE 'mem: [0-9]+MB' "$LOG/probe.log" | tail -1)"
86
+ touch "$LOG/probe.ok"
87
+ else
88
+ say "probe already passed"
89
+ fi
90
+
91
+ # ---- STEP 2: the extension --------------------------------------------------
92
+ if [ -f "$LOG/ext.ckpt" ] && [ -f "$(cat "$LOG/ext.ckpt")" ]; then
93
+ say "extension already done -> $(cat "$LOG/ext.ckpt")"
94
+ else
95
+ say "training $STEPS steps"
96
+ env $ARCH $COMMON CP_REWARMUP=50 CP_REWARMUP_PEAK=0.3 \
97
+ CP_CKPT=1 CP_CKPT_KEEP=2 CP_CKPT_FREQ=50 CP_CKPT_NEW_RUN=1 \
98
+ CP_INIT_FROM="$PWD/$PARENT" CP_DATA_ROOT="$PWD/$DATA" \
99
+ CP_B=1 CP_GLOBAL_BATCH=1048576 CP_MAX_STEPS=$STEPS \
100
+ CUDA_VISIBLE_DEVICES=$GPUS mpirun --allow-run-as-root -np $NP "$EXE" \
101
+ >> "$LOG/ext.log" 2>&1
102
+ grep -qaiE 'out of memory|bad_alloc' "$LOG/ext.log" && die "OOM during training"
103
+ RN=$(grep -aoE 'CP_Training_log[0-9]+' "$LOG/ext.log" | tail -1 | grep -oE '[0-9]+')
104
+ [ -n "$RN" ] || die "no run number"
105
+ CKF=$(ls -t $CK/blumodelcp_run${RN}_step_*.ckpt 2>/dev/null | head -1)
106
+ [ -n "$CKF" ] || die "no checkpoint written"
107
+ bn=$(basename "$CKF"); n=$(ls checkpoints_bluscriptcp/rank_*/"$bn" 2>/dev/null | wc -l)
108
+ [ "$n" -ge "$NP" ] || die "only $n/$NP rank shards for $bn"
109
+ echo "$CKF" > "$LOG/ext.ckpt"
110
+ say "ext32k -> run $RN, $bn, final loss $(grep -aE '^step ' "$LOG/ext.log" | tail -1 | grep -oE 'loss: [0-9.]+')"
111
+ fi
112
+
113
+ # ---- STEP 3: eval 1k..32k, matched cache -----------------------------------
114
+ EXT=$(basename "$(cat "$LOG/ext.ckpt")")
115
+ EXTRA="l2=lenbucket_l2_blumodelcp_run2_step_400.ckpt ext32k=$EXT"
116
+ say "eval: l2 (16k parent) vs ext32k, matched YARN_ORIG=$ORIG SCALE=$SCALE"
117
+ # PROMPT_LEN + MAX_NEW must pad up to <= CP_T (PAD=256): 32744+24 = 32768 exactly
118
+ for LEN in 1024 4096 16360 32744; do
119
+ say "PROMPT_LEN=$LEN"
120
+ GEN_DATA_ROOT=$DATA HAY="$PWD/lendata/haystack/b2val_haystack.bin" \
121
+ PY=$PY OUT=ext32k_len_$LEN TASKS="niah_single" CKPTS="l2 ext32k" N=100 \
122
+ PROMPT_LEN=$LEN MAX_NEW=24 T=$T DEPTHS="0.0,0.25,0.5,0.75,1.0" \
123
+ YARN=$SCALE YARN_ORIG=$ORIG GPUS=$GPUS JOBS_PER_GPU=1 BF16=1 GREEDY=1 \
124
+ CKPT_EXTRA="$EXTRA" ./run_longeval.sh >> "$LOG/eval_$LEN.log" 2>&1 \
125
+ || say " WARN nonzero at $LEN"
126
+ say " -> $(sed -n 1p ext32k_len_$LEN/summary.csv 2>/dev/null) / $(sed -n 2p ext32k_len_$LEN/summary.csv 2>/dev/null)"
127
+ done
128
+ say "=== 32k EXTENSION DONE ==="
129
+ say "REGRESSION CHECK: compare 1024 and 4096 against l2. A 32k gain bought with a"
130
+ say " short-context collapse is the 2026-09-02 mismatch failure repeating."