torch.utils.mobile_optimizer
Created On: Jun 11, 2025 | Last Updated On: Jun 11, 2025
PyTorch Mobile is no longer actively supported. Redirecting to ExecuTorch documentation.
Warning
PyTorch Mobile is no longer actively supported. Please check out ExecuTorch, PyTorch’s all-new on-device inference library. You can also review documentation on XNNPACK and Vulkan delegates.
-
torch.utils.mobile_optimizer.optimize_for_mobile(script_module, optimization_blocklist=None, preserved_methods=None, backend='CPU')[source] -
Optimize a torch script module for mobile deployment.
- Parameters
-
- script_module (ScriptModule) – An instance of torch script module with type of ScriptModule.
- optimization_blocklist (Optional[set[torch._C._MobileOptimizerType]]) – A set with type of MobileOptimizerType. When set is not passed, optimization method will run all the optimizer pass; otherwise, optimizer method will run the optimization pass that is not included inside optimization_blocklist.
- preserved_methods (Optional[list[~AnyStr]]) – A list of methods that needed to be preserved when freeze_module pass is invoked
- backend (str) – Device type to use for running the result model (‘CPU’(default), ‘Vulkan’ or ‘Metal’).
- Returns
-
A new optimized torch script module
- Return type
-
RecursiveScriptModule