truss


Nametruss JSON
Version 0.9.57 PyPI version JSON
download
home_pagehttps://github.com/basetenlabs/truss
SummaryA seamless bridge from model development to model delivery
upload_time2024-12-16 19:43:08
maintainerNone
docs_urlNone
authorPankaj Gupta
requires_python<3.13,>=3.8
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": "https://github.com/basetenlabs/truss",
    "name": "truss",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.13,>=3.8",
    "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/56/55/25679bde17c9603cdaa5c23cf2b77b5a6ae17049be0bd8d3eff67a089c11/truss-0.9.57.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",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A seamless bridge from model development to model delivery",
    "version": "0.9.57",
    "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": "",
            "digests": {
                "blake2b_256": "cda0494eab098719b6a133611a1d6795afda30130e670a8122fd20a8c9ed3682",
                "md5": "bf726d4b4a01286df8f1633ae6afc3d6",
                "sha256": "3cca9ae25d93870825fe6433c0308b71d6384f4f3f0fb6a5f8e7b3e0cbfe5599"
            },
            "downloads": -1,
            "filename": "truss-0.9.57-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bf726d4b4a01286df8f1633ae6afc3d6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.8",
            "size": 376564,
            "upload_time": "2024-12-16T19:43:06",
            "upload_time_iso_8601": "2024-12-16T19:43:06.595658Z",
            "url": "https://files.pythonhosted.org/packages/cd/a0/494eab098719b6a133611a1d6795afda30130e670a8122fd20a8c9ed3682/truss-0.9.57-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "565525679bde17c9603cdaa5c23cf2b77b5a6ae17049be0bd8d3eff67a089c11",
                "md5": "5fa492b547ff4618f302c3a593de30b8",
                "sha256": "69d092c7e450a4ee06062e163fe0c904ab6114481d36f3b2c52ee048b9267835"
            },
            "downloads": -1,
            "filename": "truss-0.9.57.tar.gz",
            "has_sig": false,
            "md5_digest": "5fa492b547ff4618f302c3a593de30b8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.8",
            "size": 281428,
            "upload_time": "2024-12-16T19:43:08",
            "upload_time_iso_8601": "2024-12-16T19:43:08.464465Z",
            "url": "https://files.pythonhosted.org/packages/56/55/25679bde17c9603cdaa5c23cf2b77b5a6ae17049be0bd8d3eff67a089c11/truss-0.9.57.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-16 19:43:08",
    "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: 0.43336s