forked from tracychms/amlbatchinference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
train-to-batch-score.sh
99 lines (80 loc) · 2.77 KB
/
train-to-batch-score.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
90
91
92
93
94
95
96
97
98
99
## IMPORTANT: this file and accompanying assets are the source for snippets in https://docs.microsoft.com/azure/machine-learning!
## Please reach out to the Azure ML docs & samples team before before editing for the first time.
set -e
# <set_variables>
export ENDPOINT_NAME="<YOUR_ENDPOINT_NAME>"
# </set_variables>
export ENDPOINT_NAME=endpt-`echo $RANDOM`
# <create_compute>
az ml compute create -n batch-cluster --type amlcompute --min-instances 0 --max-instances 5
# </create_compute>
# <train>
JOB_NAME=$(az ml job create -f endpoints/batch/train-to-batch-score/train/job.yml --query name -o tsv)
# </train>
# <show_job_in_studio>
az ml job show -n $JOB_NAME --web
# </show_job_in_studio>
# <stream_job_logs_to_console>
az ml job stream -n $JOB_NAME
# </stream_job_logs_to_console>
# <check_job_status>
STATUS=$(az ml job show -n $JOB_NAME --query status -o tsv)
echo $STATUS
if [[ $STATUS == "Completed" ]]
then
echo "Job completed"
elif [[ $STATUS == "Failed" ]]
then
echo "Job failed"
exit 1
else
echo "Job status not failed or completed"
exit 2
fi
# </check_job_status>
# <register_model>
# download the job output
az ml job download -n $JOB_NAME -p run-outputs
# register model
export MODEL_NAME="mlflow-model"
MODEL_VERSION=$(az ml model create -n $MODEL_NAME -l run-outputs/$JOB_NAME/nyc_taxi/ --query version -o tsv)
# </register_model>
# <create_batch_endpoint>
az ml batch-endpoint create --name $ENDPOINT_NAME
# </create_batch_endpoint>
# <create_batch_deployment_set_default>
az ml batch-deployment create --name mlflowdp --endpoint-name $ENDPOINT_NAME --file endpoints/batch/train-to-batch-score/batch-score/mlflow-deployment.yml --set-default --set model=azureml:$MODEL_NAME:$MODEL_VERSION
# </create_batch_deployment_set_default>
# <check_batch_endpooint_detail>
az ml batch-endpoint show --name $ENDPOINT_NAME
# </check_batch_endpooint_detail>
# <check_batch_deployment_detail>
az ml batch-deployment show --name mlflowdp --endpoint-name $ENDPOINT_NAME
# </check_batch_deployment_detail>
# <start_batch_scoring_job>
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --input-local-path endpoints/batch/train-to-batch-score/batch-score/data/test_data.csv --query name -o tsv)
# </start_batch_scoring_job>
# <show_job_in_studio>
az ml job show -n $JOB_NAME --web
# </show_job_in_studio>
# <stream_job_logs_to_console>
az ml job stream -n $JOB_NAME
# </stream_job_logs_to_console>
# <check_job_status>
STATUS=$(az ml job show -n $JOB_NAME --query status -o tsv)
echo $STATUS
if [[ $STATUS == "Completed" ]]
then
echo "Job completed"
elif [[ $STATUS == "Failed" ]]
then
echo "Job failed"
exit 1
else
echo "Job status not failed or completed"
exit 2
fi
# </check_job_status>
# <delete_endpoint>
az ml batch-endpoint delete --name $ENDPOINT_NAME --yes
# </delete_endpoint>