BentoML

On this page 8

BentoML is an open-source Python framework for building, packaging and serving model inference services. It turns a trained model and the code around it into a versioned, self-contained unit called a Bento, which can run as an HTTP API on a laptop, in a Docker container or on a Kubernetes cluster. Within MLOps & deployment, BentoML sits at the serving and packaging stage: it starts where the training pipeline ends and stops where monitoring and drift detection take over.

The framework is released under the Apache 2.0 license and supports classical models from scikit-learn or XGBoost as well as deep learning and large language models on GPUs. Its central idea is that a data scientist should define the service in Python, while the framework handles the web server, request batching, dependency locking and container image generation.

How BentoML builds an inference service

BentoML builds an inference service from a Python class marked with a service decorator, whose methods become API endpoints. In current versions, @bentoml.service declares the service and its resource requirements, such as GPU count, worker count and timeouts, while @bentoml.api exposes individual methods as typed endpoints. Input and output types are validated through Pydantic-style type hints, which also generate an OpenAPI specification automatically.

Trained models are stored in the local BentoML model store with a name and a version tag, for example fraud_model:3f2a1c. The service loads the model once at startup, which avoids repeated deserialization and keeps per-request latency predictable. Older releases used a separate Runner abstraction to isolate model execution; the newer service-based API replaced it with composable services linked by dependencies.

The table below lists the main building blocks and the role each plays.

ComponentWhat it isRole in deployment
ServicePython class with @bentoml.serviceDefines endpoints, resources and lifecycle
API methodMethod with @bentoml.apiReceives requests and returns typed outputs
Model storeLocal versioned model registryHolds serialized models with tags and metadata
BentoImmutable build archiveBundles code, models, dependencies and config
bentofile.yamlBuild configuration fileLists Python packages, system packages and files
Container imageOCI image from the BentoRuns the service on Docker or Kubernetes
Core BentoML components

The Bento as a deployable model artifact

A Bento is the unit of model packaging in BentoML: a directory archive that contains the service source code, the referenced models, a locked list of Python dependencies and generated Dockerfile templates. Running bentoml build produces it with a unique version tag, and bentoml containerize converts it into a standard OCI container image. Because the archive is immutable, the same Bento can move from staging to production without being rebuilt, which supports reproducible model promotion.

This design addresses a common source of training-serving skew: mismatched library versions between the notebook and the server. Pinning dependencies at build time does not remove skew caused by feature logic, however, so teams still need consistent feature pipelines and tests that compare offline and online predictions.

Performance features for production serving

BentoML improves throughput mainly through adaptive batching, which groups concurrent requests into a single model call. An endpoint marked as batchable collects incoming requests until it reaches a maximum batch size or a maximum latency budget, then runs one vectorized prediction and splits the results. On GPUs this often raises throughput several times, although the exact gain depends on model size, input shape and traffic pattern.

The following parameters have the strongest influence on latency, throughput and cost.

ParameterTypical settingMain effect
Max batch size8 to 128 inputsLarger batches raise throughput and memory use
Max latency (ms)10 to 1,000 msCaps how long a request waits for a batch
Workers1 per GPU or several per CPUControls parallel processes per replica
ResourcesGPU count, GPU type, memoryGuides scheduling on the deployment target
Traffic timeoutSeconds to minutesProtects against slow generative requests
ConcurrencyRequests per replicaDrives autoscaling decisions on managed platforms
Key serving parameters and their effects

Services also expose Prometheus metrics and support OpenTelemetry tracing, so request counts, latency percentiles and errors can feed an existing ML observability stack. For multi-step pipelines, a service can call other services through typed dependencies, allowing a CPU preprocessing step and a GPU model to scale independently.

BentoML compared with other serving tools

BentoML differs from Kubernetes-native platforms because it is Python-first and infrastructure-neutral: the same service runs locally and in a cluster. KServe and Seldon Core assume Kubernetes from the start and focus on custom resources, routing and canary rollout, while managed platforms such as Amazon SageMaker and Vertex AI bundle serving with training and registry features.

ToolPrimary focusBest fit
BentoMLPython service definition and packagingTeams wanting portable images and custom logic
KServeKubernetes inference custom resourcesPlatform teams standardizing on Kubernetes
Seldon CoreKubernetes deployment graphsComplex routing and enterprise governance
NVIDIA NIMPrebuilt optimized model containersFast GPU serving of supported models
Amazon SageMakerManaged end-to-end ML platformOrganizations committed to one cloud
BentoML and related model serving options

These tools are not mutually exclusive. A Bento container image can be deployed through KServe, and teams often pair BentoML with an experiment tracker or registry such as MLflow, importing the chosen model version into the BentoML model store at build time.

Choosing and configuring BentoML

BentoML is a strong choice when a team needs custom preprocessing, multi-model pipelines or LLM serving in plain Python and wants a portable container rather than a vendor-specific endpoint. It is less attractive when an organization already runs a mature Kubernetes serving platform with strict operational standards.

SituationRecommended approachReason
Small team, one modelSingle BentoML serviceMinimal infrastructure and fast iteration
High request volume on GPUEnable adaptive batchingBetter GPU utilization per request
Preprocessing plus heavy modelSplit into dependent servicesScale CPU and GPU parts separately
Existing Kubernetes platformContainerize and deploy via KServeReuse cluster routing and policies
Strict latency targetLower max latency budgetSmaller batches keep tail latency low
Decision guide for typical situations

Limitations and common mistakes

BentoML handles packaging and serving, not the full lifecycle. It does not detect data drift, manage labels or schedule retraining, so production systems still need monitoring and continuous training around it. The main pitfalls appear in configuration rather than in the framework itself.

  • Loading models inside the API method, which repeats deserialization on every request.
  • Oversized batch latency budgets, which raise average throughput but harm tail latency.
  • Unpinned system packages in the build file, which break image reproducibility.
  • Skipping model warm-up, which makes the first requests after a scale-up noticeably slow.
  • Mixing API generations from old Runner-based tutorials with the newer service API.

In simple terms

A trained model is like a recipe that only works in one kitchen. BentoML packs the recipe, ingredients and tools into one sealed box. Any kitchen can then cook the same dish.

The developer writes a short Python class. BentoML turns it into a web service that other programs can call. It also builds a ready-to-run container. When many requests arrive at once, it groups them together. This makes the computer, and especially the GPU, work more efficiently.

A practical example

A payments company trains a gradient-boosted fraud model and a small text model that scores transaction descriptions. The data science team defines one BentoML service for feature preprocessing on CPU and a second service for both models, linked as a typed dependency. They enable adaptive batching with a maximum latency of 20 ms and a maximum batch size of 64.

The team runs bentoml build in its CI pipeline, containerizes the Bento and deploys the image to an existing Kubernetes cluster behind a shadow deployment. After two weeks of matching predictions against the current system, the new service is promoted. Median latency stays under 30 ms at peak load, and rolling back requires only redeploying the previous Bento tag.