Using SageMaker models in BaseTen

Pankaj GuptaPankaj Gupta|

Since BaseTen launched, most of our users have been deploying machine learning models through our model deployment service because of its ease-of-use, extensibility, and scalability. However we’ve heard from some people that they are already locked into SageMaker for model deployment, yet still want to use BaseTen to create user-facing applications for their SageMaker models. Today we’re making that possible by launching a native SageMaker integration in BaseTen.

As a reminder, BaseTen makes it easy to build applications with machine learning models. Our mission is to bring models to business value quickly, wherever they are, and it is only natural to support integrations with other model serving platforms. The SageMaker integration is the first step in that direction.

Imported SageMaker models behave just like BaseTen models. You’ll be able to use them as a node in Worklets, and through Worklets make them accessible to your UI views. The integration increases the pool of models you can work with in BaseTen, and as we continue to build to support other model serving platforms, this pool will only grow.

The SageMaker integration is available to all users in our private beta.

Configuring the SageMaker connection

To import your SageMaker models into BaseTen you first need to create a SageMaker connection:

  • Click on your User icon at the bottom of the left sidebar, then click on Data connections, and then click on the New data connection button
  • Choose SageMaker as the Data Connection type
  • Enter your Access Key Id and Secret access key1
  • Enter the Region where the SageMaker model is deployed
  • Test the connection to see if the connection was successful

Importing a model from SageMaker

Once you’ve created the connection, you can bring your SageMaker models into BaseTen using the Import model flow. In this example, we’ve deployed the blazingtext model using this tutorial.

BaseTen lists all the models that are available to import with the specified connection. You can choose the model you want to bring in, the endpoint, and the desired input format (with today’s release, only the models connected to endpoints are available for invocation). BaseTen supports the two most common input formats: CSV and JSON. If your model doesn’t support CSV or JSON then you can still use them through Python nodes.

Once imported, the model will show up on the Models page and you’ll be able to use it in BaseTen. As with other BaseTen models, you can add pre-processing and post-processing nodes before and after your model.

Using SageMaker models in BaseTen

You can use your imported SageMaker models in BaseTen worklets using the Invoke Model node like you would any other model. You can test the node by giving it input as JSON; JSON is automatically converted to CSV if your model needs that.

SageMaker access through a code node

We find the Invoke Model node to be much more user-friendly, but if you need lower level access to the SageMaker API, you can use the SageMaker client directly from the Python code in code nodes. BaseTen provides a Boto3 SageMakerRuntime client, through the context argument, to your code node. You can use this client to perform many operations, including invoking endpoints.

Here’s an example of how to invoke an endpoint using the client in your code node.

import json
import codecs

def do(node_input, env, context):
   sagemaker_client = context.client('My SageMaker Connection')
   model_input = {
       'instances': [
           'Convair was an american aircraft manufacturing company.',
           'Berwick secondary college is situated in a suburb of berwick.',
   endpoint_response_raw = sagemaker_client.invoke_endpoint(
   response = json.load(codecs.getreader(‘utf-8)(endpoint_response_raw['Body']))
   return response

What’s next

We’re continuously adding integrations to BaseTen to accelerate the impact of machine learning with real user-centric use cases. Being able to use BaseTen’s application-building framework with SageMaker models is a step in that direction. We’ll soon be adding native integrations with other model serving platforms. We’d love to hear your thoughts on the SageMaker integration and what you’d like to see next.

  1. Instructions for retrieving your credentials from AWS can be found here. Please note that you may want to create a service account to restrict BaseTen’s access to your AWS details; ensure that the service account has permissions to access SageMaker models.