The easiest way to serve AI apps and models - Build Model Inference APIs, Job queues, LLM apps, Multi-model pipelines, and more!
The easiest way to serve AI apps and models - Build Model Inference APIs, Job queues, LLM apps, Multi-model pipelines, and more!
Build model inference APIs and multi-model serving systems with any open-source or custom AI models. Join our forum!
BentoML is a Python library for building online serving systems optimized for AI apps and model inference.
Install BentoML:
# Requires Python≥3.9
pip install -U bentomlDefine APIs in a service.py file.
import bentoml
@bentoml.service(
image=bentoml.images.Image(python_version="3.11").python_packages("torch", "transformers"),
)
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]Install PyTorch and Transformers packages to your Python virtual environment.
pip install torch transformers # additional dependencies for local runRun the service code locally (serving at http://localhost:3000 by default):
bentoml serveYou should expect to see the following output.
[INFO] [cli] Starting production HTTP BentoServer from "service:Summarization" listening on http://localhost:3000 (Press CTRL+C to quit)
[INFO] [entry_service:Summarization:1] Service Summarization initializedNow 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}")Run bentoml build to package necessary code, models, dependency configs into a Bento - the standardized deployable artifact in BentoML:
bentoml buildEnsure Docker is running. Generate a Docker container image for deployment:
bentoml containerize summarization:latestRun the generated image:
docker run --rm -p 3000:3000 summarization:latestBentoCloud 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 deployFor detailed explanations, read the Hello World example.
Check out the full list for more sample code and usage.
See Documentation for more tutorials and guides.
Get involved and join our Community Forum , 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.
There are many ways to contribute to the project:
Thanks to all of our amazing contributors!
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-trackOr by setting the environment variable:
export BENTOML_DO_NOT_TRACK=True`bentoml.save_config` always crashes with `yaml.representer.RepresenterError`
BUG: IndexError in IODescriptor.from_output() with bare (unparameterized) iterator return annotations
bug: `bentoml containerize` fails with `ValueError: Accessing file outside of current working directory` when using `dockerfile_template` (v1.4.36)
[HTTPXodus] Consider migrating from `httpx` to `httpx2` (the actively maintained fork)
minor bug: Swagger docs.json not correctly specified for list[PydanticModel] Output
bug: [serve] `serve-grpc` failed: <class '_bentoml_sdk.service.factory.Service'> type doesn't support gRPC serving
Remote clients drop preceding URL values for multipart list file inputs
bug: Dockerfile injection via unsanitized docker.env dict values
SSRF blocklist bypass via CGNAT range (100.64.0.0/10)
bug: Async Return Latency Issues with BentoML Image IO API