BookmarkSubscribeRSS Feed

How to deploy and run your model with SAS Model Manager to the SAS Micro Analytic Score Service

Started ‎11-13-2018 by
Modified ‎03-28-2019 by
Views 15,449

In my recent blog I focused on the process to deploy models with SAS Model Manager to Hadoop. I mentioned that deploying is a key step for any data scientist and SAS Model Manager assists in bringing the models into production processes. While publishing to Hadoop is an example for batch processing, I would like to focus now on an example where we deploy with real-time scoring execution as the end-goal.  One way to do this is by publishing a model to the SAS Micro Analytic Score Service.  And just as in my blog where I was publishing to Hadoop, SAS Model Manager can help with that.

 

But what is SAS Micro Analytics Score Service? SAS Micro Analytic Service or MAS is a memory-resident, high-performance program execution service. As a SAS platform service, it is not available for individual license, but is included in selected SAS solutions (SAS Event Stream Processing, SAS Decision Manager and SAS Model Manager).

 

Let’s see how MAS works with SAS Model Manager.  When SAS Model Manager is installed, a publishing destination for SAS Micro Analytic Service is created automatically -- it’s named “maslocal.”  So users can publish models to this SAS Micro Analytic Service publishing destination.

 

1.jpg

 

Let’s publish the Interactive_Forest that I was publishing in my blog to Hadoop now to MAS.  For that you can open the model in SAS Model manager.  We know that the model is in SAS Model Manager because we see in SAS Model Studio that it has been registered in SAS Model Manager:

 

 2.jpg

 

Important note 1: Validate the score code type

 

After opening the model in SAS Model Manager and before starting to publish to a MAS destination, it’s best to validate the score code type of your model.  That score code type can be found on the properties tab when opening the model details in SAS Model Manager.

 

3.jpg

 

Models with a score code type of DATA step, DS2 package, or DS2 multi-type can be published to the SAS Micro Analytic Service.

 

Important note 2: Configure Analytic Store file system paths

When the model that needs to be published is an analytic store, there’s some extra configuration required.  This is because the compute service will extract the analytic store (ASTORE) from the analytic store’s CAS table.  This table is located in the ModelStore caslib and the compute service copies the ASTORE to the /opt/sas/viya/config/data/modelsvr/astore directory.  Each server that hosts the SAS MAS service must have access to a /models/astores/viya file system path which maps to the /opt/sas/viya/config/data/modelsvr/astore directory.

 

Details for the above remark can be found here.

 

It should look like this:

 

4.jpg

 

Once the conditions are fulfilled, we can publish the selected model:

 

5.jpg6.jpg

 

For some more information around ASTORE and Viya 3.3 have a look here

 

With SAS Viya 3.4, there are even more procedures that can create ASTORE models:

  • BNET                     Bayesian Network
  • FACTMAC           Factorization Machine
  • FOREST                 Random Forest
  • GMM                   Gaussian Mixture Model (for Cluster Analysis / Anomaly Detection)
  • GRADBOOST     Gradient Boosting
  • MBANALYSIS     Market Basket Analysis
  • MTLEARN            Multitask Learning
  • RPCA                    Robust Principal Component Analysis
  • SVMACHINE      Support Vector Machine
  • SVDD                    Support Vector Data Description
  • TEXTMINE          Text Mining

 

After a successful publishing of the model you should see the following:

 

7.jpg

 

As mentioned before (and documented in this blog) I published the same model to Hadoop.  So the same model is now published to two different target destinations.

 

 8.jpg

 

After publishing the model to the SAS Micro Analytical Service, we can now call this model via REST API’s from other solutions.

 

Consume the published MAS model

 

Next step is to consume this model via SAS Viya REST APIs.  The API’s are based on resource-oriented URLs.  The SAS Viya REST APIs are grouped for convenience into a number of API categories.  For now we want to list and execute the MAS deployed models. 

The API’s we need for that are coming from the Decision Management group.  The documentation can be found on developer.sas.com:

https://developer.sas.com/guides/rest.html

 

9.jpg

 

Important note: before start using REST APIs you need to:

Configure your SAS Environment for API Use:

  1. Registering a client
  2. Setting Cross-Origin Resource Sharing (CORS) Options. See Setting CORS options in SAS Viya for details.

 

Understand Authentication and Access tokens: a client application that needs to make a REST API request must first be authenticated and obtain an access token. That token is then used on subsequent requests.

Info around this can be found here.

 

After configuring the environment, you can start submitting your GET and POST requests

For instance, to retrieve the collection of published MAS modules we can use:

GET /modules

 

10.jpg

https://developer.sas.com/apis/rest/DecisionManagement/?shell#get-loaded-modules

 

When doing this request with Postman it looks like this:

 

11.jpg

 

Hint: Domain and token are variables you can store within a Postman environment.

 

12.jpg

 

Hint: under tests one can write output to Postman console which is sometimes easier to read then the JSON output.

 

13.jpg14.jpg

 

Having the id of the module allows us to find the steps of the scoring module:

 

GET /modules/{moduleId}/steps

https://developer.sas.com/apis/rest/DecisionManagement/?javascript#get-module-steps

 

15.jpg 

 

From the response, we filter out the input variables which we will use in the scoring step.

 

18.jpg

 

From the response we learn as well that one of the steps is a score step:

 

19.jpg

 

Now we have all information to do the scoring of some input variables:

 

20.jpg

 

You can re-use those API calls through JavaScript in an html page:

 

21.jpg22.jpg

Comments
Thanks Frederik, a very informative blog.

Will there be one demonstrating the DS2 & python methods also?

Hey Alan,

 

thanks for your reply and very good suggestion to create extra article how to execute same model from DS2 & Python code.  I will plan to do that and let you know when ready. 

 

Frederik

 

@alancox 

Please find new article with some DS2 code that is scoring data with same published model in MAS. Python code will follow.

How SAS Model Manager can help in generating DS2 code to run your model in MAS.

Hi Frederik - this is a great post , very useful. I would just like to suggest 2 addl things to watch out for (I say this in pain after searching and figuring it out :))

 

- Those who are trying this in web apps - use JSON.stringify on your final data (the inputs) - execution fails unless everything in that input has proper quotes around the key , values etc. - irritating but necessary - in short - it should be a JSON string, not a JS object.

 

- the headers are also an important part of this process - especially in an app - include "application/vnd.sas.microanalytic.module.step.input+json" as the content-type

 

thanks and regards,

Sundaresh

@SundareshS 

 

Thanks Sundaresh for the feedback and sorry to hear it took you some time to figure things out, I'm sure you learnt a lot.. 

 

Regading the input data here how it was created in the app:

 var pl = $('#petallength').val() ;
 var pw = $('#petalwidth').val() ;
 var sl = $('#sepallength').val() ;
 var sw = $('#sepalwidth').val() ;
 var dataString = JSON.stringify({"inputs":[{"name":"petallength","value":+pw},         {"name":"petalwidth","value":+pl},{"name":"sepallength","value":+sl},   {"name":"sepalwidth","value":+sw}]});

 

Regarding the headers it's true what you are saying, the problem is that different REST calls requires different headers, so that was a bit difficult to explain into detail when writing this blog .  Here you have some examples of headers used in the web app:

    xhr.setRequestHeader('Content-Type', 'application/vnd.sas.models.model.summary');

  xhr.setRequestHeader('Content-Type', 'application/vnd.sas.microanalytic.module.step');

  xhr.setRequestHeader('Content-Type', 'application/vnd.sas.microanalytic.module.step.input+json');

 

So hope this helps.

 

Frederik.

 

 

Hi @FrederikV  - is the source code for the web app you're referencing available in the SAS github? It would be a useful demo to use & learn from when using this particular aspect of the Viya platform.

 

thanks

 

Alan

Hi @alancox , I uploaded the main html file of the test web app on my personal Github.

Let me know if you can access.

mas_sample

 

Regards,

Frederik

Thanks @FrederikV  that's great !

Frederik,

Great write.

At a point you have a web page 'Deploying and Building SAS Applications'. I guess this is what you meant by 'You can re-use those API calls through JavaScript in an html page'.

How or where can you find that page?

 

 

Hi Bogdan, there's an exampe on this github project: mas_sample

Frederik

Version history
Last update:
‎03-28-2019 02:13 PM
Updated by:
Contributors

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

Article Tags