Upload scripts/retrain_corrected_cache.sh with huggingface_hub
Browse files
scripts/retrain_corrected_cache.sh
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# =============================================================================
|
| 3 |
+
# retrain_corrected_cache.sh -- rebuild the whole checkpoint chain under the
|
| 4 |
+
# CORRECTED YaRN parameterisation (YARN_ORIG_MAXPOS=4096).
|
| 5 |
+
#
|
| 6 |
+
# WHY THE FULL CHAIN, not just the arms: run7 itself was trained with the buggy
|
| 7 |
+
# orig_maxpos=1024 default, so arms trained from it would start from weights
|
| 8 |
+
# already adapted to the wrong rotation. run8 (the 4k base) is unaffected -- it
|
| 9 |
+
# predates any YaRN scaling -- so the chain restarts there.
|
| 10 |
+
#
|
| 11 |
+
# WHY THIS IS THE REAL TEST: switching the cache at EVAL time is not a fix.
|
| 12 |
+
# Measured on this box, corrected-vs-as-trained at N=100: 1k 90 vs 84, ~4k
|
| 13 |
+
# 14-33 vs 75, 16k 17 vs 0. The corrected ramp (low=14 high=32) is a DIFFERENT
|
| 14 |
+
# function from the one the weights adapted to (low=7 high=25) -- better in some
|
| 15 |
+
# regimes, much worse around 4k. Only retraining resolves that.
|
| 16 |
+
#
|
| 17 |
+
# Recipe recovered from run7's own log + LR trace, not from memory:
|
| 18 |
+
# B=4 grad_accum=16 global_batch=1048576, Muon+AdamW ZeRO-1 symmetric, bf16
|
| 19 |
+
# mask=15, max_lr 1e-3 -> min 1e-4, rewarmup 50 to peak 0.3x (=3e-4), 750 steps
|
| 20 |
+
# =============================================================================
|
| 21 |
+
set -uo pipefail
|
| 22 |
+
cd "$(dirname "$0")"
|
| 23 |
+
ROOT="$(cd ../.. && pwd)"
|
| 24 |
+
export LD_LIBRARY_PATH="$ROOT/Tensor-Implementations/lib:$ROOT/Profiler/lib:${LD_LIBRARY_PATH:-}"
|
| 25 |
+
export OMPI_ALLOW_RUN_AS_ROOT=1 OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1
|
| 26 |
+
|
| 27 |
+
PY=${PY:-/root/Adhi/BluTrain/envv/bin/python}
|
| 28 |
+
EXE=./build/bluscriptCP_exec
|
| 29 |
+
CK=checkpoints_bluscriptcp/rank_0
|
| 30 |
+
LOG=retrain_logs; mkdir -p "$LOG"
|
| 31 |
+
M="$LOG/master.log"
|
| 32 |
+
say(){ echo "[$(date -u +%H:%M:%S)] $*" | tee -a "$M" >&2; }
|
| 33 |
+
die(){ say "FATAL: $*"; exit 1; }
|
| 34 |
+
|
| 35 |
+
T=16384; YARN=4; ORIG=4096; NP=4; GPUS=0,1,2,3
|
| 36 |
+
ARCH="CP_N_EMBD=1536 CP_N_LAYER=36 CP_N_HEAD=12 CP_N_KVHEAD=4 CP_FFN=4096 CP_WEIGHT_TYING=0"
|
| 37 |
+
COMMON="CP_SIZE=$NP CP_ATTN_MODE=ring CP_ATTN_FUSION=split CP_T=$T \
|
| 38 |
+
YARN_SCALE=$YARN YARN_ORIG_MAXPOS=$ORIG \
|
| 39 |
+
CP_ZERO=1 CP_ZERO_V2=1 CP_ZERO_SYMMETRIC=1 CP_BF16=1 CP_OPTIMIZER=muon \
|
| 40 |
+
CP_MAX_LR=1e-3 CP_MIN_LR=1e-4 CP_WARMUP=1 \
|
| 41 |
+
CP_CKPT=1 CP_CKPT_KEEP=1 CP_CKPT_NEW_RUN=1"
|
| 42 |
+
|
| 43 |
+
[ -x "$EXE" ] || die "$EXE missing"
|
| 44 |
+
FREE=$(df -BG --output=avail /root | tail -1 | tr -dc '0-9')
|
| 45 |
+
say "free disk ${FREE}G (need ~70G: 4 checkpoint sets at ~17G)"
|
| 46 |
+
[ "${FREE:-0}" -ge 75 ] || die "only ${FREE}G free"
|
| 47 |
+
|
| 48 |
+
# run a training job, then VERIFY the checkpoint exists -- a zero exit code is
|
| 49 |
+
# not proof: bluscriptCP catches a failed save, prints [WARN] and trains on.
|
| 50 |
+
train(){ # $1=label $2=logfile $3...=extra env
|
| 51 |
+
local label="$1" lf="$2"; shift 2
|
| 52 |
+
say "training $label"
|
| 53 |
+
env $ARCH $COMMON "$@" CP_DATA_ROOT="$PWD/$DATA_ROOT" \
|
| 54 |
+
CUDA_VISIBLE_DEVICES=$GPUS mpirun --allow-run-as-root -np $NP "$EXE" \
|
| 55 |
+
> "$lf" 2>&1 || die "$label training failed -- see $lf"
|
| 56 |
+
RN=$(grep -aoE 'CP_Training_log[0-9]+' "$lf" | head -1 | grep -oE '[0-9]+')
|
| 57 |
+
[ -n "$RN" ] || die "$label: no run number in $lf"
|
| 58 |
+
CKF=$(ls -t $CK/blumodelcp_run${RN}_step_*.ckpt 2>/dev/null | head -1)
|
| 59 |
+
[ -n "$CKF" ] || die "$label finished but wrote NO checkpoint (see $lf)"
|
| 60 |
+
grep -qa 'checkpoint save.*failed' "$lf" && die "$label: a checkpoint save FAILED"
|
| 61 |
+
say " $label -> run $RN, $(basename "$CKF"), final loss $(grep -aE '^step ' "$lf" | tail -1 | grep -oE 'loss: [0-9.]+')"
|
| 62 |
+
case "$CKF" in *$'\n'*) die "ckptpath sanity: multi-line checkpoint path";; esac
|
| 63 |
+
echo "$CKF"
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
# ---- 1. arm training data (deterministic at --seed 0) -----------------------
|
| 67 |
+
FILL=$(ls Data_Loader/Data/flux_train_*.bin 2>/dev/null | head -12 | tr '\n' ' ')
|
| 68 |
+
[ -n "$FILL" ] || die "no flux_train shards for in2_gen filler"
|
| 69 |
+
for A in a b c; do
|
| 70 |
+
if [ ! -f "in2_data/arm_$A/.done" ]; then
|
| 71 |
+
say "generating arm $A data"
|
| 72 |
+
$PY Tests/bluscriptcp/in2_gen.py --arm $A --T $T --examples 12816 --K 64 --shards 3 \
|
| 73 |
+
--seed 0 --d-min 64 --filler-shards $FILL --out-dir in2_data/arm_$A >>"$M" 2>&1 \
|
| 74 |
+
|| die "arm $A train data generation failed"
|
| 75 |
+
$PY Tests/bluscriptcp/in2_gen.py --arm $A --T $T --examples 64 --split val --K 64 --shards 1 \
|
| 76 |
+
--seed 0 --d-min 64 --filler-shards $(ls Data_Loader/Data/flux_val*.bin | head -1) \
|
| 77 |
+
--out-dir in2_data/arm_$A >>"$M" 2>&1 || die "arm $A val data generation failed"
|
| 78 |
+
touch "in2_data/arm_$A/.done"
|
| 79 |
+
fi
|
| 80 |
+
done
|
| 81 |
+
say "arm data ready"
|
| 82 |
+
|
| 83 |
+
# ---- 2. run7' : the YaRN 16k extension, corrected cache ---------------------
|
| 84 |
+
if [ -f "$LOG/run7c.ckptpath" ]; then
|
| 85 |
+
R7=$(cat "$LOG/run7c.ckptpath"); say "run7' already done ($R7)"
|
| 86 |
+
else
|
| 87 |
+
DATA_ROOT=Data_Loader/Data
|
| 88 |
+
R7=$(train "run7' (YaRN 16k extension, corrected cache)" "$LOG/run7c.log" \
|
| 89 |
+
CP_INIT_FROM="$PWD/$CK/blumodelcp_run8_step_1000.ckpt" \
|
| 90 |
+
CP_B=4 CP_GLOBAL_BATCH=1048576 CP_MAX_STEPS=750 \
|
| 91 |
+
CP_REWARMUP=50 CP_REWARMUP_PEAK=0.3 CP_CKPT_FREQ=250) || exit 1
|
| 92 |
+
echo "$R7" > "$LOG/run7c.ckptpath"
|
| 93 |
+
fi
|
| 94 |
+
|
| 95 |
+
# ---- 3. arms A/B/C from run7' ----------------------------------------------
|
| 96 |
+
for A in a b c; do
|
| 97 |
+
if [ -f "$LOG/arm_$A.ckptpath" ]; then say "arm $A already done"; continue; fi
|
| 98 |
+
DATA_ROOT=in2_data/arm_$A
|
| 99 |
+
P=$(train "arm $A (corrected cache)" "$LOG/arm_$A.log" \
|
| 100 |
+
CP_INIT_FROM="$PWD/$R7" \
|
| 101 |
+
CP_B=4 CP_GLOBAL_BATCH=524288 CP_MAX_STEPS=400 \
|
| 102 |
+
CP_REWARMUP=100 CP_REWARMUP_PEAK=0.3 CP_CKPT_FREQ=200) || exit 1
|
| 103 |
+
echo "$P" > "$LOG/arm_$A.ckptpath"
|
| 104 |
+
done
|
| 105 |
+
|
| 106 |
+
say "ALL DONE"
|
| 107 |
+
say " run7' : $(cat $LOG/run7c.ckptpath)"
|
| 108 |
+
for A in a b c; do say " arm $A : $(cat $LOG/arm_$A.ckptpath 2>/dev/null)"; done
|