qaihm-bot commited on
Commit
c225d27
·
verified ·
1 Parent(s): 985244f

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
+ Albert-Base-V2-Hf_float.dlc filter=lfs diff=lfs merge=lfs -text
Albert-Base-V2-Hf_float.dlc ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:78f10ca034535508d3b3325805eeeb5b82306a2e34fabea0d2217dca9f4c8548
3
+ size 60553956
Albert-Base-V2-Hf_float.onnx.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f1f8eebb717f97414ba9b7e66e822286f5a983d8df8865d5c43aa9f8b1d8a669
3
+ size 55922468
Albert-Base-V2-Hf_float.tflite ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:864c053918ee8c56f4a853017064ca6675ca4b6c259f751f719ed940d72604ca
3
+ size 45388068
LICENSE ADDED
@@ -0,0 +1 @@
 
 
1
+ The license of the original trained model can be found at https://github.com/google-research/albert/blob/master/LICENSE.
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/albert_base_v2_hf/web-assets/model_demo.png)
12
+
13
+ # Albert-Base-V2-Hf: Optimized for Mobile Deployment
14
+ ## Language model for masked language modeling and general-purpose NLP tasks
15
+
16
+
17
+ ALBERT 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 Albert-Base-V2-Hf found [here](https://github.com/google-research/albert).
20
+
21
+
22
+ This repository provides scripts to run Albert-Base-V2-Hf on Qualcomm® devices.
23
+ More details on model performance across various devices, can be found
24
+ [here](https://aihub.qualcomm.com/models/albert_base_v2_hf).
25
+
26
+
27
+
28
+ ### Model Details
29
+
30
+ - **Model Type:** Model_use_case.text_generation
31
+ - **Model Stats:**
32
+ - Model checkpoint: albert/albert-base-v2
33
+ - Input resolution: 1x384
34
+ - Number of parameters: 11.8M
35
+ - Model size (float): 43.9 MB
36
+
37
+ | Model | Precision | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit | Target Model
38
+ |---|---|---|---|---|---|---|---|---|
39
+ | Albert-Base-V2-Hf | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 73.753 ms | 0 - 285 MB | NPU | [Albert-Base-V2-Hf.tflite](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.tflite) |
40
+ | Albert-Base-V2-Hf | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN_DLC | 73.898 ms | 0 - 270 MB | NPU | [Albert-Base-V2-Hf.dlc](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.dlc) |
41
+ | Albert-Base-V2-Hf | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 37.562 ms | 0 - 375 MB | NPU | [Albert-Base-V2-Hf.tflite](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.tflite) |
42
+ | Albert-Base-V2-Hf | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | QNN_DLC | 37.485 ms | 0 - 300 MB | NPU | [Albert-Base-V2-Hf.dlc](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.dlc) |
43
+ | Albert-Base-V2-Hf | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 21.897 ms | 0 - 3 MB | NPU | [Albert-Base-V2-Hf.tflite](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.tflite) |
44
+ | Albert-Base-V2-Hf | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_DLC | 21.821 ms | 0 - 3 MB | NPU | [Albert-Base-V2-Hf.dlc](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.dlc) |
45
+ | Albert-Base-V2-Hf | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | ONNX | 29.458 ms | 0 - 3 MB | NPU | [Albert-Base-V2-Hf.onnx.zip](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.onnx.zip) |
46
+ | Albert-Base-V2-Hf | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 26.83 ms | 0 - 352 MB | NPU | [Albert-Base-V2-Hf.tflite](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.tflite) |
47
+ | Albert-Base-V2-Hf | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN_DLC | 109.922 ms | 0 - 280 MB | NPU | [Albert-Base-V2-Hf.dlc](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.dlc) |
48
+ | Albert-Base-V2-Hf | float | SA7255P ADP | Qualcomm® SA7255P | TFLITE | 73.753 ms | 0 - 285 MB | NPU | [Albert-Base-V2-Hf.tflite](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.tflite) |
49
+ | Albert-Base-V2-Hf | float | SA7255P ADP | Qualcomm® SA7255P | QNN_DLC | 73.898 ms | 0 - 270 MB | NPU | [Albert-Base-V2-Hf.dlc](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.dlc) |
50
+ | Albert-Base-V2-Hf | float | SA8295P ADP | Qualcomm® SA8295P | TFLITE | 36.75 ms | 0 - 247 MB | NPU | [Albert-Base-V2-Hf.tflite](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.tflite) |
51
+ | Albert-Base-V2-Hf | float | SA8295P ADP | Qualcomm® SA8295P | QNN_DLC | 37.364 ms | 0 - 253 MB | NPU | [Albert-Base-V2-Hf.dlc](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.dlc) |
52
+ | Albert-Base-V2-Hf | float | SA8775P ADP | Qualcomm® SA8775P | TFLITE | 26.83 ms | 0 - 352 MB | NPU | [Albert-Base-V2-Hf.tflite](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.tflite) |
53
+ | Albert-Base-V2-Hf | float | SA8775P ADP | Qualcomm® SA8775P | QNN_DLC | 109.922 ms | 0 - 280 MB | NPU | [Albert-Base-V2-Hf.dlc](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.dlc) |
54
+ | Albert-Base-V2-Hf | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 17.256 ms | 0 - 339 MB | NPU | [Albert-Base-V2-Hf.tflite](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.tflite) |
55
+ | Albert-Base-V2-Hf | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN_DLC | 17.12 ms | 0 - 326 MB | NPU | [Albert-Base-V2-Hf.dlc](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.dlc) |
56
+ | Albert-Base-V2-Hf | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | ONNX | 22.177 ms | 0 - 385 MB | NPU | [Albert-Base-V2-Hf.onnx.zip](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.onnx.zip) |
57
+ | Albert-Base-V2-Hf | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | TFLITE | 12.248 ms | 0 - 273 MB | NPU | [Albert-Base-V2-Hf.tflite](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.tflite) |
58
+ | Albert-Base-V2-Hf | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | QNN_DLC | 12.344 ms | 0 - 273 MB | NPU | [Albert-Base-V2-Hf.dlc](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.dlc) |
59
+ | Albert-Base-V2-Hf | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | ONNX | 16.984 ms | 0 - 324 MB | NPU | [Albert-Base-V2-Hf.onnx.zip](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.onnx.zip) |
60
+ | Albert-Base-V2-Hf | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen 5 Mobile | TFLITE | 10.154 ms | 0 - 276 MB | NPU | [Albert-Base-V2-Hf.tflite](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.tflite) |
61
+ | Albert-Base-V2-Hf | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen 5 Mobile | QNN_DLC | 10.289 ms | 0 - 280 MB | NPU | [Albert-Base-V2-Hf.dlc](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.dlc) |
62
+ | Albert-Base-V2-Hf | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen 5 Mobile | ONNX | 14.428 ms | 0 - 334 MB | NPU | [Albert-Base-V2-Hf.onnx.zip](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.onnx.zip) |
63
+ | Albert-Base-V2-Hf | float | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_DLC | 21.759 ms | 0 - 0 MB | NPU | [Albert-Base-V2-Hf.dlc](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.dlc) |
64
+ | Albert-Base-V2-Hf | float | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 28.925 ms | 33 - 33 MB | NPU | [Albert-Base-V2-Hf.onnx.zip](https://huggingface.co/qualcomm/Albert-Base-V2-Hf/blob/main/Albert-Base-V2-Hf.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[albert-base-v2-hf]"
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.albert_base_v2_hf.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.albert_base_v2_hf.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.albert_base_v2_hf.export
122
+ ```
123
+
124
+
125
+
126
+ ## How does this work?
127
+
128
+ This [export script](https://aihub.qualcomm.com/models/albert_base_v2_hf/qai_hub_models/models/Albert-Base-V2-Hf/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.albert_base_v2_hf 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.albert_base_v2_hf.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.albert_base_v2_hf.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 Albert-Base-V2-Hf's performance across various devices [here](https://aihub.qualcomm.com/models/albert_base_v2_hf).
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 Albert-Base-V2-Hf can be found
240
+ [here](https://github.com/google-research/albert/blob/master/LICENSE).
241
+
242
+
243
+
244
+ ## References
245
+ * [ALBERT: A Lite BERT for Self-supervised Learning of Language Representations](https://arxiv.org/abs/1909.11942)
246
+ * [Source Model Implementation](https://github.com/google-research/albert)
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