Skip to main content

A seamless bridge from model development to model delivery

Project description

Truss

Serve any model without boilerplate code

Truss logo

PyPI version ci_status

Meet Truss, a seamless bridge from model development to model delivery. Truss presents an open-source standard for packaging models built in any framework for sharing and deployment in any environment, local or production.

Get started with the end-to-end tutorial.

What can I do with Truss?

If you've ever tried to get a model out of a Jupyter notebook, Truss is for you.

Truss exposes just the right amount of complexity around things like Docker and APIs without you really having to think about them. Here are some of the things Truss does:

  • 🏎 Turns your Python model into a microservice with a production-ready API endpoint, no need for Flask or Django.
  • 🎚 For most popular frameworks, includes automatic model serialization and deserialization.
  • 🛍 Freezes dependencies via Docker to make your training environment portable.
  • 🕰 Enables rapid iteration with local development that matches your production environment.
  • 🗃 Encourages shipping parsing and even business logic alongside your model with integrated pre- and post-processing functions.
  • 🤖 Supports running predictions on GPUs. (Currently limited to certain hardware, more coming soon)
  • 🙉 Bundles secret management to securely give your model access to API keys.

Installation

Truss requires Python >=3.7, <3.11

To install from PyPi, run:

pip install truss

To download the source code directly (for development), clone this repository and follow the setup commands in our contributors' guide.

Truss is actively developed, and we recommend using the latest version. To update your Truss installation, run:

pip install --upgrade truss

Though Truss is in beta, we do care about backward compatibility. Review the release notes before upgrading, and note that we follow semantic versioning, so any breaking changes require the release of a new major version.

How to use Truss

Generate and serve predictions from a Truss with this Jupyter notebook.

Quickstart: making a Truss

!pip install --upgrade scikit-learn truss

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

# Load the iris data set
iris = load_iris()
data_x = iris['data']
data_y = iris['target']

# Train the model
rfc = RandomForestClassifier()
rfc.fit(data_x, data_y)

# Create the Truss (serializing & packaging model)
tr = truss.mk_truss(rfc, target_directory="iris_rfc_truss")

# Serve a prediction from the model
tr.server_predict({"inputs": [[0, 0, 0, 0]]})

Package your model

The truss.mk_truss() command can be used with any supported framework:

But in more complex cases, you can build a Truss manually for any model. Start with truss init my_truss and follow this guide.

Serve your model locally

Serving your model with Truss, on Docker, lets you interface with your model via HTTP requests. Start your model server with:

truss run-image iris_rfc_truss

Then, as long as the container is running, you can invoke the model as an API as follows:

curl -X POST http://127.0.0.1:8080/v1/models/model:predict -d '{"inputs": [[0, 0, 0, 0]]}'

Configure your model for deployment

Truss is configurable to its core. Every Truss must include a file config.yaml in its root directory, which is automatically generated when the Truss is created. However, configuration is optional. Every configurable value has a sensible default, and a completely empty config file is valid.

The Truss we generated above in the quickstart sample has a good example of a typical Truss config:

model_framework: sklearn
model_metadata:
  model_binary_dir: model
  supports_predict_proba: true
python_version: py39
requirements:
- scikit-learn==1.0.2
- threadpoolctl==3.0.0
- joblib==1.1.0
- numpy==1.20.3
- scipy==1.7.3

Follow the configuration guide and use the complete reference of configurable properties to make your Truss perform exactly as you wish.

Deploy your model

You can deploy a Truss anywhere that can run a Docker image, as well as purpose-built platforms like Baseten.

Follow step-by-step deployment guides for the following platforms:

Contributing

We hope this vision excites you, and we gratefully welcome contributions in accordance with our contributors' guide and code of conduct.

Truss was first developed at Baseten by maintainers Phil Howes, Pankaj Gupta, and Alex Gillmor.

GitHub Codespace

If your organization allows to access to GitHub Codespaces, you can launch a Codespace for truss development. If you are a GPU Codespace, make sure to use the .devcontainer/gpu/devcontainer.json configuration to have access to a GPU and be able to use it in Docker with truss.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

truss-0.1.13rc1.tar.gz (108.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

truss-0.1.13rc1-py3-none-any.whl (158.0 kB view details)

Uploaded Python 3

File details

Details for the file truss-0.1.13rc1.tar.gz.

File metadata

  • Download URL: truss-0.1.13rc1.tar.gz
  • Upload date:
  • Size: 108.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.9.9 Linux/5.15.0-1023-azure

File hashes

Hashes for truss-0.1.13rc1.tar.gz
Algorithm Hash digest
SHA256 c5bcc0c4ae374d56bb061e37fb2111993156043cef6dc3a26e10ca7e8ece8807
MD5 823ca0f130107a2ca99d0a8198f3218a
BLAKE2b-256 2c0d40340b22e13ce9a8c8dfc1c2c02d3ffaf8dc56b7ecb505e11ce493f16c88

See more details on using hashes here.

File details

Details for the file truss-0.1.13rc1-py3-none-any.whl.

File metadata

  • Download URL: truss-0.1.13rc1-py3-none-any.whl
  • Upload date:
  • Size: 158.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.9.9 Linux/5.15.0-1023-azure

File hashes

Hashes for truss-0.1.13rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 c2accea42280190b0431b848d115cdd51762f1a9c3c428df578a4457aafa0891
MD5 c11bb7c1b701e0f5257410e7a1661d11
BLAKE2b-256 73f2e2703d41410a1b57628c6ae88c607bdb04d58e83c8ab3ebac874a0b22b1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page