Computer Vision Yolov8n Edge Deployment and Observability in Wallaroo
The Yolov8 computer vision model is used for fast recognition of objects in images. This tutorial demonstrates how to:
Deploy a Yolov8n pre-trained model into a Wallaroo Ops server and perform inferences on it.
Publish the pipeline to the OCI registry configured in the Wallaroo Ops server.
Add an edge location to the Wallaroo pipeline publish.
Deploy the pipeline as a Wallaroo Server on an edge device through Docker, and display the inference logs submitted to the Wallaroo Ops server.
Wallaroo Ops Center provides the ability to publish Wallaroo pipelines to an Open Continer Initative (OCI) compliant registry, then deploy those pipelines on edge devices as Docker container or Kubernetes pods. See Wallaroo SDK Essentials Guide: Pipeline Edge Publication for full details.
For this tutorial, the helper module CVDemoUtils and WallarooUtils are used to transform a sample image into a pandas DataFrame. This DataFrame is then submitted to the Yolov8n model deployed in Wallaroo.
References
Wallaroo Workspaces: Workspaces are environments were users upload models, create pipelines and other artifacts. The workspace should be considered the fundamental area where work is done. Workspaces are shared with other users to give them access to the same models, pipelines, etc.
Wallaroo Model Upload and Registration: ML Models are uploaded to Wallaroo through the SDK or the MLOps API to a workspace. ML models include default runtimes (ONNX, Python Step, and TensorFlow) that are run directly through the Wallaroo engine, and containerized runtimes (Hugging Face, PyTorch, etc) that are run through in a container through the Wallaroo engine.
Wallaroo Pipelines: Pipelines are used to deploy models for inferencing. Each model is a pipeline step in a pipelines, where the inputs of the previous step are fed into the next. Pipeline steps can be ML models, Python scripts, or Arbitrary Python (these contain necessary models and artifacts for running a model).
# Import Wallaroo Python SDKimportwallaroofromwallaroo.objectimportEntityNotFoundErrorfromwallaroo.frameworkimportFrameworkfromCVDemoUtilsimportCVDemofromWallarooUtilsimportUtilcvDemo=CVDemo()
util=Util()
# used to display DataFrame information without truncatingfromIPython.displayimportdisplayimportpandasaspdpd.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.
Connect to the Wallaroo Instance Exercise
Connect to the Wallaroo instance. If connecting through the JupyterHub service, then only the wallaroo.Client() is required. If connecting externally through the Wallaroo SDK, use the wallaroo.client(api_endpoint, auth_endpoint) method.
Sample code:
wl=wallaroo.Client()
# Connect to the Wallaroo instance herewl=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, update suffix with your first and last name. For example:
suffix='lazel-geth'
Create a New Workspace Exercise
Set the model name, file name, pipeline name, and workspace name.
# set helper variables heresuffix=''model_name='yolov8n'model_filename='./models/cv-yolo/yolov8n.onnx'pipeline_name='yolo8demonstration'workspace_name=f'yolo8-edge-demonstration{suffix}'
Set the Current Workspace
Set the current workspace where the models are uploaded to and pipelines created.
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. For this model, the tensor fields are set to images to match the input parameters, and the batch configuration is set to single - only one record will be submitted at a time.
The sample image dogbike.png was converted to a DataFrame using the cvDemo helper modules. The converted DataFrame is stored as ./data/dogbike.df.json to save time.
The code sample below demonstrates how to use this module to convert the sample image to a DataFrame.
# convert the image to a tensorwidth, height=640, 640tensor1, resizedImage1=cvDemo.loadImageAndResize('dogbike.png', width, height)
tensor1.flatten()
# add the tensor to a DataFrame and save the DataFrame in pandas record formatdf=util.convert_data(tensor1,'images')
df.to_json("data.json", orient='records')
Inference Request
We submit the DataFrame to the pipeline using wallaroo.pipeline.infer, and store the results in the variable inf1. A copy of the dataframe is stored in the file ./data/dogbike.df.json.
For this, we will use our cvDemo module to resize the image and retrieve the tensor values.
Inference Request Exercise
To use the cvDemo, we will:
Convert the image to a 640x640 size to fit the model’s inputs.
Create a pandas DataFrame from the image tensor data.
Submit the inference request and save the data as a variable.
Sample code:
width, height=640, 640tensor1, resizedImage1=cvDemo.loadImageAndResize('./data/cv-yolo/dogbike.png', width, height)
# convert tensor1 to a pandas DataFrame# add the tensor to a DataFrame and save the DataFrame in pandas record formatdf=util.convert_data(tensor1,'images')
df.to_json("./data/cv-yolo/data.df.json", orient="records")
# inf1 = pipeline.infer_from_file('./data/cv-yolo/dogbike.df.json')inf1=pipeline.infer(df)
# inference code herewidth, height=640, 640tensor1, resizedImage1=cvDemo.loadImageAndResize('./data/cv-yolo/dogbike.png', width, height)
# convert tensor1 to a pandas DataFrame# add the tensor to a DataFrame and save the DataFrame in pandas record formatdf=util.convert_data(tensor1,'images')
df.to_json("./data/cv-yolo/data.df.json", orient="records")
# inf1 = pipeline.infer_from_file('./data/cv-yolo/dogbike.df.json')inf1=pipeline.infer(df)
Display Bounding Boxes
Using our helper method cvDemo we’ll identify the objects detected in the photo and their bounding boxes. Only objects with a confidence threshold of 50% or more are shown.
Note that the first inputs are the inference results from the previous inference request, and the second variable is the resized image. Note that the first two arguments are the inference results obtained from the inference request, and the resized image.
Display Bounding Boxes Exercise
Use the following code, modified based on the name of your inference results and resized image variables.
# draw the bounding boxes from the inference resultsconfidence_thres=0.50iou_thres=0.25cvDemo.drawYolo8Boxes(inf1, resizedImage1, width, height, confidence_thres, iou_thres, draw=True)
Another method of performing an inference using the pipeline’s deployment url.
Performing an inference through an API requires the following:
The authentication token to authorize the connection to the pipeline.
The pipeline’s inference URL.
Inference data to sent to the pipeline - in JSON, DataFrame records format, or Apache Arrow.
Full details are available through the Wallaroo API Connection Guide on how retrieve an authorization token and perform inferences through the pipeline’s API.
For this demonstration we’ll submit the pandas record, request a pandas record as the return, and set the authorization header. The results will be stored in the file curl_response.df.
Inference Through Pipeline API Exercise
We’ll use the pipeline deployment URL to submit the inference request as an API call. The following is sample code for adding the authentication token and setting the Content-Type to pandas dataFrame.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 38.0M 100 22.9M 100 15.0M 5910k 3890k 0:00:03 0:00:03 --:--:-- 9809k
Undeploy the Pipeline
Undeploy the pipeline and return the resources back to the Wallaroo cluster.
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.
Numerical Wallaroo id of the pipeline version published.
status
string
The 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 URL
string
The URL of the published pipeline engine in the edge registry.
Pipeline URL
string
The URL of the published pipeline in the edge registry.
Helm Chart URL
string
The URL of the helm chart for the published pipeline in the edge registry.
Helm Chart Reference
string
The help chart reference.
Helm Chart Version
string
The version of the Helm Chart of the published pipeline. This is also used as the Docker tag.
Engine Config
wallaroo.deployment_config.DeploymentConfig
The pipeline configuration included with the published pipeline.
Created At
DateTime
When the published pipeline was created.
Updated At
DateTime
When the published pipeline was updated.
Publish Exercise
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.
Save the publish to a variable for later use.
Sample code:
pub=pipeline.publish(deployment_config)
pub
pub=pipeline.publish(deployment_config)
pub
Waiting for pipeline publish... It may take up to 600 sec.
Pipeline is Publishing...Published.
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).
List Published Pipeline Exercise
List the pipelines and verify which ones are published or not.
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:
Field
Type
Description
id
integer
Numerical Wallaroo id of the published pipeline.
pipeline_version_id
integer
Numerical Wallaroo id of the pipeline version published.
engine_url
string
The URL of the published pipeline engine in the edge registry.
pipeline_url
string
The URL of the published pipeline in the edge registry.
created_by
string
The email address of the user that published the pipeline.
With the pipeline publish created, we can add an Edge Location. This allows the edge deployment to upload its inference results back to the Wallaroo Ops location, which are then added to the pipeline the publish originated from. These are added to the pipeline logs partition metadata.
First we’ll retrieve the pipeline logs for our current pipeline, and show the current pipeline logs metadata.
Then we’ll add the edge location we’ll deploy with the wallaroo.pipeline_publish.add_edge(name: string, tags: List[string]) method.
For the edge name, set it to firstname-lastname-edge-yolo.
Display the log information with the metadata.partition, then add the edge location to the publish. Note that edge names must be unique, so add your first and last name to the list.
# display log information here with partitionlogs=pipeline.logs(dataset=['time', 'out.output0', 'metadata'])
display(logs.loc[:, ['time', 'metadata.partition']])
Warning: The inference log is above the allowable limit and the following columns may have been suppressed for various rows in the logs: ['in.images']. To review the dropped columns for an individual inference’s suppressed data, include dataset=["metadata"] in the log request.
Warning: Pipeline log size limit exceeded. Please request logs using export_logs
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.
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 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.
The volumes settings allows for persistent volumes to store the session information. Without it, the one-time authentication token included in the EDGE_BUNDLE settings would have to be regenerated.
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 yolo8demonstration-engine-1 Recreated 0.5s
Attaching to yolo8demonstration-engine-1
yolo8demonstration-engine-1 | Wallaroo Engine - Standalone mode
yolo8demonstration-engine-1 | Login Succeeded
yolo8demonstration-engine-1 | Fetching manifest and config for pipeline: sample-registry.com/pipelines/yolo8demonstration:bf70eaf7-8c11-4b46-b751-916a43b1a555
yolo8demonstration-engine-1 | Fetching model layers
yolo8demonstration-engine-1 | digest: sha256:c6c8869645962e7711132a7e17aced2ac0f60dcdc2c7faa79b2de73847a87984
yolo8demonstration-engine-1 | filename: c6c8869645962e7711132a7e17aced2ac0f60dcdc2c7faa79b2de73847a87984
yolo8demonstration-engine-1 | name: yolov8n
yolo8demonstration-engine-1 | type: model
yolo8demonstration-engine-1 | runtime: onnx
yolo8demonstration-engine-1 | version: 693e19b5-0dc7-4afb-9922-e3f7feefe66d
yolo8demonstration-engine-1 |
yolo8demonstration-engine-1 | Fetched
yolo8demonstration-engine-1 | Starting engine
yolo8demonstration-engine-1 | Looking for preexisting `yaml` files in //modelconfigs
yolo8demonstration-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.
Kubernetes provides persistent volume support, so no settings are required.
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:
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:
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:
The following code segment generates a docker run template based on the previously published pipeline. Replace the $REGISTRYURL, $REGISTRYUSERNAME, and $REGISTRYPASSWORD to match the OCI Registry being used.
The following example uses the host workshop-yolo8n-x86-demo.eastus.cloudapp.azure.com. Replace with your own host name of your Edge deployed pipeline.
The following example uses the host workshop-yolo8n-x86-demo.eastus.cloudapp.azure.com. Replace with your own host name of your Edge deployed pipeline.
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.
Once deployed, we can perform an inference through the deployment URL. We’ll assume we’re running the inference request through the localhost and submitting the local file ./data/dogbike.df.json. Note that our inference endpoint is pipelines/yolo8demonstration - the same as our pipeline name.
The following example demonstrates sending an inference request to the edge deployed pipeline and storing the results in a pandas DataFrame in record format. The results can then be exported to other processes to render the detected images or other use cases.
The following example uses the host workshop-yolo8n-x86-demo.eastus.cloudapp.azure.com. Replace with your own host name of your Edge deployed pipeline.
To view the edge deployed pipeline logs, we can use wallaroo.pipeline.export_logs method to retrieve all of the recent logs from this pipeline, and show the edge inference results were sent with the edge name in the partition metadata.
# display log information here with partitionpipeline.export_logs(directory='./logs/partition-edge-observability-yolo',
file_prefix='edge-logs',
dataset=['time', 'metadata'])
# display the partition only resultsdf_logs=pd.read_json('./logs/partition-edge-observability-yolo/edge-logs-1.json',
orient="records",
lines=True)
#filter out just the `metadata.partition='houseprice-edgebaseline-examples'display(df_logs[df_logs['metadata.partition']==edge_name].loc[:, ['time', 'metadata.partition']])
# display(df_logs.loc[:, ['out.variable', 'metadata.partition']])
Warning: The inference log is above the allowable limit and the following columns may have been suppressed for various rows in the logs: ['in.images']. To review the dropped columns for an individual inference’s suppressed data, include dataset=["metadata"] in the log request.
time
metadata.partition
6
1701906109692
yolo-edge-demo-jch2
8
1701905914859
yolo-edge-demo-jch2
2 - Edge Deployment: Large Language Models (LLM) Summarization
Wallaroo Use Case Tutorials focused on Edge Deployments of Large Language Models (LLM) Summarization ML Models.
Large Language Model Summarization Deployment in Wallaroo
The Hugging Face LLM Summarization model is a pre-trained model that condenses text into a shorter format. This tutorial demonstrates how to:
Deploy a Hugging Face LLM Summarization pre-trained model into a Wallaroo Ops server and perform inferences on it.
Publish the pipeline to the OCI registry configured in the Wallaroo Ops server.
Add an edge location to the Wallaroo pipeline publish.
Deploy the pipeline as a Wallaroo Server on an edge device through Docker, and display the inference logs submitted to the Wallaroo Ops server.
Wallaroo Ops Center provides the ability to publish Wallaroo pipelines to an Open Continer Initative (OCI) compliant registry, then deploy those pipelines on edge devices as Docker container or Kubernetes pods. See Wallaroo SDK Essentials Guide: Pipeline Edge Publication for full details.
This demonstration will focus on deployment to the edge. The sample model is available at the following URL. This model should be downloaded and placed into the ./models/llm-summarization folder before beginning this demonstration.
Wallaroo Workspaces: Workspaces are environments were users upload models, create pipelines and other artifacts. The workspace should be considered the fundamental area where work is done. Workspaces are shared with other users to give them access to the same models, pipelines, etc.
Wallaroo Model Upload and Registration: ML Models are uploaded to Wallaroo through the SDK or the MLOps API to a workspace. ML models include default runtimes (ONNX, Python Step, and TensorFlow) that are run directly through the Wallaroo engine, and containerized runtimes (Hugging Face, PyTorch, etc) that are run through in a container through the Wallaroo engine.
Wallaroo Pipelines: Pipelines are used to deploy models for inferencing. Each model is a pipeline step in a pipelines, where the inputs of the previous step are fed into the next. Pipeline steps can be ML models, Python scripts, or Arbitrary Python (these contain necessary models and artifacts for running a model).
# Import Wallaroo Python SDKimportwallaroofromwallaroo.objectimportEntityNotFoundErrorfromwallaroo.frameworkimportFramework# used to display DataFrame information without truncatingfromIPython.displayimportdisplayimportpandasaspdpd.set_option('display.max_colwidth', None)
importpyarrowaspa
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, update suffix with your first and last name. For example:
suffix='lazel-geth'
Create a New Workspace Exercise
Set the model name, file name, pipeline name, and workspace name.
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 the Hugging Face framework, which is specified in the framework parameter. Hugging Face is a non-native runtime, which requires that the input and output schemas as specified during the model upload process.
The model name and file name were set in the variables above. Use them to upload the model.
Sample code:
input_schema=pa.schema([
pa.field('inputs', pa.string()),
pa.field('return_text', pa.bool_()),
pa.field('return_tensors', pa.bool_()),
pa.field('clean_up_tokenization_spaces', pa.bool_()),
# pa.field('generate_kwargs', pa.map_(pa.string(), pa.null())), # dictionaries are not currently supported by the engine])
output_schema=pa.schema([
pa.field('summary_text', pa.string()),
])
model=wl.upload_model(model_name,
model_filename,
framework=wallaroo.framework.Framework.HUGGING_FACE_SUMMARIZATION,
input_schema=input_schema,
output_schema=output_schema )
# Upload Retrained LLM Summarization Model input_schema=pa.schema([
pa.field('inputs', pa.string()),
pa.field('return_text', pa.bool_()),
pa.field('return_tensors', pa.bool_()),
pa.field('clean_up_tokenization_spaces', pa.bool_()),
# pa.field('generate_kwargs', pa.map_(pa.string(), pa.null())), # dictionaries are not currently supported by the engine])
output_schema=pa.schema([
pa.field('summary_text', pa.string()),
])
model=wl.upload_model(model_name,
model_filename,
framework=wallaroo.framework.Framework.HUGGING_FACE_SUMMARIZATION,
input_schema=input_schema,
output_schema=output_schema )
Waiting for model loading - this will take up to 10.0min.
Model is pending loading to a container runtime..
Model is attempting loading to a container runtime.............................................successful
Ready
Pipeline Deployment Configuration
For our pipeline we set the deployment configuration to set the resources the pipeline will be allocated from the Kubernetes cluster hosting the Wallaroo Ops instance. The Hugging Face model is deployed as a Containerized Runtime in Wallaroo, so the configuration specified the sidekick cpu and memory options.
We submit the DataFrame to the pipeline using wallaroo.pipeline.infer and display the results. We’ll use both the Wallaroo SDK and the MLOps API.
Inference Request Exercise
Perform an inference request. We’ll generate our sample dataframe, then use it for the inference.
Sample Code:
# sample dataframe inputinput_data= {
"inputs": ["LinkedIn (/lɪŋktˈɪn/) is a business and employment-focused social media platform that works through websites and mobile apps. It launched on May 5, 2003. It is now owned by Microsoft. The platform is primarily used for professional networking and career development, and allows jobseekers to post their CVs and employers to post jobs. From 2015 most of the company's revenue came from selling access to information about its members to recruiters and sales professionals. Since December 2016, it has been a wholly owned subsidiary of Microsoft. As of March 2023, LinkedIn has more than 900 million registered members from over 200 countries and territories. LinkedIn allows members (both workers and employers) to create profiles and connect with each other in an online social network which may represent real-world professional relationships. Members can invite anyone (whether an existing member or not) to become a connection. LinkedIn can also be used to organize offline events, join groups, write articles, publish job postings, post photos and videos, and more"], # required"return_text": [True], # optional: using the defaults, similar to not passing this parameter"return_tensors": [False], # optional: using the defaults, similar to not passing this parameter"clean_up_tokenization_spaces": [False], # optional: using the defaults, similar to not passing this parameter}
dataframe=pd.DataFrame(input_data)
dataframe
# sample dataframe inputinput_data= {
"inputs": ["LinkedIn (/lɪŋktˈɪn/) is a business and employment-focused social media platform that works through websites and mobile apps. It launched on May 5, 2003. It is now owned by Microsoft. The platform is primarily used for professional networking and career development, and allows jobseekers to post their CVs and employers to post jobs. From 2015 most of the company's revenue came from selling access to information about its members to recruiters and sales professionals. Since December 2016, it has been a wholly owned subsidiary of Microsoft. As of March 2023, LinkedIn has more than 900 million registered members from over 200 countries and territories. LinkedIn allows members (both workers and employers) to create profiles and connect with each other in an online social network which may represent real-world professional relationships. Members can invite anyone (whether an existing member or not) to become a connection. LinkedIn can also be used to organize offline events, join groups, write articles, publish job postings, post photos and videos, and more"], # required"return_text": [True], # optional: using the defaults, similar to not passing this parameter"return_tensors": [False], # optional: using the defaults, similar to not passing this parameter"clean_up_tokenization_spaces": [False], # optional: using the defaults, similar to not passing this parameter}
dataframe=pd.DataFrame(input_data)
dataframe
inputs
return_text
return_tensors
clean_up_tokenization_spaces
0
LinkedIn (/lɪŋktˈɪn/) is a business and employment-focused social media platform that works through websites and mobile apps. It launched on May 5, 2003. It is now owned by Microsoft. The platform is primarily used for professional networking and career development, and allows jobseekers to post their CVs and employers to post jobs. From 2015 most of the company's revenue came from selling access to information about its members to recruiters and sales professionals. Since December 2016, it has been a wholly owned subsidiary of Microsoft. As of March 2023, LinkedIn has more than 900 million registered members from over 200 countries and territories. LinkedIn allows members (both workers and employers) to create profiles and connect with each other in an online social network which may represent real-world professional relationships. Members can invite anyone (whether an existing member or not) to become a connection. LinkedIn can also be used to organize offline events, join groups, write articles, publish job postings, post photos and videos, and more
True
False
False
Use the Pipeline Deployment URL for the inference request, and submit the sample DataFrame as our input.
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.
Numerical Wallaroo id of the pipeline version published.
status
string
The 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 URL
string
The URL of the published pipeline engine in the edge registry.
Pipeline URL
string
The URL of the published pipeline in the edge registry.
Helm Chart URL
string
The URL of the helm chart for the published pipeline in the edge registry.
Helm Chart Reference
string
The help chart reference.
Helm Chart Version
string
The version of the Helm Chart of the published pipeline. This is also used as the Docker tag.
Engine Config
wallaroo.deployment_config.DeploymentConfig
The pipeline configuration included with the published pipeline.
Created At
DateTime
When the published pipeline was created.
Updated At
DateTime
When the published pipeline was updated.
Publish Exercise
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.
Save the publish to a variable for later use.
Sample code:
pub=pipeline.publish(deployment_config)
pub
pub=pipeline.publish(deployment_config)
pub
Waiting for pipeline publish... It may take up to 600 sec.
Pipeline is Publishing................Published.
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).
List Published Pipeline Exercise
List the pipelines and verify which ones are published or not.
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:
Field
Type
Description
id
integer
Numerical Wallaroo id of the published pipeline.
pipeline_version_id
integer
Numerical Wallaroo id of the pipeline version published.
engine_url
string
The URL of the published pipeline engine in the edge registry.
pipeline_url
string
The URL of the published pipeline in the edge registry.
created_by
string
The email address of the user that published the pipeline.
With the pipeline publish created, we can add an Edge Location. This allows the edge deployment to upload its inference results back to the Wallaroo Ops location, which are then added to the pipeline the publish originated from. These are added to the pipeline logs partition metadata.
First we’ll retrieve the pipeline logs for our current pipeline, and show the current pipeline logs metadata.
For the edge name, set it to firstname-lastname-edge-yolo.
Display the log information with the metadata.partition, then add the edge location to the publish. Note that edge names must be unique, so add your first and last name to the list.
LinkedIn is a business and employment-focused social media platform that works through websites and mobile apps. It launched on May 5, 2003. LinkedIn allows members (both workers and employers) to create profiles and connect with each other in an online social network which may represent real-world professional relationships.
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.
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 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.
The volumes settings allows for persistent volumes to store the session information. Without it, the one-time authentication token included in the EDGE_BUNDLE settings would have to be regenerated.
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 yolo8demonstration-engine-1 Recreated 0.5s
Attaching to yolo8demonstration-engine-1
yolo8demonstration-engine-1 | Wallaroo Engine - Standalone mode
yolo8demonstration-engine-1 | Login Succeeded
yolo8demonstration-engine-1 | Fetching manifest and config for pipeline: sample-registry.com/pipelines/yolo8demonstration:bf70eaf7-8c11-4b46-b751-916a43b1a555
yolo8demonstration-engine-1 | Fetching model layers
yolo8demonstration-engine-1 | digest: sha256:c6c8869645962e7711132a7e17aced2ac0f60dcdc2c7faa79b2de73847a87984
yolo8demonstration-engine-1 | filename: c6c8869645962e7711132a7e17aced2ac0f60dcdc2c7faa79b2de73847a87984
yolo8demonstration-engine-1 | name: yolov8n
yolo8demonstration-engine-1 | type: model
yolo8demonstration-engine-1 | runtime: onnx
yolo8demonstration-engine-1 | version: 693e19b5-0dc7-4afb-9922-e3f7feefe66d
yolo8demonstration-engine-1 |
yolo8demonstration-engine-1 | Fetched
yolo8demonstration-engine-1 | Starting engine
yolo8demonstration-engine-1 | Looking for preexisting `yaml` files in //modelconfigs
yolo8demonstration-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.
Kubernetes provides persistent volume support, so no settings are required.
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:
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:
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:
The following code segment generates a docker run template based on the previously published pipeline. Replace the $REGISTRYURL, $REGISTRYUSERNAME, and $REGISTRYPASSWORD to match the OCI Registry being used.
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.
Once deployed, we can perform an inference through the deployment URL. We’ll assume we’re running the inference request through the localhost and submitting the local file ./data/dogbike.df.json. Note that our inference endpoint is pipelines/yolo8demonstration - the same as our pipeline name.
The following example demonstrates sending an inference request to the edge deployed pipeline and storing the results in a pandas DataFrame in record format. The results can then be exported to other processes to render the detected images or other use cases.
[{"check_failures":[],"elapsed":[310666674,4294967295],"model_name":"hf-summarizer-standard","model_version":"7dbae7b4-20d0-40f7-a3f5-eeabdd77f418","original_data":null,"outputs":[{"String":{"data":["LinkedIn is a business and employment-focused social media platform that works through websites and mobile apps. It launched on May 5, 2003. LinkedIn allows members (both workers and employers) to create profiles and connect with each other in an online social network which may represent real-world professional relationships."],"dim":[1,1],"v":1}}],"pipeline_name":"hf-summarizer-standard","shadow_data":{},"time":1701815846451}]
3 - Edge Deployment: Forecast
Wallaroo Use Case Tutorials focused on Edge Deployments of Forecast ML Models.
Forecast Retail Deployment in Wallaroo
This tutorial demonstrates how to:
Deploy a Forecast Python trained model into a Wallaroo Ops server and perform inferences on it.
Publish the pipeline to the OCI registry configured in the Wallaroo Ops server.
Add an edge location to the Wallaroo pipeline publish.
Deploy the pipeline as a Wallaroo Server on an edge device through Docker, and display the inference logs submitted to the Wallaroo Ops server.
Wallaroo Ops Center provides the ability to publish Wallaroo pipelines to an Open Continer Initative (OCI) compliant registry, then deploy those pipelines on edge devices as Docker container or Kubernetes pods. See Wallaroo SDK Essentials Guide: Pipeline Edge Publication for full details.
This demonstration will focus on deployment to the edge.
References
Wallaroo Workspaces: Workspaces are environments were users upload models, create pipelines and other artifacts. The workspace should be considered the fundamental area where work is done. Workspaces are shared with other users to give them access to the same models, pipelines, etc.
Wallaroo Model Upload and Registration: ML Models are uploaded to Wallaroo through the SDK or the MLOps API to a workspace. ML models include default runtimes (ONNX, Python Step, and TensorFlow) that are run directly through the Wallaroo engine, and containerized runtimes (Hugging Face, PyTorch, etc) that are run through in a container through the Wallaroo engine.
Wallaroo Pipelines: Pipelines are used to deploy models for inferencing. Each model is a pipeline step in a pipelines, where the inputs of the previous step are fed into the next. Pipeline steps can be ML models, Python scripts, or Arbitrary Python (these contain necessary models and artifacts for running a model).
# Import Wallaroo Python SDKimportwallaroofromwallaroo.objectimportEntityNotFoundErrorfromwallaroo.frameworkimportFramework# used to display DataFrame information without truncatingfromIPython.displayimportdisplayimportpandasaspdpd.set_option('display.max_colwidth', None)
importpyarrowaspa
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.
Connect to the Wallaroo Instance Exercise
Connect to the Wallaroo instance. If connecting through the JupyterHub service, then only the wallaroo.Client() is required. If connecting externally through the Wallaroo SDK, use the wallaroo.client(api_endpoint, auth_endpoint) method.
Sample code:
wl=wallaroo.Client()
# connect to Wallaroo herewl=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, update suffix with your first and last name. For example:
suffix='lazel-geth'
Create a New Workspace Exercise
Set the model name, file name, pipeline name, and workspace name.
# set variablessuffix=''model_name='retail-forecast'model_filename='./models/forecast/forecast_standard.py'pipeline_name='retail-forecast'workspace_name=f'retail-forecast-edge-demo{suffix}'
Set the Current Workspace
Set the current workspace where the models are uploaded to and pipelines created.
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 a Python script, which is specified in the framework parameter. To properly receive and return inference results, we specify the input and output schemas in Apache Arrow format.
The model name and file name were set in the variables above. Use them to upload the model.
Sample code:
# set the input and output schemasinput_schema=pa.schema([
pa.field('count', pa.list_(pa.int64()))
])
output_schema=pa.schema([
pa.field('forecast', pa.list_(pa.int64())),
pa.field('weekly_average', pa.list_(pa.float64()))
])
# upload the modelsmodel_version=wl.upload_model('forecast-control-model',
'./models/forecast/forecast_standard.py',
framework=Framework.PYTHON).configure(
"python",
input_schema=input_schema,
output_schema=output_schema )
# Upload forecasting model# set the input and output schemasinput_schema=pa.schema([
pa.field('count', pa.list_(pa.int64()))
])
output_schema=pa.schema([
pa.field('forecast', pa.list_(pa.int64())),
pa.field('weekly_average', pa.list_(pa.float64()))
])
# upload the modelsmodel_version=wl.upload_model('forecast-control-model',
'./models/forecast/forecast_standard.py',
framework=Framework.PYTHON).configure(
"python",
input_schema=input_schema,
output_schema=output_schema )
Pipeline Deployment Configuration
For our pipeline we set the deployment configuration to set the resources the pipeline will be allocated from the Kubernetes cluster hosting the Wallaroo Ops instance. The Hugging Face model is deployed as a Containerized Runtime in Wallaroo, so the configuration specified the sidekick cpu and memory options.
We submit the DataFrame to the pipeline using wallaroo.pipeline.infer_from_file and display the results. We’ll use both the Wallaroo SDK and the MLOps API.
Inference Request Exercise
Perform an inference request. We’ll generate our sample dataframe, then use it for the inference.
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.
Numerical Wallaroo id of the pipeline version published.
status
string
The 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 URL
string
The URL of the published pipeline engine in the edge registry.
Pipeline URL
string
The URL of the published pipeline in the edge registry.
Helm Chart URL
string
The URL of the helm chart for the published pipeline in the edge registry.
Helm Chart Reference
string
The help chart reference.
Helm Chart Version
string
The version of the Helm Chart of the published pipeline. This is also used as the Docker tag.
Engine Config
wallaroo.deployment_config.DeploymentConfig
The pipeline configuration included with the published pipeline.
Created At
DateTime
When the published pipeline was created.
Updated At
DateTime
When the published pipeline was updated.
Publish Exercise
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.
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).
List Published Pipeline Exercise
List the pipelines and verify which ones are published or not.
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:
Field
Type
Description
id
integer
Numerical Wallaroo id of the published pipeline.
pipeline_version_id
integer
Numerical Wallaroo id of the pipeline version published.
engine_url
string
The URL of the published pipeline engine in the edge registry.
pipeline_url
string
The URL of the published pipeline in the edge registry.
created_by
string
The email address of the user that published the pipeline.
With the pipeline publish created, we can add an Edge Location. This allows the edge deployment to upload its inference results back to the Wallaroo Ops location, which are then added to the pipeline the publish originated from. These are added to the pipeline logs partition metadata.
First we’ll retrieve the pipeline logs for our current pipeline, and show the current pipeline logs metadata.
Add Edge Location Exercise
Display the log information with the metadata.partition, then add the edge location to the publish. Note that edge names must be unique, so add your first and last name to the list.
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.
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 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.
The volumes settings allows for persistent volumes to store the session information. Without it, the one-time authentication token included in the EDGE_BUNDLE settings would have to be regenerated.
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 yolo8demonstration-engine-1 Recreated 0.5s
Attaching to yolo8demonstration-engine-1
yolo8demonstration-engine-1 | Wallaroo Engine - Standalone mode
yolo8demonstration-engine-1 | Login Succeeded
yolo8demonstration-engine-1 | Fetching manifest and config for pipeline: sample-registry.com/pipelines/yolo8demonstration:bf70eaf7-8c11-4b46-b751-916a43b1a555
yolo8demonstration-engine-1 | Fetching model layers
yolo8demonstration-engine-1 | digest: sha256:c6c8869645962e7711132a7e17aced2ac0f60dcdc2c7faa79b2de73847a87984
yolo8demonstration-engine-1 | filename: c6c8869645962e7711132a7e17aced2ac0f60dcdc2c7faa79b2de73847a87984
yolo8demonstration-engine-1 | name: yolov8n
yolo8demonstration-engine-1 | type: model
yolo8demonstration-engine-1 | runtime: onnx
yolo8demonstration-engine-1 | version: 693e19b5-0dc7-4afb-9922-e3f7feefe66d
yolo8demonstration-engine-1 |
yolo8demonstration-engine-1 | Fetched
yolo8demonstration-engine-1 | Starting engine
yolo8demonstration-engine-1 | Looking for preexisting `yaml` files in //modelconfigs
yolo8demonstration-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.
Kubernetes provides persistent volume support, so no settings are required.
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:
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:
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:
The following code segment generates a docker run template based on the previously published pipeline. Replace the $REGISTRYURL, $REGISTRYUSERNAME, and $REGISTRYPASSWORD to match the OCI Registry being used.
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.
Once deployed, we can perform an inference through the deployment URL. We’ll assume we’re running the inference request through the localhost and submitting the local file ./data/dogbike.df.json. Note that our inference endpoint is pipelines/yolo8demonstration - the same as our pipeline name.
The following example demonstrates sending an inference request to the edge deployed pipeline and storing the results in a pandas DataFrame in record format. The results can then be exported to other processes to render the detected images or other use cases.
To view the edge deployed pipeline logs, we can use wallaroo.pipeline.export_logs method to retrieve all of the recent logs from this pipeline, and show the edge inference results were sent with the edge name in the partition metadata.
Sample code:
# display log information here with partitionpipeline.export_logs(directory='./logs/partition-edge-observability-forecasting',
file_prefix='edge-logs',
dataset=['time', 'metadata'])
# display the partition only resultsdf_logs=pd.read_json('./logs/partition-edge-observability-forecasting/edge-logs-1.json',
orient="records",
lines=True)
# display just the entries with out edge locationdisplay(df_logs[df_logs['metadata.partition']==edge_name].loc[:, ['time', 'metadata.partition']])
# display log information here with partitionpipeline.export_logs(directory='./logs/partition-edge-observability-forecasting',
file_prefix='edge-logs',
dataset=['time', 'metadata'])
# display the partition only resultsdf_logs=pd.read_json('./logs/partition-edge-observability-forecasting/edge-logs-1.json',
orient="records",
lines=True)
# display just the entries with out edge locationdisplay(df_logs[df_logs['metadata.partition']==edge_name].loc[:, ['time', 'metadata.partition']])