Upload scripts/p1_680m.sh with huggingface_hub
Browse files- scripts/p1_680m.sh +107 -0
scripts/p1_680m.sh
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# =============================================================================
|
| 3 |
+
# Phase 1 of the 680M ladder: 4k -> 16k via YaRN, on a 50/30/20 mix.
|
| 4 |
+
#
|
| 5 |
+
# WHY THIS MODEL
|
| 6 |
+
# varybatch step 3400: 681,328,128 params at 10.5 tok/param, vs the 1.06B's
|
| 7 |
+
# 0.99. On identical data it scores 3.05 where the 1.06B scores 3.17. The
|
| 8 |
+
# whole long-context programme has pointed at the pretrain deficit as the root
|
| 9 |
+
# cause of the retrieval collapse; this is the first base good enough to test
|
| 10 |
+
# that.
|
| 11 |
+
#
|
| 12 |
+
# It required fixing a real bug first: GPT::forward's tied-embedding path cast
|
| 13 |
+
# a TRANSPOSED (strided) tensor to bf16, and the cast ignores strides, so the
|
| 14 |
+
# tied head multiplied a garbled weight (NLL 12.13 vs 3.05). Invisible until
|
| 15 |
+
# now because every model trained here uses weight_tying=0. Fixed by
|
| 16 |
+
# cast -> transpose -> contiguous(); the 1.06B is unchanged (3.1717 -> 3.1719).
|
| 17 |
+
#
|
| 18 |
+
# DATA
|
| 19 |
+
# b3 50% (docs 16k-32k: >= the NEW window, contiguous)
|
| 20 |
+
# b2 30% / b1 20% (sub-window: supply the document boundaries that 100%
|
| 21 |
+
# long-data lacked -- the composition that collapsed twice before).
|
| 22 |
+
# Phases 2 and 3 use fresh token ranges via --skip-tokens; b3 is only 20%
|
| 23 |
+
# consumed here so it remains available as filler later.
|
| 24 |
+
#
|
| 25 |
+
# YaRN: 4 * 4096 == 16384 exactly. ORIG_MAXPOS must be the length the base was
|
| 26 |
+
# actually trained at (4096), not the 1024 default.
|
| 27 |
+
# =============================================================================
|
| 28 |
+
set -uo pipefail
|
| 29 |
+
cd "$(dirname "$0")"
|
| 30 |
+
ROOT="$(cd ../.. && pwd)"
|
| 31 |
+
export LD_LIBRARY_PATH="$ROOT/Tensor-Implementations/lib:$ROOT/Profiler/lib:${LD_LIBRARY_PATH:-}"
|
| 32 |
+
export OMPI_ALLOW_RUN_AS_ROOT=1 OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1
|
| 33 |
+
export PATH=/usr/local/cuda/bin:$PATH
|
| 34 |
+
PY=/root/Adhi/BluTrain/envv/bin/python
|
| 35 |
+
EXE=./build/bluscriptCP_exec
|
| 36 |
+
CK=checkpoints_680m/rank_0
|
| 37 |
+
LOG=p1_logs; mkdir -p "$LOG"; M="$LOG/master.log"
|
| 38 |
+
T=16384; NP=2; CPSZ=2; GPUS=0,1
|
| 39 |
+
ORIG=4096; SCALE=4
|
| 40 |
+
STEPS=${STEPS:-1200}; WARM=100; TAIL=2; FREQ=200; KEEP=3
|
| 41 |
+
STABLE=$(( STEPS - WARM - TAIL ))
|
| 42 |
+
GB=524288
|
| 43 |
+
DATA=Data_Loader/Data/p1mix
|
| 44 |
+
PARENT="$CK/varybatch.ckpt"; PARENT_SZ=1362674564
|
| 45 |
+
say(){ echo "[$(date -u +%H:%M:%S)] $*" | tee -a "$M" >&2; }
|
| 46 |
+
die(){ say "FATAL: $*"; exit 1; }
|
| 47 |
+
|
| 48 |
+
$PY -c "import tiktoken" 2>/dev/null || die "tiktoken missing"
|
| 49 |
+
[ -x "$EXE" ] || die "$EXE not built"
|
| 50 |
+
S=build/objects/.cp_rope_flags
|
| 51 |
+
grep -q 'CP_FUSED_ROPE=1' "$S" && grep -q 'CP_ATTN_SPLIT=1' "$S" || die "binary lacks split kernels ($(cat $S))"
|
| 52 |
+
[ -f "$PARENT" ] || die "parent missing"
|
| 53 |
+
[ "$(stat -c%s "$PARENT")" = "$PARENT_SZ" ] || die "parent wrong size"
|
| 54 |
+
[ -d "$DATA" ] || die "$DATA missing"
|
| 55 |
+
[ $((SCALE*ORIG)) -eq $T ] || die "YaRN invariant: $SCALE*$ORIG != $T"
|
| 56 |
+
U=$($PY - <<'PY'
|
| 57 |
+
import glob,os
|
| 58 |
+
BT=16384;GA=32;t=0
|
| 59 |
+
for p in sorted(glob.glob("Data_Loader/Data/p1mix/train_shard_*.bin")):
|
| 60 |
+
n=os.path.getsize(p)//2;pos=0;b=0
|
| 61 |
+
while pos+BT+1<=n:
|
| 62 |
+
b+=1;pos+=BT
|
| 63 |
+
if pos+(BT+1)>n:break
|
| 64 |
+
t+=b
|
| 65 |
+
print(t//GA)
|
| 66 |
+
PY
|
| 67 |
+
)
|
| 68 |
+
[ "$STEPS" -le "$U" ] || die "STEPS=$STEPS exceeds usable=$U (loader would WRAP silently)"
|
| 69 |
+
[ $(( WARM + STABLE )) -lt $(( STEPS - 1 )) ] || die "illegal WSD"
|
| 70 |
+
|
| 71 |
+
say "=== 680M phase 1: 4k -> 16k (2x H100, cp=$CPSZ) ==="
|
| 72 |
+
say "parent: varybatch step 3400, 10.5 tok/param, scores 3.05 (1.06B scores 3.17)"
|
| 73 |
+
say "data: $DATA b3=50% b2=30% b1=20% usable $U steps, running $STEPS"
|
| 74 |
+
say "YaRN: SCALE=$SCALE ORIG=$ORIG -> $((SCALE*ORIG)) == CP_T=$T OK"
|
| 75 |
+
say "WSD: warmup $WARM stable $STABLE tail $TAIL"
|
| 76 |
+
|
| 77 |
+
ARCH="CP_N_EMBD=1536 CP_N_LAYER=24 CP_N_HEAD=12 CP_N_KVHEAD=4 CP_FFN=4096 CP_WEIGHT_TYING=1"
|
| 78 |
+
BASE="CP_SIZE=$CPSZ CP_ATTN_MODE=ring CP_ATTN_FUSION=split CP_T=$T \
|
| 79 |
+
YARN_SCALE=$SCALE YARN_ORIG_MAXPOS=$ORIG CP_ROPE_THETA=500000 \
|
| 80 |
+
CP_ZERO=1 CP_ZERO_V2=1 CP_BF16=1 CP_OPTIMIZER=muon \
|
| 81 |
+
CP_WARMUP=$WARM CP_REWARMUP=$WARM CP_REWARMUP_PEAK=0.3 \
|
| 82 |
+
CP_STABLE=$STABLE CP_CKPT=1 CP_CKPT_FREQ=$FREQ CP_CKPT_KEEP=$KEEP"
|
| 83 |
+
|
| 84 |
+
if [ ! -f "$LOG/probe.ok" ]; then
|
| 85 |
+
say "PHASE 1a: 3-step probe ($((T/CPSZ)) tok/rank)"
|
| 86 |
+
env $ARCH $BASE CP_STABLE=0 CP_CKPT=0 CP_INIT_FROM="$PWD/$PARENT" \
|
| 87 |
+
CP_DATA_ROOT="$PWD/$DATA" CP_B=1 CP_GLOBAL_BATCH=$(( T * NP / CPSZ )) CP_MAX_STEPS=3 \
|
| 88 |
+
CUDA_VISIBLE_DEVICES=$GPUS mpirun --allow-run-as-root -np $NP "$EXE" > "$LOG/probe.log" 2>&1
|
| 89 |
+
RC=$?
|
| 90 |
+
grep -qaiE 'out of memory|bad_alloc' "$LOG/probe.log" && die "PROBE OOM"
|
| 91 |
+
grep -qaE 'terminate called|Signal: Aborted' "$LOG/probe.log" && {
|
| 92 |
+
say "PROBE CRASHED:"; grep -aA1 'terminate called' "$LOG/probe.log"|grep -a 'what()'|head -1 >&2; exit 1; }
|
| 93 |
+
N=$(grep -acE '^step +[0-9]+ \|' "$LOG/probe.log"); P=$(grep -aoE 'mem: [0-9]+MB' "$LOG/probe.log"|tail -1)
|
| 94 |
+
[ "$RC" -eq 0 ] && [ "$N" -ge 1 ] && [ -n "$P" ] || { say "PROBE FAILED rc=$RC steps=$N peak='$P'"; tail -12 "$LOG/probe.log" >&2; exit 1; }
|
| 95 |
+
say "PROBE OK: $N steps, peak $P of 81559 MiB/card"; touch "$LOG/probe.ok"
|
| 96 |
+
fi
|
| 97 |
+
|
| 98 |
+
say "PHASE 1b: training $STEPS steps"
|
| 99 |
+
env $ARCH $BASE CP_INIT_FROM="$PWD/$PARENT" CP_CKPT_NEW_RUN=1 CP_DATA_ROOT="$PWD/$DATA" \
|
| 100 |
+
CP_B=1 CP_GLOBAL_BATCH=$GB CP_MAX_STEPS=$STEPS \
|
| 101 |
+
CUDA_VISIBLE_DEVICES=$GPUS mpirun --allow-run-as-root -np $NP "$EXE" >> "$LOG/train.log" 2>&1
|
| 102 |
+
grep -qaiE 'out of memory|bad_alloc' "$LOG/train.log" && die "OOM"
|
| 103 |
+
RN=$(grep -aoE 'CP_Training_log[0-9]+' "$LOG/train.log" | head -1 | grep -oE '[0-9]+')
|
| 104 |
+
[ -n "$RN" ] || die "no run number"; echo "$RN" > "$LOG/runnum"
|
| 105 |
+
say "training done, run $RN, $(grep -aE '^step ' "$LOG/train.log" | tail -1 | grep -oE 'loss: [0-9.]+')"
|
| 106 |
+
say " peak mem $(grep -aoE 'mem: [0-9]+MB' "$LOG/train.log" | tail -1)"
|
| 107 |
+
say "=== PHASE 1 TRAINING COMPLETE ==="
|