The following steps show how to download a model training in H2O Driverless AI and push it to production in cnvrg.io:
$ pip install driverlessai
import driverlessai
dai = driverlessai.Client(address='<IP address of Driverless AI instance', username='<username>', password='<password>')
ex = dai.experiments.list()[<Experiment number>]
artifacts = ex.artifacts.download(overwrite=True)
The ZIP file includes all the artifacts required for model inference. The scoring pipeline includes the run_example.sh and common-functions.sh files, which install all the required libraries in a Python virtual environment that is required for model serving.
$ patch run_example.sh patchfile1
The following are the contents of the patchfile1 file:
21,22c21,22
< virtualenv -p python3.8 --system-site-packages --never-download --copies --app-data env_app_data_dir --setuptools embed --pip embed --wheel embed env
< source env/bin/activate
---
> #virtualenv -p python3.8 --system-site-packages --never-download --copies --app-data env_app_data_dir --setuptools embed --pip embed --wheel embed env
> #source env/bin/activate
30,31c30,31
< virtualenv -p python3.8 --never-download --copies --app-data env_app_data_dir --setuptools embed --pip embed --wheel embed env || virtualenv -p python3.8 --never-download env
< source env/bin/activate
---
> #virtualenv -p python3.8 --never-download --copies --app-data env_app_data_dir --setuptools embed --pip embed --wheel embed env || virtualenv -p python3.8 --never-download env
> #source env/bin/activate
45,47c45,47
< mv $spackagespath/xgboost $spackagespath/xgboost_h2o4gpu
< mv $spackagespath/lightgbm_gpu $spackagespath/lightgbm_gpu_h2o4gpu
< mv $spackagespath/lightgbm_cpu $spackagespath/lightgbm_cpu_h2o4gpu
---
> #mv $spackagespath/xgboost $spackagespath/xgboost_h2o4gpu
> #mv $spackagespath/lightgbm_gpu $spackagespath/lightgbm_gpu_h2o4gpu
> #mv $spackagespath/lightgbm_cpu $spackagespath/lightgbm_cpu_h2o4gpu
61c61,62
< source env/bin/activate
---
> #source env/bin/activate
> echo "just pass"
114c115
< set_PYTHON
---
> #set_PYTHON
169c170
< source "./common-functions.sh"
---
> source "./modified-common-functions.sh"
172a174
>
$ patch common-functions.sh patchfile2
The following are the contents of the patchfile2 file:
< PYTHON=`realpath env/bin/python`
---
> #PYTHON=`realpath env/bin/python`
> PYTHON=`realpath /usr/bin/python3`
76c77,78
< spackagespath=`$PYTHON -c "from sysconfig import get_paths ; info = get_paths() ; print(info['purelib'])"`
---
> #spackagespath=`$PYTHON -c "from sysconfig import get_paths ; info = get_paths() ; print(info['purelib'])"`
> spackagespath="/usr/local/lib/python3.8/dist-packages"
133c135,136
< export PYTHON=`realpath env/bin/python`
---
> #export PYTHON=`realpath env/bin/python`
> export PYTHON=`realpath /usr/bin/python3`
135c138,139
< export spackagespath=`$PYTHON -c "from sysconfig import get_paths ; info = get_paths() ; print(info['purelib'])"`
---
> #export spackagespath=`$PYTHON -c "from sysconfig import get_paths ; info = get_paths() ; print(info['purelib'])"`
> export spackagespath="/usr/local/lib/python3.8/dist-packages"
140a145
>
$ apt-get update && apt install -y build-essential libmagic-dev libopenblas-dev git locales unzip wget
$ /usr/bin/python3.8 -m pip install --upgrade pip
$ cd /driverless/scoring-pipeline
$ ./ run_example.sh
This Docker container can be used in cnvrg.io for model serving.
To push a model to production, cnvrg requires a predict function to implement the model prediction. H2O Driverless AI implements model prediction using a scorer function. Use the following example Python predict wrapper function:
import os
import pandas as pd
import numpy as np
from numpy import nan
from scipy.special._ufuncs import expit
# import scoring_pipeline
from <scoring experiment module> import Scorer
os.environ['DRIVERLESS_AI_LICENSE_KEY']="<License key>"
def predict(*input_text):
"""
Function to read input texts and predict the sentiment associated
"""
# create scorer instance
scorer = Scorer()
model_input = input_text
# predict using score using the instance
prediction = scorer.score(model_input)
scorer.finish()
return prediction