File size: 2,299 Bytes
df64241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Waits for the final Stage 1 checkpoint (ckpt_571999), then:
#  1) keeps it forever as a hard-link copy (no extra disk space; survives deletion of the original)
#  2) exports a weights-only bf16 file (~8 GB) for downloading to a PC, plus its md5 fingerprint
# Warns and stops if training gets past step 572,100 without that checkpoint (e.g. disk was full).
# Run once on the login node:  nohup ./save_stage1.sh > logs/save_stage1.log 2>&1 &
set -uo pipefail
AR=${AR:-/fsx/ajay-stu/AR}
CKDIR=${CKDIR:-/fsx/ajay-stu/ar-data/checkpoints}
OUT=${OUT:-/fsx/ajay-stu/ar-data/stage1_final}
NAME=ckpt_571999
EXC="ip-10-0-136-14,ip-10-0-136-94,ip-10-0-136-253,ip-10-0-138-178,ip-10-0-139-113,ip-10-0-140-247"
cd "$AR" || exit 1
[ -f .venv/bin/activate ] && source .venv/bin/activate
export PYTHONPATH=$PWD

# latest training step from the running job's log (0 if unknown)
latest_step() {
  local j
  j=$(squeue -u "${USER:-$(id -un)}" -h -n ar-real -t RUNNING -o %i 2>/dev/null | head -1)
  [ -n "$j" ] && grep "^step" "logs/real_$j.log" 2>/dev/null | tail -1 | awk '{print $2}' || true
}

# 1) wait until the checkpoint is completely written (.metadata is written last)
echo "$(date -u) waiting for $CKDIR/$NAME"
until [ -f "$CKDIR/$NAME/.metadata" ]; do
  s=$(latest_step)
  if [ "${s:-0}" -gt 572100 ]; then
    echo "$(date -u) WARNING: training is at step $s but $NAME was never saved (disk full at step 571,999?)"
    exit 1
  fi
  sleep "${POLL:-300}"
done
sleep "${SETTLE:-60}"                                     # let the last file writes settle
echo "$(date -u) found complete $NAME"

# 2) permanent hard-link copy
mkdir -p "$OUT"
[ -d "$OUT/$NAME" ] || cp -al "$CKDIR/$NAME" "$OUT/$NAME" || { echo "hard-link copy failed"; exit 1; }
echo "$(date -u) permanent copy: $OUT/$NAME ($(ls "$OUT/$NAME" | wc -l) files)"

# 3) weights-only bf16 export for the PC (CPU job, ~5 min) and its fingerprint
M=$OUT/model_stage1_final.pt
if [ ! -f "$M" ]; then
  srun -p dev -N1 -n1 --gpus=0 --cpus-per-task=16 --exclude=$EXC \
    python -m ar.eval.export_ckpt --ckpt "$OUT/$NAME" --out "$M" || { echo "export failed"; exit 1; }
fi
( cd "$OUT" && md5sum model_stage1_final.pt > model_stage1_final.md5 )
ls -lh "$M"
cat "$OUT/model_stage1_final.md5"
echo "$(date -u) DONE: Stage 1 final model saved"