Wallaroo SDK Upload and Deploy Tutorial: XGBoost Booster RF Classification

How to upload a XGBoost Booster RF Classification model to Wallaroo

This tutorial and the assets can be downloaded as part of the Wallaroo Tutorials repository.

Booster RF Classification Example Example

The following tutorial demonstrates deploying and serving an Booster RF Classification Example model to Wallaroo.

The following XGBoost model types are supported by Wallaroo. XGBoost models not supported by Wallaroo are supported via the Arbitrary Python models, also known as Bring Your Own Predict (BYOP).

XGBoost Model TypeWallaroo Auto Packaging Supported
Booster Classifier
Booster Classifier
Booster Regressor
Booster Random Forest Regressor
Booster Random Forest Classifier
  • XGBRanker XGBoost models are currently supported via converting them to BYOP models.


Upload, deploy, and serve a sample Booster RF Classification Example model.


This tutorial provides the following:

  • Models:
    • /models/xgb_booster_rf_classification.pkl: The sample XGBoost model that receives the sklearn.datasets.load_breast_cancer dataset.


  • A deployed Wallaroo instance with Edge Registry Services and Edge Observability enabled.
  • The following Python libraries installed:
    • wallaroo: The Wallaroo SDK. Included with the Wallaroo JupyterHub service by default.
    • pandas: Pandas, mainly used for Pandas DataFrame
  • A X64 Docker deployment to deploy the model on an edge location.
  • The notebook “Wallaroo Run Anywhere Model Drift Observability with Assays: Preparation” has been run, and the model edge deployments executed.


Import Libraries

The first step is to import the libraries we will need. See ./requirements.txt for a list of additional libraries used with this tutorial.

import wallaroo
from wallaroo.deployment_config import DeploymentConfigBuilder
import pyarrow as pa
from wallaroo.framework import Framework

import pickle
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from xgboost import train, DMatrix

Open a Connection to Wallaroo

The next step is connect to Wallaroo through the Wallaroo client. The Python library is included in the Wallaroo install and available through the Jupyter Hub interface provided with your Wallaroo environment.

This is accomplished using the wallaroo.Client() command, which provides a URL to grant the SDK permission to your specific Wallaroo environment. When displayed, enter the URL into a browser and confirm permissions. Store the connection into a variable that can be referenced later.

If logging into the Wallaroo instance through the internal JupyterHub service, use wl = wallaroo.Client(). If logging in externally, update the wallarooPrefix and wallarooSuffix variables with the proper DNS information. For more information on Wallaroo DNS settings, see the Wallaroo DNS Integration Guide.

wl = wallaroo.Client()

Set Variables

We’ll set the name of our workspace, pipeline, models and files. Workspace names must be unique across the Wallaroo workspace. For this, we’ll add in a randomly generated 4 characters to the workspace name to prevent collisions with other users’ workspaces. If running this tutorial, we recommend hard coding the workspace name so it will function in the same workspace each time it’s run.

workspace_name = f'xgb-booster-rf-classification'
pipeline_name = f'xgb-booster-rf-classification'

model_name = 'xgb-booster-rf-classification'
model_file_name = './models/xgb_booster_rf_classification.pkl'

Create Workspace and Pipeline

We will now create the Wallaroo workspace to store our model and set it as the current workspace. Future commands will default to this workspace for pipeline creation, model uploads, etc. We’ll create our Wallaroo pipeline to deploy our model.

workspace = wl.get_workspace(name=workspace_name, create_if_not_exist=True)

pipeline = wl.build_pipeline(pipeline_name)

Upload XGBoost Model

XGBoost models are uploaded to Wallaroo through the wallaroo.client.Client.upload_model method.

Upload XGBoost Model Parameters

The following parameters are available for XGBoost models.

namestring (Required)The name of the model. Model names are unique per workspace. Models that are uploaded with the same name are assigned as a new version of the model.
pathstring (Required)The path to the model file being uploaded.
frameworkstring (Required)Set as Framework.XGBOOST.
input_schemapyarrow.lib.Schema (Required)The input schema in Apache Arrow schema format.
output_schemapyarrow.lib.Schema (Required)The output schema in Apache Arrow schema format.
convert_waitbool (Optional) (Default: True)
  • True: Waits in the script for the model conversion completion.
  • False: Proceeds with the script without waiting for the model conversion process to display complete.

Once the upload process starts, the model is containerized by the Wallaroo instance. This process may take up to 10 minutes.

Upload XGBoost Model Return

The following is returned with a successful model upload and conversion.

namestringThe name of the model.
versionstringThe model version as a unique UUID.
file_namestringThe file name of the model as stored in Wallaroo.
image_pathstringThe image used to deploy the model in the Wallaroo engine.
last_update_timeDateTimeWhen the model was last updated.

Configure Input and Output Schemas

First we configure the input and output schemas in PyArrow format.

input_schema = pa.schema([
    pa.field('inputs', pa.list_(pa.float32(), list_size=30))

output_schema = pa.schema([
    pa.field('probabilities', pa.float32()),

Upload Model Example

With the input and output schemas defined, we now upload the XGBoost model.

model = wl.upload_model(model_name, 
Waiting for model loading - this will take up to 10.0min.
Model is pending loading to a native runtime.
Model is attempting loading to a native runtime.successful

File Namexgb_booster_rf_classification.pkl
Image PathNone
Updated At2024-11-Apr 20:32:26

Deploy Pipeline

With the model uploaded and packaged, we add the model as a pipeline model step. For our deployment, we will set a minimum deployment configuration - this is the amount of resources the deployed pipeline uses from the cluster.

Once set, we deploy the pipeline, which allocates the assigned resources for the cluster and makes it available for inference requests.


deployment_config = DeploymentConfigBuilder() \
    .cpus(0.25).memory('1Gi') \
{'status': 'Running',
 'details': [],
 'engines': [{'ip': '',
   'name': 'engine-78c594678b-hqqs5',
   'status': 'Running',
   'reason': None,
   'details': [],
   'pipeline_statuses': {'pipelines': [{'id': 'xgb-booster-rf-classification',
      'status': 'Running'}]},
   'model_statuses': {'models': [{'name': 'xgb-booster-rf-classification',
      'sha': '141eeb77f04e16b500b5f0e60864be208586af4d61030de4fa1de8488b54fda4',
      'status': 'Running',
      'version': 'b3a619f1-7f6d-47d2-857c-73dbe943f759'}]}}],
 'engine_lbs': [{'ip': '',
   'name': 'engine-lb-d7cc8fc9c-6gdst',
   'status': 'Running',
   'reason': None,
   'details': []}],
 'sidekicks': []}

Run Sample Inference

The dataset is from the sklearn.datasets.load_breast_cancer examples. These are converted to a pandas DataFrame, that is submitted to the deployed model in Wallaroo for an inference request.

dataset = load_breast_cancer()
X, y = dataset.data, dataset.target
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42
dtrain = DMatrix(X_train, label=y_train)
dtest = DMatrix(X_test, label=y_test)

data = dtest.get_data().todense()[:100]
import pandas as pd

dataframe = pd.DataFrame({"inputs": data.tolist()})
0[12.470000267028809, 18.600000381469727, 81.08...
1[18.940000534057617, 21.309999465942383, 123.5...
2[15.460000038146973, 19.479999542236328, 101.6...
3[12.399999618530273, 17.68000030517578, 81.470...
4[11.539999961853027, 14.4399995803833, 74.6500...
95[9.777000427246094, 16.989999771118164, 62.5, ...
96[20.1299991607666, 28.25, 131.1999969482422, 1...
97[13.8100004196167, 23.75, 91.55999755859375, 5...
98[11.149999618530273, 13.079999923706055, 70.87...
99[17.270000457763672, 25.420000076293945, 112.4...

100 rows × 1 columns

results = pipeline.infer(dataframe)
02024-04-11 20:32:46.108[12.470000267, 18.6000003815, 81.0899963379, 4...0.8720630
12024-04-11 20:32:46.108[18.9400005341, 21.3099994659, 123.5999984741,...0.1269890
22024-04-11 20:32:46.108[15.4600000381, 19.4799995422, 101.6999969482,...0.1269890
32024-04-11 20:32:46.108[12.3999996185, 17.6800003052, 81.4700012207, ...0.8720630
42024-04-11 20:32:46.108[11.5399999619, 14.4399995804, 74.6500015259, ...0.8720630
952024-04-11 20:32:46.108[9.7770004272, 16.9899997711, 62.5, 290.200012...0.8720630
962024-04-11 20:32:46.108[20.1299991608, 28.25, 131.1999969482, 1261.0,...0.1269890
972024-04-11 20:32:46.108[13.8100004196, 23.75, 91.5599975586, 597.7999...0.1269890
982024-04-11 20:32:46.108[11.1499996185, 13.0799999237, 70.8700027466, ...0.8720630
992024-04-11 20:32:46.108[17.2700004578, 25.4200000763, 112.4000015259,...0.1269890

100 rows × 4 columns

Undeploy the Pipeline

With the tutorial complete, we undeploy the pipeline and return the resources back to the cluster.

created2024-04-11 20:32:16.776672+00:00
last_updated2024-04-11 20:32:29.554629+00:00
versions3d8f88f7-13d0-4042-a34b-7535fd3dc323, a94a9327-1255-4cca-b3a5-8eb598512a71