truss


Nametruss JSON
Version 0.9.70 PyPI version JSON
download
home_pageNone
SummaryA seamless bridge from model development to model delivery
upload_time2025-03-20 00:17:10
maintainerNone
docs_urlNone
authorPankaj Gupta
requires_python<3.13,>=3.9
licenseMIT
keywords mlops ai model serving model deployment machine learning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Truss

**The simplest way to serve AI/ML models in production**

[![PyPI version](https://badge.fury.io/py/truss.svg)](https://badge.fury.io/py/truss)
[![ci_status](https://github.com/basetenlabs/truss/actions/workflows/release.yml/badge.svg)](https://github.com/basetenlabs/truss/actions/workflows/release.yml)

## Why Truss?

* **Write once, run anywhere:** Package and test model code, weights, and dependencies with a model server that behaves the same in development and production.
* **Fast developer loop:** Implement your model with fast feedback from a live reload server, and skip Docker and Kubernetes configuration with a batteries-included model serving environment.
* **Support for all Python frameworks**: From `transformers` and `diffusers` to `PyTorch` and `TensorFlow` to `TensorRT` and `Triton`, Truss supports models created and served with any framework.

See Trusses for popular models including:

* 🦙 [Llama 2 7B](https://github.com/basetenlabs/truss-examples/tree/main/llama/llama-2-7b-chat) ([13B](https://github.com/basetenlabs/truss-examples/tree/main/llama/llama-2-13b-chat)) ([70B](https://github.com/basetenlabs/truss-examples/tree/main/llama/llama-2-70b-chat))
* 🎨 [Stable Diffusion XL](https://github.com/basetenlabs/truss-examples/tree/main/stable-diffusion/stable-diffusion-xl-1.0)
* 🗣 [Whisper](https://github.com/basetenlabs/truss-examples/tree/main/whisper/whisper-truss)

and [dozens more examples](https://github.com/basetenlabs/truss-examples/).

## Installation

Install Truss with:

```
pip install --upgrade truss
```

## Quickstart

As a quick example, we'll package a [text classification pipeline](https://huggingface.co/docs/transformers/main_classes/pipelines) from the open-source [`transformers` package](https://github.com/huggingface/transformers).

### Create a Truss

To get started, create a Truss with the following terminal command:

```sh
truss init text-classification
```

When prompted, give your Truss a name like `Text classification`.

Then, navigate to the newly created directory:

```sh
cd text-classification
```

### Implement the model

One of the two essential files in a Truss is `model/model.py`. In this file, you write a `Model` class: an interface between the ML model that you're packaging and the model server that you're running it on.

There are two member functions that you must implement in the `Model` class:

* `load()` loads the model onto the model server. It runs exactly once when the model server is spun up or patched.
* `predict()` handles model inference. It runs every time the model server is called.

Here's the complete `model/model.py` for the text classification model:

```python
from transformers import pipeline


class Model:
    def __init__(self, **kwargs):
        self._model = None

    def load(self):
        self._model = pipeline("text-classification")

    def predict(self, model_input):
        return self._model(model_input)
```

### Add model dependencies

The other essential file in a Truss is `config.yaml`, which configures the model serving environment. For a complete list of the config options, see [the config reference](https://truss.baseten.co/reference/config).

The pipeline model relies on [Transformers](https://huggingface.co/docs/transformers/index) and [PyTorch](https://pytorch.org/). These dependencies must be specified in the Truss config.

In `config.yaml`, find the line `requirements`. Replace the empty list with:

```yaml
requirements:
  - torch==2.0.1
  - transformers==4.30.0
```

No other configuration is needed.

## Deployment

Truss is maintained by [Baseten](https://baseten.co), which provides infrastructure for running ML models in production. We'll use Baseten as the remote host for your model.

Other remotes are coming soon, starting with AWS SageMaker.

### Get an API key

To set up the Baseten remote, you'll need a [Baseten API key](https://app.baseten.co/settings/account/api_keys). If you don't have a Baseten account, no worries, just [sign up for an account](https://app.baseten.co/signup/) and you'll be issued plenty of free credits to get you started.

### Run `truss push`

With your Baseten API key ready to paste when prompted, you can deploy your model:

```sh
truss push
```

You can monitor your model deployment from [your model dashboard on Baseten](https://app.baseten.co/models/).

### Invoke the model

After the model has finished deploying, you can invoke it from the terminal.

**Invocation**

```sh
truss predict -d '"Truss is awesome!"'
```

**Response**

```json
[
  {
    "label": "POSITIVE",
    "score": 0.999873161315918
  }
]
```

## Truss contributors

Truss is backed by Baseten and built in collaboration with ML engineers worldwide. Special thanks to [Stephan Auerhahn](https://github.com/palp) @ [stability.ai](https://stability.ai/) and [Daniel Sarfati](https://github.com/dsarfati) @ [Salad Technologies](https://salad.com/) for their contributions.

We enthusiastically welcome contributions in accordance with our [contributors' guide](CONTRIBUTING.md) and [code of conduct](CODE_OF_CONDUCT.md).


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "truss",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.13,>=3.9",
    "maintainer_email": null,
    "keywords": "MLOps, AI, Model Serving, Model Deployment, Machine Learning",
    "author": "Pankaj Gupta",
    "author_email": "pankaj@baseten.co",
    "download_url": "https://files.pythonhosted.org/packages/c0/9b/b69e35b098b78a29bcc41ad707ebd604593579f3ca6b5d1fb8034e012237/truss-0.9.70.tar.gz",
    "platform": null,
    "description": "# Truss\n\n**The simplest way to serve AI/ML models in production**\n\n[![PyPI version](https://badge.fury.io/py/truss.svg)](https://badge.fury.io/py/truss)\n[![ci_status](https://github.com/basetenlabs/truss/actions/workflows/release.yml/badge.svg)](https://github.com/basetenlabs/truss/actions/workflows/release.yml)\n\n## Why Truss?\n\n* **Write once, run anywhere:** Package and test model code, weights, and dependencies with a model server that behaves the same in development and production.\n* **Fast developer loop:** Implement your model with fast feedback from a live reload server, and skip Docker and Kubernetes configuration with a batteries-included model serving environment.\n* **Support for all Python frameworks**: From `transformers` and `diffusers` to `PyTorch` and `TensorFlow` to `TensorRT` and `Triton`, Truss supports models created and served with any framework.\n\nSee Trusses for popular models including:\n\n* \ud83e\udd99 [Llama 2 7B](https://github.com/basetenlabs/truss-examples/tree/main/llama/llama-2-7b-chat) ([13B](https://github.com/basetenlabs/truss-examples/tree/main/llama/llama-2-13b-chat)) ([70B](https://github.com/basetenlabs/truss-examples/tree/main/llama/llama-2-70b-chat))\n* \ud83c\udfa8 [Stable Diffusion XL](https://github.com/basetenlabs/truss-examples/tree/main/stable-diffusion/stable-diffusion-xl-1.0)\n* \ud83d\udde3 [Whisper](https://github.com/basetenlabs/truss-examples/tree/main/whisper/whisper-truss)\n\nand [dozens more examples](https://github.com/basetenlabs/truss-examples/).\n\n## Installation\n\nInstall Truss with:\n\n```\npip install --upgrade truss\n```\n\n## Quickstart\n\nAs a quick example, we'll package a [text classification pipeline](https://huggingface.co/docs/transformers/main_classes/pipelines) from the open-source [`transformers` package](https://github.com/huggingface/transformers).\n\n### Create a Truss\n\nTo get started, create a Truss with the following terminal command:\n\n```sh\ntruss init text-classification\n```\n\nWhen prompted, give your Truss a name like `Text classification`.\n\nThen, navigate to the newly created directory:\n\n```sh\ncd text-classification\n```\n\n### Implement the model\n\nOne of the two essential files in a Truss is `model/model.py`. In this file, you write a `Model` class: an interface between the ML model that you're packaging and the model server that you're running it on.\n\nThere are two member functions that you must implement in the `Model` class:\n\n* `load()` loads the model onto the model server. It runs exactly once when the model server is spun up or patched.\n* `predict()` handles model inference. It runs every time the model server is called.\n\nHere's the complete `model/model.py` for the text classification model:\n\n```python\nfrom transformers import pipeline\n\n\nclass Model:\n    def __init__(self, **kwargs):\n        self._model = None\n\n    def load(self):\n        self._model = pipeline(\"text-classification\")\n\n    def predict(self, model_input):\n        return self._model(model_input)\n```\n\n### Add model dependencies\n\nThe other essential file in a Truss is `config.yaml`, which configures the model serving environment. For a complete list of the config options, see [the config reference](https://truss.baseten.co/reference/config).\n\nThe pipeline model relies on [Transformers](https://huggingface.co/docs/transformers/index) and [PyTorch](https://pytorch.org/). These dependencies must be specified in the Truss config.\n\nIn `config.yaml`, find the line `requirements`. Replace the empty list with:\n\n```yaml\nrequirements:\n  - torch==2.0.1\n  - transformers==4.30.0\n```\n\nNo other configuration is needed.\n\n## Deployment\n\nTruss is maintained by [Baseten](https://baseten.co), which provides infrastructure for running ML models in production. We'll use Baseten as the remote host for your model.\n\nOther remotes are coming soon, starting with AWS SageMaker.\n\n### Get an API key\n\nTo set up the Baseten remote, you'll need a [Baseten API key](https://app.baseten.co/settings/account/api_keys). If you don't have a Baseten account, no worries, just [sign up for an account](https://app.baseten.co/signup/) and you'll be issued plenty of free credits to get you started.\n\n### Run `truss push`\n\nWith your Baseten API key ready to paste when prompted, you can deploy your model:\n\n```sh\ntruss push\n```\n\nYou can monitor your model deployment from [your model dashboard on Baseten](https://app.baseten.co/models/).\n\n### Invoke the model\n\nAfter the model has finished deploying, you can invoke it from the terminal.\n\n**Invocation**\n\n```sh\ntruss predict -d '\"Truss is awesome!\"'\n```\n\n**Response**\n\n```json\n[\n  {\n    \"label\": \"POSITIVE\",\n    \"score\": 0.999873161315918\n  }\n]\n```\n\n## Truss contributors\n\nTruss is backed by Baseten and built in collaboration with ML engineers worldwide. Special thanks to [Stephan Auerhahn](https://github.com/palp) @ [stability.ai](https://stability.ai/) and [Daniel Sarfati](https://github.com/dsarfati) @ [Salad Technologies](https://salad.com/) for their contributions.\n\nWe enthusiastically welcome contributions in accordance with our [contributors' guide](CONTRIBUTING.md) and [code of conduct](CODE_OF_CONDUCT.md).\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A seamless bridge from model development to model delivery",
    "version": "0.9.70",
    "project_urls": {
        "Baseten": "https://baseten.co",
        "Bug Reports": "https://github.com/basetenlabs/truss/issues",
        "Documentation": "https://truss.baseten.co",
        "Homepage": "https://truss.baseten.co",
        "Repository": "https://github.com/basetenlabs/truss"
    },
    "split_keywords": [
        "mlops",
        " ai",
        " model serving",
        " model deployment",
        " machine learning"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "efa9c22c1e1f361f2f65cb91d74515cdfb1ca47c04a933e5dce2733873f5f9f3",
                "md5": "1e8c91bac6c4263c5e50b020bd923d1e",
                "sha256": "ef5edb309061dc08405fbe8cdeddb3a08c5ec8a3d4d619538a5bb5d69ba80a5d"
            },
            "downloads": -1,
            "filename": "truss-0.9.70-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1e8c91bac6c4263c5e50b020bd923d1e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.9",
            "size": 407880,
            "upload_time": "2025-03-20T00:17:07",
            "upload_time_iso_8601": "2025-03-20T00:17:07.581923Z",
            "url": "https://files.pythonhosted.org/packages/ef/a9/c22c1e1f361f2f65cb91d74515cdfb1ca47c04a933e5dce2733873f5f9f3/truss-0.9.70-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c09bb69e35b098b78a29bcc41ad707ebd604593579f3ca6b5d1fb8034e012237",
                "md5": "9a7e621d541b421df85f973d80f53aee",
                "sha256": "a3cf6a8cd6e07e50b34d8f775dddb62f2f657aab2420149641f4ebb949b3353d"
            },
            "downloads": -1,
            "filename": "truss-0.9.70.tar.gz",
            "has_sig": false,
            "md5_digest": "9a7e621d541b421df85f973d80f53aee",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.9",
            "size": 304125,
            "upload_time": "2025-03-20T00:17:10",
            "upload_time_iso_8601": "2025-03-20T00:17:10.155927Z",
            "url": "https://files.pythonhosted.org/packages/c0/9b/b69e35b098b78a29bcc41ad707ebd604593579f3ca6b5d1fb8034e012237/truss-0.9.70.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-03-20 00:17:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "basetenlabs",
    "github_project": "truss",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "truss"
}
        
Elapsed time: 7.94917s