-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunUberJar.sh
executable file
·89 lines (74 loc) · 2.21 KB
/
runUberJar.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
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
set -e
set -u
set -o pipefail
detectOSPlatform() {
OSNAME=$(uname)
if [[ "${OSNAME}" = "Darwin" ]]; then
OSNAME=macosx
elif [[ "${OSNAME}" = "Linux" ]]; then
OSNAME=linux
fi
echo ${OSNAME}
}
downloadModelAndDatabase() {
./download-model-and-review-database.sh
}
checkBackendForMacOSX(){
if [[ "${OSNAME}" = "macosx" ]]; then
echo "";
echo "GPUs are not accessible on MacOSX by the app hence we will use CPU as the backend."
BACKEND=cpu
fi
}
forGPUBuildsRunKnowYourGPUsScript() {
if [[ "${BACKEND}" = "gpu" ]]; then
VH_OUTPUTS_DIR=${VH_OUTPUTS_DIR:-"."}
./know-your-gpus.sh &> "${VH_OUTPUTS_DIR}/run-time-know-your-gpus.logs"
fi
}
getJarFile() {
FOLDER=${1:-"."}
echo $(ls "${FOLDER}"/dl4j-nlp-${DL4J_VERSION}-*-${OSNAME}-bin.jar | awk '{print $1}' || true)
}
copyJarForTrainingIfOnValohaiPlatform() {
if [[ "${ACTION}" = "train" ]] && [[ ! -z "${VH_INPUTS_DIR:-}" ]]; then
echo "~~~ Copying ${VH_INPUTS_DIR}/${BACKEND}-linux-uberjar/dl4j-nlp-1.0.0-beta5-${BACKEND}-linux-bin.jar into ${VH_REPOSITORY_DIR}"
cp ${VH_INPUTS_DIR}/${BACKEND}-linux-uberjar/dl4j-nlp-1.0.0-beta5-${BACKEND}-linux-bin.jar ${VH_REPOSITORY_DIR}
fi
}
checkIfJarExistsOrExit() {
TARGET_JAR_FILE=$(getJarFile)
if [[ -z "${TARGET_JAR_FILE}" ]]; then
TARGET_JAR_FILE=$(getJarFile "target")
if [[ ! -s "${TARGET_JAR_FILE}" ]]; then
echo "Could not find the target executable jar file"
exit -1
fi
fi
}
runJar() {
java -version
time java -Djava.library.path="" \
-jar "${TARGET_JAR_FILE}" \
$*
}
copyModelForTrainingIfOnValohaiPlatform() {
if [[ "${ACTION}" = "train" ]] && [[ ! -z "${VH_OUTPUTS_DIR:-}" ]]; then
echo "~~~ Copying all created models and checkpoints into ${VH_OUTPUTS_DIR}"
for filename in *.pb ; do mv $filename "${filename%.*}-${BACKEND}.pb" ; done
cp *.pb ${VH_OUTPUTS_DIR}
cp ./checkpoint* ${VH_OUTPUTS_DIR}
fi
}
DL4J_VERSION="1.0.0-beta5"
BACKEND=${BACKEND:-gpu}
OSNAME=$(detectOSPlatform)
TARGET_JAR_FILE=""
downloadModelAndDatabase
checkBackendForMacOSX
forGPUBuildsRunKnowYourGPUsScript
copyJarForTrainingIfOnValohaiPlatform
checkIfJarExistsOrExit
runJar $*
copyModelForTrainingIfOnValohaiPlatform