v0.36.0
Browse filesSee https://github.com/quic/ai-hub-models/releases/v0.36.0 for changelog.
- .gitattributes +2 -0
- DEPLOYMENT_MODEL_LICENSE.pdf +3 -0
- EfficientFormer.dlc +3 -0
- EfficientFormer.onnx.zip +3 -0
- EfficientFormer.tflite +3 -0
- EfficientFormer_w8a8.onnx.zip +3 -0
- EfficientFormer_w8a8.tflite +3 -0
- LICENSE +2 -0
- README.md +260 -0
- precompiled/qualcomm-snapdragon-x-elite/EfficientFormer.bin +3 -0
- precompiled/qualcomm-snapdragon-x-elite/EfficientFormer.onnx.zip +3 -0
- precompiled/qualcomm-snapdragon-x-elite/sdk_versions.yml +5 -0
- sdk_versions.yml +9 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
DEPLOYMENT_MODEL_LICENSE.pdf filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
EfficientFormer.dlc filter=lfs diff=lfs merge=lfs -text
|
DEPLOYMENT_MODEL_LICENSE.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4409f93b0e82531303b3e10f52f1fdfb56467a25f05b7441c6bbd8bb8a64b42c
|
| 3 |
+
size 109629
|
EfficientFormer.dlc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d7ed539d638b4003e83edf0a4e030ea604613ff76792b526d4d918cac2d1ca7d
|
| 3 |
+
size 49272548
|
EfficientFormer.onnx.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8308cdd0906e5359cebe3f07ed80d988e0cb06243912786435bdb4046db0bf87
|
| 3 |
+
size 45831683
|
EfficientFormer.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d87b3fab318a4ea699fa72477cbfb31bafc738c3af67139f179af0047cae6a87
|
| 3 |
+
size 49132840
|
EfficientFormer_w8a8.onnx.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a461cef4fcb123515da48e7819989bb193ee15a257f140ee9dac7c5a58b05e5b
|
| 3 |
+
size 27911082
|
EfficientFormer_w8a8.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3d2b064c522d847cadf33fac954a318743981c51ebff54cc07b9702a63ee14bb
|
| 3 |
+
size 12793736
|
LICENSE
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The license of the original trained model can be found at https://github.com/snap-research/EfficientFormer?tab=License-1-ov-file#readme.
|
| 2 |
+
The license for the deployable model files (.tflite, .onnx, .dlc, .bin, etc.) can be found in DEPLOYMENT_MODEL_LICENSE.pdf.
|
README.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: pytorch
|
| 3 |
+
license: other
|
| 4 |
+
tags:
|
| 5 |
+
- android
|
| 6 |
+
pipeline_tag: image-classification
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+

|
| 11 |
+
|
| 12 |
+
# EfficientFormer: Optimized for Mobile Deployment
|
| 13 |
+
## Imagenet classifier and general purpose backbone
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
EfficientFormer is a vision transformer model that can classify images from the Imagenet dataset.
|
| 17 |
+
|
| 18 |
+
This model is an implementation of EfficientFormer found [here](https://github.com/snap-research/EfficientFormer).
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
This repository provides scripts to run EfficientFormer on Qualcomm® devices.
|
| 22 |
+
More details on model performance across various devices, can be found
|
| 23 |
+
[here](https://aihub.qualcomm.com/models/efficientformer).
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
### Model Details
|
| 28 |
+
|
| 29 |
+
- **Model Type:** Model_use_case.image_classification
|
| 30 |
+
- **Model Stats:**
|
| 31 |
+
- Model checkpoint: efficientformer_l1_300d
|
| 32 |
+
- Input resolution: 224x224
|
| 33 |
+
- Number of parameters: 12.3M
|
| 34 |
+
- Model size (float): 46.9 MB
|
| 35 |
+
- Model size (w8a16): 12.2 MB
|
| 36 |
+
|
| 37 |
+
| Model | Precision | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit | Target Model
|
| 38 |
+
|---|---|---|---|---|---|---|---|---|
|
| 39 |
+
| EfficientFormer | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 4.93 ms | 0 - 48 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.tflite) |
|
| 40 |
+
| EfficientFormer | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN_DLC | 4.994 ms | 1 - 34 MB | NPU | [EfficientFormer.dlc](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.dlc) |
|
| 41 |
+
| EfficientFormer | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 3.825 ms | 0 - 55 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.tflite) |
|
| 42 |
+
| EfficientFormer | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | QNN_DLC | 5.702 ms | 0 - 42 MB | NPU | [EfficientFormer.dlc](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.dlc) |
|
| 43 |
+
| EfficientFormer | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 1.519 ms | 0 - 157 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.tflite) |
|
| 44 |
+
| EfficientFormer | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_DLC | 1.617 ms | 1 - 11 MB | NPU | [EfficientFormer.dlc](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.dlc) |
|
| 45 |
+
| EfficientFormer | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 2.096 ms | 0 - 48 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.tflite) |
|
| 46 |
+
| EfficientFormer | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN_DLC | 2.298 ms | 1 - 34 MB | NPU | [EfficientFormer.dlc](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.dlc) |
|
| 47 |
+
| EfficientFormer | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | TFLITE | 1.523 ms | 0 - 156 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.tflite) |
|
| 48 |
+
| EfficientFormer | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | QNN_DLC | 1.651 ms | 1 - 10 MB | NPU | [EfficientFormer.dlc](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.dlc) |
|
| 49 |
+
| EfficientFormer | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | ONNX | 5.967 ms | 0 - 39 MB | NPU | [EfficientFormer.onnx.zip](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.onnx.zip) |
|
| 50 |
+
| EfficientFormer | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 1.057 ms | 0 - 59 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.tflite) |
|
| 51 |
+
| EfficientFormer | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN_DLC | 1.125 ms | 1 - 44 MB | NPU | [EfficientFormer.dlc](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.dlc) |
|
| 52 |
+
| EfficientFormer | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | ONNX | 4.096 ms | 0 - 45 MB | NPU | [EfficientFormer.onnx.zip](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.onnx.zip) |
|
| 53 |
+
| EfficientFormer | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | TFLITE | 0.941 ms | 0 - 52 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.tflite) |
|
| 54 |
+
| EfficientFormer | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | QNN_DLC | 0.825 ms | 1 - 38 MB | NPU | [EfficientFormer.dlc](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.dlc) |
|
| 55 |
+
| EfficientFormer | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | ONNX | 3.739 ms | 1 - 42 MB | NPU | [EfficientFormer.onnx.zip](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.onnx.zip) |
|
| 56 |
+
| EfficientFormer | float | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_DLC | 1.904 ms | 102 - 102 MB | NPU | [EfficientFormer.dlc](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.dlc) |
|
| 57 |
+
| EfficientFormer | float | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 6.192 ms | 24 - 24 MB | NPU | [EfficientFormer.onnx.zip](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer.onnx.zip) |
|
| 58 |
+
| EfficientFormer | w8a8 | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 1.695 ms | 0 - 27 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer_w8a8.tflite) |
|
| 59 |
+
| EfficientFormer | w8a8 | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 0.852 ms | 0 - 46 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer_w8a8.tflite) |
|
| 60 |
+
| EfficientFormer | w8a8 | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 0.744 ms | 0 - 59 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer_w8a8.tflite) |
|
| 61 |
+
| EfficientFormer | w8a8 | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 0.997 ms | 0 - 27 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer_w8a8.tflite) |
|
| 62 |
+
| EfficientFormer | w8a8 | RB3 Gen 2 (Proxy) | Qualcomm® QCS6490 (Proxy) | TFLITE | 4.185 ms | 0 - 39 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer_w8a8.tflite) |
|
| 63 |
+
| EfficientFormer | w8a8 | RB5 (Proxy) | Qualcomm® QCS8250 (Proxy) | TFLITE | 44.509 ms | 1 - 80 MB | GPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer_w8a8.tflite) |
|
| 64 |
+
| EfficientFormer | w8a8 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | TFLITE | 0.743 ms | 0 - 59 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer_w8a8.tflite) |
|
| 65 |
+
| EfficientFormer | w8a8 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | ONNX | 9.494 ms | 25 - 49 MB | NPU | [EfficientFormer.onnx.zip](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer_w8a8.onnx.zip) |
|
| 66 |
+
| EfficientFormer | w8a8 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 0.53 ms | 0 - 45 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer_w8a8.tflite) |
|
| 67 |
+
| EfficientFormer | w8a8 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | ONNX | 6.246 ms | 23 - 82 MB | NPU | [EfficientFormer.onnx.zip](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer_w8a8.onnx.zip) |
|
| 68 |
+
| EfficientFormer | w8a8 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | TFLITE | 0.41 ms | 1 - 34 MB | NPU | [EfficientFormer.tflite](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer_w8a8.tflite) |
|
| 69 |
+
| EfficientFormer | w8a8 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | ONNX | 5.503 ms | 28 - 71 MB | NPU | [EfficientFormer.onnx.zip](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer_w8a8.onnx.zip) |
|
| 70 |
+
| EfficientFormer | w8a8 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 8.31 ms | 25 - 25 MB | NPU | [EfficientFormer.onnx.zip](https://huggingface.co/qualcomm/EfficientFormer/blob/main/EfficientFormer_w8a8.onnx.zip) |
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
## Installation
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
Install the package via pip:
|
| 79 |
+
```bash
|
| 80 |
+
pip install "qai-hub-models[efficientformer]"
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
|
| 85 |
+
|
| 86 |
+
Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
|
| 87 |
+
Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
|
| 88 |
+
|
| 89 |
+
With this API token, you can configure your client to run models on the cloud
|
| 90 |
+
hosted devices.
|
| 91 |
+
```bash
|
| 92 |
+
qai-hub configure --api_token API_TOKEN
|
| 93 |
+
```
|
| 94 |
+
Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
## Demo off target
|
| 99 |
+
|
| 100 |
+
The package contains a simple end-to-end demo that downloads pre-trained
|
| 101 |
+
weights and runs this model on a sample input.
|
| 102 |
+
|
| 103 |
+
```bash
|
| 104 |
+
python -m qai_hub_models.models.efficientformer.demo
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
The above demo runs a reference implementation of pre-processing, model
|
| 108 |
+
inference, and post processing.
|
| 109 |
+
|
| 110 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
| 111 |
+
environment, please add the following to your cell (instead of the above).
|
| 112 |
+
```
|
| 113 |
+
%run -m qai_hub_models.models.efficientformer.demo
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
### Run model on a cloud-hosted device
|
| 118 |
+
|
| 119 |
+
In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
|
| 120 |
+
device. This script does the following:
|
| 121 |
+
* Performance check on-device on a cloud-hosted device
|
| 122 |
+
* Downloads compiled assets that can be deployed on-device for Android.
|
| 123 |
+
* Accuracy check between PyTorch and on-device outputs.
|
| 124 |
+
|
| 125 |
+
```bash
|
| 126 |
+
python -m qai_hub_models.models.efficientformer.export
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
## How does this work?
|
| 132 |
+
|
| 133 |
+
This [export script](https://aihub.qualcomm.com/models/efficientformer/qai_hub_models/models/EfficientFormer/export.py)
|
| 134 |
+
leverages [Qualcomm�� AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
|
| 135 |
+
on-device. Lets go through each step below in detail:
|
| 136 |
+
|
| 137 |
+
Step 1: **Compile model for on-device deployment**
|
| 138 |
+
|
| 139 |
+
To compile a PyTorch model for on-device deployment, we first trace the model
|
| 140 |
+
in memory using the `jit.trace` and then call the `submit_compile_job` API.
|
| 141 |
+
|
| 142 |
+
```python
|
| 143 |
+
import torch
|
| 144 |
+
|
| 145 |
+
import qai_hub as hub
|
| 146 |
+
from qai_hub_models.models.efficientformer import Model
|
| 147 |
+
|
| 148 |
+
# Load the model
|
| 149 |
+
torch_model = Model.from_pretrained()
|
| 150 |
+
|
| 151 |
+
# Device
|
| 152 |
+
device = hub.Device("Samsung Galaxy S24")
|
| 153 |
+
|
| 154 |
+
# Trace model
|
| 155 |
+
input_shape = torch_model.get_input_spec()
|
| 156 |
+
sample_inputs = torch_model.sample_inputs()
|
| 157 |
+
|
| 158 |
+
pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
|
| 159 |
+
|
| 160 |
+
# Compile model on a specific device
|
| 161 |
+
compile_job = hub.submit_compile_job(
|
| 162 |
+
model=pt_model,
|
| 163 |
+
device=device,
|
| 164 |
+
input_specs=torch_model.get_input_spec(),
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
# Get target model to run on-device
|
| 168 |
+
target_model = compile_job.get_target_model()
|
| 169 |
+
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
Step 2: **Performance profiling on cloud-hosted device**
|
| 174 |
+
|
| 175 |
+
After compiling models from step 1. Models can be profiled model on-device using the
|
| 176 |
+
`target_model`. Note that this scripts runs the model on a device automatically
|
| 177 |
+
provisioned in the cloud. Once the job is submitted, you can navigate to a
|
| 178 |
+
provided job URL to view a variety of on-device performance metrics.
|
| 179 |
+
```python
|
| 180 |
+
profile_job = hub.submit_profile_job(
|
| 181 |
+
model=target_model,
|
| 182 |
+
device=device,
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
+
Step 3: **Verify on-device accuracy**
|
| 188 |
+
|
| 189 |
+
To verify the accuracy of the model on-device, you can run on-device inference
|
| 190 |
+
on sample input data on the same cloud hosted device.
|
| 191 |
+
```python
|
| 192 |
+
input_data = torch_model.sample_inputs()
|
| 193 |
+
inference_job = hub.submit_inference_job(
|
| 194 |
+
model=target_model,
|
| 195 |
+
device=device,
|
| 196 |
+
inputs=input_data,
|
| 197 |
+
)
|
| 198 |
+
on_device_output = inference_job.download_output_data()
|
| 199 |
+
|
| 200 |
+
```
|
| 201 |
+
With the output of the model, you can compute like PSNR, relative errors or
|
| 202 |
+
spot check the output with expected output.
|
| 203 |
+
|
| 204 |
+
**Note**: This on-device profiling and inference requires access to Qualcomm®
|
| 205 |
+
AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
## Run demo on a cloud-hosted device
|
| 210 |
+
|
| 211 |
+
You can also run the demo on-device.
|
| 212 |
+
|
| 213 |
+
```bash
|
| 214 |
+
python -m qai_hub_models.models.efficientformer.demo --eval-mode on-device
|
| 215 |
+
```
|
| 216 |
+
|
| 217 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
| 218 |
+
environment, please add the following to your cell (instead of the above).
|
| 219 |
+
```
|
| 220 |
+
%run -m qai_hub_models.models.efficientformer.demo -- --eval-mode on-device
|
| 221 |
+
```
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
## Deploying compiled model to Android
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
The models can be deployed using multiple runtimes:
|
| 228 |
+
- TensorFlow Lite (`.tflite` export): [This
|
| 229 |
+
tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
|
| 230 |
+
guide to deploy the .tflite model in an Android application.
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
- QNN (`.so` export ): This [sample
|
| 234 |
+
app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
|
| 235 |
+
provides instructions on how to use the `.so` shared library in an Android application.
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
## View on Qualcomm® AI Hub
|
| 239 |
+
Get more details on EfficientFormer's performance across various devices [here](https://aihub.qualcomm.com/models/efficientformer).
|
| 240 |
+
Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
## License
|
| 244 |
+
* The license for the original implementation of EfficientFormer can be found
|
| 245 |
+
[here](https://github.com/snap-research/EfficientFormer?tab=License-1-ov-file#readme).
|
| 246 |
+
* The license for the compiled assets for on-device deployment can be found [here](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/Qualcomm+AI+Hub+Proprietary+License.pdf)
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
## References
|
| 251 |
+
* [Rethinking Vision Transformers for MobileNet Size and Speed](https://arxiv.org/abs/2212.08059)
|
| 252 |
+
* [Source Model Implementation](https://github.com/snap-research/EfficientFormer)
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
## Community
|
| 257 |
+
* Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
|
| 258 |
+
* For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).
|
| 259 |
+
|
| 260 |
+
|
precompiled/qualcomm-snapdragon-x-elite/EfficientFormer.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:faa13fb1305a48e8729d51f25737b9c7be890b196ab2fb31965d800089609b39
|
| 3 |
+
size 26038272
|
precompiled/qualcomm-snapdragon-x-elite/EfficientFormer.onnx.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:333cce0de66dbaf7e4f2f1efbca72419bc896d032d2ea9905ca7c4ef45348469
|
| 3 |
+
size 23135539
|
precompiled/qualcomm-snapdragon-x-elite/sdk_versions.yml
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
sdk_versions:
|
| 2 |
+
qnn_context_binary:
|
| 3 |
+
qairt: 2.37.0.250724175447_124859
|
| 4 |
+
precompiled_qnn_onnx:
|
| 5 |
+
qairt: 2.33.2.250410134701_117956
|
sdk_versions.yml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
sdk_versions:
|
| 2 |
+
tflite:
|
| 3 |
+
qairt: 2.37.0.250724175447_124859
|
| 4 |
+
tflite: 2.17.0
|
| 5 |
+
qnn_dlc:
|
| 6 |
+
qairt: 2.37.0.250724175447_124859
|
| 7 |
+
onnx:
|
| 8 |
+
qairt: 2.33.2.250410134701_117956
|
| 9 |
+
onnx_runtime: 1.22.0
|