-
Notifications
You must be signed in to change notification settings - Fork 1
/
generic.sh
executable file
·76 lines (59 loc) · 2.07 KB
/
generic.sh
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
#!/bin/bash
# This is a generic running script. It can run in two configurations:
# Single job mode: pass the python arguments to this script
# Batch job mode: pass a file with first the job tag and second the commands per line
####SBATCH --cpus-per-task=4
###SBATCH --gres=gpu:1
set -e # fail fully on first line failure
# Customize this line to point to conda installation
path_to_conda="/oak/stanford/groups/rbaltman/dnsosa/anaconda3"
echo "Running on $(hostname)"
if [ -z "$SLURM_ARRAY_TASK_ID" ]
then
# Not in Slurm Job Array - running in single mode
JOB_ID=$SLURM_JOB_ID
# Just read in what was passed over cmdline
JOB_CMD="${@}"
else
# In array
JOB_ID="${SLURM_ARRAY_JOB_ID}_${SLURM_ARRAY_TASK_ID}"
# Get the line corresponding to the task id
JOB_CMD=$(head -n ${SLURM_ARRAY_TASK_ID} "$1" | tail -1)
fi
## Find what was passed to --output_folder
regexp="--output_folder\s+(\S+)"
if [[ $JOB_CMD =~ $regexp ]]
then
JOB_OUTPUT=${BASH_REMATCH[1]}
else
echo "Error: did not find a --output_folder argument"
### exit 1
fi
# Check if results exists, if so remove slurm log and skip
### if [ -f "$JOB_OUTPUT/results.json" ]
if [ -f "$JOB_OUTPUT/train_history.txt" ]
then
echo "Results already done - exiting"
rm "slurm-${JOB_ID}.out"
exit 0
fi
# Check if the output folder exists at all. We could remove the folder in that case.
if [ -d "$JOB_OUTPUT" ]
then
echo "Folder exists, but was unfinished or is ongoing (no results.json)."
echo "Starting job as usual"
# It might be worth removing the folder at this point:
# echo "Removing current output before continuing"
# rm -r "$JOB_OUTPUT"
# Since this is a destructive action it is not on by default
fi
# Use this line if you need to create the environment first on a machine
# ./run_locked.sh ${path_to_conda}/bin/conda-env update -f environment.yml
# Activate the environment
source ${path_to_conda}/bin/activate base
# Train the model
###srun python $JOB_CMD
#pip install -e .
srun $JOB_CMD
# Move the log file to the job folder
mv "slurm-${JOB_ID}.out" "${JOB_OUTPUT}/"