Skip to main content
Welcome to this tutorial on serving machine learning models with BentoML. In this guide, you’ll learn how to download a model, register it with BentoML, and deploy a service to handle predictions. This step-by-step lesson is designed for improved performance tracking and production-grade serving. ──────────────────────────────────────── Step 1: Download and Prepare the Model ──────────────────────────────────────── Begin by downloading your machine learning model (for example, a pickle file named model.pkl) from your chosen source. Once downloaded, place the model file into your project’s root directory using VS Code or your preferred editor. ──────────────────────────────────────── Step 2: Register the Model with BentoML ──────────────────────────────────────── Create a Python script (e.g., register_model.py) to load your pickle file and register it with BentoML. Use the code below:
Run the script by executing:
If the model registration is successful, you’ll see output similar to the following:
This output confirms successful integration with both MLflow (for experiment tracking) and BentoML (for model serving).
──────────────────────────────────────── Step 3: Verify Registration in BentoML ──────────────────────────────────────── After registration, ensure that the model is stored in the BentoML registry. Execute the following command:
A typical output should show your model details:
This confirms that your model artifact is securely stored in the BentoML repository. Although multiple experiments might be tracked with MLflow, only the model registered in BentoML is used for serving. ──────────────────────────────────────── Step 4: Create the BentoML Service for Serving ──────────────────────────────────────── Define a service to serve your model by creating a file (e.g., service.py) with the following content:
This service creates an endpoint (/predict) that accepts feature data in a Pandas DataFrame format and returns predictions in JSON. ──────────────────────────────────────── Step 5: Running the BentoML Service ──────────────────────────────────────── Start the BentoML service with live-reloading enabled to pick up any local changes automatically. Run:
By default, BentoML serves on port 3000. Open your browser and navigate to the BentoML UI. You will see the /predict endpoint readily available. The API endpoint specifications are as follows:
This endpoint is intended for receiving feature data (for instance, from a CSV file uploaded by an insurance claims agent) and returning prediction results.
──────────────────────────────────────── Next Steps ──────────────────────────────────────── In this lesson, you registered a machine learning model with BentoML and created a simple prediction API. In the upcoming lesson, you’ll learn how to integrate this API into a web application so insurance claims agents can upload CSV files and receive predictions effortlessly. Happy serving! For more information, refer to the official BentoML Documentation and MLflow Documentation.

Watch Video