Skip to content

Commit

Permalink
Quick fixes for files referenced on docs (Azure#2164)
Browse files Browse the repository at this point in the history
* batch endpoint CLI folders

* fixes

* docs sync

* black

---------

Co-authored-by: santiagxf <fasantia@microsfot.com>
  • Loading branch information
santiagxf and santiagxf committed Mar 31, 2023
1 parent 7c4cee3 commit 287140b
Show file tree
Hide file tree
Showing 16 changed files with 1,039 additions and 949 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ ENDPOINT_SUFIX=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-5} | head
ENDPOINT_NAME="heart-classifier-$ENDPOINT_SUFIX"

# <register_model>
MODEL_NAME='heart-classifier'
az ml model create --name $MODEL_NAME --type "mlflow_model" --path "model"
MODEL_NAME='heart-classifier-sklpipe'
az ml model create --name $MODEL_NAME --type "custom_model" --path "model"
# <register_model>

echo "Creating compute"
Expand All @@ -25,7 +25,7 @@ az ml batch-endpoint create -n $ENDPOINT_NAME -f endpoint.yml

echo "Creating batch deployment $DEPLOYMENT_NAME for endpoint $ENDPOINT_NAME"
# <create_batch_deployment_set_default>
az ml batch-deployment create --file deployment-parquet/deployment.yml --endpoint-name $ENDPOINT_NAME --set-default
az ml batch-deployment create --file deployment.yml --endpoint-name $ENDPOINT_NAME --set-default
# </create_batch_deployment_set_default>

echo "Update the batch deployment as default for the endpoint"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ $schema: https://azuremlschemas.azureedge.net/latest/batchDeployment.schema.json
endpoint_name: heart-classifier-batch
name: classifier-xgboost-custom
description: A heart condition classifier based on XGBoost and Scikit-Learn pipelines that append predictions on parquet files.
model:
path: model
name: heart-classifier-sklpipe
model: azureml:heart-classifier-sklpipe@latest
environment:
name: batch-mlflow-xgboost
image: mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04:latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ az ml batch-endpoint create --file endpoint.yml --name $ENDPOINT_NAME

echo "Creating batch deployment for endpoint $ENDPOINT_NAME"
# <create_batch_deployment_set_default>
az ml batch-deployment create --file deployment.yml --endpoint-name $ENDPOINT_NAME --set-default
az ml batch-deployment create --file deployment-by-file.yml --endpoint-name $ENDPOINT_NAME --set-default
# </create_batch_deployment_set_default>

echo "Showing details of the batch endpoint"
Expand All @@ -46,9 +46,18 @@ DEPLOYMENT_NAME="imagenet-classifier-resnetv2"
az ml batch-deployment show --name $DEPLOYMENT_NAME --endpoint-name $ENDPOINT_NAME
# </check_batch_deployment_detail>

# <download_sample_data>
wget https://azuremlexampledata.blob.core.windows.net/data/imagenet-1000.zip
unzip imagenet-1000.zip -d data
# </download_sample_data>

# <create_sample_data_asset>
az ml data create -f imagenet-sample-unlabeled.yml
# </create_sample_data_asset>

echo "Invoking batch endpoint with local data"
# <start_batch_scoring_job>
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --input data --input-type uri_folder --query name -o tsv)
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --input azureml:imagenet-sample-unlabeled@latest --query name -o tsv)
# </start_batch_scoring_job>

echo "Showing job detail"
Expand Down Expand Up @@ -77,9 +86,45 @@ else
fi
# </check_job_status>

# <download_scores>
az ml job download --name $JOB_NAME --output-name score --download-path .
# </download_scores>

echo "Creating batch deployment for endpoint $ENDPOINT_NAME with high throughput"
# <create_batch_deployment_ht>
az ml batch-deployment create --file deployment-by-batch.yml --endpoint-name $ENDPOINT_NAME --default
# </create_batch_deployment_ht>

echo "Invoking batch endpoint with local data"
# <start_batch_scoring_job_ht>
JOB_NAME=$(az ml batch-endpoint invoke --name $ENDPOINT_NAME --input azureml:imagenet-sample-unlabeled@latest --query name -o tsv)
# </start_batch_scoring_job_ht>

echo "Stream job logs to console"
# <stream_job_logs_to_console_ht>
az ml job stream -n $JOB_NAME
# </stream_job_logs_to_console_ht>

# <check_job_status_ht>
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_ht>

# <delete_endpoint>
az ml batch-endpoint delete --name $ENDPOINT_NAME --yes
# </delete_endpoint>

echo "Clean temp files"
find ./model -exec rm -rf {} +
find ./data -exec rm -rf {} +
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ code_configuration:
scoring_script: batch_driver.py
resources:
instance_count: 2
tags:
device_acceleration: CUDA
device_batching: 16
max_concurrency_per_instance: 1
mini_batch_size: 5
output_action: append_row
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$schema: https://azuremlschemas.azureedge.net/latest/data.schema.json
name: imagenet-sample-unlabeled
description: A sample of 1000 images from the original ImageNet dataset. Download content from https://azuremlexampledata.blob.core.windows.net/data/imagenet-1000.zip.
type: uri_folder
path: data
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: mnist-keras-dpl
description: A deployment using Keras with TensorFlow to solve the MNIST classification dataset.
endpoint_name: mnist-batch
model:
name: mnist-classifier-keras
path: model
code_configuration:
code: code
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license.

import os
import pandas as pd
import torch
Expand Down Expand Up @@ -47,8 +44,8 @@ def run(mini_batch: List[str]) -> pd.DataFrame:
results.append(
{
"file": basename(image_path),
"class": predicted_class.numpy(),
"probability": predicted_prob.numpy(),
"class": predicted_class.numpy()[0],
"probability": predicted_prob.numpy()[0],
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ $schema: https://azuremlschemas.azureedge.net/latest/batchDeployment.schema.json
name: mnist-torch-dpl
description: A deployment using Torch to solve the MNIST classification dataset.
endpoint_name: mnist-batch
model:
model:
name: mnist-classifier-torch
path: model
code_configuration:
code: code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"\n",
"### 2.1 About the model\n",
"\n",
"This example shows how you can deploy an MLflow model to a batch endpoint to perform batch predictions. This example uses a model based on the UCI Heart Disease Data Set. The database contains 76 attributes, but we are using a subset of 14 of them. The model tries to predict the presence of heart disease in a patient. It is integer valued from 0 (no presence) to 1 (presence).\n",
"This example shows how you can deploy a model to a batch endpoint to perform batch predictions. This example uses a model based on the UCI Heart Disease Data Set. The database contains 76 attributes, but we are using a subset of 14 of them. The model tries to predict the presence of heart disease in a patient. It is integer valued from 0 (no presence) to 1 (presence).\n",
"\n",
"The model has been trained using an `XGBBoost` classifier and all the required preprocessing has been packaged as a `scikit-learn` pipeline, making this model an end-to-end pipeline that goes from raw data to predictions.\n",
"\n",
Expand All @@ -145,7 +145,7 @@
},
"outputs": [],
"source": [
"model_name = \"heart-classifier\"\n",
"model_name = \"heart-classifier-sklpipe\"\n",
"model_description = \"A heart condition classifier trained with XGBoosts and Scikit-Learn for feature processing.\"\n",
"model_local_path = \"model\""
]
Expand Down Expand Up @@ -490,6 +490,7 @@
"outputs": [],
"source": [
"environment = Environment(\n",
" name=\"batch-mlflow-xgboost\",\n",
" conda_file=\"environment/conda.yml\",\n",
" image=\"mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04:latest\",\n",
")"
Expand Down
Loading

0 comments on commit 287140b

Please sign in to comment.