 model.

How do you use it?

Deploy a logged modelFollowing MLflow's documentation, if we want to deploy a model as a local inference server, we need the model to be logged in the MLflow experiment tracker first. Once the model is logged, we can use the model URI either from the artifact path saved with the MLflow run or using model name and version if a model is registered in the MLflow model registry.

In the following examples, we will show how to deploy a model using the MLflow Model Deployer, in two different scenarios:

We already know the logged model URI and we want to deploy it as a local inference server.

from zenml import pipeline, step, get_step_context

from zenml.client import Client

@step

def deploy_model() -> Optional[MLFlowDeploymentService]:

# Deploy a model using the MLflow Model Deployer

zenml_client = Client()

model_deployer = zenml_client.active_stack.model_deployer

mlflow_deployment_config = MLFlowDeploymentConfig(

name: str = "mlflow-model-deployment-example",

description: str = "An example of deploying a model using the MLflow Model Deployer",

pipeline_name: str = get_step_context().pipeline_name,

pipeline_step_name: str = get_step_context().step_name,

model_uri: str = "runs:/<run_id>/model" or "models:/<model_name>/<model_version>",

model_name: str = "model",

workers: int = 1

mlserver: bool = False

timeout: int = DEFAULT_SERVICE_START_STOP_TIMEOUT

service = model_deployer.deploy_model(mlflow_deployment_config)

logger.info(f"The deployed service info: {model_deployer.get_model_server_info(service)}")

return service

We don't know the logged model URI, since the model was logged in a previous step. We want to deploy the model as a local inference server. ZenML provides set of functionalities that would make it easier to get the model URI from the current run and deploy it.

from zenml import pipeline, step, get_step_context

from zenml.client import Client

from mlflow.tracking import MlflowClient, artifact_utils

@step