Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -125,20 +125,61 @@ This [export script](https://aihub.qualcomm.com/models/whisper_tiny_en/qai_hub_m
|
|
| 125 |
leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
|
| 126 |
on-device. Lets go through each step below in detail:
|
| 127 |
|
| 128 |
-
Step 1: **
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
-
Upload compiled models from `qai_hub_models.models.whisper_tiny_en` on hub.
|
| 131 |
```python
|
| 132 |
import torch
|
| 133 |
|
| 134 |
import qai_hub as hub
|
| 135 |
-
from qai_hub_models.models.whisper_tiny_en import
|
| 136 |
|
| 137 |
# Load the model
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
model_WhisperEncoder = hub.upload_model(model.encoder.get_target_model_path())
|
| 141 |
-
model_WhisperDecoder = hub.upload_model(model.decoder.get_target_model_path())
|
| 142 |
```
|
| 143 |
|
| 144 |
|
|
|
|
| 125 |
leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
|
| 126 |
on-device. Lets go through each step below in detail:
|
| 127 |
|
| 128 |
+
Step 1: **Compile model for on-device deployment**
|
| 129 |
+
|
| 130 |
+
To compile a PyTorch model for on-device deployment, we first trace the model
|
| 131 |
+
in memory using the `jit.trace` and then call the `submit_compile_job` API.
|
| 132 |
|
|
|
|
| 133 |
```python
|
| 134 |
import torch
|
| 135 |
|
| 136 |
import qai_hub as hub
|
| 137 |
+
from qai_hub_models.models.whisper_tiny_en import WhisperEncoder,WhisperDecoder
|
| 138 |
|
| 139 |
# Load the model
|
| 140 |
+
encoder_model = WhisperEncoder.from_pretrained()
|
| 141 |
+
|
| 142 |
+
decoder_model = WhisperDecoder.from_pretrained()
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
# Device
|
| 146 |
+
device = hub.Device("Samsung Galaxy S23")
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
# Trace model
|
| 150 |
+
encoder_input_shape = encoder_model.get_input_spec()
|
| 151 |
+
encoder_sample_inputs = encoder_model.sample_inputs()
|
| 152 |
+
|
| 153 |
+
traced_encoder_model = torch.jit.trace(encoder_model, [torch.tensor(data[0]) for _, data in encoder_sample_inputs.items()])
|
| 154 |
+
|
| 155 |
+
# Compile model on a specific device
|
| 156 |
+
encoder_compile_job = hub.submit_compile_job(
|
| 157 |
+
model=traced_encoder_model ,
|
| 158 |
+
device=device,
|
| 159 |
+
input_specs=encoder_model.get_input_spec(),
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
# Get target model to run on-device
|
| 163 |
+
encoder_target_model = encoder_compile_job.get_target_model()
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
# Trace model
|
| 167 |
+
decoder_input_shape = decoder_model.get_input_spec()
|
| 168 |
+
decoder_sample_inputs = decoder_model.sample_inputs()
|
| 169 |
+
|
| 170 |
+
traced_decoder_model = torch.jit.trace(decoder_model, [torch.tensor(data[0]) for _, data in decoder_sample_inputs.items()])
|
| 171 |
+
|
| 172 |
+
# Compile model on a specific device
|
| 173 |
+
decoder_compile_job = hub.submit_compile_job(
|
| 174 |
+
model=traced_decoder_model ,
|
| 175 |
+
device=device,
|
| 176 |
+
input_specs=decoder_model.get_input_spec(),
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
# Get target model to run on-device
|
| 180 |
+
decoder_target_model = decoder_compile_job.get_target_model()
|
| 181 |
+
|
| 182 |
|
|
|
|
|
|
|
| 183 |
```
|
| 184 |
|
| 185 |
|