-
Notifications
You must be signed in to change notification settings - Fork 2
/
2_training.sh
executable file
·73 lines (55 loc) · 1.99 KB
/
2_training.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
#!/usr/bin/env sh
# The script exits when a command fails or it uses undeclared variables
set -o errexit
set -o nounset
# shellcheck disable=SC1091
. "$(dirname "$0")/mlflow_funcs.sh"
# Argument parsing
while [ "$#" -gt 0 ]; do
case $1 in
-p|--project_path) project_path="$2"; shift ;;
-i|--input_file) input_file="$2"; shift ;;
-t|--train_folder) train_folder="$2"; shift ;;
-o|--output_dir) output_dir="$2"; shift ;;
-a|--mlflow_args) mlflow_args="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
# Define auxiliary variables
MODEL_FILE_ABS_PATH="${output_dir}/Model.tar.gz"
MODEL_INFO_ABS_PATH="${output_dir}/models"
# Cleanup previous files (useful when run locally)
rm -rf "${MODEL_FILE_ABS_PATH}"
rm -rf "${MODEL_INFO_ABS_PATH}"
mkdir -p "${MODEL_INFO_ABS_PATH}"
### IMPORTANT NOTE:
###
### When the MLFlow metrics / artifacts are stored locally, the provided MLFlow
### Tracking URI must be sanitized, to inject the WORKDIR value at the beginning.
###
### This is necessary to avoid file permission errors in REANA.
### Ref: https://github.com/scailfin/madminer-workflow/issues/40
if [ -n "${MLFLOW_TRACKING_URI:-}" ]; then
uri="${MLFLOW_TRACKING_URI}"
uri=$(sanitize_tracking_uri "${uri}" "${output_dir}")
export MLFLOW_TRACKING_URI="${uri}"
fi
# Prepare MLFlow optional arguments
mlflow_parsed_args=$(parse_mlflow_args "${mlflow_args:-}")
# Perform actions
eval mlflow run \
--experiment-name "madminer-ml-train" \
--entry-point "train" \
--backend "local" \
--no-conda \
--param-list "project_path=${project_path}" \
--param-list "inputs_file=${input_file}" \
--param-list "train_folder=${train_folder}" \
--param-list "output_folder=${output_dir}" \
"${mlflow_parsed_args}" \
"${project_path}"
# Kubernetes at CERN sandwich with set +o errexit
set +o errexit
tar -czf "${MODEL_FILE_ABS_PATH}" -C "${MODEL_INFO_ABS_PATH}" .
set -o errexit