Many organizations produce powerful analytical models but then struggle to deploy them into production. Research by SAS shows that less than 50% of models are deployed. What’s more, over 90% of deployed models take at least three months to be deployed into production, and about 44% of models take over seven months.
How can you speed up this process? One way is to publish your model to a container. In this blog, I am going to show you how to do this using SAS Model Manager.
The ability to publish to a container destination is a new feature that has been added to the new release of SAS Model Manager. This makes it easier to deploy your model into production. One of the biggest advantages of containers is that you only have to build them once, and you can then run them anywhere. When you build a container, you include all the necessary dependencies to run your application or analytical model. This allows you to move your analytical model into production without having to manage these dependencies again. This is particularly useful for open source models, because it can become quite difficult to manage the different versions of packages used by a model.
Another advantage of this ‘build once, run anywhere’ approach is that it allows you to scale the computational resources required to run your model. You can start by running the container on a local docker installation, but if you start to need more resources you can just pick up the container and deploy it elsewhere—say on a Kubernetes cluster running in the cloud, where you will, in theory, have infinite resources available.
To publish Python or R models to a container, you need Docker. You can either use an existing installation of Docker that is running on a separate machine or you can install Docker on the same machine as your model management software.
To use an existing installation of Docker, you will need to configure the Docker host to go through TCP. For more about this process, click on this page.
To use Docker on the same machine as your model management software, you may need to draw on some technical support, because this may need some additional configuration of your system.
Registry
You need to have a Docker registry available to store the Docker images. This can either be a private registry or an AWS Elastic Container Registry (AWS ECR).
There are three steps to publishing Python or R models to a container destination:
I’m using SAS Model Manager, which supports publishing to both a private Docker registry and an AWS Elastic Container Registry (AWS ECR).
Screenshot shows an example of a docker registry destination defined in Model Manager
To define a private Docker registry as a destination in Model Manager, you will need to use the Model Publish API service via an API call. You will need to provide the properties for a destination.
For example, if you want to define a private Docker registry, you would need to create the following request using a REST client like postman, curl or application code like Python.
URL: http://<server>/modelPublish/destinations/
Content-Type: application/vnd.sas.models.publishing.destination.privatedocker+json
Access-Token: please refer to these instructions on how to authenticate against the Viya system
Request body
{ "name": "PrivateDocker", "destinationType": "privateDocker", "properties": [{ "name": "baseRepoUrl", "value": "<YOUR REGISTRY>" }] } |
The second step is to build the runtime container base images. SAS Model Manager can register open source models built in either R or Python. It has three different base images, python 2, python 3 and R, depending on what you’re using. Before you can publish a model to one of the defined container destinations, these base images need to be built using the Model Publish API service. This service uses Docker to build the container base images and push them to the Docker registry.
To build the images, use a REST client like postman, curl or application code like Python to execute the REST call.
URL: http://<server>/modelPublish/models
Content-Type: application/vnd.sas.models.publishing.request+json
Access-Token: please refer to these instructions on how to authenticate against the Viya system
Request body
{ "name":"publish python3 baseimage", "modelContents":[ { "modelName": "python", "modelId": "base", "modelVersionId": "3" } ], "destinationName": <YOUR-DESTINATION-NAME> } |
Make sure that you substitute the destination name with the name of the destination that you created in the previous step!
Generating an R base image requires several modifications to the request body, so here’s an example of the request body that you can use to generate the R base image:
{ "name":"publish R baseimage", "modelContents":[ { "modelName": "r", "modelId": "base" } ], "destinationName": <YOUR-DESTINATION-NAME> } |
The final step is to publish the model into a runtime container. In SAS Model Manager, this is done through the main software interface in several steps:
After you click on ‘publish’, the software will create a new docker image containing the model. This image can then be used to create a runtime container to execute your model.
Model management software can be an easy way to help organizations to get analytical models deployed into production, especially when it supports the use of containers. Have you tried this approach, in SAS Model Manager or elsewhere? I’d love to hear about your experience.
Good article Alex!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.