Sagemaker SKLearn Example

  • Train a model on AWS Sagemaker

  • Deploy locally on Seldon Core

This tutorial assumes you are already familiar with Sagemaker and have an AWS account you can use.

Dependencies

  • AWS CLI

  • Docker

  • Git

  • Minikube

Train Scikit-learn Iris Model

We will use the Sagemaker example notebook Iris Training and Prediction with Sagemaker Scikit-learn

  1. Run this notebook inside Sagemaker but change the training step to include an output_path parameter with value an S3 bucket you have created. For example output_path="s3://<my-bucket>/<my-path> as shown below:

  2. Once trained you should find the model saved to the location you specified. You will need to use this S3 location later when deploying locally.

Create Sagemaker SKLearn Image

To run your model locally you will need to create the sagemaker sklearn image

Build the base container.

Specify the location of the model.tar.gz that AWS Sagemaker created on S3 An example is shown below.

Prepare Prediction Code

We will create the methods required to load and predict against our trained model as a module that can be loaded by the Sagemaker scikit-learn-container image we created.

Package the code as a tar.gz file

Set the path to store the code

We can now do a local test with Docker. To make this work you will need to have your aws credentials in ~/.aws/config.

Test the running image with a prediction call

Test with Seldon-Core in Minikube

Setup Seldon Core

Use the setup notebook to Setup Cluster with Ambassador Ingress and Install Seldon Core. Instructions also online.

Wrap Model and Test

Recreate the Sagemaker scikit-learn base and final containers inside Minikube. In a production scenario you would build these images and push to your DockerHub or private repo.

Create AWS Credential Secret from Template

Edit aws-config-secret.yaml and fill in the base64 encoded values, for example you can run on linux:

echo -n <my_aws_access_id> | base64

Take the value and place into the file.

Once completed you can create the secret via kubectl

Create Seldon Deployment from Template

We will use the environment variables you set above to fill in the details for the Seldon Deployment so the Sagemake image container knows where to download your code.

Test Predictive Endpoint

Teardown

Last updated

Was this helpful?