File size: 2,233 Bytes
23c39b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash
# =============================================================================
# Submit a chain of dependent training jobs: each starts when the previous
# one ENDS (afterany — including timeout/failure), auto-resuming from the
# latest completed epoch via train.sbatch's RESUME_AUTO logic. A job that
# finds training already complete exits immediately, so overshooting N_JOBS
# is harmless.
#
# Usage:
#   RUN_NAME=L-4n-repro ./slurm/submit_chain.sh
#   RUN_NAME=L-4n N_JOBS=5 NODES=4 PARTITION=batch TIME=04:00:00 ./slurm/submit_chain.sh
#
#   N_JOBS     number of chained jobs           (default 4)
#   NODES      nodes per job — SAME for all,    (default 4)
#              resume requires equal world size
#   PARTITION  slurm partition                  (default batch)
#   TIME       per-job time limit               (default 04:00:00)
#   RUN_NAME   REQUIRED: fixed run name so every job hits the same
#              checkpoint dir (this is what links the chain together)
# Extra env (WANDB_API_KEY, EXTRA_ARGS, SAMPLED_SRC, ...) passes through.
#
# Sizing hint: 4 nodes ≈ 3.5 h/epoch -> one 4 h batch-partition job per
# epoch, so N_JOBS=5 with defaults comfortably covers a full 4-epoch run.
# =============================================================================
set -euo pipefail

N_JOBS=${N_JOBS:-4}
NODES=${NODES:-4}
PARTITION=${PARTITION:-batch}
TIME=${TIME:-04:00:00}
RUN_NAME=${RUN_NAME:?set RUN_NAME (fixed name links the chain to one checkpoint dir)}

cd "$(dirname "$0")/.."

DEP=()
for i in $(seq 1 "$N_JOBS"); do
    JOB_ID=$(RUN_NAME=$RUN_NAME RESUME_AUTO=1 \
             sbatch --parsable --export=ALL \
                    --nodes="$NODES" --partition="$PARTITION" --time="$TIME" \
                    --job-name="hrm-$RUN_NAME-$i" "${DEP[@]}" slurm/train.sbatch)
    echo "job $i/$N_JOBS: $JOB_ID ${DEP[*]:-<no dependency>}"
    DEP=(--dependency=afterany:"$JOB_ID")
done

echo
echo "Chain submitted. Checkpoints: checkpoints/HRM-Text/$RUN_NAME"
echo "Watch:  squeue --me ; tail -f slurm/logs/hrm-$RUN_NAME-*_<jobid>.out"
echo "Cancel: scancel \$(squeue --me -h -n $(for i in $(seq 1 "$N_JOBS"); do printf 'hrm-%s-%s,' "$RUN_NAME" "$i"; done | sed 's/,$//') -o %i | tr '\n' ' ')"