shreyajn commited on
Commit
649fe98
1 Parent(s): a0151f5

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +215 -0
README.md ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ license: mit
4
+ pipeline_tag: automatic-speech-recognition
5
+ tags:
6
+ - backbone
7
+ - android
8
+
9
+ ---
10
+
11
+ ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/huggingface_wavlm_base_plus/web-assets/banner.png)
12
+
13
+ # HuggingFace-WavLM-Base-Plus: Optimized for Mobile Deployment
14
+ ## Real-time Speech processing
15
+
16
+ HuggingFaceWavLMBasePlus is a real time speech processing backbone based on Microsoft's WavLM model.
17
+
18
+ This model is an implementation of HuggingFace-WavLM-Base-Plus found [here](https://huggingface.co/patrickvonplaten/wavlm-libri-clean-100h-base-plus/tree/main).
19
+ This repository provides scripts to run HuggingFace-WavLM-Base-Plus on Qualcomm® devices.
20
+ More details on model performance across various devices, can be found
21
+ [here](https://aihub.qualcomm.com/models/huggingface_wavlm_base_plus).
22
+
23
+
24
+ ### Model Details
25
+
26
+ - **Model Type:** Speech recognition
27
+ - **Model Stats:**
28
+ - Model checkpoint: wavlm-libri-clean-100h-base-plus
29
+ - Input resolution: 1x320000
30
+ - Number of parameters: 95.1M
31
+ - Model size: 363 MB
32
+
33
+
34
+ | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
35
+ | ---|---|---|---|---|---|---|---|
36
+ | Samsung Galaxy S23 Ultra (Android 13) | Snapdragon® 8 Gen 2 | TFLite | 463.847 ms | 10 - 13 MB | FP32 | CPU | [HuggingFace-WavLM-Base-Plus.tflite](https://huggingface.co/qualcomm/HuggingFace-WavLM-Base-Plus/blob/main/HuggingFace-WavLM-Base-Plus.tflite)
37
+
38
+
39
+ ## Installation
40
+
41
+ This model can be installed as a Python package via pip.
42
+
43
+ ```bash
44
+ pip install "qai-hub-models[huggingface_wavlm_base_plus]"
45
+ ```
46
+
47
+
48
+
49
+ ## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
50
+
51
+ Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
52
+ Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
53
+
54
+ With this API token, you can configure your client to run models on the cloud
55
+ hosted devices.
56
+ ```bash
57
+ qai-hub configure --api_token API_TOKEN
58
+ ```
59
+ Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
60
+
61
+
62
+
63
+ ## Demo off target
64
+
65
+ The package contains a simple end-to-end demo that downloads pre-trained
66
+ weights and runs this model on a sample input.
67
+
68
+ ```bash
69
+ python -m qai_hub_models.models.huggingface_wavlm_base_plus.demo
70
+ ```
71
+
72
+ The above demo runs a reference implementation of pre-processing, model
73
+ inference, and post processing.
74
+
75
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
76
+ environment, please add the following to your cell (instead of the above).
77
+ ```
78
+ %run -m qai_hub_models.models.huggingface_wavlm_base_plus.demo
79
+ ```
80
+
81
+
82
+ ### Run model on a cloud-hosted device
83
+
84
+ In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
85
+ device. This script does the following:
86
+ * Performance check on-device on a cloud-hosted device
87
+ * Downloads compiled assets that can be deployed on-device for Android.
88
+ * Accuracy check between PyTorch and on-device outputs.
89
+
90
+ ```bash
91
+ python -m qai_hub_models.models.huggingface_wavlm_base_plus.export
92
+ ```
93
+
94
+ ```
95
+ Profile Job summary of HuggingFace-WavLM-Base-Plus
96
+ --------------------------------------------------
97
+ Device: Samsung Galaxy S23 Ultra (13)
98
+ Estimated Inference Time: 463.85 ms
99
+ Estimated Peak Memory Range: 10.22-13.22 MB
100
+ Compute Units: GPU (88),CPU (748) | Total (836)
101
+
102
+
103
+ ```
104
+ ## How does this work?
105
+
106
+ This [export script](https://github.com/quic/ai-hub-models/blob/main/qai_hub_models/models/HuggingFace-WavLM-Base-Plus/export.py)
107
+ leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
108
+ on-device. Lets go through each step below in detail:
109
+
110
+ Step 1: **Compile model for on-device deployment**
111
+
112
+ To compile a PyTorch model for on-device deployment, we first trace the model
113
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
114
+
115
+ ```python
116
+ import torch
117
+
118
+ import qai_hub as hub
119
+ from qai_hub_models.models.huggingface_wavlm_base_plus import Model
120
+
121
+ # Load the model
122
+ torch_model = Model.from_pretrained()
123
+ torch_model.eval()
124
+
125
+ # Device
126
+ device = hub.Device("Samsung Galaxy S23")
127
+
128
+ # Trace model
129
+ input_shape = torch_model.get_input_spec()
130
+ sample_inputs = torch_model.sample_inputs()
131
+
132
+ pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
133
+
134
+ # Compile model on a specific device
135
+ compile_job = hub.submit_compile_job(
136
+ model=pt_model,
137
+ device=device,
138
+ input_specs=torch_model.get_input_spec(),
139
+ )
140
+
141
+ # Get target model to run on-device
142
+ target_model = compile_job.get_target_model()
143
+
144
+ ```
145
+
146
+
147
+ Step 2: **Performance profiling on cloud-hosted device**
148
+
149
+ After compiling models from step 1. Models can be profiled model on-device using the
150
+ `target_model`. Note that this scripts runs the model on a device automatically
151
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
152
+ provided job URL to view a variety of on-device performance metrics.
153
+ ```python
154
+ profile_job = hub.submit_profile_job(
155
+ model=target_model,
156
+ device=device,
157
+ )
158
+
159
+ ```
160
+
161
+ Step 3: **Verify on-device accuracy**
162
+
163
+ To verify the accuracy of the model on-device, you can run on-device inference
164
+ on sample input data on the same cloud hosted device.
165
+ ```python
166
+ input_data = torch_model.sample_inputs()
167
+ inference_job = hub.submit_inference_job(
168
+ model=target_model,
169
+ device=device,
170
+ inputs=input_data,
171
+ )
172
+
173
+ on_device_output = inference_job.download_output_data()
174
+
175
+ ```
176
+ With the output of the model, you can compute like PSNR, relative errors or
177
+ spot check the output with expected output.
178
+
179
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
180
+ AI Hub. [Sign up for early access](https://aihub.qualcomm.com/sign-up).
181
+
182
+
183
+
184
+ ## Deploying compiled model to Android
185
+
186
+
187
+ The models can be deployed using multiple runtimes:
188
+ - TensorFlow Lite (`.tflite` export): [This
189
+ tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
190
+ guide to deploy the .tflite model in an Android application.
191
+
192
+
193
+ - QNN (`.so` export ): This [sample
194
+ app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
195
+ provides instructions on how to use the `.so` shared library in an Android application.
196
+
197
+
198
+ ## View on Qualcomm® AI Hub
199
+ Get more details on HuggingFace-WavLM-Base-Plus's performance across various devices [here](https://aihub.qualcomm.com/models/huggingface_wavlm_base_plus).
200
+ Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
201
+
202
+ ## License
203
+ - The license for the original implementation of HuggingFace-WavLM-Base-Plus can be found
204
+ [here](https://github.com/microsoft/unilm/blob/master/LICENSE).
205
+ - 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).
206
+
207
+ ## References
208
+ * [WavLM: Large-Scale Self-Supervised Pre-Training for Full Stack Speech Processing](https://arxiv.org/abs/2110.13900)
209
+ * [Source Model Implementation](https://huggingface.co/patrickvonplaten/wavlm-libri-clean-100h-base-plus/tree/main)
210
+
211
+ ## Community
212
+ * Join [our AI Hub Slack community](https://join.slack.com/t/qualcomm-ai-hub/shared_invite/zt-2dgf95loi-CXHTDRR1rvPgQWPO~ZZZJg) to collaborate, post questions and learn more about on-device AI.
213
+ * For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).
214
+
215
+