Skip to content

Commit a0d4ce6

Browse files
salilsdesaiSvetlana Karslioglukimishpatel
authored
Update script_optimized and vulkan_workflow docs with new optimization options (#2163)
* Update script_optimized and vulkan_workflow docs with new optimization options Co-authored-by: Svetlana Karslioglu <svekars@fb.com> Co-authored-by: Kimish Patel <kimishpatel@fb.com>
1 parent 8500f5e commit a0d4ce6

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

prototype_source/vulkan_workflow.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Python script to save pretrained mobilenet_v2 to a file:
102102
script_model = torch.jit.script(model)
103103
torch.jit.save(script_model, "mobilenet2.pt")
104104

105-
PyTorch 1.7 Vulkan backend supports only float 32bit operators. The default model needs additional step that will optimize operators fusing
105+
PyTorch 1.7 Vulkan backend supports only float 32bit operators. The default model needs additional step that will optimize operators fusing
106106

107107
::
108108

@@ -112,6 +112,10 @@ PyTorch 1.7 Vulkan backend supports only float 32bit operators. The default mode
112112

113113
The result model can be used only on Vulkan backend as it contains specific to the Vulkan backend operators.
114114

115+
By default, ``optimize_for_mobile`` with ``backend='vulkan'`` rewrites the graph so that inputs are transferred to the Vulkan backend, and outputs are transferred to the CPU backend, therefore, the model can be run on CPU inputs and produce CPU outputs. To disable this, add the argument ``optimization_blocklist={MobileOptimizerType.VULKAN_AUTOMATIC_GPU_TRANSFER}`` to ``optimize_for_mobile``. (``MobileOptimizerType`` can be imported from ``torch.utils.mobile_optimizer``)
116+
117+
For more information, see the `torch.utils.mobile_optimizer` `API documentation <https://pytorch.org/docs/stable/mobile_optimizer.html>`_.
118+
115119
Using Vulkan backend in code
116120
----------------------------
117121

@@ -219,19 +223,19 @@ Or if you need only specific abi you can set it as an argument:
219223
Add prepared model ``mobilenet2-vulkan.pt`` to test applocation assets:
220224

221225
::
222-
226+
223227
cp mobilenet2-vulkan.pt $PYTORCH_ROOT/android/test_app/app/src/main/assets/
224228

225229

226-
3. Build and Install test applocation to connected android device
230+
3. Build and Install test applocation to connected android device
227231
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
228232

229233
::
230234

231235
cd $PYTORCH_ROOT
232236
gradle -p android test_app:installMbvulkanLocalBaseDebug
233237

234-
After successful installation, the application with the name 'MBQ' can be launched on the device.
238+
After successful installation, the application with the name 'MBQ' can be launched on the device.
235239

236240

237241

recipes_source/script_optimized.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,23 @@ The optimized model can then be saved and deployed in mobile apps:
194194

195195
optimized_torchscript_model.save("optimized_torchscript_model.pth")
196196

197-
By default, `optimize_for_mobile` will perform the following types of optimizations:
197+
By default, for the CPU backend, `optimize_for_mobile` performs the following types of optimizations:
198198

199-
* Conv2D and BatchNorm fusion which folds Conv2d-BatchNorm2d into Conv2d;
199+
* `Conv2D and BatchNorm fusion` which folds Conv2d-BatchNorm2d into Conv2d;
200200

201-
* Insert and fold prepacked ops which rewrites the model graph to replace 2D convolutions and linear ops with their prepacked counterparts.
201+
* `Insert and fold prepacked ops` which rewrites the model graph to replace 2D convolutions and linear ops with their prepacked counterparts.
202202

203-
* ReLU and hardtanh fusion which rewrites graph by finding ReLU/hardtanh ops and fuses them together.
203+
* `ReLU and hardtanh fusion` which rewrites graph by finding ReLU/hardtanh ops and fuses them together.
204204

205-
* Dropout removal which removes dropout nodes from this module when training is false.
205+
* `Dropout removal` which removes dropout nodes from this module when training is false.
206206

207+
* `Conv packed params hoisting` which moves convolution packed params to the root module, so that the convolution structs can be deleted. This decreases model size without impacting numerics.
208+
209+
For the Vulkan backend,`optimize_for_mobile` performs the following type of optimization:
210+
211+
* `Automatic GPU transfer` which rewrites the graph so that moving input and output data to and from the GPU becomes part of the model.
212+
213+
Optimization types can be disabled by passing an optimization blocklist as an argument to `optimize_for_mobile`.
207214

208215
Learn More
209216
-----------------

0 commit comments

Comments
 (0)