Rate this Page

torch.utils.mobile_optimizer#

Created On: Jun 11, 2025 | Last Updated On: Jun 11, 2025

PyTorch Mobile is no longer actively supported. Redirecting toExecuTorch documentation.

Warning

PyTorch Mobile is no longer actively supported. Please check outExecuTorch, PyTorch’sall-new on-device inference library. You can also reviewdocumentation onXNNPACKandVulkan 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 (set[_MobileOptimizerType]|None) – A set with type of MobileOptimizerType. When set is not passed,optimization method will run all the optimizer pass; otherwise, optimizermethod will run the optimization pass that is not included inside optimization_blocklist.

  • preserved_methods (list[AnyStr]|None) – 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