Overview
BentoML is an open-source Python library for building online serving systems for AI apps and model inference. You wrap your inference code in a Python class, add type hints, and BentoML turns it into a REST API server. It works with any ML framework, modality, and inference runtime, from LLMs and diffusion models to embeddings and computer vision.
It is aimed at ML engineers and Python developers who need to move a model from a notebook or script into a service that other systems can call. A single config file declares the Python version, dependencies, and model versions, and BentoML generates a Docker image from it so the same setup runs locally and in production.
Within the model serving and deployment space, BentoML focuses on packaging and serving. It includes built-in serving features such as dynamic batching, model parallelism, and multi-model inference graphs, and can deploy to Docker or to the managed BentoCloud service.
What it does
- Turn any model inference script into a REST API server with a few lines of code and standard Python type hints
- Generate reproducible Docker images from a single config file that manages environments, dependencies, and model versions
- Built-in serving optimizations: dynamic (adaptive) batching, model parallelism, multi-stage pipelines, and multi-model inference graphs
- Framework-agnostic: supports any ML framework, modality, and inference runtime
- Package code, models, and dependency configs into a Bento, the standardized deployable artifact
- Develop and debug locally, then deploy with Docker containers or to the managed BentoCloud service
Getting started
Install BentoML, define a service class in service.py, and serve it locally before containerizing for deployment.
Install BentoML
Requires Python 3.9 or newer.
# Requires Python≥3.9
pip install -U bentomlDefine an API in service.py
Wrap your model in a class decorated with @bentoml.service and expose methods with @bentoml.api.
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]Run the service locally
Install your model's dependencies, then serve the API at http://localhost:3000.
pip install torch transformers # additional dependencies for local run
bentoml serveBuild and containerize for deployment
Package code, models, and configs into a Bento, then generate and run a Docker image.
bentoml build
bentoml containerize summarization:latest
docker run --rm -p 3000:3000 summarization:latestCommands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Expose a trained model as a REST inference API that other services or applications can call
- Package a model and its dependencies into a reproducible Docker image for consistent deployment across environments
- Serve LLMs, diffusion models, embeddings, or computer vision models with built-in batching and GPU utilization
- Compose multiple models into a single inference graph or pipeline behind one API
How BentoML compares
BentoML alongside other open-source serving & deployment tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| Transformers | ★ 166k | Hugging Face Transformers is a Python framework that defines and runs state-of-the-art pretrained models for text, vision, audio, and multimodal tasks, for both inference and training. |
| vLLM | ★ 92.1k | A high-throughput LLM serving engine that uses PagedAttention and continuous batching to serve many requests at once. |
| SGLang | ★ 36.1k | A serving framework for LLMs and multimodal models that boosts throughput by reusing shared prompt prefixes across requests. |
| Modular Platform | ★ 29.8k | Modular's AI platform: the MAX inference framework with an OpenAI-compatible serving endpoint and GPU kernel library, plus the Mojo language and compiler. |
| TensorRT-LLM | ★ 14.6k | NVIDIA's library that compiles LLMs into optimized engines for the fastest inference on its data-center GPUs. |
| OpenLLM | ★ 12.5k | A tool to run any open-source LLM as an OpenAI-compatible API endpoint locally or in the cloud. |
| LMCache | ★ 11.9k | A KV-cache layer that stores and shares cached attention state across engines and requests to cut repeated computation. |
| BentoML | ★ 8.8k | Turn any AI/ML model into a production inference API and Docker container |
