_model = bentoml_model_deployer_step(

bento=bentomodel_name="pytorch_mnist",  # Name of the model

port=3001,  # Port to be used by the http server

ZenML BentoML Pipeline examples

Once all the steps have been defined, we can create a ZenML pipeline and run it. The bento builder step expects to get the trained model as an input, so we need to make sure either we have a previous step that trains the model and outputs it or loads the model from a previous run. Then the deployer step expects to get the bento bundle as an input, so we need to make sure either we have a previous step that builds the bento bundle and outputs it or load the bento bundle from a previous run or external source.

The following example shows how to create a ZenML pipeline that trains a model, builds a bento bundle, and deploys it to a local HTTP server.

# Import the pipeline to use the pipeline decorator

from zenml.pipelines import pipeline

# Pipeline definition

@pipeline

def bentoml_pipeline(

importer,

trainer,

evaluator,

deployment_trigger,

bento_builder,

deployer,

):

"""Link all the steps and artifacts together"""

train_dataloader, test_dataloader = importer()

model = trainer(train_dataloader)

accuracy = evaluator(test_dataloader=test_dataloader, model=model)

decision = deployment_trigger(accuracy=accuracy)

bento = bento_builder(model=model)

deployer(deploy_decision=decision, bento=bento)

In more complex scenarios, you might want to build a pipeline that trains a model and builds a bento bundle in a remote environment. Then creates a new pipeline that retrieves the bento bundle and deploys it to a local http server, or to a cloud provider. The following example shows a pipeline example that does exactly that.

# Import the pipeline to use the pipeline decorator

from zenml.pipelines import pipeline

# Pipeline definition

@pipeline

def remote_train_pipeline(

importer,

trainer,

evaluator,

bento_builder,

):

"""Link all the steps and artifacts together"""

train_dataloader, test_dataloader = importer()