qaihm-bot commited on
Commit
f153b26
·
verified ·
1 Parent(s): d25bb05

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