Upload scripts/t128d_train.sh with huggingface_hub
Browse files- scripts/t128d_train.sh +91 -0
scripts/t128d_train.sh
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# =============================================================================
|
| 3 |
+
# 128k run #4 (t128d) -- the long-range-density fix. 4x H200.
|
| 4 |
+
#
|
| 5 |
+
# DIAGNOSIS (measured 2026-09-23: BM25 cosine between 16,384-token chunks of a
|
| 6 |
+
# real 131,072-token training window; "far" = ~98k apart, vs a cross-window floor)
|
| 7 |
+
#
|
| 8 |
+
# b6 >=131k institutional 3.01x <-- the ONLY bucket with 128k-range structure
|
| 9 |
+
# b5 64-131k CommonCrawl 1.26x
|
| 10 |
+
# b4 32-64k 0.97x \
|
| 11 |
+
# b3 16-32k 1.01x > AT THE RANDOM FLOOR
|
| 12 |
+
# b1 4-8k 0.99x /
|
| 13 |
+
#
|
| 14 |
+
# t128c trained on 35% b6, so 65% of its windows held NO long-range dependency.
|
| 15 |
+
# The model learns from the majority that distant context is irrelevant and NIAH
|
| 16 |
+
# erodes with training: 92 @300 -> 75 @400 -> 69 @450.
|
| 17 |
+
#
|
| 18 |
+
# t64 never collapsed because at its 65,536 window, b5 documents (65,536-131,072)
|
| 19 |
+
# SPANNED the window. Same data, different window, different long-range density.
|
| 20 |
+
#
|
| 21 |
+
# FIX: b6 60 / b5 20 / b2 10 / b1 10. Measured mix coherence:
|
| 22 |
+
# mix128_splice30 1.91x (SPLiCe -- worse than what we had, not used)
|
| 23 |
+
# mix128_b6_35 2.20x (what t128c trained on)
|
| 24 |
+
# mix128_b6_60 2.58x <-- this
|
| 25 |
+
#
|
| 26 |
+
# ONE variable changes vs t128c: the mix. Batch stays 1,048,576 (8 seq/step);
|
| 27 |
+
# LR stays 1.8e-4. Anneal over the last 60 steps instead of stopping dead.
|
| 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 |
+
export PATH=/usr/local/cuda/bin:$PATH
|
| 35 |
+
PY=${PY:-/root/Adhi/BluTrain/envv/bin/python}
|
| 36 |
+
EXE=./build/bluscriptCP_exec
|
| 37 |
+
LOG=t128d_logs; mkdir -p "$LOG"; M="$LOG/master.log"
|
| 38 |
+
|
| 39 |
+
NP=${NP:-4}; CPSZ=$NP
|
| 40 |
+
T=131072; SCALE=32; ORIG=4096
|
| 41 |
+
GB=1048576 # 8 seq/step
|
| 42 |
+
STEPS=360; WARM=60; STABLE=240; FREQ=50; KEEP=4 # decay_start=300 -> 60-step anneal
|
| 43 |
+
DATA=data/mix128_b6_60
|
| 44 |
+
CK=checkpoints_bluscriptcp/rank_0
|
| 45 |
+
PARENT="${PARENT_OVERRIDE:-$CK/t64.ckpt}"
|
| 46 |
+
say(){ echo "[$(date -u +%H:%M:%S)] $*" | tee -a "$M" >&2; }
|
| 47 |
+
die(){ say "FATAL: $*"; exit 1; }
|
| 48 |
+
|
| 49 |
+
[ -x "$EXE" ] || die "binary missing"
|
| 50 |
+
grep -q 'CP_ATTN_SPLIT=1' build/objects/.cp_rope_flags || die "binary lacks split kernels"
|
| 51 |
+
[ "$(stat -c%s "$PARENT")" = 2423335522 ] || die "parent t64 wrong size"
|
| 52 |
+
[ -d "$DATA" ] || die "$DATA missing"
|
| 53 |
+
[ $((SCALE*ORIG)) -eq $T ] || die "YaRN INVARIANT BROKEN: $SCALE*$ORIG != $T"
|
| 54 |
+
[ $(( WARM + STABLE )) -lt $(( STEPS - 1 )) ] || die "illegal WSD"
|
| 55 |
+
AV=$(df -BG --output=avail . | tail -1 | tr -dc 0-9)
|
| 56 |
+
[ "$AV" -gt $(( KEEP * 18 + 20 )) ] || die "disk ${AV}G < $(( KEEP*18+20 ))G"
|
| 57 |
+
U=$($PY - "$DATA" "$T" "$GB" <<'PY'
|
| 58 |
+
import glob,os,sys
|
| 59 |
+
d,BT,G=sys.argv[1],int(sys.argv[2]),int(sys.argv[3]); GA=G//BT; t=0
|
| 60 |
+
for p in sorted(glob.glob(f"{d}/train_shard_*.bin")):
|
| 61 |
+
n=os.path.getsize(p)//2; pos=0; b=0
|
| 62 |
+
while pos+BT+1<=n:
|
| 63 |
+
b+=1; pos+=BT
|
| 64 |
+
if pos+(BT+1)>n: break
|
| 65 |
+
t+=b
|
| 66 |
+
print(t//GA)
|
| 67 |
+
PY
|
| 68 |
+
)
|
| 69 |
+
[ "$STEPS" -le "$U" ] || die "STEPS=$STEPS > usable=$U"
|
| 70 |
+
|
| 71 |
+
ARCH="CP_N_EMBD=1536 CP_N_LAYER=24 CP_N_HEAD=12 CP_N_KVHEAD=4 CP_FFN=4096 CP_WEIGHT_TYING=1"
|
| 72 |
+
BASE="CP_SIZE=$CPSZ CP_ATTN_MODE=ring CP_ATTN_FUSION=split CP_T=$T \
|
| 73 |
+
CP_SAVE_KV_BF16=1 CP_RING_BF16=1 \
|
| 74 |
+
YARN_SCALE=$SCALE YARN_ORIG_MAXPOS=$ORIG CP_ROPE_THETA=500000 \
|
| 75 |
+
CP_ZERO=1 CP_ZERO_V2=1 CP_BF16=1 CP_OPTIMIZER=muon \
|
| 76 |
+
CP_WARMUP=$WARM CP_REWARMUP=$WARM CP_REWARMUP_PEAK=${PEAK:-0.3} \
|
| 77 |
+
CP_STABLE=$STABLE CP_CKPT=1 CP_CKPT_FREQ=$FREQ CP_CKPT_KEEP=$KEEP"
|
| 78 |
+
|
| 79 |
+
say "=== t128d: long-range-density fix, NP=$NP (4x H200) ==="
|
| 80 |
+
say "parent : $PARENT (t64 step 1200)"
|
| 81 |
+
say "data : $DATA b6 60 / b5 20 / b2 10 / b1 10 (2.58x far/cross vs 2.20x) usable $U"
|
| 82 |
+
say "batch : $GB = $((GB/T)) seq/step peak = ${PEAK:-0.3} x 6e-4"
|
| 83 |
+
say "WSD : warm $WARM, stable $STABLE, decay_start $((WARM+STABLE)) of $STEPS -> 60-step anneal"
|
| 84 |
+
say "GATE : ckpt every $FREQ. If niah_single @4096 < 98, STOP and diagnose."
|
| 85 |
+
env $ARCH $BASE CP_INIT_FROM="$PWD/$PARENT" CP_CKPT_NEW_RUN=1 CP_DATA_ROOT="$PWD/$DATA" \
|
| 86 |
+
CP_B=1 CP_GLOBAL_BATCH=$GB CP_MAX_STEPS=$STEPS \
|
| 87 |
+
mpirun --allow-run-as-root -np $NP "$EXE" >> "$LOG/train.log" 2>&1
|
| 88 |
+
grep -qaiE 'out of memory|bad_alloc' "$LOG/train.log" && die "OOM -- lower NP or check bf16 flags"
|
| 89 |
+
RN=$(grep -aoE 'CP_Training_log[0-9]+' "$LOG/train.log" | head -1 | grep -oE '[0-9]+')
|
| 90 |
+
echo "${RN:-?}" > "$LOG/runnum"
|
| 91 |
+
say "done, run ${RN:-?}: $(grep -aE '^step ' "$LOG/train.log"|tail -1|grep -oE 'loss: [0-9.]+')"
|