Truss Deployment Guide to SaladCloud Portal and API
Introduction
Truss is a Python library that simplifies the deployment of machine learning models by creating containerized models that can be served via HTTP requests. This guide will show you how to deploy a Truss container to SaladCloud Portal and ** SaladCloud API** so that your model can be accessed from anywhere.
Prerequisites Before you begin, you will need the following:
- A SaladCloud account
- A project in SaladCloud
- A container image built using Truss
- The Truss library installed.
Truss requires Python >=3.7 and <3.11. To install Truss from PyPi, To install Truss, run this command:
Here is a complete guide and docs to guide you through Truss
Step 1: Obtain Your API Key
To authenticate your API requests, you’ll need an API key. To obtain your API key, follow these steps:
- Log in to your SaladCloud account at https://portal.salad.com
- Click on your profile in the top right corner of the page, then click API Key.
- Copy the API key that is displayed. You’ll need this in the next step.
Step 2: Package Your Model
Before deploying your model to SaladCloud Portal and API, you need to package it as a Truss container. Follow these steps:
- Install the required dependencies for your model. For example, if you used
scikit-learn
to create your model, run:pip install --upgrade scikit-learn truss
- Create your model using the Truss library. For example, if you used
scikit-learn
to create your model, run the following code:
- Serve your model locally using Docker by running:
The container will start running on port 8080.
- Ensure that the container is running, then invoke the model as an API using a POST request:
- Configure Your Model for Deployment : To configure your Truss, include a file config.yaml in the root directory of your Truss. Configuration is optional, as every configurable value has a sensible default. The Truss we generated in the quickstart sample provides a good example of a typical Truss config:
-
Create a Docker image for your Truss model by following the steps outlined in the Quickstart: making a Truss” section of the Truss documentation guide. Make sure to replace “iris_rfc_truss” with a name that reflects your model.
-
Upload your container to Dockerhub First, ensure that you have a DockerHub account. If you don’t, create one at https://hub.docker.com/signup.
-
Next, create a Docker image for your Truss model. This can be done by running the following command in your terminal or command prompt:
-
Build the Docker image by running the following command in your terminal:
-
Replace
<image-name>
with a name for your Docker image and<path-to-Dockerfile>
with the path to the directory containing your Dockerfile. -
Once the build process is complete, you can push the image to DockerHub by running the following command:
- Test your Docker image by running the following command in your terminal:
-
This should start the Truss container and make it available at http://localhost:8080.
-
Stop the running Docker container by running the following command in your terminal:
Step 3: Deploy the Container Image to SaladCloud Portal.
Follow this step-by-step guide to deploy a container to SaladCloud Portal here
Step 4: Deploy the Container Image to SaladCloud API
To deploy your container image to SaladCloud API, follow these steps:
- Send a POST request to the following URL:
Replace organization_name}
and {project_name}
with the name of your organization and project, respectively.
- In the headers of the POST request, include
accept: application/json
andcontent-type: application/json
. - In the body of the POST request, include the following JSON data, replacing
{API_KEY}
with your SaladCloud API key and{CONTAINER_IMAGE_URL}
with the URL of your container image:
- Send a POST request using
curl
- Check the status of the deployment by sending a GET request to the following URL:
Congratulations, You have successfully deployed a Truss container to SaladCloud Portal and API! Remember to configure your Truss as needed for deployment and update it regularly. If you encounter any issues or have any questions, don’t hesitate to reach out to the SaladCloud support team.
Was this page helpful?