Skip to content

Commit e5b0dfc

Browse files
authored
[BES notebooks] - Fix the issue with cli-batch-score (#3728)
1 parent 577f58f commit e5b0dfc

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

.github/workflows/cli-scripts-batch-score.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
steps:
2828
- name: check out repo
2929
uses: actions/checkout@v2
30+
with:
31+
lfs: true
3032
- name: azure login
3133
uses: azure/login@v1
3234
with:

cli/batch-score.sh

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,18 @@ az ml batch-deployment show --name $DEPLOYMENT_NAME --endpoint-name $ENDPOINT_NA
3737

3838
sleep 60
3939

40-
echo "Invoking batch endpoint with public URI (MNIST)"
40+
echo "Extracting MNIST data from zip file"
41+
# <extract_data>
42+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
43+
REPO_ROOT="$(dirname "$SCRIPT_DIR")"
44+
TEMP_DATA_PATH="$REPO_ROOT/temp_mnist_data"
45+
mkdir -p $TEMP_DATA_PATH
46+
unzip -q "$REPO_ROOT/assets/batch-endpoints-data/mnist-batch/data.zip" -d $TEMP_DATA_PATH
47+
# </extract_data>
48+
49+
echo "Invoking batch endpoint with local data (MNIST)"
4150
# <start_batch_scoring_job>
42-
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --input https://azuremlexampledata.blob.core.windows.net/data/mnist/sample --input-type uri_folder --query name -o tsv)
51+
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --input $TEMP_DATA_PATH/data --input-type uri_folder --query name -o tsv)
4352
# </start_batch_scoring_job>
4453

4554
echo "Showing job detail"
@@ -71,13 +80,13 @@ fi
7180
echo "Invoke batch endpoint with specific output file name"
7281
# <start_batch_scoring_job_configure_output_settings>
7382
export OUTPUT_FILE_NAME=predictions_`echo $RANDOM`.csv
74-
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --input https://azuremlexampledata.blob.core.windows.net/data/mnist/sample --input-type uri_folder --output-path azureml://datastores/workspaceblobstore/paths/$ENDPOINT_NAME --set output_file_name=$OUTPUT_FILE_NAME --query name -o tsv)
83+
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --input $TEMP_DATA_PATH/data --input-type uri_folder --output-path azureml://datastores/workspaceblobstore/paths/$ENDPOINT_NAME --set output_file_name=$OUTPUT_FILE_NAME --query name -o tsv)
7584
# </start_batch_scoring_job_configure_output_settings>
7685

7786
echo "Invoke batch endpoint with specific overwrites"
7887
# <start_batch_scoring_job_overwrite>
7988
export OUTPUT_FILE_NAME=predictions_`echo $RANDOM`.csv
80-
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --input https://azuremlexampledata.blob.core.windows.net/data/mnist/sample --input-type uri_folder --mini-batch-size 20 --instance-count 5 --query name -o tsv)
89+
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --input $TEMP_DATA_PATH/data --input-type uri_folder --mini-batch-size 20 --instance-count 5 --query name -o tsv)
8190
# </start_batch_scoring_job_overwrite>
8291

8392
echo "Stream job detail"
@@ -114,7 +123,7 @@ az ml batch-deployment create --file endpoints/batch/deploy-models/mnist-classif
114123
echo "Invoke batch endpoint with public data"
115124
# <test_new_deployment>
116125
DEPLOYMENT_NAME="mnist-keras-dpl"
117-
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --deployment-name $DEPLOYMENT_NAME --input https://azuremlexampledata.blob.core.windows.net/data/mnist/sample --input-type uri_folder --query name -o tsv)
126+
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --deployment-name $DEPLOYMENT_NAME --input $TEMP_DATA_PATH/data --input-type uri_folder --query name -o tsv)
118127
# </test_new_deployment>
119128

120129
echo "Show job detail"
@@ -155,7 +164,7 @@ az ml batch-endpoint show --name $ENDPOINT_NAME --query "{Name:name, Defaults:de
155164

156165
echo "Invoke batch endpoint with the new default deployment with public URI"
157166
# <test_new_default_deployment>
158-
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --input https://azuremlexampledata.blob.core.windows.net/data/mnist/sample --input-type uri_folder --query name -o tsv)
167+
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --input $TEMP_DATA_PATH/data --input-type uri_folder --query name -o tsv)
159168
# </test_new_default_deployment>
160169

161170
echo "Stream job logs to console"
@@ -184,21 +193,32 @@ echo "Get Scoring URI"
184193
SCORING_URI=$(az ml batch-endpoint show --name $ENDPOINT_NAME --query scoring_uri -o tsv)
185194
# </get_scoring_uri>
186195

196+
echo "Upload data to datastore for REST API call"
197+
# <upload_data_to_datastore>
198+
DATA_ASSET_NAME="mnist-batch-data-$(date +%s)"
199+
az ml data create --name $DATA_ASSET_NAME --version 1 --type uri_folder --path $TEMP_DATA_PATH/data
200+
# </upload_data_to_datastore>
201+
187202
echo "Get Token"
188203
# <get_token>
189204
AUTH_TOKEN=$(az account get-access-token --resource https://ml.azure.com --query accessToken -o tsv)
190205
# </get_token>
191206

192207
echo "Invoke batch endpoint with REST API call"
193208
# <start_batch_scoring_job_rest>
209+
SUBSCRIPTION_ID=$(az account show --query id -o tsv)
210+
RESOURCE_GROUP=$(az configure -l --query "[?name=='group'].value" -o tsv)
211+
WORKSPACE=$(az configure -l --query "[?name=='workspace'].value" -o tsv)
212+
DATA_URI="azureml://subscriptions/$SUBSCRIPTION_ID/resourcegroups/$RESOURCE_GROUP/workspaces/$WORKSPACE/data/$DATA_ASSET_NAME/versions/1"
213+
194214
RESPONSE=$(curl --location --request POST "$SCORING_URI" \
195215
--header "Authorization: Bearer $AUTH_TOKEN" \
196216
--header "Content-Type: application/json" \
197217
--data-raw "{
198218
\"properties\": {
199219
\"dataset\": {
200220
\"dataInputType\": \"DataUrl\",
201-
\"Path\": \"https://azuremlexampledata.blob.core.windows.net/data/mnist/sample\"
221+
\"Path\": \"$DATA_URI\"
202222
}
203223
}
204224
}")
@@ -253,3 +273,8 @@ az ml batch-deployment delete --name nonmlflowdp --endpoint-name $ENDPOINT_NAME
253273
# <delete_endpoint>
254274
az ml batch-endpoint delete --name $ENDPOINT_NAME --yes
255275
# </delete_endpoint>
276+
277+
echo "Cleaning up temporary data folder"
278+
# <cleanup_temp_data>
279+
rm -rf $TEMP_DATA_PATH
280+
# </cleanup_temp_data>

cli/endpoints/batch/deploy-models/mnist-classifier/deployment-keras/deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ code_configuration:
1111
scoring_script: batch_driver.py
1212
environment:
1313
name: batch-tensorflow-py38
14-
image: mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04:latest
14+
image: mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu22.04:latest
1515
conda_file: environment/conda.yaml
1616
compute: azureml:batch-cluster
1717
resources:

cli/endpoints/batch/deploy-models/mnist-classifier/deployment-torch/deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ code_configuration:
1111
scoring_script: batch_driver.py
1212
environment:
1313
name: batch-torch-py38
14-
image: mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04:latest
14+
image: mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu22.04:latest
1515
conda_file: environment/conda.yaml
1616
compute: azureml:batch-cluster
1717
resources:

0 commit comments

Comments
 (0)