Wallaroo Edge Observability with Classification Financial Models

A demonstration on publishing an a Classification Financial model with Edge Observability through Wallaroo.

The following tutorial is available on the Wallaroo Github Repository.

Classification Financial Services Edge Deployment Demonstration

This notebook will walk through building Wallaroo pipeline with a a Classification model deployed to detect the likelihood of credit card fraud, then publishing that pipeline to an Open Container Initiative (OCI) Registry where it can be deployed in other Docker and Kubernetes environments.

This demonstration will focus on deployment to the edge. For further examples of using Wallaroo with this computer vision models, see Wallaroo 101.

This demonstration performs the following:

  • In Wallaroo Ops:
    • Setting up a workspace, pipeline, and model for deriving the price of a house based on inputs.
    • Creating an assay from a sample of inferences.
    • Display the inference result and upload the assay to the Wallaroo instance where it can be referenced later.
  • In a remote aka edge location:
    • Deploying the Wallaroo pipeline as a Wallaroo Inference Server deployed on an edge device with observability features.
  • In Wallaroo Ops:
    • Observe the Wallaroo Ops and remote Wallaroo Inference Server inference results as part of the pipeline logs.

Prerequisites

  • A deployed Wallaroo Ops instance.
  • A location with Docker or Kubernetes with helm for Wallaroo Inference server deployments.
  • The following Python libraries installed:
    • wallaroo: The Wallaroo SDK. Included with the Wallaroo JupyterHub service by default.
    • pandas: Pandas, mainly used for Pandas DataFrame

References

Data Scientist Pipeline Publish Steps

Load Libraries

The first step is to import the libraries used in this notebook.

import wallaroo
from wallaroo.object import EntityNotFoundError

import pyarrow as pa
import pandas as pd
import requests

# used to display dataframe information without truncating
from IPython.display import display
pd.set_option('display.max_colwidth', None)

Connect to the Wallaroo Instance through the User Interface

The next step is to 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(). For more information on Wallaroo Client settings, see the Client Connection guide.

wl = wallaroo.Client()

Create a New Workspace

We’ll use the SDK below to create our workspace , assign as our current workspace, then display all of the workspaces we have at the moment. We’ll also set up variables for our models and pipelines down the road, so we have one spot to change names to whatever fits your organization’s standards best.

To allow this tutorial to be run by multiple users in the same Wallaroo instance, a random 4 character prefix will be added to the workspace, pipeline, and model. Feel free to set suffix='' if this is not required.

import string
import random

# make a random 4 character suffix to verify uniqueness in tutorials
random_suffix= ''.join(random.choice(string.ascii_lowercase) for i in range(4))

suffix='jch'

workspace_name = f'edge-observability-demo{suffix}'
pipeline_name = 'edge-observability-pipeline'
xgboost_model_name = 'ccfraud-xgboost'
xgboost_model_file_name = './models/xgboost_ccfraud.onnx'
def get_workspace(name):
    workspace = None
    for ws in wl.list_workspaces():
        if ws.name() == name:
            workspace= ws
    if(workspace == None):
        workspace = wl.create_workspace(name)
    return workspace

def get_pipeline(name):
    try:
        pipeline = wl.pipelines_by_name(name)[0]
    except EntityNotFoundError:
        pipeline = wl.build_pipeline(name)
    return pipeline
workspace = get_workspace(workspace_name)

wl.set_current_workspace(workspace)
{'name': 'edge-observability-demojch', 'id': 14, 'archived': False, 'created_by': 'b3deff28-04d0-41b8-a04f-b5cf610d6ce9', 'created_at': '2023-10-31T20:12:45.456363+00:00', 'models': [], 'pipelines': []}

Upload the Model

When a model is uploaded to a Wallaroo cluster, it is optimized and packaged to make it ready to run as part of a pipeline. In many times, the Wallaroo Server can natively run a model without any Python overhead. In other cases, such as a Python script, a custom Python environment will be automatically generated. This is comparable to the process of “containerizing” a model by adding a small HTTP server and other wrapping around it.

Our pretrained model is in ONNX format, which is specified in the framework parameter.

xgboost_edge_demo_model = wl.upload_model(
    xgboost_model_name,
    xgboost_model_file_name,
    framework=wallaroo.framework.Framework.ONNX,
).configure(tensor_fields=["tensor"])

Reserve Pipeline Resources

Before deploying an inference engine we need to tell wallaroo what resources it will need.
To do this we will use the wallaroo DeploymentConfigBuilder() and fill in the options listed below to determine what the properties of our inference engine will be.

We will be testing this deployment for an edge scenario, so the resource specifications are kept small – what’s the minimum needed to meet the expected load on the planned hardware.

  • cpus - 1 => allow the engine to use 4 CPU cores when running the neural net
  • memory - 900Mi => each inference engine will have 2 GB of memory, which is plenty for processing a single image at a time.
  • arch - we will specify the X86 architecture.
deploy_config = (wallaroo
                 .DeploymentConfigBuilder()
                 .replica_count(1)
                 .cpus(1)
                 .memory("900Mi")
                 .build()
                 )

Simulated Edge Deployment

We will now deploy our pipeline into the current Kubernetes environment using the specified resource constraints. This is a “simulated edge” deploy in that we try to mimic the edge hardware as closely as possible.

pipeline = get_pipeline(pipeline_name)
display(pipeline)

# clear the pipeline if previously run
pipeline.clear()
pipeline.add_model_step(xgboost_edge_demo_model)

pipeline.deploy(deployment_config = deploy_config)
nameedge-observability-pipeline
created2023-10-31 20:12:45.895294+00:00
last_updated2023-10-31 20:12:45.895294+00:00
deployed(none)
archNone
tags
versions5d440e01-f2db-440c-a4f9-cd28bb491b6c
steps
publishedFalse
Waiting for deployment - this will take up to 45s ....... ok
nameedge-observability-pipeline
created2023-10-31 20:12:45.895294+00:00
last_updated2023-10-31 20:12:46.009712+00:00
deployedTrue
archNone
tags
versions2b335efd-5593-422c-9ee9-52542b59601a, 5d440e01-f2db-440c-a4f9-cd28bb491b6c
stepsccfraud-xgboost
publishedFalse

Run Single Image Inference

A single image, encoded using the Apache Arrow format, is sent to the deployed pipeline. Arrow is used here because, as a binary protocol, there is far lower network and compute overhead than using JSON. The Wallaroo Server engine accepts both JSON, pandas DataFrame, and Apache Arrow formats.

The sample DataFrames and arrow tables are in the ./data directory. We’ll use the Apache Arrow table cc_data_10k.arrow.

Once complete, we’ll display how long the inference request took.

import datetime
import time

deploy_url = pipeline._deployment._url()

headers = wl.auth.auth_header()

headers['Content-Type']='application/vnd.apache.arrow.file'
# headers['Content-Type']='application/json; format=pandas-records'
headers['Accept']='application/json; format=pandas-records'

dataFile = './data/cc_data_1k.arrow'
local_inference_start = datetime.datetime.now()
!curl -X POST {deploy_url} \
     -H "Authorization:{headers['Authorization']}" \
     -H "Content-Type:{headers['Content-Type']}" \
     -H "Accept:{headers['Accept']}" \
     --data-binary @{dataFile} > curl_response_xgboost.df.json
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  799k  100  685k  100  114k  39.3M  6733k --:--:-- --:--:-- --:--:-- 45.9M

We will import the inference output, and isolate the metadata partition to store where the inference results are stored in the pipeline logs.

# display the first 20 results

df_results = pd.read_json('./curl_response_xgboost.df.json', orient="records")
# get just the partition
df_results['partition'] = df_results['metadata'].map(lambda x: x['partition'])
# display(df_results.head(20))
display(df_results.head(20).loc[:, ['time', 'out', 'partition']])
timeoutpartition
01698783174953{'variable': [1.0094898]}engine-5d9b58dbd9-v5rvw
11698783174953{'variable': [1.0094898]}engine-5d9b58dbd9-v5rvw
21698783174953{'variable': [1.0094898]}engine-5d9b58dbd9-v5rvw
31698783174953{'variable': [1.0094898]}engine-5d9b58dbd9-v5rvw
41698783174953{'variable': [-1.9073485999999998e-06]}engine-5d9b58dbd9-v5rvw
51698783174953{'variable': [-4.4882298e-05]}engine-5d9b58dbd9-v5rvw
61698783174953{'variable': [-9.36985e-05]}engine-5d9b58dbd9-v5rvw
71698783174953{'variable': [-8.3208084e-05]}engine-5d9b58dbd9-v5rvw
81698783174953{'variable': [-8.332728999999999e-05]}engine-5d9b58dbd9-v5rvw
91698783174953{'variable': [0.0004896521599999999]}engine-5d9b58dbd9-v5rvw
101698783174953{'variable': [0.0006609559]}engine-5d9b58dbd9-v5rvw
111698783174953{'variable': [7.57277e-05]}engine-5d9b58dbd9-v5rvw
121698783174953{'variable': [-0.000100553036]}engine-5d9b58dbd9-v5rvw
131698783174953{'variable': [-0.0005198717]}engine-5d9b58dbd9-v5rvw
141698783174953{'variable': [-3.695488e-06]}engine-5d9b58dbd9-v5rvw
151698783174953{'variable': [-0.00010883808]}engine-5d9b58dbd9-v5rvw
161698783174953{'variable': [-0.00017666817]}engine-5d9b58dbd9-v5rvw
171698783174953{'variable': [-2.8312206e-05]}engine-5d9b58dbd9-v5rvw
181698783174953{'variable': [2.1755695e-05]}engine-5d9b58dbd9-v5rvw
191698783174953{'variable': [-8.493661999999999e-05]}engine-5d9b58dbd9-v5rvw

Undeploy Pipeline

With our testing complete, we will undeploy the pipeline and return the resources back to the cluster.

pipeline.undeploy()
Waiting for undeployment - this will take up to 45s .................................... ok
nameedge-observability-pipeline
created2023-10-31 20:12:45.895294+00:00
last_updated2023-10-31 20:12:46.009712+00:00
deployedFalse
archNone
tags
versions2b335efd-5593-422c-9ee9-52542b59601a, 5d440e01-f2db-440c-a4f9-cd28bb491b6c
stepsccfraud-xgboost
publishedFalse

Publish the Pipeline for Edge Deployment

It worked! For a demo, we’ll take working once as “tested”. So now that we’ve tested our pipeline, we are ready to publish it for edge deployment.

Publishing it means assembling all of the configuration files and model assets and pushing them to an Open Container Initiative (OCI) repository set in the Wallaroo instance as the Edge Registry service. DevOps engineers then retrieve that image and deploy it through Docker, Kubernetes, or similar deployments.

See Edge Deployment Registry Guide for details on adding an OCI Registry Service to Wallaroo as the Edge Deployment Registry.

This is done through the SDK command wallaroo.pipeline.publish(deployment_config) which has the following parameters and returns.

Publish a Pipeline Parameters

The publish method takes the following parameters. The containerized pipeline will be pushed to the Edge registry service with the model, pipeline configurations, and other artifacts needed to deploy the pipeline.

ParameterTypeDescription
deployment_configwallaroo.deployment_config.DeploymentConfig (Optional)Sets the pipeline deployment configuration. For example: For more information on pipeline deployment configuration, see the Wallaroo SDK Essentials Guide: Pipeline Deployment Configuration.

Publish a Pipeline Returns

FieldTypeDescription
idintegerNumerical Wallaroo id of the published pipeline.
pipeline version idintegerNumerical Wallaroo id of the pipeline version published.
statusstringThe status of the pipeline publication. Values include:
  • PendingPublish: The pipeline publication is about to be uploaded or is in the process of being uploaded.
  • Published: The pipeline is published and ready for use.
Engine URLstringThe URL of the published pipeline engine in the edge registry.
Pipeline URLstringThe URL of the published pipeline in the edge registry.
Helm Chart URLstringThe URL of the helm chart for the published pipeline in the edge registry.
Helm Chart ReferencestringThe help chart reference.
Helm Chart VersionstringThe version of the Helm Chart of the published pipeline. This is also used as the Docker tag.
Engine Configwallaroo.deployment_config.DeploymentConfigThe pipeline configuration included with the published pipeline.
Created AtDateTimeWhen the published pipeline was created.
Updated AtDateTimeWhen the published pipeline was updated.

Publish Example

We will now publish the pipeline to our Edge Deployment Registry with the pipeline.publish(deployment_config) command. deployment_config is an optional field that specifies the pipeline deployment. This can be overridden by the DevOps engineer during deployment.

pub=pipeline.publish(deploy_config)
display(pub)
Waiting for pipeline publish... It may take up to 600 sec.
Pipeline is Publishing....Published.
ID2
Pipeline Version1a5a21e2-f0e8-4148-9ee2-23c877c0ac90
StatusPublished
Engine URLus-central1-docker.pkg.dev/wallaroo-dev-253816/uat/engines/proxy/wallaroo/ghcr.io/wallaroolabs/standalone-mini:v2023.4.0-4092
Pipeline URLus-central1-docker.pkg.dev/wallaroo-dev-253816/uat/pipelines/edge-observability-pipeline:1a5a21e2-f0e8-4148-9ee2-23c877c0ac90
Helm Chart URLoci://us-central1-docker.pkg.dev/wallaroo-dev-253816/uat/charts/edge-observability-pipeline
Helm Chart Referenceus-central1-docker.pkg.dev/wallaroo-dev-253816/uat/charts@sha256:8bf628174b5ff87d913590d34a4c3d5eaa846b8b2a52bcf6a76295cd588cb6e8
Helm Chart Version0.0.1-1a5a21e2-f0e8-4148-9ee2-23c877c0ac90
Engine Config{'engine': {'resources': {'limits': {'cpu': 1.0, 'memory': '512Mi'}, 'requests': {'cpu': 1.0, 'memory': '512Mi'}}}, 'engineAux': {'images': {}}, 'enginelb': {'resources': {'limits': {'cpu': 1.0, 'memory': '512Mi'}, 'requests': {'cpu': 1.0, 'memory': '512Mi'}}}}
User Images[]
Created Byjohn.hummel@wallaroo.ai
Created At2023-10-31 20:13:32.751657+00:00
Updated At2023-10-31 20:13:32.751657+00:00
Docker Run Variables{}

List Published Pipelines

The method wallaroo.client.list_pipelines() shows a list of all pipelines in the Wallaroo instance, and includes the published field that indicates whether the pipeline was published to the registry (True), or has not yet been published (False).

wl.list_pipelines()
namecreatedlast_updateddeployedarchtagsversionsstepspublished
edge-observability-pipeline2023-31-Oct 20:12:452023-31-Oct 20:13:32FalseNone1a5a21e2-f0e8-4148-9ee2-23c877c0ac90, 2b335efd-5593-422c-9ee9-52542b59601a, 5d440e01-f2db-440c-a4f9-cd28bb491b6cccfraud-xgboostTrue
housepricesagapipeline2023-31-Oct 20:04:582023-31-Oct 20:13:02TrueNone0056edf3-730f-452d-a6ed-2dfa47ff5567, 8bc714ea-8257-4512-a102-402baf3143b3, 76006480-b145-4d6a-9e95-9b2e7a4f8d8ehousepricesagacontrolTrue

List Publishes from a Pipeline

All publishes created from a pipeline are displayed with the wallaroo.pipeline.publishes method. The pipeline_version_id is used to know what version of the pipeline was used in that specific publish. This allows for pipelines to be updated over time, and newer versions to be sent and tracked to the Edge Deployment Registry service.

List Publishes Parameters

N/A

List Publishes Returns

A List of the following fields:

FieldTypeDescription
idintegerNumerical Wallaroo id of the published pipeline.
pipeline_version_idintegerNumerical Wallaroo id of the pipeline version published.
engine_urlstringThe URL of the published pipeline engine in the edge registry.
pipeline_urlstringThe URL of the published pipeline in the edge registry.
created_bystringThe email address of the user that published the pipeline.
Created AtDateTimeWhen the published pipeline was created.
Updated AtDateTimeWhen the published pipeline was updated.
pipeline.publishes()
idpipeline_version_nameengine_urlpipeline_urlcreated_bycreated_atupdated_at
21a5a21e2-f0e8-4148-9ee2-23c877c0ac90us-central1-docker.pkg.dev/wallaroo-dev-253816/uat/engines/proxy/wallaroo/ghcr.io/wallaroolabs/standalone-mini:v2023.4.0-4092us-central1-docker.pkg.dev/wallaroo-dev-253816/uat/pipelines/edge-observability-pipeline:1a5a21e2-f0e8-4148-9ee2-23c877c0ac90john.hummel@wallaroo.ai2023-31-Oct 20:13:322023-31-Oct 20:13:32

DevOps - Pipeline Edge Deployment

Once a pipeline is deployed to the Edge Registry service, it can be deployed in environments such as Docker, Kubernetes, or similar container running services by a DevOps engineer as a Wallaroo Server.

The following guides will demonstrate publishing a Wallaroo Pipeline as a Wallaroo Server.

Add Edge Location

Wallaroo Servers can optionally connect to the Wallaroo Ops instance and transmit their inference results. These are added to the pipeline logs for the published pipeline the Wallaroo Server is associated with.

Wallaroo Servers are added with the wallaroo.pipeline_publish.add_edge(name: string) method. The name is the unique primary key for each edge added to the pipeline publish and must be unique.

This returns a Publish Edge with the following fields:

FieldTypeDescription
idIntegerThe integer ID of the pipeline publish.
created_atDateTimeThe DateTime of the pipeline publish.
docker_run_variablesStringThe Docker variables in UUID format that include the following: The BUNDLE_VERSION, EDGE_NAME, JOIN_TOKEN_, OPSCENTER_HOST, PIPELINE_URL, and WORKSPACE_ID.
engine_configStringThe Wallaroo wallaroo.deployment_config.DeploymentConfig for the pipeline.
pipeline_version_idIntegerThe integer identifier of the pipeline version published.
statusStringThe status of the publish. Published is a successful publish.
updated_atDateTimeThe DateTime when the pipeline publish was updated.
user_imagesList[String]User images used in the pipeline publish.
created_byStringThe UUID of the Wallaroo user that created the pipeline publish.
engine_urlStringThe URL for the published pipeline’s Wallaroo engine in the OCI registry.
errorStringAny errors logged.
helmStringThe helm chart, helm reference and helm version.
pipeline_urlStringThe URL for the published pipeline’s container in the OCI registry.
pipeline_version_nameStringThe UUID identifier of the pipeline version published.
additional_propertiesStringAny other identities.

Two edge publishes will be created so we can demonstrate removing an edge shortly.

edge_01_name = f'edge-ccfraud-observability{random_suffix}'
edge01 = pub.add_edge(edge_01_name)
display(edge01)

edge_02_name = f'edge-ccfraud-observability-02{random_suffix}'
edge02 = pub.add_edge(edge_02_name)
display(edge02)
ID2
Pipeline Version1a5a21e2-f0e8-4148-9ee2-23c877c0ac90
StatusPublished
Engine URLus-central1-docker.pkg.dev/wallaroo-dev-253816/uat/engines/proxy/wallaroo/ghcr.io/wallaroolabs/standalone-mini:v2023.4.0-4092
Pipeline URLus-central1-docker.pkg.dev/wallaroo-dev-253816/uat/pipelines/edge-observability-pipeline:1a5a21e2-f0e8-4148-9ee2-23c877c0ac90
Helm Chart URLoci://us-central1-docker.pkg.dev/wallaroo-dev-253816/uat/charts/edge-observability-pipeline
Helm Chart Referenceus-central1-docker.pkg.dev/wallaroo-dev-253816/uat/charts@sha256:8bf628174b5ff87d913590d34a4c3d5eaa846b8b2a52bcf6a76295cd588cb6e8
Helm Chart Version0.0.1-1a5a21e2-f0e8-4148-9ee2-23c877c0ac90
Engine Config{'engine': {'resources': {'limits': {'cpu': 1.0, 'memory': '512Mi'}, 'requests': {'cpu': 1.0, 'memory': '512Mi'}}}, 'engineAux': {'images': {}}, 'enginelb': {'resources': {'limits': {'cpu': 1.0, 'memory': '512Mi'}, 'requests': {'cpu': 1.0, 'memory': '512Mi'}}}}
User Images[]
Created Byjohn.hummel@wallaroo.ai
Created At2023-10-31 20:13:32.751657+00:00
Updated At2023-10-31 20:13:32.751657+00:00
Docker Run Variables{'EDGE_BUNDLE': 'abcde'}
ID2
Pipeline Version1a5a21e2-f0e8-4148-9ee2-23c877c0ac90
StatusPublished
Engine URLus-central1-docker.pkg.dev/wallaroo-dev-253816/uat/engines/proxy/wallaroo/ghcr.io/wallaroolabs/standalone-mini:v2023.4.0-4092
Pipeline URLus-central1-docker.pkg.dev/wallaroo-dev-253816/uat/pipelines/edge-observability-pipeline:1a5a21e2-f0e8-4148-9ee2-23c877c0ac90
Helm Chart URLoci://us-central1-docker.pkg.dev/wallaroo-dev-253816/uat/charts/edge-observability-pipeline
Helm Chart Referenceus-central1-docker.pkg.dev/wallaroo-dev-253816/uat/charts@sha256:8bf628174b5ff87d913590d34a4c3d5eaa846b8b2a52bcf6a76295cd588cb6e8
Helm Chart Version0.0.1-1a5a21e2-f0e8-4148-9ee2-23c877c0ac90
Engine Config{'engine': {'resources': {'limits': {'cpu': 1.0, 'memory': '512Mi'}, 'requests': {'cpu': 1.0, 'memory': '512Mi'}}}, 'engineAux': {'images': {}}, 'enginelb': {'resources': {'limits': {'cpu': 1.0, 'memory': '512Mi'}, 'requests': {'cpu': 1.0, 'memory': '512Mi'}}}}
User Images[]
Created Byjohn.hummel@wallaroo.ai
Created At2023-10-31 20:13:32.751657+00:00
Updated At2023-10-31 20:13:32.751657+00:00
Docker Run Variables{'EDGE_BUNDLE': 'abcde'}
pipeline.list_edges()
IDNameTagsPipeline VersionSPIFFE ID
898bb58c-77c2-4164-b6cc-f004dc39e125edge-ccfraud-observabilityymgy[]6wallaroo.ai/ns/deployments/edge/898bb58c-77c2-4164-b6cc-f004dc39e125
1f35731a-f4f6-4cd0-a23a-c4a326b73277edge-ccfraud-observability-02ymgy[]6wallaroo.ai/ns/deployments/edge/1f35731a-f4f6-4cd0-a23a-c4a326b73277

Remove Edge Location

Wallaroo Servers are removed with the wallaroo.pipeline_publish.remove_edge(name: string) method.

This returns a Publish Edge with the following fields:

FieldTypeDescription
idIntegerThe integer ID of the pipeline publish.
created_atDateTimeThe DateTime of the pipeline publish.
docker_run_variablesStringThe Docker variables in UUID format that include the following: The BUNDLE_VERSION, EDGE_NAME, JOIN_TOKEN_, OPSCENTER_HOST, PIPELINE_URL, and WORKSPACE_ID.
engine_configStringThe Wallaroo wallaroo.deployment_config.DeploymentConfig for the pipeline.
pipeline_version_idIntegerThe integer identifier of the pipeline version published.
statusStringThe status of the publish. Published is a successful publish.
updated_atDateTimeThe DateTime when the pipeline publish was updated.
user_imagesList[String]User images used in the pipeline publish.
created_byStringThe UUID of the Wallaroo user that created the pipeline publish.
engine_urlStringThe URL for the published pipeline’s Wallaroo engine in the OCI registry.
errorStringAny errors logged.
helmStringThe helm chart, helm reference and helm version.
pipeline_urlStringThe URL for the published pipeline’s container in the OCI registry.
pipeline_version_nameStringThe UUID identifier of the pipeline version published.
additional_propertiesStringAny other identities.

Two edge publishes will be created so we can demonstrate removing an edge shortly.

sample = pub.remove_edge(edge_02_name)
display(sample)
None
pipeline.list_edges()
IDNameTagsPipeline VersionSPIFFE ID
898bb58c-77c2-4164-b6cc-f004dc39e125edge-ccfraud-observabilityymgy[]6wallaroo.ai/ns/deployments/edge/898bb58c-77c2-4164-b6cc-f004dc39e125

Docker Deployment

First, the DevOps engineer must authenticate to the same OCI Registry service used for the Wallaroo Edge Deployment registry.

For more details, check with the documentation on your artifact service. The following are provided for the three major cloud services:

For the deployment, the engine URL is specified with the following environmental variables:

  • DEBUG (true|false): Whether to include debug output.
  • OCI_REGISTRY: The URL of the registry service.
  • CONFIG_CPUS: The number of CPUs to use.
  • OCI_USERNAME: The edge registry username.
  • OCI_PASSWORD: The edge registry password or token.
  • PIPELINE_URL: The published pipeline URL.

Docker Deployment Example

Using our sample environment, here’s sample deployment using Docker with a computer vision ML model, the same used in the Wallaroo Use Case Tutorials Computer Vision: Retail tutorials.

docker run -p 8080:8080 \
    -e DEBUG=true \
    -e OCI_REGISTRY={your registry server} \
    -e EDGE_BUNDLE={Your edge bundle['EDGE_BUNDLE']}
    -e CONFIG_CPUS=1 \
    -e OCI_USERNAME=oauth2accesstoken \
    -e OCI_PASSWORD={registry token here} \
    -e PIPELINE_URL={your registry server}{Your Wallaroo Server pipeline} \
    {your registry server}/{Your Wallaroo Server engine}

Docker Compose Deployment

For users who prefer to use docker compose, the following sample compose.yaml file is used to launch the Wallaroo Edge pipeline. This is the same used in the Wallaroo Use Case Tutorials Computer Vision: Retail tutorials.

services:
  engine:
    image: {Your Engine URL}
    ports:
      - 8080:8080
    environment:
      EDGE_BUNDLE: {Your Edge Bundle['EDGE_BUNDLE']}
      PIPELINE_URL: {Your Pipeline URL}
      OCI_REGISTRY: {Your Edge Registry URL}
      OCI_USERNAME:  {Your Registry Username}
      OCI_PASSWORD: {Your Token or Password}
      CONFIG_CPUS: 1

For example:

services:
  engine:
    image: sample-registry.com/engine:v2023.3.0-main-3707
    ports:
      - 8080:8080
    environment:
      PIPELINE_URL: sample-registry.com/pipelines/edge-cv-retail:bf70eaf7-8c11-4b46-b751-916a43b1a555
      OCI_REGISTRY: sample-registry.com
      OCI_USERNAME:  _json_key_base64
      OCI_PASSWORD: abc123
      CONFIG_CPUS: 1

Docker Compose Deployment Example

The deployment and undeployment is then just a simple docker compose up and docker compose down. The following shows an example of deploying the Wallaroo edge pipeline using docker compose.

docker compose up
[+] Running 1/1
 ✔ Container cv_data-engine-1  Recreated                                                                                                                                                                 0.5s
Attaching to cv_data-engine-1
cv_data-engine-1  | Wallaroo Engine - Standalone mode
cv_data-engine-1  | Login Succeeded
cv_data-engine-1  | Fetching manifest and config for pipeline: sample-registry.com/pipelines/edge-cv-retail:bf70eaf7-8c11-4b46-b751-916a43b1a555
cv_data-engine-1  | Fetching model layers
cv_data-engine-1  | digest: sha256:c6c8869645962e7711132a7e17aced2ac0f60dcdc2c7faa79b2de73847a87984
cv_data-engine-1  |   filename: c6c8869645962e7711132a7e17aced2ac0f60dcdc2c7faa79b2de73847a87984
cv_data-engine-1  |   name: resnet-50
cv_data-engine-1  |   type: model
cv_data-engine-1  |   runtime: onnx
cv_data-engine-1  |   version: 693e19b5-0dc7-4afb-9922-e3f7feefe66d
cv_data-engine-1  |
cv_data-engine-1  | Fetched
cv_data-engine-1  | Starting engine
cv_data-engine-1  | Looking for preexisting `yaml` files in //modelconfigs
cv_data-engine-1  | Looking for preexisting `yaml` files in //pipelines

Helm Deployment

Published pipelines can be deployed through the use of helm charts.

Helm deployments take up to two steps - the first step is in retrieving the required values.yaml and making updates to override.

  1. Pull the helm charts from the published pipeline. The two fields are the Helm Chart URL and the Helm Chart version to specify the OCI . This typically takes the format of:
helm pull oci://{published.helm_chart_url} --version {published.helm_chart_version}
  1. Extract the tgz file and copy the values.yaml and copy the values used to edit engine allocations, etc. The following are required for the deployment to run:
ociRegistry:
  registry: {your registry service}
  username:  {registry username here}
  password: {registry token here}

Store this into another file, suc as local-values.yaml.

  1. Create the namespace to deploy the pipeline to. For example, the namespace wallaroo-edge-pipeline would be:
kubectl create -n wallaroo-edge-pipeline
  1. Deploy the helm installation with helm install through one of the following options:

    1. Specify the tgz file that was downloaded and the local values file. For example:

      helm install --namespace {namespace} --values {local values file} {helm install name} {tgz path}
      
    2. Specify the expended directory from the downloaded tgz file.

      helm install --namespace {namespace} --values {local values file} {helm install name} {helm directory path}
      
    3. Specify the Helm Pipeline Helm Chart and the Pipeline Helm Version.

      helm install --namespace {namespace} --values {local values file} {helm install name} oci://{published.helm_chart_url} --version {published.helm_chart_version}
      
  2. Once deployed, the DevOps engineer will have to forward the appropriate ports to the svc/engine-svc service in the specific pipeline. For example, using kubectl port-forward to the namespace ccfraud that would be:

    kubectl port-forward svc/engine-svc -n ccfraud01 8080 --address 0.0.0.0`
    

The following code segment generates a docker run template based on the previously published pipeline. Replace the $REGISTRYURL, $REGISTRYUSERNAME and $REGISTRYPASSWORD with your OCI registry values.

docker_command = f'''
docker run -p 8080:8080 \\
    -e DEBUG=true \\
    -e OCI_REGISTRY=$REGISTRYURL \\
    -e EDGE_BUNDLE={edge01.docker_run_variables['EDGE_BUNDLE']} \\
    -e CONFIG_CPUS=1 \\
    -e OCI_USERNAME=$REGISTRYUSERNAME \\
    -e OCI_PASSWORD=$REGISTRYPASSWORD \\
    -e PIPELINE_URL={edge01.pipeline_url} \\
    {edge01.engine_url}
'''

print(docker_command)

Edge Deployed Pipeline API Endpoints

Once deployed, we can check the pipelines and models available. We’ll use a curl command, but any HTTP based request will work the same way.

The endpoint /pipelines returns:

  • id (String): The name of the pipeline.
  • status (String): The status as either Running, or Error if there are any issues.

For this example, the deployment is made on a machine called localhost. Replace this URL with the URL of you edge deployment.

!curl testboy.local:8080/pipelines

The endpoint /models returns a List of models with the following fields:

  • name (String): The model name.
  • sha (String): The sha hash value of the ML model.
  • status (String): The status of either Running or Error if there are any issues.
  • version (String): The model version. This matches the version designation used by Wallaroo to track model versions in UUID format.
!curl testboy.local:8080/models

Edge Inference Endpoint

The inference endpoint takes the following pattern:

  • /pipelines/{pipeline-name}: The pipeline-name is the same as returned from the /pipelines endpoint as id.

Wallaroo inference endpoint URLs accept the following data inputs through the Content-Type header:

  • Content-Type: application/vnd.apache.arrow.file: For Apache Arrow tables.
  • Content-Type: application/json; format=pandas-records: For pandas DataFrame in record format.

Once deployed, we can perform an inference through the deployment URL.

The endpoint returns Content-Type: application/json; format=pandas-records by default with the following fields:

  • check_failures (List[Integer]): Whether any validation checks were triggered. For more information, see Wallaroo SDK Essentials Guide: Pipeline Management: Anomaly Testing.
  • elapsed (List[Integer]): A list of time in nanoseconds for:
    • [0] The time to serialize the input.
    • [1…n] How long each step took.
  • model_name (String): The name of the model used.
  • model_version (String): The version of the model in UUID format.
  • original_data: The original input data. Returns null if the input may be too long for a proper return.
  • outputs (List): The outputs of the inference result separated by data type, where each data type includes:
    • data: The returned values.
    • dim (List[Integer]): The dimension shape returned.
    • v (Integer): The vector shape of the data.
  • pipeline_name (String): The name of the pipeline.
  • shadow_data: Any shadow deployed data inferences in the same format as outputs.
  • time (Integer): The time since UNIX epoch.
!curl -X POST testboy.local:8080/pipelines/edge-observability-pipeline \
    -H "Content-Type: application/vnd.apache.arrow.file" \
    --data-binary @./data/cc_data_1k.arrow > curl_response_edge.df.json
# display the first 20 results

df_results = pd.read_json('./curl_response_edge.df.json', orient="records")
# display(df_results.head(20))
display(df_results.head(20).loc[:, ['time', 'out', 'metadata']])
pipeline.export_logs(
    limit=30000,
    directory='partition-edge-observability',
    file_prefix='edge-logs',
    dataset=['time', 'out', 'metadata']
)
# display the head 20 results

df_logs = pd.read_json('./partition-edge-observability/edge-logs-1.json', orient="records", lines=True)
# get just the partition
# df_results['partition'] = df_results['metadata'].map(lambda x: x['partition'])
# display(df_results.head(20))
display(df_logs.head(20).loc[:, ['time', 'out.variable', 'metadata.partition']])
display(pd.unique(df_logs['metadata.partition']))