Repository navigation
Expand file tree
/
Copy pathsubmit-competition.sh
More file actions
executable file
·167 lines (151 loc) · 4.95 KB
/
Copy pathsubmit-competition.sh
File metadata and controls
executable file
·167 lines (151 loc) · 4.95 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
# Submit one competition run as two Slurm arrays that share a run directory:
# CPU frameworks on CPU nodes, and GPU frameworks (SAPS_DEVICE=gpu in the
# competition config) on GPU nodes. A final job combines both arrays' results.
#
# Arguments other than --resume and --after go to bin/run_benchmark.py in both
# arrays. SAPS_CHUNK_COUNT and SAPS_GPU_CHUNK_COUNT set the arrays' sizes, for
# example for the training set:
# SAPS_CHUNK_COUNT=8 SAPS_GPU_CHUNK_COUNT=4 $0 --tag suite-train
set -euo pipefail
usage() {
echo "usage: $0 [--resume RUN_DIRECTORY] [--after JOB_ID] [RUN_BENCHMARK_ARGS...]" >&2
exit 2
}
run_directory=""
dependency=()
forwarded_args=()
while (($# > 0)); do
case "$1" in
--resume)
(($# >= 2)) || usage
run_directory=$(cd -- "$2" && pwd -P)
shift 2
;;
--after)
(($# >= 2)) || usage
dependency=(--dependency="afterok:$2")
shift 2
;;
*)
forwarded_args+=("$1")
shift
;;
esac
done
submission_directory=$(pwd -P)
# Escape literal percent signs in Slurm filename patterns.
log_directory="${submission_directory//%/%%}"
script_directory=$(cd -- "$(dirname -- "$0")" && pwd)
repo_directory=$(cd -- "$script_directory/.." && pwd)
account="${SAPS_SLURM_ACCOUNT:-gts-wahrens6-pose}"
competition_config="${SAPS_COMPETITION_CONFIG:-$repo_directory/competition.config.json}"
chunk_count="${SAPS_CHUNK_COUNT:-128}"
# Fewer GPU tasks, so the GPU array holds fewer V100 nodes at once.
gpu_chunk_count="${SAPS_GPU_CHUNK_COUNT:-32}"
if ((chunk_count < 1)); then
echo "SAPS_CHUNK_COUNT must be at least 1" >&2
exit 1
fi
if ((gpu_chunk_count < 1)); then
echo "SAPS_GPU_CHUNK_COUNT must be at least 1" >&2
exit 1
fi
# Every framework needs a unique SAPS_FRAMEWORK_NAME, which the combine job
# uses to tell results apart, so refuse a bad config before queuing anything.
# Also skip the GPU array when no framework needs a GPU, rather than holding
# GPU nodes only for the runner to find nothing to do.
uses_gpu=$(
python3 - "$competition_config" <<'EOF'
import json
import sys
with open(sys.argv[1]) as f:
config = json.load(f)
includes = config.get("include", [])
names = [include.get("env_nobuild", {}).get("SAPS_FRAMEWORK_NAME") for include in includes]
missing = [i for i, name in enumerate(names) if not name]
if missing:
sys.exit(f"{sys.argv[1]}: include entries {missing} lack SAPS_FRAMEWORK_NAME")
duplicates = sorted({name for name in names if names.count(name) > 1})
if duplicates:
sys.exit(f"{sys.argv[1]}: duplicate SAPS_FRAMEWORK_NAME {duplicates}")
print(
"true"
if any(
include.get("env_nobuild", {}).get("SAPS_DEVICE") == "gpu"
for include in includes
)
else "false"
)
EOF
)
# If a later submission fails, cancel the earlier ones instead of leaving half
# a run queued without its combine job.
submitted=()
cancel_submitted() {
local status=$?
if ((status != 0)) && ((${#submitted[@]} > 0)); then
echo "submission failed; cancelling ${submitted[*]}" >&2
scancel "${submitted[@]}" || true
fi
}
trap cancel_submitted EXIT
# Command substitutions do not inherit set -e in bash, so fail explicitly.
submit_job() {
local job_id
job_id=$(sbatch --parsable "$@") || return 1
[[ -n "$job_id" ]] || return 1
echo "${job_id%%;*}"
}
submit_array() {
local device=$1
local count=$2
shift 2
submit_job \
-A "$account" \
${dependency[@]+"${dependency[@]}"} \
--array="0-$((count - 1))" \
--output "$log_directory/competition-$device-%A_%a.log" \
--chdir "$repo_directory" \
--export=ALL,SAPS_REPO_DIRECTORY="$repo_directory" \
"$script_directory/competition-$device.slurm" \
"$@" \
${forwarded_args[@]+"${forwarded_args[@]}"}
}
if [[ -n "$run_directory" ]]; then
cpu_job_id=$(submit_array cpu "$chunk_count" --resume "$run_directory")
submitted+=("$cpu_job_id")
else
# A new run is named after the CPU array; the GPU array joins it.
cpu_job_id=$(submit_array cpu "$chunk_count")
submitted+=("$cpu_job_id")
run_directory="$repo_directory/competition/run_$cpu_job_id"
mkdir -p "$run_directory"
fi
gpu_job_id=""
combine_after="afterany:$cpu_job_id"
if $uses_gpu; then
gpu_job_id=$(submit_array gpu "$gpu_chunk_count" --resume "$run_directory")
submitted+=("$gpu_job_id")
combine_after="$combine_after:$gpu_job_id"
fi
combine_command="export PATH=\"\$HOME/.pixi/bin:\$PATH\" && pixi run ./scripts/combine_competition_results.py --run-directory $(printf %q "$run_directory")"
combine_job_id=$(
submit_job \
-A "$account" \
-p cpu-small \
--job-name=saps-combine \
--mem=16G \
--time=00:30:00 \
--dependency="$combine_after" \
--output "$log_directory/competition-combine-%j.log" \
--chdir "$repo_directory" \
--wrap "$combine_command"
)
cat <<EOF
submitted SAPS competition:
run directory: $run_directory
cpu array: $cpu_job_id
gpu array: ${gpu_job_id:-skipped (no SAPS_DEVICE=gpu frameworks in $competition_config)}
combine: $combine_job_id
EOF