Skip to main content

BentoML: The easiest way to serve AI apps and models

Project description

BentoML: Unified Model Serving Framework

Unified Model Serving Framework

🍱 Build model inference APIs and multi-model serving systems with any open-source or custom AI models. 👉 Join our Slack community!

License: Apache-2.0 Releases CI Twitter Community

What is BentoML?

BentoML is a Python library for building online serving systems optimized for AI apps and model inference.

  • 🍱 Easily build APIs for Any AI/ML Model. Turn any model inference script into a REST API server with just a few lines of code and standard Python type hints.
  • 🐳 Docker Containers made simple. No more dependency hell! Manage your environments, dependencies and model versions with a simple config file. BentoML automatically generates Docker images, ensures reproducibility, and simplifies how you deploy to different environments.
  • 🧭 Maximize CPU/GPU utilization. Build high performance inference APIs leveraging built-in serving optimization features like dynamic batching, model parallelism, multi-stage pipeline and multi-model inference-graph orchestration.
  • 👩‍💻 Fully customizable. Easily implement your own APIs or task queues, with custom business logic, model inference and multi-model composition. Supports any ML framework, modality, and inference runtime.
  • 🚀 Ready for Production. Develop, run and debug locally. Seamlessly deploy to production with Docker containers or BentoCloud.

Getting started

Install BentoML:

# Requires Python≥3.9
pip install -U bentoml

Define APIs in a service.py file.

from __future__ import annotations

import bentoml

@bentoml.service(
    resources={"cpu": "4"}
)
class Summarization:
    def __init__(self) -> None:
        import torch
        from transformers import pipeline

        device = "cuda" if torch.cuda.is_available() else "cpu"
        self.pipeline = pipeline('summarization', device=device)

    @bentoml.api(batchable=True)
    def summarize(self, texts: list[str]) -> list[str]:
        results = self.pipeline(texts)
        return [item['summary_text'] for item in results]

Run the service code locally (serving at http://localhost:3000 by default):

pip install torch transformers  # additional dependencies for local run

bentoml serve

Now you can run inference from your browser at http://localhost:3000 or with a Python script:

import bentoml

with bentoml.SyncHTTPClient('http://localhost:3000') as client:
    summarized_text: str = client.summarize([bentoml.__doc__])[0]
    print(f"Result: {summarized_text}")

Deploying your first Bento

To deploy your BentoML Service code, configure the runtime environment in service.py.

+ my_image = bentoml.images.PythonImage(python_version="3.11") \
+        .requirements_file("requirements.txt")


@bentoml.service(
+    image=my_image,
    resources={"cpu": "4"},
    traffic={"timeout": 30},
)

Then, choose one of the following ways for deployment:

🐳 Docker Container

Run bentoml build to package necessary code, models, dependency configs into a Bento - the standardized deployable artifact in BentoML:

bentoml build

Ensure Docker is running. Generate a Docker container image for deployment:

bentoml containerize summarization:latest

Run the generated image:

docker run --rm -p 3000:3000 summarization:latest
☁️ BentoCloud

BentoCloud provides compute infrastructure for rapid and reliable GenAI adoption. It helps speed up your BentoML development process leveraging cloud compute resources, and simplify how you deploy, scale and operate BentoML in production.

Sign up for BentoCloud for personal access; for enterprise use cases, contact our team.

# After signup, run the following command to create an API token:
bentoml cloud login

# Deploy from current directory:
bentoml deploy

bentocloud-ui

For detailed explanations, read the Hello World example.

Examples

Check out the full list for more sample code and usage.

Advanced topics

See Documentation for more tutorials and guides.

Community

Get involved and join our Community Slack 💬, where thousands of AI/ML engineers help each other, contribute to the project, and talk about building AI products.

To report a bug or suggest a feature request, use GitHub Issues.

Contributing

There are many ways to contribute to the project:

Thanks to all of our amazing contributors!

Usage tracking and feedback

The BentoML framework collects anonymous usage data that helps our community improve the product. Only BentoML's internal API calls are being reported. This excludes any sensitive information, such as user code, model data, model names, or stack traces. Here's the code used for usage tracking. You can opt-out of usage tracking by the --do-not-track CLI option:

bentoml [command] --do-not-track

Or by setting the environment variable:

export BENTOML_DO_NOT_TRACK=True

License

Apache License 2.0

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

bentoml-1.4.1.tar.gz (968.4 kB view details)

Uploaded Source

Built Distribution

bentoml-1.4.1-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file bentoml-1.4.1.tar.gz.

File metadata

  • Download URL: bentoml-1.4.1.tar.gz
  • Upload date:
  • Size: 968.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bentoml-1.4.1.tar.gz
Algorithm Hash digest
SHA256 20c538eb8367b04ecf0c691ea5805fa71b2d82c3a3cabcb3720a109e09653381
MD5 54626b5b7eee2ce98bc28e28c767f93e
BLAKE2b-256 7e5eacb7cbd1b757f7e585a28b5d568a6c25ceb785e98ad20ec9f5d7dc45afb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for bentoml-1.4.1.tar.gz:

Publisher: release.yml on bentoml/BentoML

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bentoml-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: bentoml-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bentoml-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b622f5301bd55043f528be6677c660005acbf4619eef38d60d98e6b7ce05ad2
MD5 22959ce545d594308b56404a7a1c8483
BLAKE2b-256 82de6d65c876a1c3b5d809e20c6a18e2678f76542fd8452bd49b1b64633e554b

See more details on using hashes here.

Provenance

The following attestation bundles were made for bentoml-1.4.1-py3-none-any.whl:

Publisher: release.yml on bentoml/BentoML

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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