shreyajn commited on
Commit
aa3f1f0
·
verified ·
1 Parent(s): 8af04ce

Upload README.md with huggingface_hub

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