Make writing a habit together! This is the 15th day of my participation in the “Gold Digging Day New Plan · April More text Challenge”. Click here for more details.

BentoML provides easy-to-use local and centralized shops to manage models and Bentos.

This article focuses on the local file system-based model and the use of the Bento store. For more information about the centralized store solution, see BentoML Yatai.

Management model

Create the model

Recall from the previous tutorial that models are saved using the frame-specific save() function. In our example, we use the save() function in the SkLearn module for the Scikit Learn framework, as shown below.

import bentoml.sklearn

bentoml.sklearn.save("iris_classifier_model", clf)
Copy the code

Models can also be imported from registries specific to the supported frameworks. In the following example, the model is imported from the MLFlow model registry.

import bentoml.mlflow

bentoml.mlflow.import_from_uri("mlflow_model", uri=mlflow_registry_uri)
Copy the code

By default, saved and imported models are added to the local file system-based model repository in the $HOME/ Bentoml/Models directory.

List the model

To list all created models, use the list() Python function in the Bentoml.models module or the models List CLI command.

The following is an example Python function:

import bentoml.models

bentoml.models.list(a)# get a list of all models

# [
# {
# tag: Tag("iris_classifier_model", "vkorlosfifi6zhqqvtpeqaare"),
# framework: "SKLearn",
# created: 2021/11/14 03:55:11
#}.
# {
# tag: Tag("iris_classifier_model", "vlqdohsfifi6zhqqvtpeqaare"),
# framework: "SKLearn",
# created: 2021/11/14 03:55:15
#}.
# {
# tag: Tag("iris_classifier_model", "vmiqwpcfifi6zhqqvtpeqaare"),
# framework: "SKLearn",
# created: 2021/11/14 03:55:25
#}.
# {
# tag: Tag("fraud_detection_model", "5v4pdccfifi6zhqqvtpeqaare"),
# framework: "PyTorch",
# created: 2021/11/14 03:57:01
#}.
# {
# tag: Tag("fraud_detection_model", "5xorursfifi6zhqqvtpeqaare"),
# framework: "PyTorch",
# created: 2021/11/14 03:57:45
#}.
#]
bentoml.models.list("iris_classifier_model") # get a list of all versions of a specific model
bentoml.models.list(Tag("iris_classifier_model".None))
# [
# {
# tag: Tag("iris_classifier_model", "vkorlosfifi6zhqqvtpeqaare"),
# framework: "SKLearn",
# created: 2021/11/14 03:55:11
#}.
# {
# tag: Tag("iris_classifier_model", "vlqdohsfifi6zhqqvtpeqaare"),
# framework: "SKLearn",
# created: 2021/11/14 03:55:15
#}.
# {
# tag: Tag("iris_classifier_model", "vmiqwpcfifi6zhqqvtpeqaare"),
# framework: "SKLearn",
# created: 2021/11/14 03:55:25
#}.
#]
Copy the code

The following is an example command line:

> bentoml models list # list all models

MODEL                 FRAMEWORK   VERSION                    CREATED
iris_classifier_model SKLearn     vkorlosfifi6zhqqvtpeqaare  2021/11/14 03:55:11
iris_classifier_model SKLearn     vlqdohsfifi6zhqqvtpeqaare  2021/11/14 03:55:15
iris_classifier_model SKLearn     vmiqwpcfifi6zhqqvtpeqaare  2021/11/14 03:55:25
fraud_detection_model PyTorch     5v4pdccfifi6zhqqvtpeqaare  2021/11/14 03:57:01
fraud_detection_model PyTorch     5xorursfifi6zhqqvtpeqaare  2021/11/14 03:57:45


> bentoml models list iris_classifier # list all version of my-model

MODEL           FRAMEWORK   VERSION          CREATED
iris_classifier_model PyTorch     vkorlosfifi6zhqqvtpeqaare  2021/11/14 03:55:11
iris_classifier_model PyTorch     vlqdohsfifi6zhqqvtpeqaare  2021/11/14 03:55:15
iris_classifier_model SKLearn     vmiqwpcfifi6zhqqvtpeqaare  2021/11/14 03:55:25
Copy the code

To obtain model information, use the Get () function under the Bentoml.models module or the models Get CLI command.

The following is an example Python function:

import bentoml.models

bentoml.models.get("iris_classifier_model:vmiqwpcfifi6zhqqvtpeqaare")
bentoml.models.get(Tag("iris_classifier_model"."vmiqwpcfifi6zhqqvtpeqaare"))
# Model(
# tag: Tag("iris_classifier_model", "vmiqwpcfifi6zhqqvtpeqaare"),
# framework: "SKLearn",
# created: 2021/11/14 03:55:25
# description: "The iris classifier model"
# path: "/user/home/bentoml/models/iris_classifier_model/vmiqwpcfifi6zhqqvtpeqaare"
#)
Copy the code

The following is an example command line:

> bentoml models get iris_classifier_model:vmiqwpcfifi6zhqqvtpeqaare TAG iris_classifier_model:vmiqwpcfifi6zhqqvtpeqaare  FRAMEWORK SKLearn CREATED 2021/9/21 10:07:45 DESCRIPTION The iris classifier model PATH /user/home/bentoml/models/iris_classifier_model/vmiqwpcfifi6zhqqvtpeqaareCopy the code

Remove the model

To delete a model from the model store, use the delete() function under the Bentoml.models module or the models delete CLI command.

The following is an example Python function:

import bentoml.models

bentoml.models.delete("iris_classifier_model:vmiqwpcfifi6zhqqvtpeqaare", skip_confirm=True)
Copy the code

The following is an example command line:

> bentoml models delete iris_classifier_model:vmiqwpcfifi6zhqqvtpeqaare
Copy the code

Management Bentos

Create Bentos

Bentos is created through the Bento build process. Recall from the getting started guide that Bentos was built using the Build CLI command. For more details, see Building Bentos.

By default, the built-in Bentos are added to the local file system-based Bento store under $HOME/ Bentoml /bentos.

> bentoml build
Copy the code

List the Bentos

To view Bentos in the Bento store, use the list CLI command.

> bentoml list

BENTO                   VERSION                    LABELS      CREATED
iris_classifier_service v5mgcacfgzi6zdz7vtpeqaare  iris,prod   2021/09/19 10:15:50
Copy the code

Delete Bentos

To delete Bentos in the Bento store, use the delete CLI command.

> bentoml delete iris_classifier_service:v5mgcacfgzi6zdz7vtpeqaare
Copy the code