qaihm-bot commited on
Commit
397aca8
·
verified ·
1 Parent(s): 6267892

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +261 -0
README.md ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ license: apache-2.0
4
+ tags:
5
+ - android
6
+ pipeline_tag: text-generation
7
+
8
+ ---
9
+
10
+ ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/nomic_embed_text/web-assets/model_demo.png)
11
+
12
+ # Nomic-Embed-Text: Optimized for Mobile Deployment
13
+ ## Resizable Production Embeddings
14
+
15
+
16
+ A text encoder that surpasses OpenAI text-embedding-ada-002 and text-embedding-3-small performance on short and long context tasks.
17
+
18
+ This model is an implementation of Nomic-Embed-Text found [here](https://huggingface.co/nomic-ai/nomic-embed-text-v1.5).
19
+
20
+
21
+ This repository provides scripts to run Nomic-Embed-Text on Qualcomm® devices.
22
+ More details on model performance across various devices, can be found
23
+ [here](https://aihub.qualcomm.com/models/nomic_embed_text).
24
+
25
+
26
+ ### Model Details
27
+
28
+ - **Model Type:** Text generation
29
+ - **Model Stats:**
30
+ - Model checkpoint: v1.5
31
+ - Input resolution: 1x128 (seqlen can vary)
32
+ - Number of parameters: 137M
33
+ - Model size: 547 MB
34
+
35
+ | Model | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
36
+ |---|---|---|---|---|---|---|---|---|
37
+ | Nomic-Embed-Text | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 10.558 ms | 0 - 21 MB | FP16 | NPU | [Nomic-Embed-Text.tflite](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.tflite) |
38
+ | Nomic-Embed-Text | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 8.117 ms | 0 - 2 MB | FP16 | NPU | [Nomic-Embed-Text.so](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.so) |
39
+ | Nomic-Embed-Text | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 7.626 ms | 0 - 406 MB | FP16 | NPU | [Nomic-Embed-Text.tflite](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.tflite) |
40
+ | Nomic-Embed-Text | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 5.848 ms | 0 - 20 MB | FP16 | NPU | [Nomic-Embed-Text.so](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.so) |
41
+ | Nomic-Embed-Text | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 7.369 ms | 0 - 362 MB | FP16 | NPU | [Nomic-Embed-Text.tflite](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.tflite) |
42
+ | Nomic-Embed-Text | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 6.16 ms | 0 - 324 MB | FP16 | NPU | Use Export Script |
43
+ | Nomic-Embed-Text | SA7255P ADP | SA7255P | TFLITE | 186.829 ms | 0 - 360 MB | FP16 | NPU | [Nomic-Embed-Text.tflite](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.tflite) |
44
+ | Nomic-Embed-Text | SA7255P ADP | SA7255P | QNN | 181.788 ms | 0 - 9 MB | FP16 | NPU | Use Export Script |
45
+ | Nomic-Embed-Text | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 10.275 ms | 0 - 20 MB | FP16 | NPU | [Nomic-Embed-Text.tflite](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.tflite) |
46
+ | Nomic-Embed-Text | SA8255 (Proxy) | SA8255P Proxy | QNN | 8.125 ms | 0 - 2 MB | FP16 | NPU | Use Export Script |
47
+ | Nomic-Embed-Text | SA8295P ADP | SA8295P | TFLITE | 14.386 ms | 0 - 348 MB | FP16 | NPU | [Nomic-Embed-Text.tflite](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.tflite) |
48
+ | Nomic-Embed-Text | SA8295P ADP | SA8295P | QNN | 11.182 ms | 0 - 17 MB | FP16 | NPU | Use Export Script |
49
+ | Nomic-Embed-Text | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 10.549 ms | 0 - 19 MB | FP16 | NPU | [Nomic-Embed-Text.tflite](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.tflite) |
50
+ | Nomic-Embed-Text | SA8650 (Proxy) | SA8650P Proxy | QNN | 8.168 ms | 0 - 2 MB | FP16 | NPU | Use Export Script |
51
+ | Nomic-Embed-Text | SA8775P ADP | SA8775P | TFLITE | 15.481 ms | 0 - 360 MB | FP16 | NPU | [Nomic-Embed-Text.tflite](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.tflite) |
52
+ | Nomic-Embed-Text | SA8775P ADP | SA8775P | QNN | 12.227 ms | 0 - 10 MB | FP16 | NPU | Use Export Script |
53
+ | Nomic-Embed-Text | QCS8275 (Proxy) | QCS8275 Proxy | TFLITE | 186.829 ms | 0 - 360 MB | FP16 | NPU | [Nomic-Embed-Text.tflite](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.tflite) |
54
+ | Nomic-Embed-Text | QCS8275 (Proxy) | QCS8275 Proxy | QNN | 181.788 ms | 0 - 9 MB | FP16 | NPU | Use Export Script |
55
+ | Nomic-Embed-Text | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 10.388 ms | 0 - 18 MB | FP16 | NPU | [Nomic-Embed-Text.tflite](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.tflite) |
56
+ | Nomic-Embed-Text | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 8.06 ms | 0 - 2 MB | FP16 | NPU | Use Export Script |
57
+ | Nomic-Embed-Text | QCS9075 (Proxy) | QCS9075 Proxy | TFLITE | 15.481 ms | 0 - 360 MB | FP16 | NPU | [Nomic-Embed-Text.tflite](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.tflite) |
58
+ | Nomic-Embed-Text | QCS9075 (Proxy) | QCS9075 Proxy | QNN | 12.227 ms | 0 - 10 MB | FP16 | NPU | Use Export Script |
59
+ | Nomic-Embed-Text | QCS8450 (Proxy) | QCS8450 Proxy | TFLITE | 12.932 ms | 0 - 401 MB | FP16 | NPU | [Nomic-Embed-Text.tflite](https://huggingface.co/qualcomm/Nomic-Embed-Text/blob/main/Nomic-Embed-Text.tflite) |
60
+ | Nomic-Embed-Text | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 11.278 ms | 0 - 364 MB | FP16 | NPU | Use Export Script |
61
+ | Nomic-Embed-Text | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 8.353 ms | 0 - 0 MB | FP16 | NPU | Use Export Script |
62
+
63
+
64
+
65
+
66
+ ## Installation
67
+
68
+
69
+ Install the package via pip:
70
+ ```bash
71
+ pip install "qai-hub-models[nomic-embed-text]"
72
+ ```
73
+
74
+
75
+ ## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
76
+
77
+ Sign-in to [Qualcomm® AI Hub](https://app.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://app.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.nomic_embed_text.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.nomic_embed_text.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.nomic_embed_text.export
118
+ ```
119
+ ```
120
+ Profiling Results
121
+ ------------------------------------------------------------
122
+ Nomic-Embed-Text
123
+ Device : Samsung Galaxy S23 (13)
124
+ Runtime : TFLITE
125
+ Estimated inference time (ms) : 10.6
126
+ Estimated peak memory usage (MB): [0, 21]
127
+ Total # Ops : 906
128
+ Compute Unit(s) : NPU (906 ops)
129
+ ```
130
+
131
+
132
+ ## How does this work?
133
+
134
+ This [export script](https://aihub.qualcomm.com/models/nomic_embed_text/qai_hub_models/models/Nomic-Embed-Text/export.py)
135
+ leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
136
+ on-device. Lets go through each step below in detail:
137
+
138
+ Step 1: **Compile model for on-device deployment**
139
+
140
+ To compile a PyTorch model for on-device deployment, we first trace the model
141
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
142
+
143
+ ```python
144
+ import torch
145
+
146
+ import qai_hub as hub
147
+ from qai_hub_models.models.nomic_embed_text import Model
148
+
149
+ # Load the model
150
+ torch_model = Model.from_pretrained()
151
+
152
+ # Device
153
+ device = hub.Device("Samsung Galaxy S24")
154
+
155
+ # Trace model
156
+ input_shape = torch_model.get_input_spec()
157
+ sample_inputs = torch_model.sample_inputs()
158
+
159
+ pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
160
+
161
+ # Compile model on a specific device
162
+ compile_job = hub.submit_compile_job(
163
+ model=pt_model,
164
+ device=device,
165
+ input_specs=torch_model.get_input_spec(),
166
+ )
167
+
168
+ # Get target model to run on-device
169
+ target_model = compile_job.get_target_model()
170
+
171
+ ```
172
+
173
+
174
+ Step 2: **Performance profiling on cloud-hosted device**
175
+
176
+ After compiling models from step 1. Models can be profiled model on-device using the
177
+ `target_model`. Note that this scripts runs the model on a device automatically
178
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
179
+ provided job URL to view a variety of on-device performance metrics.
180
+ ```python
181
+ profile_job = hub.submit_profile_job(
182
+ model=target_model,
183
+ device=device,
184
+ )
185
+
186
+ ```
187
+
188
+ Step 3: **Verify on-device accuracy**
189
+
190
+ To verify the accuracy of the model on-device, you can run on-device inference
191
+ on sample input data on the same cloud hosted device.
192
+ ```python
193
+ input_data = torch_model.sample_inputs()
194
+ inference_job = hub.submit_inference_job(
195
+ model=target_model,
196
+ device=device,
197
+ inputs=input_data,
198
+ )
199
+ on_device_output = inference_job.download_output_data()
200
+
201
+ ```
202
+ With the output of the model, you can compute like PSNR, relative errors or
203
+ spot check the output with expected output.
204
+
205
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
206
+ AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
207
+
208
+
209
+
210
+ ## Run demo on a cloud-hosted device
211
+
212
+ You can also run the demo on-device.
213
+
214
+ ```bash
215
+ python -m qai_hub_models.models.nomic_embed_text.demo --on-device
216
+ ```
217
+
218
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
219
+ environment, please add the following to your cell (instead of the above).
220
+ ```
221
+ %run -m qai_hub_models.models.nomic_embed_text.demo -- --on-device
222
+ ```
223
+
224
+
225
+ ## Deploying compiled model to Android
226
+
227
+
228
+ The models can be deployed using multiple runtimes:
229
+ - TensorFlow Lite (`.tflite` export): [This
230
+ tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
231
+ guide to deploy the .tflite model in an Android application.
232
+
233
+
234
+ - QNN (`.so` export ): This [sample
235
+ app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
236
+ provides instructions on how to use the `.so` shared library in an Android application.
237
+
238
+
239
+ ## View on Qualcomm® AI Hub
240
+ Get more details on Nomic-Embed-Text's performance across various devices [here](https://aihub.qualcomm.com/models/nomic_embed_text).
241
+ Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
242
+
243
+
244
+ ## License
245
+ * The license for the original implementation of Nomic-Embed-Text can be found
246
+ [here](https://huggingface.co/datasets/choosealicense/licenses/blob/main/markdown/apache-2.0.md).
247
+ * 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)
248
+
249
+
250
+
251
+ ## References
252
+ * [Introducing Nomic Embed: A Truly Open Embedding Model](https://www.nomic.ai/blog/posts/nomic-embed-text-v1)
253
+ * [Source Model Implementation](https://huggingface.co/nomic-ai/nomic-embed-text-v1.5)
254
+
255
+
256
+
257
+ ## Community
258
+ * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
259
+ * For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).
260
+
261
+