qaihm-bot commited on
Commit
38ca9c7
·
verified ·
1 Parent(s): 217812a

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