bhushans commited on
Commit
df164c5
·
verified ·
1 Parent(s): 92b87ff

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +73 -7
README.md CHANGED
@@ -155,9 +155,11 @@ This [export script](https://aihub.qualcomm.com/models/controlnet_quantized/qai_
155
  leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
156
  on-device. Lets go through each step below in detail:
157
 
158
- Step 1: **Upload compiled model**
 
 
 
159
 
160
- Upload compiled models from `qai_hub_models.models.controlnet_quantized` on hub.
161
  ```python
162
  import torch
163
 
@@ -165,12 +167,76 @@ import qai_hub as hub
165
  from qai_hub_models.models.controlnet_quantized import Model
166
 
167
  # Load the model
168
- model = Model.from_precompiled()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
- model_textencoder_quantized = hub.upload_model(model.text_encoder.get_target_model_path())
171
- model_unet_quantized = hub.upload_model(model.unet.get_target_model_path())
172
- model_vaedecoder_quantized = hub.upload_model(model.vae_decoder.get_target_model_path())
173
- model_controlnet_quantized = hub.upload_model(model.controlnet.get_target_model_path())
174
  ```
175
 
176
 
 
155
  leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
156
  on-device. Lets go through each step below in detail:
157
 
158
+ Step 1: **Compile model for on-device deployment**
159
+
160
+ To compile a PyTorch model for on-device deployment, we first trace the model
161
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
162
 
 
163
  ```python
164
  import torch
165
 
 
167
  from qai_hub_models.models.controlnet_quantized import Model
168
 
169
  # Load the model
170
+ model = Model.from_pretrained()
171
+ text_encoder_model = model.text_encoder
172
+ unet_model = model.unet
173
+ vae_decoder_model = model.vae_decoder
174
+ controlnet_model = model.controlnet
175
+
176
+ # Device
177
+ device = hub.Device("Samsung Galaxy S23")
178
+
179
+ # Trace model
180
+ text_encoder_input_shape = text_encoder_model.get_input_spec()
181
+ text_encoder_sample_inputs = text_encoder_model.sample_inputs()
182
+
183
+ traced_text_encoder_model = torch.jit.trace(text_encoder_model, [torch.tensor(data[0]) for _, data in text_encoder_sample_inputs.items()])
184
+
185
+ # Compile model on a specific device
186
+ text_encoder_compile_job = hub.submit_compile_job(
187
+ model=traced_text_encoder_model ,
188
+ device=device,
189
+ input_specs=text_encoder_model.get_input_spec(),
190
+ )
191
+
192
+ # Get target model to run on-device
193
+ text_encoder_target_model = text_encoder_compile_job.get_target_model()
194
+ # Trace model
195
+ unet_input_shape = unet_model.get_input_spec()
196
+ unet_sample_inputs = unet_model.sample_inputs()
197
+
198
+ traced_unet_model = torch.jit.trace(unet_model, [torch.tensor(data[0]) for _, data in unet_sample_inputs.items()])
199
+
200
+ # Compile model on a specific device
201
+ unet_compile_job = hub.submit_compile_job(
202
+ model=traced_unet_model ,
203
+ device=device,
204
+ input_specs=unet_model.get_input_spec(),
205
+ )
206
+
207
+ # Get target model to run on-device
208
+ unet_target_model = unet_compile_job.get_target_model()
209
+ # Trace model
210
+ vae_decoder_input_shape = vae_decoder_model.get_input_spec()
211
+ vae_decoder_sample_inputs = vae_decoder_model.sample_inputs()
212
+
213
+ traced_vae_decoder_model = torch.jit.trace(vae_decoder_model, [torch.tensor(data[0]) for _, data in vae_decoder_sample_inputs.items()])
214
+
215
+ # Compile model on a specific device
216
+ vae_decoder_compile_job = hub.submit_compile_job(
217
+ model=traced_vae_decoder_model ,
218
+ device=device,
219
+ input_specs=vae_decoder_model.get_input_spec(),
220
+ )
221
+
222
+ # Get target model to run on-device
223
+ vae_decoder_target_model = vae_decoder_compile_job.get_target_model()
224
+ # Trace model
225
+ controlnet_input_shape = controlnet_model.get_input_spec()
226
+ controlnet_sample_inputs = controlnet_model.sample_inputs()
227
+
228
+ traced_controlnet_model = torch.jit.trace(controlnet_model, [torch.tensor(data[0]) for _, data in controlnet_sample_inputs.items()])
229
+
230
+ # Compile model on a specific device
231
+ controlnet_compile_job = hub.submit_compile_job(
232
+ model=traced_controlnet_model ,
233
+ device=device,
234
+ input_specs=controlnet_model.get_input_spec(),
235
+ )
236
+
237
+ # Get target model to run on-device
238
+ controlnet_target_model = controlnet_compile_job.get_target_model()
239
 
 
 
 
 
240
  ```
241
 
242