#!/usr/bin/env bash # E3: math-heavy s3 mix, full fine-tune without activation checkpointing, WSD schedule (warmup -> constant -> linear decay # to 0 over the last 25%). Evals of base / E1 / E2 run while the GPUs would otherwise idle (s3 upload + build); after # training only E3 is evaluated, spread over all 8 GPUs. Same instruments for every model. set -uo pipefail cd /workspace/slayer1b source /venv/main/bin/activate export SLAYER_TRAINER=/workspace/ckpt/train_gpt_ref_r24_2.py SLAYER_TOKENIZER=/workspace/ckpt/tokenizer.json PYTORCH_ALLOC_CONF=expandable_segments:True LR=${LR:-5e-5} NGSM=${NGSM:-500} log() { echo "$(date -u +%FT%TZ) $*" | tee -a logs/e3_pipeline.log; } ALL=$(/workspace/benchrepo/research/.venv-eval/bin/python -c " import sys; sys.path.insert(0,'/workspace/benchrepo/research/common'); import zadania as Z ids=set() for v in vars(Z).values(): if isinstance(v, dict): ids |= {k for k, t in v.items() if isinstance(t, dict) and t.get('repo') and k[:1]=='T' and k[1:].isdigit()} print(' '.join(sorted(ids, key=lambda k:int(k[1:]))))") chunks() { # $1 = number of chunks -> comma lists of task ids, one per line python3 - "$1" $ALL <<'PY' import sys n, ids = int(sys.argv[1]), sys.argv[2:] for i in range(n): print(",".join(ids[i::n])) PY } bench_spread() { # $1 ckpt, $2 label, $3.. gpus local ck=$1 lab=$2; shift 2 local gpus=("$@") i=0 while read -r z; do ZAD="$z" timeout 3000 bash bench_suite.sh "$ck" "${lab}_p$i" "${gpus[$i]}" > "logs/benchfull_${lab}_p$i.log" 2>&1 & i=$((i+1)) done < <(chunks ${#gpus[@]}) wait } gsm() { # $1 ckpt, $2 label, $3 first gpu, $4 n gpus for r in $(seq 0 $(($4-1))); do CUDA_VISIBLE_DEVICES=$(($3+r)) python gsm_chat_eval.py run "$1" --rank $r --world $4 --n $NGSM --out results/gsm/$2 > logs/gsm_$2_r$r.log 2>&1 & done; wait } log "wait for teacher shards" until [ "$(grep -l SHARD_DONE logs/teacher_s[0-7].log 2>/dev/null | wc -l)" = 8 ]; do if grep -l Traceback logs/teacher_s[0-7].log >/dev/null 2>&1; then log "teacher failed"; exit 1; fi sleep 20 done log "teacher done: $(cat /workspace/s3gen/*.jsonl | wc -l) rows" CUDA_VISIBLE_DEVICES=0 /workspace/.venv-vllm/bin/python gsm_chat_eval.py translate --n $NGSM --out data/eval/gsm8k_test_pl.jsonl > logs/gsm_translate.log 2>&1 log "gsm pl translated; idle-GPU evals of base/E1/E2 start" ( bench_spread /workspace/ckpt/wagi_95000.pt full_base 0 1 2 timeout 1500 bash bench_format.sh /workspace/pkg/full_base_p0 base 0 > logs/fmt_base.log 2>&1 ) & ( bench_spread runs/e2/sft_step601.pt full_e2 3 4 5 timeout 1500 bash bench_format.sh /workspace/pkg/full_e2_p0 e2 3 > logs/fmt_e2.log 2>&1 ) & ( gsm runs/e1/sft_step592.pt e1 6 2; gsm runs/e2/sft_step601.pt e2 6 2 ) & until [ -f data/s3_base/UPLOAD_OK ] && grep -q "^items" logs/decon_index.log; do sleep 20; done python build_s3.py --base data/s3_base --gen /workspace/s3gen --synth /workspace/s3synth --src /workspace/s3src --decon /workspace/s3decon \ --out data/s3 --added-frac 0.5 > logs/build_s3.log 2>&1 || { log "build_s3 failed"; exit 1; } log "s3 built; waiting for idle-GPU evals" wait log "base/E1/E2 evals done; training" torchrun --nproc_per_node 8 train.py --ckpt /workspace/ckpt/wagi_95000.pt --ckpt-sha256 ad675d0cd61b2291b4cfbfd93c8a5d28217a12498fef7c7f997728911ddb952b \ --data data/s3 --out runs/e3 --lr "$LR" --epochs 1 --mb-tokens 6144 --accum 6 --no-act-ckpt --schedule wsd --decay-frac 0.25 \ --min-lr-ratio 0.0 --warmup 0.02 --eval-every 300 --save-every 0 --save-before-decay > logs/e3_train.log 2>&1 || { log "train failed"; exit 1; } E3=$(ls -t runs/e3/sft_step*.pt | head -1) log "trained $E3" DATA=data/s2_toolcall bash vast_run.sh eval "$E3" > logs/e3_eval.log 2>&1 & wait log "E3 agent evals done" bench_spread "$E3" full_e3 0 1 2 3 & gsm "$E3" e3 4 2 & ( CUDA_VISIBLE_DEVICES=6 python probe_suite.py "$E3" r3_t0 --temp 0 > logs/probe_r3_t0.log 2>&1 ) & ( CUDA_VISIBLE_DEVICES=7 python probe_suite.py "$E3" r3_t0.7 --temp 0.7 > logs/probe_r3_t0.7.log 2>&1 ) & wait timeout 1500 bash bench_format.sh /workspace/pkg/full_e3_p0 e3 0 > logs/fmt_e3.log 2>&1 log "E3_PIPELINE_DONE (stop the instance to stop billing)"