-
Notifications
You must be signed in to change notification settings - Fork 14
/
run.sh
executable file
·55 lines (47 loc) · 1.03 KB
/
run.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
#!/usr/bin/env bash
command="$0 $@"
function usage {
echo "Usage: $0 [-c checkpoint_dir] [-m min_memory] [-g gpu] [-h|--help] [tf_params]"
python3 main.py -h
}
min_memory=6000
params=
while [[ $# -gt 0 ]]; do
case "$1" in
-c)
params="$params --checkpoint_dir $2"
shift
;;
-g)
GPUID="$2"
shift
;;
-m)
min_memory="$2"
shift
;;
-h|--help)
usage
exit 0
;;
*)
params="$params $1"
;;
esac
shift
done
if [[ -z "$GPUID" ]]; then
GPUID=$(nvidia-smi --query-gpu=index,memory.free --format=csv,noheader,nounits \
| awk -F',' "{ if(\$2 > ${min_memory}) print \$1 }" | head -n 1)
[[ -z "$GPUID" ]] && echo "No gpu available with $min_memory GB of GPU memory" && exit 1
fi
# save command in case we crash
if [[ ! -d checkpoint ]]; then
mkdir checkpoint
fi
echo "$command" >> checkpoint/commands.log
# output info
echo "Using gpu $GPUID"
echo "Parameters: $params"
# run actual script
CUDA_VISIBLE_DEVICES="$GPUID" python3 main.py $params