Skip to content

Commit 98b508e

Browse files
committed
fix: refine scripts
1 parent 3037c65 commit 98b508e

2 files changed

Lines changed: 149 additions & 3 deletions

File tree

scripts/train_distributed_all_models.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,18 @@ submit_job() {
9292

9393
echo ">>> Submitting experiment $experiment_id: $job_name"
9494

95-
if [[ "$model" == "header" ]]; then
95+
if [[ "$model" == "header" ]] || [[ "$model" == "citation" ]]; then
9696
job_id=$(sbatch $SBATCH_OPTS \
9797
--job-name="$job_name" \
9898
--output="$log_file" \
9999
--error="$log_file" \
100-
--wrap="$PYTHON_CMD $model train --architecture $architecture --incremental --num-workers 6" 2>&1 | grep -oP '\d+')
100+
--wrap="$PYTHON_CMD $model train --architecture $architecture --num-workers 6 --max-sequence-length 3000" 2>&1 | grep -oP '\d+')
101101
else
102102
job_id=$(sbatch $SBATCH_OPTS \
103103
--job-name="$job_name" \
104104
--output="$log_file" \
105105
--error="$log_file" \
106-
--wrap="$PYTHON_CMD $model train --architecture $architecture --incremental" 2>&1 | grep -oP '\d+')
106+
--wrap="$PYTHON_CMD $model train --architecture $architecture" 2>&1 | grep -oP '\d+')
107107
fi
108108

109109
if [[ -n "$job_id" ]]; then
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#!/bin/bash
2+
# Distributed training script for all GROBID models with multiple architectures
3+
# Uses sbatch for parallel job submission to fully exploit the cluster
4+
#
5+
# This script trains all available models with the following architectures:
6+
# - BidLSTM_CRF
7+
# - BidLSTM_CRF_FEATURES
8+
# - BidLSTM_ChainCRF
9+
# - BidLSTM_ChainCRF_FEATURES
10+
11+
set -e
12+
13+
# Parallelization settings
14+
MAX_PARALLEL_JOBS=${MAX_PARALLEL_JOBS:-4}
15+
WAIT_INTERVAL=${WAIT_INTERVAL:-30}
16+
17+
# Common SLURM configuration
18+
SBATCH_OPTS="--container-mounts=/netscratch:/netscratch,$HOME:$HOME \
19+
--container-workdir=/netscratch/lfoppiano/delft/delft_tf2.17.1-updated \
20+
--container-image=/netscratch/lfoppiano/enroot/tensorflow-2.17.2-gpu-delft-updated.sqsh \
21+
--mem=100G \
22+
-p V100-32GB,RTX3090,RTXA6000 \
23+
--gpus=1 \
24+
--nodes=1 \
25+
--time=3-00:00"
26+
27+
PYTHON_CMD=".venv/bin/python -m delft.applications.grobidTagger"
28+
29+
# Architectures to train
30+
ARCHITECTURES=(
31+
"BidLSTM_CRF"
32+
"BidLSTM_CRF_FEATURES"
33+
"BidLSTM_ChainCRF"
34+
"BidLSTM_ChainCRF_FEATURES"
35+
)
36+
37+
# Models available in data/sequenceLabelling/grobid
38+
MODELS=(
39+
"affiliation-address"
40+
"citation"
41+
"date"
42+
"figure"
43+
"funding-acknowledgement"
44+
"header"
45+
"name-citation"
46+
"name-header"
47+
"reference-segmenter"
48+
"table"
49+
)
50+
51+
# Log directory for job outputs
52+
LOG_DIR="${HOME}/slurm_logs/train_distributed_$(date +%Y%m%d_%H%M%S)"
53+
mkdir -p "$LOG_DIR"
54+
55+
# Track submitted job IDs
56+
declare -a JOB_IDS
57+
58+
# Function to count running jobs for this experiment set
59+
count_running_jobs() {
60+
local count=0
61+
for job_id in "${JOB_IDS[@]}"; do
62+
if squeue -j "$job_id" &>/dev/null 2>&1; then
63+
state=$(squeue -j "$job_id" -h -o "%t" 2>/dev/null)
64+
if [[ "$state" == "R" || "$state" == "PD" ]]; then
65+
count=$((count + 1))
66+
fi
67+
fi
68+
done
69+
echo $count
70+
}
71+
72+
# Function to wait until we have capacity for more jobs
73+
wait_for_capacity() {
74+
while true; do
75+
running=$(count_running_jobs)
76+
if [[ $running -lt $MAX_PARALLEL_JOBS ]]; then
77+
break
78+
fi
79+
echo "Currently $running jobs running/pending (max: $MAX_PARALLEL_JOBS). Waiting..."
80+
sleep $WAIT_INTERVAL
81+
done
82+
}
83+
84+
# Function to submit a training job
85+
submit_job() {
86+
local model=$1
87+
local architecture=$2
88+
local experiment_id=$3
89+
90+
local job_name="train_${model}_${architecture}"
91+
local log_file="${LOG_DIR}/${job_name}_%j.log"
92+
93+
echo ">>> Submitting experiment $experiment_id: $job_name"
94+
95+
if [[ "$model" == "header" ]] || [[ "$model" == "citation" ]]; then
96+
job_id=$(sbatch $SBATCH_OPTS \
97+
--job-name="$job_name" \
98+
--output="$log_file" \
99+
--error="$log_file" \
100+
--wrap="$PYTHON_CMD $model train --architecture $architecture --num-workers 6 --max-sequence-length 3000 --incremental" 2>&1 | grep -oP '\d+')
101+
else
102+
job_id=$(sbatch $SBATCH_OPTS \
103+
--job-name="$job_name" \
104+
--output="$log_file" \
105+
--error="$log_file" \
106+
--wrap="$PYTHON_CMD $model train --architecture $architecture --incremental" 2>&1 | grep -oP '\d+')
107+
fi
108+
109+
if [[ -n "$job_id" ]]; then
110+
JOB_IDS+=("$job_id")
111+
echo " Submitted job ID: $job_id"
112+
else
113+
echo " Warning: Failed to submit job for $job_name"
114+
fi
115+
}
116+
117+
# Calculate total number of experiments
118+
total_experiments=$((${#MODELS[@]} * ${#ARCHITECTURES[@]}))
119+
120+
# Main submission loop
121+
echo "==========================================="
122+
echo "Starting distributed training of all GROBID models"
123+
echo "Total experiments: $total_experiments"
124+
echo "Max parallel jobs: $MAX_PARALLEL_JOBS"
125+
echo "Log directory: $LOG_DIR"
126+
echo "==========================================="
127+
echo ""
128+
129+
experiment_count=0
130+
131+
for model in "${MODELS[@]}"; do
132+
for arch in "${ARCHITECTURES[@]}"; do
133+
experiment_count=$((experiment_count + 1))
134+
wait_for_capacity
135+
submit_job "$model" "$arch" "$experiment_count"
136+
done
137+
done
138+
139+
echo ""
140+
echo "==========================================="
141+
echo "All $total_experiments experiments submitted!"
142+
echo "Job IDs: ${JOB_IDS[*]}"
143+
echo "Monitor with: squeue -u \$USER"
144+
echo "Logs in: $LOG_DIR"
145+
echo "==========================================="
146+

0 commit comments

Comments
 (0)