An open-source platform for machine learning model serving.
Project description
From ML model to production API endpoint with a few lines of code
BentoML is an open-source platform for machine learning model serving.
What does BentoML do?
- Turn your ML model into production API endpoint with just a few lines of code
- Support all major machine learning training frameworks
- High performance API serving system with adaptive micro-batching support
- DevOps best practices baked in, simplify the transition from model development to production
- Model management for teams, providing CLI and Web UI dashboard
- Flexible model deployment orchestration with support for AWS Lambda, SageMaker, EC2, Docker, Kubernetes, KNative and more
👉 Join BentoML Slack community to hear about the latest development updates.
Getting Started
Installing BentoML with pip
:
pip install bentoml
A minimal prediction service in BentoML looks something like this:
from bentoml import env, artifacts, api, BentoService
from bentoml.handlers import DataframeHandler
from bentoml.artifact import SklearnModelArtifact
@env(auto_pip_dependencies=True)
@artifacts([SklearnModelArtifact('model')])
class IrisClassifier(BentoService):
@api(DataframeHandler)
def predict(self, df):
return self.artifacts.model.predict(df)
This code defines a prediction service that requires a scikit-learn model, and asks
BentoML to figure out the required PyPI pip packages automatically. It also defined
an API, which is the entry point for accessing this prediction service. And the API is
expecting a pandas.DataFrame
object as its input data.
Now you are ready to train a model and serve the model with the IrisClassifier
service
defined above:
from sklearn import svm
from sklearn import datasets
if __name__ == "__main__":
# Load training data
iris = datasets.load_iris()
X, y = iris.data, iris.target
# Model Training
clf = svm.SVC(gamma='scale')
clf.fit(X, y)
# Create a iris classifier service instance
iris_classifier_service = IrisClassifier()
# Pack the newly trained model artifact
iris_classifier_service.pack('model', clf)
# Save the prediction service to disk for model serving
saved_path = iris_classifier_service.save()
You've just created a BentoService SavedBundle, it's a versioned file archive that is
ready for production deployment. It contains the BentoService class you defined, all its
python code dependencies and PyPI dependencies, and the trained scikit-learn model. By
default, BentoML saves those files and related metadata under ~/bentoml
directory, but
this is easily customizable to a different directory or cloud storage like
Amazon S3.
You can now start a REST API server by specifying the BentoService's name and version, or provide the file path to the saved bundle:
bentoml serve IrisClassifier:latest
# or
bentoml serve {saved_path}
The REST API server provides web UI for testing and debugging the server. If you are
running this command on your local machine, visit http://127.0.0.1:5000 in your browser
and try out sending API request to the server. You can also send prediction request
with curl
from command line:
curl -i \
--header "Content-Type: application/json" \
--request POST \
--data '[[5.1, 3.5, 1.4, 0.2]]' \
http://localhost:5000/predict
The BentoService SavedBundle directory is structured to work as a docker build context, that can be used to build a API server docker container image:
docker build -t my-org/iris-classifier:v1 {saved_path}
docker run -p 5000:5000 -e BENTOML_ENABLE_MICROBATCH=True my-org/iris-classifier:v1
You can also deploy your BentoService directly to cloud services such as AWS Lambda with bentoml CLI's deployment management commands:
> bentoml get IrisClassifier
BENTO_SERVICE CREATED_AT APIS ARTIFACTS
IrisClassifier:20200121114004_360ECB 2020-01-21 19:40 predict<DataframeHandler> model<SklearnModelArtifact>
IrisClassifier:20200120082658_4169CF 2020-01-20 16:27 predict<DataframeHandler> clf<PickleArtifact>
...
> bentoml lambda deploy test-deploy -b IrisClassifier:20200121114004_360ECB
...
> bentoml deployment list
NAME NAMESPACE PLATFORM BENTO_SERVICE STATUS AGE
test-deploy dev aws-lambda IrisClassifier:20200121114004_360ECB running 2 days and 11 hours
...
More detailed code and walkthrough can be found in the BentoML Quickstart Guide.
Documentation
Full documentation and API references: https://docs.bentoml.org/
Examples
Visit bentoml/gallery repository for more examples and tutorials.
FastAI
- Pet Image Classification - Google Colab | nbviewer | source
- Salary Range Prediction - Google Colab | nbviewer | source
Scikit-Learn
- Sentiment Analysis - Google Colab | nbviewer | source
PyTorch
- Fashion MNIST - Google Colab | nbviewer | source
- CIFAR-10 Image Classification - Google Colab | nbviewer | source
Tensorflow Keras
- Fashion MNIST - Google Colab | nbviewer | source
- Text Classification - Google Colab | nbviewer | source
- Toxic Comment Classifier - Google Colab | nbviewer | source
Tensorflow 2.0
- tf.Function model - Google Colab | nbviewer | source
- Fashion MNIST - Google Colab | nbviewer | source
XGBoost
- Titanic Survival Prediction - Google Colab | nbviewer | source
- League of Legend win Prediction - Google Colab | nbviewer | source
LightGBM
- Titanic Survival Prediction - Google Colab | nbviewer | source
H2O
- Loan Default Prediction - Google Colab | nbviewer | source
- Prostate Cancer Prediction - Google Colab | nbviewer | source
Deployment guides:
-
Automated end-to-end deployment workflow with BentoML
-
Clipper Deployment
-
Mannual Deployment
Contributing
Have questions or feedback? Post a new github issue or discuss in our Slack channel:
Want to help build BentoML? Check out our contributing guide and the development guide.
Releases
BentoML is under active development and is evolving rapidly. Currently it is a Beta release, we may change APIs in future releases.
Read more about the latest features and changes in BentoML from the releases page.
Usage Tracking
BentoML by default collects anonymous usage data using Amplitude. It only collects BentoML library's own actions and parameters, no user or model data will be collected. Here is the code that does it.
This helps BentoML team to understand how the community is using this tool and what to build next. You can easily opt-out of usage tracking by running the following command:
# From terminal:
bentoml config set usage_tracking=false
# From python:
import bentoml
bentoml.config().set('core', 'usage_tracking', 'False')
License
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
Built Distribution
File details
Details for the file BentoML-0.7.2.tar.gz
.
File metadata
- Download URL: BentoML-0.7.2.tar.gz
- Upload date:
- Size: 2.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e7deb969d8b67d42dbd7d709a26a17d476cfd18fb02b7e6256a48eb5251f8dd |
|
MD5 | cd00b8c411b8a8047a9f854852709a54 |
|
BLAKE2b-256 | a045684702c13c139c5520c5134b16e5495aee05dc365d9a59351c758beb50f1 |
File details
Details for the file BentoML-0.7.2-py3-none-any.whl
.
File metadata
- Download URL: BentoML-0.7.2-py3-none-any.whl
- Upload date:
- Size: 3.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b297c715d6ebea19579e64c2dc713c764b64ab8ec17a21e2601cb085ecace7d0 |
|
MD5 | 92abf4e9a03725d929eeb2101881f566 |
|
BLAKE2b-256 | f2949050760a547efd8918a29145f5c74ac1b6626bb4518f23a6d59eed17c0cb |