qaihm-bot commited on
Commit
93d9e61
·
verified ·
1 Parent(s): 6bc436a

See https://github.com/quic/ai-hub-models/releases/v0.45.0 for changelog.

.gitattributes CHANGED
@@ -33,3 +33,4 @@ 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
+ Distil-Bert-Base-Uncased-Hf_float.dlc filter=lfs diff=lfs merge=lfs -text
Distil-Bert-Base-Uncased-Hf_float.dlc ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e624a0d5c06113c46505064278a0285ea61e4ea48dc68391029880806d29daf6
3
+ size 361513804
Distil-Bert-Base-Uncased-Hf_float.onnx.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dadc2bfa3da2ed479e188117cf19cebf4c348589f70ee67b70356e89e8f6354e
3
+ size 333235472
Distil-Bert-Base-Uncased-Hf_float.tflite ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dad476b54d432ea1cc12db1f69de7603e22f94f989ae8cabfd77d97a9430453b
3
+ size 268192700
LICENSE ADDED
@@ -0,0 +1 @@
 
 
1
+ The license of the original trained model can be found at https://huggingface.co/distilbert/distilbert-base-uncased/blob/f8354bcfbd3068faf2c5149654881cb4214e931d/LICENSE.
README.md ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ license: other
4
+ tags:
5
+ - backbone
6
+ - android
7
+ pipeline_tag: text-generation
8
+
9
+ ---
10
+
11
+ ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/distil_bert_base_uncased_hf/web-assets/model_demo.png)
12
+
13
+ # Distil-Bert-Base-Uncased-Hf: Optimized for Mobile Deployment
14
+ ## Language model for masked language modeling and general-purpose NLP tasks
15
+
16
+ DistilBERT is a lightweight BERT model designed for efficient self-supervised learning of language representations. It can be used for masked language modeling and as a backbone for various NLP tasks.
17
+
18
+ This repository provides scripts to run Distil-Bert-Base-Uncased-Hf on Qualcomm® devices.
19
+ More details on model performance across various devices, can be found
20
+ [here](https://aihub.qualcomm.com/models/distil_bert_base_uncased_hf).
21
+
22
+
23
+
24
+ ### Model Details
25
+
26
+ - **Model Type:** Model_use_case.text_generation
27
+ - **Model Stats:**
28
+ - Model checkpoint: distil_bert_base_uncased_hf
29
+ - Input resolution: 1x384
30
+ - Number of parameters: 11.3M
31
+ - Model size (float): 43.3 MB
32
+
33
+ | Model | Precision | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit | Target Model
34
+ |---|---|---|---|---|---|---|---|---|
35
+ | Distil-Bert-Base-Uncased-Hf | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 49.949 ms | 0 - 466 MB | NPU | [Distil-Bert-Base-Uncased-Hf.tflite](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.tflite) |
36
+ | Distil-Bert-Base-Uncased-Hf | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN_DLC | 49.581 ms | 0 - 458 MB | NPU | [Distil-Bert-Base-Uncased-Hf.dlc](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.dlc) |
37
+ | Distil-Bert-Base-Uncased-Hf | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 37.087 ms | 0 - 472 MB | NPU | [Distil-Bert-Base-Uncased-Hf.tflite](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.tflite) |
38
+ | Distil-Bert-Base-Uncased-Hf | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | QNN_DLC | 36.633 ms | 0 - 474 MB | NPU | [Distil-Bert-Base-Uncased-Hf.dlc](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.dlc) |
39
+ | Distil-Bert-Base-Uncased-Hf | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 14.793 ms | 0 - 4 MB | NPU | [Distil-Bert-Base-Uncased-Hf.tflite](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.tflite) |
40
+ | Distil-Bert-Base-Uncased-Hf | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_DLC | 15.16 ms | 0 - 2 MB | NPU | [Distil-Bert-Base-Uncased-Hf.dlc](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.dlc) |
41
+ | Distil-Bert-Base-Uncased-Hf | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | ONNX | 20.274 ms | 0 - 195 MB | NPU | [Distil-Bert-Base-Uncased-Hf.onnx.zip](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.onnx.zip) |
42
+ | Distil-Bert-Base-Uncased-Hf | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 18.862 ms | 0 - 465 MB | NPU | [Distil-Bert-Base-Uncased-Hf.tflite](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.tflite) |
43
+ | Distil-Bert-Base-Uncased-Hf | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN_DLC | 18.616 ms | 0 - 460 MB | NPU | [Distil-Bert-Base-Uncased-Hf.dlc](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.dlc) |
44
+ | Distil-Bert-Base-Uncased-Hf | float | SA7255P ADP | Qualcomm® SA7255P | TFLITE | 49.949 ms | 0 - 466 MB | NPU | [Distil-Bert-Base-Uncased-Hf.tflite](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.tflite) |
45
+ | Distil-Bert-Base-Uncased-Hf | float | SA7255P ADP | Qualcomm® SA7255P | QNN_DLC | 49.581 ms | 0 - 458 MB | NPU | [Distil-Bert-Base-Uncased-Hf.dlc](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.dlc) |
46
+ | Distil-Bert-Base-Uncased-Hf | float | SA8295P ADP | Qualcomm® SA8295P | TFLITE | 23.121 ms | 0 - 443 MB | NPU | [Distil-Bert-Base-Uncased-Hf.tflite](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.tflite) |
47
+ | Distil-Bert-Base-Uncased-Hf | float | SA8295P ADP | Qualcomm® SA8295P | QNN_DLC | 23.748 ms | 0 - 441 MB | NPU | [Distil-Bert-Base-Uncased-Hf.dlc](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.dlc) |
48
+ | Distil-Bert-Base-Uncased-Hf | float | SA8775P ADP | Qualcomm® SA8775P | TFLITE | 18.862 ms | 0 - 465 MB | NPU | [Distil-Bert-Base-Uncased-Hf.tflite](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.tflite) |
49
+ | Distil-Bert-Base-Uncased-Hf | float | SA8775P ADP | Qualcomm® SA8775P | QNN_DLC | 18.616 ms | 0 - 460 MB | NPU | [Distil-Bert-Base-Uncased-Hf.dlc](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.dlc) |
50
+ | Distil-Bert-Base-Uncased-Hf | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 11.743 ms | 0 - 505 MB | NPU | [Distil-Bert-Base-Uncased-Hf.tflite](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.tflite) |
51
+ | Distil-Bert-Base-Uncased-Hf | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN_DLC | 11.688 ms | 0 - 499 MB | NPU | [Distil-Bert-Base-Uncased-Hf.dlc](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.dlc) |
52
+ | Distil-Bert-Base-Uncased-Hf | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | ONNX | 15.221 ms | 0 - 470 MB | NPU | [Distil-Bert-Base-Uncased-Hf.onnx.zip](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.onnx.zip) |
53
+ | Distil-Bert-Base-Uncased-Hf | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | TFLITE | 8.215 ms | 0 - 459 MB | NPU | [Distil-Bert-Base-Uncased-Hf.tflite](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.tflite) |
54
+ | Distil-Bert-Base-Uncased-Hf | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | QNN_DLC | 8.007 ms | 0 - 457 MB | NPU | [Distil-Bert-Base-Uncased-Hf.dlc](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.dlc) |
55
+ | Distil-Bert-Base-Uncased-Hf | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | ONNX | 10.5 ms | 0 - 427 MB | NPU | [Distil-Bert-Base-Uncased-Hf.onnx.zip](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.onnx.zip) |
56
+ | Distil-Bert-Base-Uncased-Hf | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen 5 Mobile | TFLITE | 7.089 ms | 0 - 430 MB | NPU | [Distil-Bert-Base-Uncased-Hf.tflite](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.tflite) |
57
+ | Distil-Bert-Base-Uncased-Hf | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen 5 Mobile | QNN_DLC | 6.83 ms | 0 - 430 MB | NPU | [Distil-Bert-Base-Uncased-Hf.dlc](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.dlc) |
58
+ | Distil-Bert-Base-Uncased-Hf | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen 5 Mobile | ONNX | 8.982 ms | 0 - 445 MB | NPU | [Distil-Bert-Base-Uncased-Hf.onnx.zip](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.onnx.zip) |
59
+ | Distil-Bert-Base-Uncased-Hf | float | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_DLC | 14.263 ms | 0 - 0 MB | NPU | [Distil-Bert-Base-Uncased-Hf.dlc](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.dlc) |
60
+ | Distil-Bert-Base-Uncased-Hf | float | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 19.002 ms | 179 - 179 MB | NPU | [Distil-Bert-Base-Uncased-Hf.onnx.zip](https://huggingface.co/qualcomm/Distil-Bert-Base-Uncased-Hf/blob/main/Distil-Bert-Base-Uncased-Hf.onnx.zip) |
61
+
62
+
63
+
64
+
65
+ ## Installation
66
+
67
+
68
+ Install the package via pip:
69
+ ```bash
70
+ # NOTE: 3.10 <= PYTHON_VERSION < 3.14 is supported.
71
+ pip install "qai-hub-models[distil-bert-base-uncased-hf]"
72
+ ```
73
+
74
+
75
+ ## Configure Qualcomm® AI Hub Workbench to run this model on a cloud-hosted device
76
+
77
+ Sign-in to [Qualcomm® AI Hub Workbench](https://workbench.aihub.qualcomm.com/) with your
78
+ Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
79
+
80
+ With this API token, you can configure your client to run models on the cloud
81
+ hosted devices.
82
+ ```bash
83
+ qai-hub configure --api_token API_TOKEN
84
+ ```
85
+ Navigate to [docs](https://workbench.aihub.qualcomm.com/docs/) for more information.
86
+
87
+
88
+
89
+ ## Demo off target
90
+
91
+ The package contains a simple end-to-end demo that downloads pre-trained
92
+ weights and runs this model on a sample input.
93
+
94
+ ```bash
95
+ python -m qai_hub_models.models.distil_bert_base_uncased_hf.demo
96
+ ```
97
+
98
+ The above demo runs a reference implementation of pre-processing, model
99
+ inference, and post processing.
100
+
101
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
102
+ environment, please add the following to your cell (instead of the above).
103
+ ```
104
+ %run -m qai_hub_models.models.distil_bert_base_uncased_hf.demo
105
+ ```
106
+
107
+
108
+ ### Run model on a cloud-hosted device
109
+
110
+ In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
111
+ device. This script does the following:
112
+ * Performance check on-device on a cloud-hosted device
113
+ * Downloads compiled assets that can be deployed on-device for Android.
114
+ * Accuracy check between PyTorch and on-device outputs.
115
+
116
+ ```bash
117
+ python -m qai_hub_models.models.distil_bert_base_uncased_hf.export
118
+ ```
119
+
120
+
121
+
122
+ ## How does this work?
123
+
124
+ This [export script](https://aihub.qualcomm.com/models/distil_bert_base_uncased_hf/qai_hub_models/models/Distil-Bert-Base-Uncased-Hf/export.py)
125
+ leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
126
+ on-device. Lets go through each step below in detail:
127
+
128
+ Step 1: **Compile model for on-device deployment**
129
+
130
+ To compile a PyTorch model for on-device deployment, we first trace the model
131
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
132
+
133
+ ```python
134
+ import torch
135
+
136
+ import qai_hub as hub
137
+ from qai_hub_models.models.distil_bert_base_uncased_hf import Model
138
+
139
+ # Load the model
140
+ torch_model = Model.from_pretrained()
141
+
142
+ # Device
143
+ device = hub.Device("Samsung Galaxy S25")
144
+
145
+ # Trace model
146
+ input_shape = torch_model.get_input_spec()
147
+ sample_inputs = torch_model.sample_inputs()
148
+
149
+ pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
150
+
151
+ # Compile model on a specific device
152
+ compile_job = hub.submit_compile_job(
153
+ model=pt_model,
154
+ device=device,
155
+ input_specs=torch_model.get_input_spec(),
156
+ )
157
+
158
+ # Get target model to run on-device
159
+ target_model = compile_job.get_target_model()
160
+
161
+ ```
162
+
163
+
164
+ Step 2: **Performance profiling on cloud-hosted device**
165
+
166
+ After compiling models from step 1. Models can be profiled model on-device using the
167
+ `target_model`. Note that this scripts runs the model on a device automatically
168
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
169
+ provided job URL to view a variety of on-device performance metrics.
170
+ ```python
171
+ profile_job = hub.submit_profile_job(
172
+ model=target_model,
173
+ device=device,
174
+ )
175
+
176
+ ```
177
+
178
+ Step 3: **Verify on-device accuracy**
179
+
180
+ To verify the accuracy of the model on-device, you can run on-device inference
181
+ on sample input data on the same cloud hosted device.
182
+ ```python
183
+ input_data = torch_model.sample_inputs()
184
+ inference_job = hub.submit_inference_job(
185
+ model=target_model,
186
+ device=device,
187
+ inputs=input_data,
188
+ )
189
+ on_device_output = inference_job.download_output_data()
190
+
191
+ ```
192
+ With the output of the model, you can compute like PSNR, relative errors or
193
+ spot check the output with expected output.
194
+
195
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
196
+ AI Hub Workbench. [Sign up for access](https://myaccount.qualcomm.com/signup).
197
+
198
+
199
+
200
+ ## Run demo on a cloud-hosted device
201
+
202
+ You can also run the demo on-device.
203
+
204
+ ```bash
205
+ python -m qai_hub_models.models.distil_bert_base_uncased_hf.demo --eval-mode on-device
206
+ ```
207
+
208
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
209
+ environment, please add the following to your cell (instead of the above).
210
+ ```
211
+ %run -m qai_hub_models.models.distil_bert_base_uncased_hf.demo -- --eval-mode on-device
212
+ ```
213
+
214
+
215
+ ## Deploying compiled model to Android
216
+
217
+
218
+ The models can be deployed using multiple runtimes:
219
+ - TensorFlow Lite (`.tflite` export): [This
220
+ tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
221
+ guide to deploy the .tflite model in an Android application.
222
+
223
+
224
+ - QNN (`.so` export ): This [sample
225
+ app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
226
+ provides instructions on how to use the `.so` shared library in an Android application.
227
+
228
+
229
+ ## View on Qualcomm® AI Hub
230
+ Get more details on Distil-Bert-Base-Uncased-Hf's performance across various devices [here](https://aihub.qualcomm.com/models/distil_bert_base_uncased_hf).
231
+ Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
232
+
233
+
234
+ ## License
235
+ * The license for the original implementation of Distil-Bert-Base-Uncased-Hf can be found
236
+ [here](https://huggingface.co/distilbert/distilbert-base-uncased/blob/f8354bcfbd3068faf2c5149654881cb4214e931d/LICENSE).
237
+
238
+
239
+
240
+ ## References
241
+ * [DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter](https://arxiv.org/abs/1910.01108)
242
+
243
+
244
+
245
+ ## Community
246
+ * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
247
+ * For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).
248
+
249
+
tool-versions.yaml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ tool_versions:
2
+ onnx:
3
+ qairt: 2.37.1.250807093845_124904
4
+ onnx_runtime: 1.23.0