BookmarkSubscribeRSS Feed

How to Score a SAS Model in an Azure Container Instance

Started ‎10-17-2021 by
Modified ‎10-31-2021 by
Views 5,444

SAS Container Runtime (SCR) allows you to publish a SAS model as a container image in Azure. In this post you will learn how to create a container instance in Azure. Then, how to score the model using a simple curl command.

 

SAS Container Runtime (SCR)

SAS Container Runtime  (SCR, pronounced "soccer") is available since the SAS Viya version 2021.1.3. Azure, as a SAS model publishing destination is available from the same version.

 

SAS Container Runtime:

  • Does not require SAS Viya for execution.
  • Has a much smaller runtime compute cost.
  • Uses standard technology such as Docker and container registry.
  • Has a smaller footprint for production.
  • Is highly scalable.
  • Gives you more choices. SAS container runtime is cloud agnostic. Develop once, then deploy anywhere.

 

The Essential

The two minutes video shows you how to create an Azure Container Instance from a SCR image and how to score the SAS model inside, using curl.

 

 

The shade highlights the components discussed in this post. (Drawing credits: Deva Kumar).

 

bt_1_200-How-to-Score-a-SAS-Model-in-an-Azure-Container-Instance.png

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

Pre-requisites

The scenario assumes you published a SAS model, with SCR, as a container image, to an Azure Container Registry (ACR). You can read more about the required configuration in How to Publish a SAS Model to Azure with SCR: A Start-to-Finish Guide.  

 

Scenario

In the Azure Container Registry (ACR), named modelmanager, you can see two repositories, containing SCR images:

  • Qs_tree1 – is the champion model (a decision tree).
  • Qs_reg1 – is the challenger model (a logistic regression).

 

bt_2_210-SAS-Container-Runtime-Images-Models-in-an-Azure-Container-Registry-1024x301.png

 

When you drill-down into the individual image (model) and tag (version), you will notice the SCR container image can be pulled with a simple docker command.  

 

220-SAS-bt_3_Container-Runtime-Image-Champion-Model-in-an-Azure-Container-Registry-1024x488.png

 

To score the model inside the image:

  • Create an Azure Container Instance from the image (Azure Container Registry repository)
  • Score the model, using a simple command (curl)

 

Create an Azure Container Instance for a model

In the video, a container instance was created, for the champion model, called qs_tree1. To score the model, you will need these elements:

  1. The container instance created and the container is running.
  2. The FQDN eastus.azurecontainer.io or the public IP address of the container instance.

 

bt_4_230-SAS-Container-Runtime-Model-Running-in-an-Azure-Container-Instance-1024x385.png

 

  1. The name of the model (also called module), qs_tree1, running inside the container.

bt_5_240-SAS-Container-Runtime-Model-Running-in-an-Azure-Container-Instance-1024x320.png

 

  1. The port on which the container is listening. For SCR containers, this is 8080. You can see it in the container log.

 

  1. 250-bt_6_SAS-Container-Runtime-Model-Running-in-an-Azure-Container-Instance-Log-1024x488.png

 

 

Model Scoring Command

From a functional perspective, the model is classifying if the home loan application is likely to default, or not. The input data is for a home loan application. You will recognize without doubt, the structure of the famous HMEQ data set. The data section contains one data record, in json format.  

 

To score the model you can write a simple curl command, from a Linux machine. The machine must be able (and allowed) to reach the Azure container instance. 

 

curl --location --request POST 'http://qstree1.eastus.azurecontainer.io:8080/qs_tree1'  --header 'Content-Type: application/json'  --header 'Accept: application/json'  --data ' {
    "inputs": [
        { "name": "CLAGE", "value": 94.36666667 },
        { "name": "CLNO", "value": 9 },
        { "name": "DEBTINC", "value": 0 },
        { "name": "DELINQ", "value": 0 },
        { "name": "DEROG", "value": 0 },
        { "name": "JOB", "value": "Other" },
        { "name": "LOAN", "value": 0 },
        { "name": "MORTDUE", "value": 25860 },
        { "name": "NINQ", "value": 1 },
        { "name": "REASON", "value": "HomeImp" },
        { "name": "VALUE", "value": 39025 },
        { "name": "YOJ", "value": 10.5 }
    ]
} '

 

To format the json response, you can use jq, a JSON processor. Just add at the end:

 

 | jq

 

so that you have:

 

} ' | jq

 

Model Scoring Response

The response of the model score comes back in .json format.

 

bt_7_260-Score-a-Model-in-a-SAS-Container-Runtime-Azure-Container-Instance-Using-curl.png

 

In plain language, the model determines a 94% probability of no default on this home loan, and assigns I_BAD = 0, the predicted class.  

 

Container Activity

In the Azure portal, you can watch the container activity: every curl request creates a spike. You can look at the container logs, connect and explore the container folders, set alerts and so on.

 

270-SAS-Cbt_8_ontainer-Runtime-Model-Running-in-an-Azure-Container-Instance-Overview-1024x488.png

 

 

Versioning

If you publish a new model version from SAS, you need to redeploy your container instance.

 

The ACR keeps track of the published versions. The :latest tag is associated with the last version published ( such as 2.0, 3.0, etc.). The number is the model version in SAS Model Manager, from when you published the model to Azure.

 

Acknowledgements

All the credits go to my colleague Deva Kumar. Thank you for teaching me how to score a model in Azure.

 

Conclusions

It is quite easy to create a container instance in Azure, from a SCR container image. Then, you can score the model using a simple curl command.

 

Additional Resources

SAS documentation

SAS Communities and YouTube

 

Thank you for your time reading this article. If you liked the post, give it a thumbs up. Please comment and tell us what you think about the new SCR and Azure publishing destination.

 

Find more articles from SAS Global Enablement and Learning here.

Version history
Last update:
‎10-31-2021 09:24 PM
Updated by:

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started