BookmarkSubscribeRSS Feed

How to Score a SAS Decision Published to Azure with SCR

Started ‎10-31-2021 by
Modified ‎10-31-2021 by
Views 6,456

 

SAS Container Runtime (SCR) allows you to publish SAS decisions as container images in Azure. In this post you will learn how to make use of these images in Azure. Firstly, you can create a container instance, in Azure, from the published image. Secondly, you can score the decision using a simple curl command or Python program.

 

SAS Container Runtime (SCR)

 

SAS Container Runtime  (SCR, pronounced “soccer”) is available since the SAS Viya version 2021.1.3. You can publish decisions as container images, in Azure, since the 2021.1.4 SAS Viya stable version.

 

SAS Container Runtime benefits:

 

  • Self-contained: once the image is published, it includes all the libraries and files that are required to score the decision. It has no dependencies on SAS Viya anymore for execution.
  • Minimal disk footprint: around 370 MB for a bare SCR image. The size is increased by the decision files. (The whole container image size used in this post is 391 MB.)
  • Fast start-up: once the image pulled, the container starts in 12-15 seconds.
  • Immutable design: the container image is designed for execution. If you must change something in your decision, you need to publish a new decision version. That means a new container image.
  • Flexible deployment options: you can deploy it to any compute environment that supports a docker pull command. In Azure, you can run your SCR image in an Azure Container Instance (ACI), Azure Web App or App Service Plan, Azure Kubernetes Service (AKS) pod. Deployment is not limited to Azure. You can start your container on a Linux machine with docker. Push the image to an Amazon Elastic Container Registry, deploy it on AWS, etc.
  • High scalability: because each decision exists in its own container image, each running container can be scaled independently. I will focus on a later post on how to scale SCR containers in Azure.
  • Has a much smaller runtime compute cost. Execution not being tied to hundreds of running microservices has its advantages. The immediate one is lower running cost / scoring request.

 

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 decision inside, using curl.

 

 

From a conceptual perspective, the post discusses the highlighted components:

 

bt_1_200-How-to-Score-a-SAS-Model-in-an-Azure-Container-Instance (2).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 have already published a SAS decision, with SCR, to an Azure Container Registry (ACR).

 

bt_2_320-SAS-Intelligent-Decisioning-decision-1-1024x487.png

 

 

Autoauctiondec1_0 is a decision, with a branch, two rule sets and a DS2 code file. The decision recommends you to Bid (or not) on cars auctioned online.

 

Analytical models supported by SCR (analytical store, DS2) can also be included in the decision.

 

You can read more about in How to Publish a Decision to Azure with SAS Container Runtime. To configure the Azure publishing destination in SAS, read How to Publish a SAS Model to Azure with SCR: A Start-to-Finish Guide.

 

Steps Towards Scoring

 

Azure Container Registry Images

 

The decision has been published as a SCR container image to an Azure Container Registry (ACR) repository.  

 

bt_3_410-SAS-Decision-Published-with-SCR-in-the-Azure-Container-Registry.png

 

When you drill-down into the individual image (decision name + version), and then by tag (latest published version), you will notice the SCR container image can be retrieved with a simple docker command.

 

bt_4_415-SAS-Decision-Published-with-SCR-in-the-Azure-Container-Registry-1024x343.png

 

 

To score the decision inside a container:

  • Create an Azure Container Instance from the decision SCR image stored in the Azure Container Registry
  • Score the decision, using a simple command (curl), a python program, etc.

 

Create an Azure Container Instance

 

The video above shows you how to create a container instance, called autoauctiondec. To score the model, you will need these elements:

 

  1. The container instance created and the container running.
  2. The fully qualified domain name (FQDN) eastus.azurecontainer.io or the public IP address of the container instance.

 

bt_5_420-SAS-Decision-Running-in-an-Azure-Container-Instance-1024x517.png

 

  1. The name of the model, also called SCR module, autoaouctiondec1_0, running inside the container.
  2. The port on which the container is listening. For SCR containers, this is 8080.

 

Model Scoring Command

 

From a functional perspective, the decision is assessing cars and bid data and, telling you if you should bid, or not. The data section contains one 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://autoauctiondec.eastus.azurecontainer.io:8080/autoauctiondec1_0'  --header 'Content-Type: application/json'  --header 'Accept: application/json'  --data '{
	"version":1,
	"inputs":[
	{"name":"BlueBookPrice","value":80000},
	{"name":"CurrentBid","value":90000},
	{"name":"Make","value":"Tesla"},
	{"name":"Miles","value":5000},
	{"name":"Model","value":"X100D"},
	{"name":"OriginalInvoice","value":100000},
	{"name":"OriginalMSRP","value":100000},
	{"name":"state","value":"CA"},
	{"name":"VIN","value":"12345678901234562"},
	{"name":"Year","value":2017}
	]
	}'

 

To format the json response, you can use jq, a JSON processor. You can add it at the end, so that you have:

 

...}]} ' | jq

 

Scoring Response

 

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

 

bt_6_430-Score-with-curl-a-SAS-Decision-Running-in-an-Azure-Container-Instance.png

 

 

In plain language, the decision determines you should bid on this car, and assigns Bid = 1.

 

Alternative with python:

 

import http.client
import json
conn = http.client.HTTPConnection("autoauctiondec.eastus.azurecontainer.io:8080")
payload = json.dumps({
    "inputs":[
    {"name":"BlueBookPrice","value":80000},
    {"name":"CurrentBid","value":90000},
    {"name":"Make","value":"Tesla"},
    {"name":"Miles","value":5000},
    {"name":"Model","value":"X100D"},
    {"name":"OriginalInvoice","value":100000},
    {"name":"OriginalMSRP","value":100000},
    {"name":"state","value":"CA"},
    {"name":"VIN","value":"12345678901234562"},
    {"name":"Year","value":2017}
    ]
    })
headers = {
  'Accept': 'application/json',
  'Content-Type': 'application/json'
}
conn.request("POST", "/autoauctiondec1_0", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

 

SCR Container Response Troubleshoot

 

For the same decision published to MAS, the data input expected would have been:

 

curl --location --request POST 'https://{{viya_server_host}}:443/microanalyticScore/modules/ autoauctiondec1_0/steps/execute/' --header 'Content-Type: application/json'  --header 'Accept: application/json'  --data '{
	"version":1,
	"inputs":[
	{"name":"BLUEBOOKPRICE_","value":80000},
	{"name":"CURRENTBID_","value":90000},
	{"name":"MAKE_","value":"Tesla"},
	{"name":"MILES_","value":5000},
	{"name":"MODEL_","value":"X100D"},
	{"name":"ORIGINALINVOICE_","value":100000},
	{"name":"ORIGINALMSRP_","value":100000},
	{"name":"STATE_","value":"CA"},
	{"name":"VIN_","value":"12345678901234562"},
	{"name":"YEAR_","value":2017}
	]
	}'

 

If you pass the input data for a MAS request to a SCR container, you will get your response back with null values. You have been warned.

 

bt_7_440-Score-with-curl-a-SAS-Decision-troubleshooting.png

 

 

If ever in doubt about your data input format, browse the container:

 

ls
cd modules
ls
cat _module_definition.json 

 

You will see the exact field names you have to use in your request. These are preceeded by in_out: BlueBookPrice is expected, not BLUEBOOK nor BLUEBOOK_.

bt_8_450-Explore-the-Running-in-an-Azure-Container-Instance-1024x422.png

 

Rule Sets

 

You can publish rule sets, independent of decisions. You can score them in a container, in the exact same way.

 

Scope

 

Not all decision components from SAS Intelligent Decisioning are supported. Read more in the How to Publish a Decision to Azure with SAS Container Runtime, the Caveats paragraph.

 

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 decision using a simple command to call the SCR REST API with curl, python, SAS, etc.

 

Additional Resources

 

SAS documentation

 

SAS Communities and YouTube

 


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

 

 

Find more articles from SAS Global Enablement and Learning here.

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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

Article Tags