More

Example: XGBoost Deployment

A guide to deploy XGBoost Models

This tutorial will assume that you have already installed clipper_admin and its dependencies.

In order to keep the base images small, containers limit the packages they come with default; however, Clipper also supports the installation of additional packages onto model containers using pip. Packages such as XGBoost can be installed and deployed in this way.

We also must define our predict function for our model. In order to deploy the XGBoost model to Clipper, we define a closure that references the XGBoost model. Clipper’s model deployer will automatically track down everything that is referenced in the closure (including the XGBoost model), and include it in the model container. We loop through every element in the batch to account for Clipper’s adaptive batching, which may add duplicates of requests to batches to figure out the optimal batch size for a model container. (For more info on adaptive batching, check out this link)

def predict(xs):
return bst.predict(xgb.DMatrix(xs))

Now that we have a model, as well as a predict function, we must deploy our model container. We will use a python_closure_container, and install the xgboost module using pip.

from clipper_admin.deployers import python as python_deployer
# We specify which packages to install in the pkgs_to_install arg.
# For example, if we wanted to install xgboost and psycopg2, we would use
# pkgs_to_install = ['xgboost', 'psycopg2']
python_deployer.deploy_python_closure(cl, name='xgboost-model', version=1,
input_type="integers", func=predict, pkgs_to_install=['xgboost'])

The next step is to link the model container to our app, so that Clipper can route requests for the “xgboost-test” application to the “xgboost-model” container.