Upload scripts/ext32k_b4.sh with huggingface_hub
Browse files- scripts/ext32k_b4.sh +134 -0
scripts/ext32k_b4.sh
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# =============================================================================
|
| 3 |
+
# ext32k_b4.sh -- YaRN extension 16k -> 32k on b4, then evaluate 1k..32k.
|
| 4 |
+
#
|
| 5 |
+
# WHY b4 AND NOT b3, at a 32,768 window:
|
| 6 |
+
# b3 documents are 16,384-32,768 tokens -- mean 21,224 = 65% of the window, and
|
| 7 |
+
# the MINIMUM is 16,384. So every b3 sample carries an EOT boundary plus part of
|
| 8 |
+
# a second document, and no dependency can span 32k. That is the same defect as
|
| 9 |
+
# the original flux corpus (median 826 tok), one scale up.
|
| 10 |
+
# b4 documents are 32,768-65,536 -- the minimum EQUALS the window, so every
|
| 11 |
+
# sample is one contiguous document and a 32k-spanning dependency is possible.
|
| 12 |
+
# Truncating a 44k document to 32k is fine; a straddled window is not.
|
| 13 |
+
#
|
| 14 |
+
# YaRN INVARIANT (the bug that cost 27pp at 16k):
|
| 15 |
+
# SCALE * ORIG_MAXPOS must equal seq_len EXACTLY, and ORIG_MAXPOS must be the
|
| 16 |
+
# length the parent was actually TRAINED at. 2 * 16384 = 32768. The default
|
| 17 |
+
# ORIG_MAXPOS is 1024 (YARNOps.cpp:57) and would silently be wrong.
|
| 18 |
+
#
|
| 19 |
+
# PARENT: l2 = the best 16k arm (b2 docs, which fit the 16k window). Extending
|
| 20 |
+
# from the strongest 16k model, not from run7'.
|
| 21 |
+
#
|
| 22 |
+
# GLOBAL BATCH held at 524,288 (B=1, T=32768, grad_accum=16) so the optimizer
|
| 23 |
+
# trajectory matches every 16k arm. Only the window changed.
|
| 24 |
+
#
|
| 25 |
+
# MEMORY: 2x H200 = 143 GB. cp=2 puts 16,384 tokens on each rank -> ~130.8 GB,
|
| 26 |
+
# 91% utilisation. That is close enough that fragmentation could still OOM, so
|
| 27 |
+
# PHASE 1 is a 3-step probe and the full run only starts if it survives.
|
| 28 |
+
# =============================================================================
|
| 29 |
+
set -uo pipefail
|
| 30 |
+
cd "$(dirname "$0")"
|
| 31 |
+
ROOT="$(cd ../.. && pwd)"
|
| 32 |
+
export LD_LIBRARY_PATH="$ROOT/Tensor-Implementations/lib:$ROOT/Profiler/lib:${LD_LIBRARY_PATH:-}"
|
| 33 |
+
export OMPI_ALLOW_RUN_AS_ROOT=1 OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1
|
| 34 |
+
|
| 35 |
+
PY=/root/envv/bin/python3
|
| 36 |
+
EXE=./build/bluscriptCP_exec
|
| 37 |
+
CK=checkpoints_bluscriptcp/rank_0
|
| 38 |
+
LOG=ext32k_logs; mkdir -p "$LOG"
|
| 39 |
+
M="$LOG/master.log"
|
| 40 |
+
say(){ echo "[$(date -u +%H:%M:%S)] $*" | tee -a "$M" >&2; }
|
| 41 |
+
die(){ say "FATAL: $*"; exit 1; }
|
| 42 |
+
|
| 43 |
+
T=32768; NP=2; GPUS=0,1
|
| 44 |
+
ORIG=16384; SCALE=2 # 2 * 16384 == 32768 exactly
|
| 45 |
+
STEPS=${STEPS:-750}
|
| 46 |
+
STABLE=${STABLE:-$(( STEPS - 200 ))} # WSD: flat LR, minimal legal decay tail
|
| 47 |
+
FREQ=${FREQ:-50}
|
| 48 |
+
KEEP=${KEEP:-1} # disk is tight on this box (~45 GB free)
|
| 49 |
+
DATA=lendata/b4_32768_65536
|
| 50 |
+
PARENT="$CK/lenbucket_l2_blumodelcp_run2_step_400.ckpt"
|
| 51 |
+
HAY="$PWD/lendata/haystack/b2val_haystack.bin"
|
| 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 |
+
|
| 54 |
+
$PY -c "import tiktoken" 2>/dev/null || die "tiktoken missing"
|
| 55 |
+
[ -x "$EXE" ] || die "$EXE not built"
|
| 56 |
+
[ -f "$PARENT" ] || die "parent l2 missing: $PARENT"
|
| 57 |
+
[ -f "$HAY" ] || die "haystack missing"
|
| 58 |
+
[ -d "$DATA" ] || die "$DATA missing"
|
| 59 |
+
ntr=$(ls "$DATA"/*train*.bin 2>/dev/null | wc -l); nva=$(ls "$DATA"/*val*.bin 2>/dev/null | wc -l)
|
| 60 |
+
[ "$ntr" -ge 1 ] && [ "$nva" -ge 1 ] || die "need >=1 train and >=1 val shard in $DATA (have $ntr/$nva)"
|
| 61 |
+
have=$(( $(du -cb "$DATA"/*train*.bin | tail -1 | cut -f1) / 2 ))
|
| 62 |
+
need=$(( STEPS*524288 ))
|
| 63 |
+
say "=== 16k -> 32k YaRN extension on b4 ==="
|
| 64 |
+
say "$ntr train shards = $(echo "scale=3; $have/1000000000" | bc) B tokens; need $(echo "scale=3; $need/1000000000" | bc) B for $STEPS steps"
|
| 65 |
+
[ "$have" -lt "$need" ] && say "WARNING: data repeats $(echo "scale=2; $need/$have" | bc)x"
|
| 66 |
+
say "YaRN: SCALE=$SCALE ORIG_MAXPOS=$ORIG -> $((SCALE*ORIG)) (must equal CP_T=$T)"
|
| 67 |
+
[ $((SCALE*ORIG)) -eq $T ] || die "YaRN invariant violated"
|
| 68 |
+
|
| 69 |
+
COMMON="CP_SIZE=$NP CP_ATTN_MODE=ring CP_ATTN_FUSION=split CP_T=$T \
|
| 70 |
+
YARN_SCALE=$SCALE YARN_ORIG_MAXPOS=$ORIG \
|
| 71 |
+
CP_ZERO=1 CP_ZERO_V2=1 CP_ZERO_SYMMETRIC=1 CP_BF16=1 CP_OPTIMIZER=muon \
|
| 72 |
+
CP_MAX_LR=1e-3 CP_MIN_LR=1e-4 CP_WARMUP=100 CP_REWARMUP=100 CP_REWARMUP_PEAK=0.3"
|
| 73 |
+
|
| 74 |
+
# ---- PHASE 1: does 32k fit at cp=2 on 143 GB? -----------------------------
|
| 75 |
+
if [ ! -f "$LOG/probe.ok" ]; then
|
| 76 |
+
say "PHASE 1: 3-step memory probe (projected 130.8 GB of 143 GB = 91%)"
|
| 77 |
+
env $ARCH $COMMON CP_STABLE=0 CP_CKPT=0 \
|
| 78 |
+
CP_INIT_FROM="$PWD/$PARENT" CP_DATA_ROOT="$PWD/$DATA" \
|
| 79 |
+
CP_B=1 CP_GLOBAL_BATCH=65536 CP_MAX_STEPS=3 \
|
| 80 |
+
CUDA_VISIBLE_DEVICES=$GPUS mpirun --allow-run-as-root -np $NP "$EXE" \
|
| 81 |
+
> "$LOG/probe.log" 2>&1
|
| 82 |
+
if grep -qaiE 'out of memory|bad_alloc' "$LOG/probe.log"; then
|
| 83 |
+
say "PROBE OOM -- 32k does not fit at cp=2 on this box."
|
| 84 |
+
say " 32k needs cp=4 (67.5 GB/GPU). Options: a 4-GPU box, or stop here."
|
| 85 |
+
grep -aoE 'cudaMallocAsync\(size=[0-9]+\) failed' "$LOG/probe.log" | head -2 | sed 's/^/ /' >&2
|
| 86 |
+
exit 1
|
| 87 |
+
fi
|
| 88 |
+
grep -aE '^step +[0-9]+ \|' "$LOG/probe.log" | tail -1 | sed 's/^/ /' >&2
|
| 89 |
+
say "PROBE OK: peak $(grep -aoE 'mem: [0-9]+MB' "$LOG/probe.log" | tail -1)"
|
| 90 |
+
touch "$LOG/probe.ok"
|
| 91 |
+
fi
|
| 92 |
+
|
| 93 |
+
# ---- PHASE 2: the extension ------------------------------------------------
|
| 94 |
+
if [ -f "$LOG/ext.ckpt" ] && [ -f "$(cat "$LOG/ext.ckpt")" ]; then
|
| 95 |
+
say "extension already trained -> $(cat "$LOG/ext.ckpt")"
|
| 96 |
+
else
|
| 97 |
+
say "PHASE 2: $STEPS steps, stable=$STABLE, ckpt every $FREQ keep $KEEP"
|
| 98 |
+
env $ARCH $COMMON CP_STABLE=$STABLE \
|
| 99 |
+
CP_CKPT=1 CP_CKPT_FREQ=$FREQ CP_CKPT_KEEP=$KEEP CP_CKPT_NEW_RUN=1 \
|
| 100 |
+
CP_INIT_FROM="$PWD/$PARENT" CP_DATA_ROOT="$PWD/$DATA" \
|
| 101 |
+
CP_B=1 CP_GLOBAL_BATCH=524288 CP_MAX_STEPS=$STEPS \
|
| 102 |
+
CUDA_VISIBLE_DEVICES=$GPUS mpirun --allow-run-as-root -np $NP "$EXE" \
|
| 103 |
+
> "$LOG/ext.log" 2>&1
|
| 104 |
+
grep -qaiE 'out of memory|bad_alloc' "$LOG/ext.log" && die "OOM during the full run"
|
| 105 |
+
RN=$(grep -aoE 'CP_Training_log[0-9]+' "$LOG/ext.log" | head -1 | grep -oE '[0-9]+')
|
| 106 |
+
[ -n "$RN" ] || die "no run number"
|
| 107 |
+
CKF=$(ls -t $CK/blumodelcp_run${RN}_step_*.ckpt 2>/dev/null | head -1)
|
| 108 |
+
[ -n "$CKF" ] || die "run $RN wrote NO checkpoint"
|
| 109 |
+
n=$(ls checkpoints_bluscriptcp/rank_*/"$(basename "$CKF")" 2>/dev/null | wc -l)
|
| 110 |
+
[ "$n" -ge "$NP" ] || die "only $n/$NP rank shards"
|
| 111 |
+
echo "$CKF" > "$LOG/ext.ckpt"
|
| 112 |
+
say "ext32k -> run $RN, $(basename "$CKF"), loss $(grep -aE '^step ' "$LOG/ext.log" | tail -1 | grep -oE 'loss: [0-9.]+')"
|
| 113 |
+
say " peak mem $(grep -aoE 'mem: [0-9]+MB' "$LOG/ext.log" | tail -1)"
|
| 114 |
+
fi
|
| 115 |
+
|
| 116 |
+
# ---- PHASE 3: evaluate, including the new 32k point ------------------------
|
| 117 |
+
EXT=$(basename "$(cat "$LOG/ext.ckpt")")
|
| 118 |
+
EXTRA="ext32k=$EXT"
|
| 119 |
+
[ -f "$CK/lenbucket_l2_blumodelcp_run2_step_400.ckpt" ] && \
|
| 120 |
+
EXTRA="$EXTRA l2=lenbucket_l2_blumodelcp_run2_step_400.ckpt"
|
| 121 |
+
MODELS=$(echo $EXTRA | tr ' ' '\n' | cut -d= -f1 | tr '\n' ' ')
|
| 122 |
+
say "PHASE 3: eval models $MODELS"
|
| 123 |
+
# 32744 + MAX_NEW 24 = 32768 exactly; 32760 would pad to 33024 and abort.
|
| 124 |
+
for LEN in 4096 8192 16360 32744; do
|
| 125 |
+
say "eval PROMPT_LEN=$LEN"
|
| 126 |
+
GEN_DATA_ROOT=$DATA HAY="$HAY" PY=$PY OUT=ext32k_len_$LEN TASKS="niah_single" \
|
| 127 |
+
CKPTS="$MODELS" N=100 PROMPT_LEN=$LEN MAX_NEW=24 T=$T \
|
| 128 |
+
DEPTHS="0.0,0.25,0.5,0.75,1.0" YARN_ORIG=$ORIG YARN=$SCALE \
|
| 129 |
+
GPUS=0,1 JOBS_PER_GPU=1 BF16=1 GREEDY=1 \
|
| 130 |
+
CKPT_EXTRA="$EXTRA" ./run_longeval.sh >> "$LOG/eval_$LEN.log" 2>&1 \
|
| 131 |
+
|| say " WARN nonzero at $LEN"
|
| 132 |
+
[ -s "ext32k_len_$LEN/summary.csv" ] && say " -> $(sed -n 1p ext32k_len_$LEN/summary.csv) / $(sed -n 2p ext32k_len_$LEN/summary.csv)"
|
| 133 |
+
done
|
| 134 |
+
say "=== EXT32K DONE ==="
|