Register H2O Driverless AI models in the MLflow Model Registry¶
In order to register H2O Driverless AI (DAI) models in the MLflow Model Registry, you must download the Python H2O.ai MLflow Custom Flavor wheel file and install it in your MLflow cluster. You can download the required wheel file from the H2O MLOps downloads page. The Python H2O.ai MLflow Custom Flavor wheel file saves the DAI model as a MLflow custom flavor that's compatible with the MLflow model specification and supported as part of the H2O MLOps model ingestion process.
Install the H2O MLflow wheel file¶
-
Download the Python H2O.ai MLflow Custom Flavor wheel file from the H2O MLOps downloads page.
-
In Azure Databricks, go to the Compute page, and then select an existing compute instance or create and select a new one.
-
Click the Libraries tab.
-
Click the Install New button.
-
Select the Python H2O.ai MLflow Custom Flavor wheel file that you downloaded in step one.
-
When the installation is finished, click More > Restart.
Note
If you don't have the level of access necessary to install the wheel file, contact your administrator for assistance.
Register DAI models in the MLflow Model Registry¶
To register DAI models in the MLflow Model Registry, run the following Python commands.
# Ensure that driverlessai, h2osteam and the DAI MLflow flavor are installed in your cluster.
# Install the DAI MLflow flavor.
pip install h2oai_mlflow_flavors
# Import the required libraries.
import driverlessai
import os
import h2osteam
from h2osteam.clients import DriverlessClient
# Connect to an existing DAI instance.
Name='<dai_instance>'
h2osteam.login(url="<steam_url>", username="<user_id>", password="steam_token>", verify_ssl=True)
instance = DriverlessClient.get_instance(name=Name)
instance.start()
# instance=DriverlessClient().get_instance(name="query")
# instance=DriverlessClient().get_instance(name="Dai_test")
instance.details()
# Get the DAI instance details.
import h2osteam
from h2osteam.clients import DriverlessClient
name='mw-dai-mlflow-test'
h2osteam.login(url="<steam_url>", username="<user_id>", password="steam_token>", verify_ssl=True)
instance = DriverlessClient().get_instance(name=Name)
client = instance.connect(use_own_client=True)
instance.details()
dai=client
# Get all experiments from the DAI instance.
experiment_list = dai.experiments.list()
experiment_list
# Select an experiment.
exp = experiment_list[0]
exp
# Download the experiment MOJO and Python pipeline.
import os
exp.artifacts.create('python_pipeline')
exp.artifacts.download(only='python_pipeline', dst_dir='/dbfs/FileStore/DAI_Experiments/', overwrite=True)
exp.artifacts.download(only='mojo_pipeline', dst_dir='/dbfs/FileStore/DAI_Experiments/', overwrite=True)
# Import the log_model function
from h2o_mlflow_flavors.driverless import log_model
# Log an experiment in MLflow.
# Use scorer.zip for a Python pipeline.
# Use mojo.zip for a MOJO.
log_model(h2o_dai_artifact_location="/dbfs/FileStore/DAI_Experiments/scorer.zip", artifact_path ="<name_of_model>")
# Alternatively, manually create a registered model or version.
log_model(h2o_dai_artifact_location="/dbfs/FileStore/DAI_Experiments/scorer.zip", artifact_path ="<name_of_model>")