MCPcopy Create free account
hub / github.com/pytorch/executorch / export_module_to_program

Function export_module_to_program

test/models/export_program.py:317–354  ·  view source on GitHub ↗

Exports the module and returns the serialized program data.

(
    module_class: Type[nn.Module],
    external_constants: bool = False,
)

Source from the content-addressed store, hash-verified

315
316
317def export_module_to_program(
318 module_class: Type[nn.Module],
319 external_constants: bool = False,
320) -> ExecutorchProgramManager:
321 """Exports the module and returns the serialized program data."""
322 torch.manual_seed(0)
323 # Look for an optional @staticmethod that defines custom trace params.
324 export_kwargs: Dict[str, Any] = {}
325 if hasattr(module_class, "get_export_kwargs"):
326 # pyre-ignore[16]: pyre doesn't know about get_export_kwargs.
327 export_kwargs = module_class.get_export_kwargs()
328 export_joint = False
329 export_state_names = False
330 share_mutable_buffers = False
331 if hasattr(module_class, "export_joint"):
332 # pyre-ignore[16]: pyre just cant figure it out
333 export_joint = module_class.export_joint()
334 if hasattr(module_class, "export_state_names"):
335 # pyre-ignore[16]: pyre just cant figure it out
336 export_state_names = module_class.export_state_names()
337 if hasattr(module_class, "get_method_names_to_export"):
338 # pyre-ignore[16]: pyre just cant figure it out
339 methods = module_class.get_method_names_to_export()
340 else:
341 methods = ["forward"]
342 if hasattr(module_class, "share_mutable_buffers"):
343 # pyre-ignore[16]: pyre just cant figure it out
344 share_mutable_buffers = module_class.share_mutable_buffers()
345 module = ExportedModule.export(
346 module_class,
347 methods,
348 export_joint_graph=export_joint,
349 external_constants=external_constants,
350 export_state_names=export_state_names,
351 share_mutable_buffers=share_mutable_buffers,
352 **export_kwargs,
353 )
354 return module.executorch_program
355
356
357def main() -> None:

Callers 1

mainFunction · 0.70

Calls 6

export_jointMethod · 0.80
export_state_namesMethod · 0.80
share_mutable_buffersMethod · 0.80
get_export_kwargsMethod · 0.45
exportMethod · 0.45

Tested by

no test coverage detected