BookmarkSubscribeRSS Feed

Publishing your model into a container

Started ‎12-13-2019 by
Modified ‎12-13-2019 by
Views 5,379

Publishing your model into a container

 

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.

 

Why use containers?

 

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.

 

What do you need for container publishing?

 

Docker

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).

 

Three-step process to publish your model into a container

 

There are three steps to publishing Python or R models to a container destination:

 

  1. Define a publishing destination in your model management software

I’m using SAS Model Manager, which supports publishing to both a private Docker registry and an AWS Elastic Container Registry (AWS ECR).

 

publishing-destinations.png

 

 

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>"

            }]

}

 

  1. Build the runtime container base image

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>

}

 

  1. Publish model into runtime container

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:

 

  1. Open the project that contains the Python or R model you would like to deploy.
  2. Select the model and make sure that it is set as the champion.
  3. Click on three vertical dots in the upper right side of the screen and select

   

 

publish.png

 

  1. This will bring up a screen in which you can select the publishing destination

 

publish-models.png

 

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.

 

Conclusion

 

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.

 

Comments

Good article Alex!

Version history
Last update:
‎12-13-2019 06:06 AM
Updated by:
Contributors

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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 Labels
Article Tags