Skip to content

Commit e10bbd1

Browse files
Azure integration (#1066)
* add azure * edit readme * edit readme * edit readme * edit readme * refactored script * quality check * cleanup * add docstrings * add diagram * added nm logo --------- Co-authored-by: Michael Goin <[email protected]>
1 parent f2d3296 commit e10bbd1

File tree

4 files changed

+498
-0
lines changed

4 files changed

+498
-0
lines changed

Diff for: examples/azure-vm/README.md

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<!--
2+
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing,
11+
software distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
# **Getting Started With DeepSparse in an Azure VM**
18+
19+
![diagram](./azure-vm-pic.png)
20+
21+
Neural Magic’s DeepSparse is an inference runtime that can be deployed directly from a public Docker image. DeepSparse supports various CPU instance types and sizes, allowing you to quickly deploy the infrastructure that works best for your use case, based on cost and performance.
22+
23+
If you are interested in configuring and launching an instance with DeepSparse in Python, follow the step-by-step guide below.
24+
25+
We recommend installing the [Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) for easy access to Azure's functionalities although it is not required.
26+
27+
## Step 1: Create a Subscription
28+
Create an [Azure subscription](https://learn.microsoft.com/en-us/azure/cost-management-billing/manage/create-subscription) to gain access to a `subscription id`.
29+
30+
31+
## Step 2: Install Dependencies
32+
33+
```bash
34+
git clone https://github.com/neuralmagic/deepsparse.git
35+
cd deepsparse/examples/azure-vm
36+
pip install -r requirements.txt
37+
```
38+
39+
## Step 3: Run Script
40+
41+
The [azure-vm.py](https://github.com/neuralmagic/deepsparse/tree/main/examples/azure-vm/azure-vm.py) script creates an Azure resource group, launches an Ubuntu instance and returns the Public IP address so you can SSH into the instance after it finishes staging. Additionally, it also contains a bash script which automatically downloads Docker and pulls Neural Magic's public DeepSparse image into your instance.
42+
43+
To execute the script, run the following command and pass in your `subscription id` from step 1, your VMs `location`, `vm-type`, a resources `group name`, your `virtual machine's name` and the `password` for logging in to your instance:
44+
45+
```bash
46+
python azure-vm.py create-vm --subscription-id <SUBSCRIPTION-ID> --location <LOCATION> --vm-type <VM-TYPE> --group-name <GROUP-NAME> --vm-name <VM-NAME> --pw <PASSWORD>
47+
```
48+
49+
To leverage CPU optimized instances, we recommend using the [`Fsv2-series`](https://learn.microsoft.com/en-us/azure/virtual-machines/sizes-compute) instances which contain AVX-512 instructions. Here's an example command for launching a VM in the US East location using a F4s-v2 instance (4 vCPUs and 8GB of RAM):
50+
51+
```bash
52+
python azure-vm.py create-vm --subscription-id <sub-id> --location eastus --vm-type Standard_F4s_v2 --group-name deepsparse-group --vm-name deepsparse-vm --pw Password123!
53+
```
54+
55+
**PRO-TIP**: The password passed into the CLI command must satisfy the following conditions:
56+
57+
1) Contains an uppercase character.
58+
2) Contains a lowercase character.
59+
3) Contains a numeric digit.
60+
4) Contains a special character.
61+
5) Control characters are not allowed.
62+
63+
## **Step 4: SSH Into the Instance**
64+
65+
After running the script, your instance's public IP address will be printed out in the terminal. Pass the IP address into the following CLI command to SSH into your running instance:
66+
67+
```bash
68+
ssh testuser@<PUBLIC-IP>
69+
```
70+
71+
After entering your password, get root access:
72+
73+
```bash
74+
sudo su
75+
```
76+
77+
## **Step 5: Run DeepSparse**
78+
79+
We recommend giving your instance 2-3 mins. to finish executing the bash script. To make sure you have the DeepSparse image imported, run the following command:
80+
81+
```bash
82+
docker images
83+
```
84+
You should be able to see a downloaded DeepSparse image, if it shows an empty table, the bash script hasn't completed execution.
85+
86+
Upon image download, you can now use DeepSparse. Here's an example of benchmarking a pruned-quantized version of BERT trained on SQuAD from Docker:
87+
88+
```bash
89+
docker run -it deepsparse_docker deepsparse.benchmark zoo:nlp/question_answering/bert-base/pytorch/huggingface/squad/pruned95_obs_quant-none -i [64,128] -b 64 -nstreams 1 -s sync
90+
```
91+
92+
## **Step 6: Delete Instance and Resource Group**
93+
94+
```bash
95+
python azure-vm.py delete-vm-rg --subscription-id <SUBSCRIPTION-ID> --group-name <GROUP-NAME> --vm-name <VM-NAME>
96+
```

Diff for: examples/azure-vm/azure-vm-pic.png

49.7 KB
Loading

0 commit comments

Comments
 (0)