Skip to content

Deploy SqueezeNet 1.0 INT8 model with ONNX Runtime on Azure Cobalt 100 #2139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: Deploy SqueezeNet 1.0 INT8 model with ONNX Runtime on Azure Cobalt 100

minutes_to_complete: 60

who_is_this_for: This Learning Path introduces ONNX deployment on Microsoft Azure Cobalt 100 (Arm-based) virtual machines. It is designed for developers migrating ONNX-based applications from x86_64 to Arm with minimal or no changes.

learning_objectives:
- Provision an Azure Arm64 virtual machine using Azure console, with Ubuntu as the base image.
- Learn how to create an Azure Linux 3.0 Docker container.
- Deploy an ONNX-based application inside an Azure Linux 3.0 Arm based Docker container and an Azure Linux 3.0 custom-image based Azure virtual machine.
- Perform ONNX benchmarking inside the container as well as the custom virtual machine.

prerequisites:
- A [Microsoft Azure](https://azure.microsoft.com/) account with access to Cobalt 100 based instances (Dpsv6).
- A machine with [Docker](/install-guides/docker/) installed.
- Basic understanding of Python and machine learning concepts.
- Familiarity with ONNX Runtime and Azure cloud services.

author: Jason Andrews

### Tags
skilllevels: Advanced
subjects: ML
cloud_service_providers: Microsoft Azure

armips:
- Neoverse

tools_software_languages:
- Python
- Docker
- ONNX Runtime

operatingsystems:
- Linux

further_reading:
- resource:
title: Azure Virtual Machines documentation
link: https://learn.microsoft.com/en-us/azure/virtual-machines/
type: documentation
- resource:
title: Azure Container Instances documentation
link: https://learn.microsoft.com/en-us/azure/container-instances/
type: documentation
- resource:
title: ONNX Runtime Docs
link: https://onnxruntime.ai/docs/
type: documentation
- resource:
title: ONNX (Open Neural Network Exchange) documentation
link: https://onnx.ai/
type: documentation
- resource:
title: onnxruntime_perf_test tool - ONNX Runtime performance benchmarking
link: https://onnxruntime.ai/docs/performance/tune-performance/profiling-tools.html#in-code-performance-profiling
type: documentation


### FIXED, DO NOT MODIFY
# ================================================================================
weight: 1 # _index.md always has weight of 1 to order correctly
layout: "learningpathall" # All files under learning paths have this same wrapper
learning_path_main_page: "yes" # This should be surfaced when looking for related content. Only set for _index.md of learning path content.
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# ================================================================================
# FIXED, DO NOT MODIFY THIS FILE
# ================================================================================
weight: 21 # Set to always be larger than the content in this path to be at the end of the navigation.
title: "Next Steps" # Always the same, html page title.
layout: "learningpathall" # All files under learning paths have this same wrapper for Hugo processing.
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: "About Cobalt 100 Arm-based processor and ONNX"

weight: 2

layout: "learningpathall"
---

## What is Cobalt 100 Arm-based processor?

Azure’s Cobalt 100 is built on Microsoft's first-generation, in-house Arm-based processor: the Cobalt 100. Designed entirely by Microsoft and based on Arm’s Neoverse N2 architecture, this 64-bit CPU delivers improved performance and energy efficiency across a broad spectrum of cloud-native, scale-out Linux workloads. These include web and application servers, data analytics, open-source databases, caching systems, and more. Running at 3.4 GHz, the Cobalt 100 processor allocates a dedicated physical core for each vCPU, ensuring consistent and predictable performance.

To learn more about Cobalt 100, refer to the blog [Announcing the preview of new Azure virtual machine based on the Azure Cobalt 100 processor](https://techcommunity.microsoft.com/blog/azurecompute/announcing-the-preview-of-new-azure-vms-based-on-the-azure-cobalt-100-processor/4146353).

## Introduction to Azure Linux 3.0

Azure Linux 3.0 is Microsoft's in-house, lightweight Linux distribution optimized for running cloud-native workloads on Azure. Designed with performance, security, and reliability in mind, it is fully supported by Microsoft and tailored for containers, microservices, and Kubernetes. With native support for Arm64 (AArch64) architecture, Azure Linux 3.0 enables efficient execution of workloads on energy-efficient Arm-based infrastructure, making it a powerful choice for scalable and cost-effective cloud deployments.

## Introduction to ONNX

ONNX (Open Neural Network Exchange) is an open standard for representing machine learning models, enabling interoperability between different AI frameworks. It allows you to train a model in one framework (like PyTorch or TensorFlow) and run it using ONNX Runtime for optimized inference.

In this Learning Path, we deploy ONNX on Azure Linux 3.0 (Arm64) and benchmark its performance using the[ onnxruntime_perf_test tool](https://onnxruntime.ai/docs/performance/tune-performance/profiling-tools.html#in-code-performance-profiling).
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: Baseline Testing
weight: 6

### FIXED, DO NOT MODIFY
layout: learningpathall
---


## Baseline testing using ONNX Runtime:

This test measures the inference latency of the ONNX Runtime by timing how long it takes to process a single input using the `squeezenet-int8.onnx model`. It helps evaluate how efficiently the model runs on the target hardware.

Create a **baseline.py** file with the below code for baseline test of ONNX:

```python
import onnxruntime as ort
import numpy as np
import time

session = ort.InferenceSession("squeezenet-int8.onnx")
input_name = session.get_inputs()[0].name
data = np.random.rand(1, 3, 224, 224).astype(np.float32)

start = time.time()
outputs = session.run(None, {input_name: data})
end = time.time()

print("Inference time:", end - start)
```

Run the baseline test:

```console
python3 baseline.py
```
You should see an output similar to:
```output
Inference time: 0.02060103416442871
```
{{% notice Note %}}Inference time is the amount of time it takes for a trained machine learning model to make a prediction (i.e., produce output) after receiving input data.
input tensor of shape (1, 3, 224, 224):
- 1: batch size
- 3: color channels (RGB)
- 224 x 224: image resolution (common for models like SqueezeNet)
{{% /notice %}}

#### Output summary:

- Single inference latency: ~2.60 milliseconds (0.00260 sec)
- This shows the initial (cold-start) inference performance of ONNX Runtime on CPU using an optimized int8 quantized model.
- This demonstrates that the setup is fully working, and ONNX Runtime efficiently executes quantized models on Arm64.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
title: Benchmarking via onnxruntime_perf_test
weight: 7

### FIXED, DO NOT MODIFY
layout: learningpathall
---

Now that you’ve set up and run the ONNX model (e.g., SqueezeNet), you can use it to benchmark inference performance using Python-based timing or tools like **onnxruntime_perf_test**. This helps evaluate the ONNX Runtime efficiency on Azure Arm64-based Cobalt 100 instances.

You can also compare the inference time between Cobalt 100 (Arm64) and similar D-series x86_64-based virtual machine on Azure.
As noted before, the steps to benchmark remain the same, whether it's a Docker container or a custom virtual machine.

## Run the performance tests using onnxruntime_perf_test
The **onnxruntime_perf_test** is a performance benchmarking tool included in the ONNX Runtime source code. It is used to measure the inference performance of ONNX models under various runtime conditions (like CPU, GPU, or other execution providers).

### Install Required Build Tools

```console
tdnf install -y cmake make gcc-c++ git
```
#### Install Protobuf

```console
tdnf install -y protobuf protobuf-devel
```
Then verify:
```console
protoc --version
```
You should see an output similar to:

```output
libprotoc 3.x.x
```
If installation via the package manager fails, or the version is too old for ONNX Runtime; then proceed with installing Protobuf using the AArch64 pre-built zip artifact, as discussed below.

#### Install Protobuf with Prebuilt AArch64 ZIP Artifact

```console
wget https://github.com/protocolbuffers/protobuf/releases/download/v31.1/protoc-31.1-linux-aarch_64.zip -O protoc-31.1.zip
mkdir -p $HOME/tools/protoc-31.1
unzip protoc-31.1.zip -d $HOME/tools/protoc-31.1
echo 'export PATH="$HOME/tools/protoc-31.1/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
```

Then verify:
```console
protoc --version
```
You should see an output similar to:
```output
libprotoc x.x.x
```

### Clone and Build ONNX Runtime from Source:

The benchmarking tool, **onnxruntime_perf_test**, isn’t available as a pre-built binary artifact for any platform. So, you have to build it from the source, which is expected to take around 40-50 minutes.

Install the required tools and clone onnxruntime:
```console
tdnf install -y protobuf-compiler libprotobuf-dev libprotoc-dev
git clone --recursive https://github.com/microsoft/onnxruntime
cd onnxruntime
```
Now, build the benchmark as below:

```console
./build.sh --config Release --build_dir build/Linux --build_shared_lib --parallel --build --update --skip_tests
```
This will build the benchmark tool inside ./build/Linux/Release/onnxruntime_perf_test.

### Run the benchmark
Now that the benchmarking tool has been built, you can benchmark the **squeezenet-int8.onnx** model, as below:

```console
./build/Linux/Release/onnxruntime_perf_test -e cpu -r 100 -m times -s -Z -I <path-to-squeezenet-int8.onnx>
```

- **e cpu**: Use the CPU execution provider (not GPU or any other backend).
- **r 100**: Run 100 inferences.
- **m times**: Use "repeat N times" mode.
- **s**: Show detailed statistics.
- **Z**: Disable intra-op thread spinning (reduces CPU usage when idle between runs).
- **I**: Input the ONNX model path without using input/output test data.

### Benchmark summary on x86_64:

The following benchmark results are collected on two different x86_64 environments: a **Docker container running Azure Linux 3.0 hosted on a D4s_v6 Ubuntu-based Azure virtual machine**, and a **D4s_v4 Azure virtual machine created from the Azure Linux 3.0 image published by Ntegral Inc**.

| **Metric** | **Value on Docker Container** | **Value on Virtual Machine** |
|--------------------------|----------------------------------------|-----------------------------------------|
| **Average Inference Time** | 1.4713 ms | 1.8961 ms |
| **Throughput** | 679.48 inferences/sec | 527.25 inferences/sec |
| **CPU Utilization** | 100% | 95% |
| **Peak Memory Usage** | 39.8 MB | 36.1 MB |
| **P50 Latency** | 1.4622 ms | 1.8709 ms |
| **Max Latency** | 2.3384 ms | 2.7826 ms |
| **Latency Consistency** | Consistent | Consistent |


### Benchmark summary on Arm64:

The following benchmark results are collected on two different Arm64 environments: a **Docker container running Azure Linux 3.0 hosted on a D4ps_v6 Ubuntu-based Azure virtual machine**, and a **D4ps_v6 Azure virtual machine created from the Azure Linux 3.0 custom image using the AArch64 ISO**.

| **Metric** | **Value on Docker Container** | **Value on Virtual Machine** |
|---------------------------|---------------------------------------|---------------------------------------------|
| **Average Inference Time**| 1.9183 ms | 1.9169 ms |
| **Throughput** | 521.09 inferences/sec | 521.41 inferences/sec |
| **CPU Utilization** | 98% | 100% |
| **Peak Memory Usage** | 35.36 MB | 33.57 MB |
| **P50 Latency** | 1.9165 ms | 1.9168 ms |
| **Max Latency** | 2.0142 ms | 1.9979 ms |
| **Latency Consistency** | Consistent | Consistent |


### Highlights from Azure Linux Arm64 Benchmarking (ONNX Runtime with SqueezeNet)
- **Low-Latency Inference:** Achieved consistent average inference times of ~1.92 ms across both Docker and virtual machine environments on Arm64.
- **Strong and Stable Throughput:** Sustained throughput of over 521 inferences/sec using the squeezenet-int8.onnx model on D4ps_v6 instances.
- **Lightweight Resource Footprint:** Peak memory usage stayed below 36 MB, with CPU utilization reaching ~98–100%, ideal for efficient edge or cloud inference.
- **Consistent Performance:** P50 and Max latency remained tightly bound across both setups, showcasing reliable performance on Azure Cobalt 100 Arm-based infrastructure.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: Setup Azure Linux 3.0 Environment
weight: 4

### FIXED, DO NOT MODIFY
layout: learningpathall
---


You have an option to choose between working with the Azure Linux 3.0 Docker image or inside the virtual machine created with the OS image.

### Working inside Azure Linux 3.0 Docker container
The Azure Linux Container Host is an operating system image that's optimized for running container workloads on Azure Kubernetes Service (AKS). Microsoft maintains the Azure Linux Container Host and based it on CBL-Mariner, an open-source Linux distribution created by Microsoft. To know more about Azure Linux 3.0, kindly refer [What is Azure Linux Container Host for AKS](https://learn.microsoft.com/en-us/azure/azure-linux/intro-azure-linux).

Azure Linux 3.0 offers support for AArch64. However, the standalone virtual machine image for Azure Linux 3.0 or CBL Mariner 3.0 is not available for Arm. Hence, to use the default software stack provided by the Microsoft team, you can create a docker container with Azure Linux 3.0 as a base image, and run the ONNX application inside the container.

#### Create Azure Linux 3.0 Docker Container
The [Microsoft Artifact Registry](https://mcr.microsoft.com/en-us/artifact/mar/azurelinux/base/core/about) offers updated docker image for the Azure Linux 3.0.

To create a docker container, install docker, and then follow the below instructions:

```console
sudo docker run -it --rm mcr.microsoft.com/azurelinux/base/core:3.0
```
The default container startup command is bash. tdnf and dnf are the default package managers.

### Working with Azure Linux 3.0 OS image
As of now, the Azure Marketplace offers official virtual machine images of Azure Linux 3.0 only for x64-based architectures, published by Ntegral Inc. However, native Arm64 (AArch64) images are not yet officially available. Hence, for this Learning Path, you can create your own custom Azure Linux 3.0 virtual machine image for AArch64 using the [AArch64 ISO for Azure Linux 3.0](https://github.com/microsoft/azurelinux#iso).

Refer [Create an Azure Linux 3.0 virtual machine with Cobalt 100 processors](https://learn.arm.com/learning-paths/servers-and-cloud-computing/azure-vm) for the details.

Whether you're using an Azure Linux 3.0 Docker container, or a virtual machine created from a custom Azure Linux 3.0 image, the deployment and benchmarking steps remain the same.

Once the setup has been established, you can proceed with the ONNX Installation ahead.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: Create an Arm based cloud virtual machine using Microsoft Cobalt 100 CPU
weight: 3

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## Introduction

There are several ways to create an Arm-based Cobalt 100 virtual machine : the Microsoft Azure console, the Azure CLI tool, or using your choice of IaC (Infrastructure as Code). This guide will use the Azure console to create a virtual machine with Arm-based Cobalt 100 Processor.

This learning path focuses on the general-purpose virtual machine of the D series. Please read the guide on [Dpsv6 size series](https://learn.microsoft.com/en-us/azure/virtual-machines/sizes/general-purpose/dpsv6-series) offered by Microsoft Azure.

If you have never used the Microsoft Cloud Platform before, please review the microsoft [guide to Create a Linux virtual machine in the Azure portal](https://learn.microsoft.com/en-us/azure/virtual-machines/linux/quick-create-portal?tabs=ubuntu).

#### Create an Arm-based Azure Virtual Machine

Creating a virtual machine based on Azure Cobalt 100 is no different from creating any other virtual machine in Azure. To create an Azure virtual machine, launch the Azure portal and navigate to Virtual Machines.

Select “Create”, and fill in the details such as Name, and Region. Choose the image for your virtual machine (for example – Ubuntu 24.04) and select “Arm64” as the virtual machine architecture.

In the “Size” field, click on “See all sizes” and select the D-Series v6 family of virtual machine. Select “D4ps_v6” from the list and create the virtual machine.

![Instance Screenshot](./instance.png)

The virtual machine should be ready and running; you can SSH into the virtual machine using the PEM key, along with the Public IP details.

{{% notice Note %}}

To learn more about Arm-based virtual machine in Azure, refer to “Getting Started with Microsoft Azure” in [Get started with Arm-based cloud instances](https://learn.arm.com/learning-paths/servers-and-cloud-computing/csp/azure) .

{{% /notice %}}
Loading