|
| 1 | +set -x |
| 2 | +# the commands in this file map to steps in this notebook: https://aka.ms/azureml-infer-online-sdk-question-answering |
| 3 | +# the sample scoring file available in the same folder as the above notebook |
| 4 | + |
| 5 | +# script inputs |
| 6 | +registry_name="azureml" |
| 7 | +subscription_id="<SUBSCRIPTION_ID>" |
| 8 | +resource_group_name="<RESOURCE_GROUP>" |
| 9 | +workspace_name="<WORKSPACE_NAME>" |
| 10 | + |
| 11 | +# This is the model from system registry that needs to be deployed |
| 12 | +model_name="deepset-minilm-uncased-squad2" |
| 13 | + |
| 14 | +# Validate the existence of the model in the registry and get the latest version |
| 15 | +model_list=$(az ml model list --name ${model_name} --registry-name ${registry_name} 2>&1) |
| 16 | +if [[ ${model_list} == *"[]"* ]]; then |
| 17 | + echo "Model doesn't exist in registry. Check the model list and try again."; exit 1; |
| 18 | +fi |
| 19 | +version_temp=${model_list#*\"version\": \"} |
| 20 | +model_version=${version_temp%%\"*} |
| 21 | + |
| 22 | +version=$(date +%s) |
| 23 | +endpoint_name="question-answering-$version" |
| 24 | + |
| 25 | +# todo: fetch deployment_sku from the min_inference_sku tag of the model |
| 26 | +deployment_sku="Standard_DS2_v2" |
| 27 | + |
| 28 | +# scoring_file |
| 29 | +scoring_file="../../../../../sdk/python/foundation-models/system/inference/question-answering/squad-dataset/sample_score.json" |
| 30 | + |
| 31 | +# 1. Setup pre-requisites |
| 32 | +if [ "$subscription_id" = "<SUBSCRIPTION_ID>" ] || \ |
| 33 | + ["$resource_group_name" = "<RESOURCE_GROUP>" ] || \ |
| 34 | + [ "$workspace_name" = "<WORKSPACE_NAME>" ]; then |
| 35 | + echo "Please update the script with the subscription_id, resource_group_name and workspace_name" |
| 36 | + exit 1 |
| 37 | +fi |
| 38 | + |
| 39 | +az account set -s $subscription_id |
| 40 | +workspace_info="--resource-group $resource_group_name --workspace-name $workspace_name" |
| 41 | + |
| 42 | +# 2. Check if the model exists in the registry |
| 43 | +# need to confirm model show command works for registries outside the tenant (aka system registry) |
| 44 | +if ! az ml model show --name $model_name --version $model_version --registry-name $registry_name |
| 45 | +then |
| 46 | + echo "Model $model_name:$model_version does not exist in registry $registry_name" |
| 47 | + exit 1 |
| 48 | +fi |
| 49 | + |
| 50 | +# 3. Deploy the model to an endpoint |
| 51 | +# create online endpoint |
| 52 | +az ml online-endpoint create --name $endpoint_name $workspace_info || { |
| 53 | + echo "endpoint create failed"; exit 1; |
| 54 | +} |
| 55 | + |
| 56 | +# deploy model from registry to endpoint in workspace |
| 57 | +az ml online-deployment create --file deploy.yml $workspace_info --all-traffic --set \ |
| 58 | + endpoint_name=$endpoint_name model=azureml://registries/$registry_name/models/$model_name/versions/$model_version \ |
| 59 | + instance_type=$deployment_sku || { |
| 60 | + echo "deployment create failed"; exit 1; |
| 61 | +} |
| 62 | + |
| 63 | +# 4. Try a sample scoring request |
| 64 | + |
| 65 | +# Check if scoring data file exists |
| 66 | +if [ -f $scoring_file ]; then |
| 67 | + echo "Invoking endpoint $endpoint_name with following input:\n\n" |
| 68 | + cat $scoring_file |
| 69 | + echo "\n\n" |
| 70 | +else |
| 71 | + echo "Scoring file $scoring_file does not exist" |
| 72 | + exit 1 |
| 73 | +fi |
| 74 | + |
| 75 | +az ml online-endpoint invoke --name $endpoint_name --request-file $scoring_file $workspace_info || { |
| 76 | + echo "endpoint invoke failed"; exit 1; |
| 77 | +} |
| 78 | + |
| 79 | +# 6. Delete the endpoint |
| 80 | +az ml online-endpoint delete --name $endpoint_name $workspace_info --yes || { |
| 81 | + echo "endpoint delete failed"; exit 1; |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | + |
0 commit comments