Deploying your Kaggle models to Baseten

👋 Introduction

Hi y’all! I’m Jesse Mostipak, a Developer Advocate here at Baseten. Before joining Baseten I was a Developer Advocate at RStudio, and before RStudio I had my first ever Developer Advocate role at Kaggle. And while there are about a million things I’d love to talk with you all about, I wanted to focus my first blog post on Truss, an open source solution for model deployment, created here at Baseten.

Why a Kaggle notebook

I really like using Kaggle notebooks because they connect readily to Kaggle datasets, and then I can take advantage of GPU and TPU accelerators for my model training. I also really enjoy being able to see what other people have created, and then fork their notebooks and adapt them to my own projects.  

And so when I started working with Truss, I wondered how easy it would be to use it to get a model from Kaggle and deploy it to the Baseten platform. It worked perfectly the first time I tried it, which made me so excited that I wanted to share it with everyone! 

You can access the full notebook here, or follow along with the code and information below!

💻 Let’s code!

From within your Kaggle notebook, we’ll start by adding Truss:

!pip install truss

And then setting up our environment:

import truss
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris

From there we’ll load the iris dataset and train a Random Forest Classifier model:

iris = load_iris()
data_x = iris['data']
data_y = iris['target']
rfc = RandomForestClassifier()
rfc.fit(data_x, data_y)

And now for Truss! Truss works by serializing and packaging our model as a Docker image, and all you need is one line of code 😍 We’ll create a Truss like this:

my_truss = truss.mk_truss(rfc, target_directory="iris_rfc_truss")

🐋 Deploying our model from Kaggle to Baseten

While you can deploy your model to any service that uses Docker (such as Google Cloud Run or AWS ECS), we’re going to deploy to Baseten. 

For this little adventure, you’ll need:

And you won’t need:

  • Your wallet. Baseten allows all users to have one (1) free model and one (1) free application! Oh, did I not mention this? Baseten is also a platform where you can monitor your model’s health, build or connect to data tables, and quickly and efficiently build entire web applications for your end users. 
!pip install baseten
baseten.login("your-API-key-goes-here")
baseten.deploy_truss(my_truss)
Screenshot from a Kaggle notebook showing the model deployment message from Baseten, indicating that the deployment was successful and our model's name is "amiable-beluga"

When you run the above code you’ll see the output in your Kaggle notebook, similar to the image above. To see your model (and work with it on the Baseten platform) log in to Baseten, and click on Models. If you go to Baseten right away you’ll likely see that your model is still being built, but within a few minutes it should be active, allowing you to call the model as well as start building out an application.

💚 Learn more about Baseten + Truss 

If you’d like to learn more about Truss you can check out our Truss documentation here. And feel free to check out the Truss GitHub repo, where you can keep an eye on things by starring the repo, as well as file issues and provide feedback.

If you’d like to explore what to do with your model now that it’s been deployed to Baseten, follow along with our very own Philip Kiely as he walks you through building a starter application! And if you’re more of the “choose your own adventure” type, our Docs are a great way to get started, while our Gallery is the perfect place to find some inspiration.