Generates an `ETRecord` from the given objects, serializes it and saves it to the given path. The objects that will be serialized to an `ETRecord` are all the graph modules present in the `extra_recorded_export_modules` dict, the graph module present in the edge dialect program object,
(
et_record: Union[str, os.PathLike, BinaryIO, IO[bytes]],
edge_dialect_program: Union[EdgeProgramManager, ExirExportedProgram],
executorch_program: Union[
ExecutorchProgram,
ExecutorchProgramManager,
BundledProgram,
],
exported_program: Optional[
Union[ExportedProgram, Dict[str, ExportedProgram]]
] = None,
extra_recorded_export_modules: Optional[
Dict[
str,
Union[
ExportedProgram,
ExirExportedProgram,
EdgeProgramManager,
],
]
] = None,
)
| 559 | |
| 560 | |
| 561 | def generate_etrecord( |
| 562 | et_record: Union[str, os.PathLike, BinaryIO, IO[bytes]], |
| 563 | edge_dialect_program: Union[EdgeProgramManager, ExirExportedProgram], |
| 564 | executorch_program: Union[ |
| 565 | ExecutorchProgram, |
| 566 | ExecutorchProgramManager, |
| 567 | BundledProgram, |
| 568 | ], |
| 569 | exported_program: Optional[ |
| 570 | Union[ExportedProgram, Dict[str, ExportedProgram]] |
| 571 | ] = None, |
| 572 | extra_recorded_export_modules: Optional[ |
| 573 | Dict[ |
| 574 | str, |
| 575 | Union[ |
| 576 | ExportedProgram, |
| 577 | ExirExportedProgram, |
| 578 | EdgeProgramManager, |
| 579 | ], |
| 580 | ] |
| 581 | ] = None, |
| 582 | ) -> None: |
| 583 | """ |
| 584 | Generates an `ETRecord` from the given objects, serializes it and saves it to the given path. |
| 585 | The objects that will be serialized to an `ETRecord` are all the graph modules present |
| 586 | in the `extra_recorded_export_modules` dict, the graph module present in the edge dialect program object, |
| 587 | and also the graph module present in the ExecuTorch program object, which |
| 588 | is the closest graph module representation of what is eventually run on the device. |
| 589 | In addition to all the graph modules, we also serialize the program buffer, which the users |
| 590 | can provide to the ExecuTorch runtime to run the model, and the debug handle map |
| 591 | for Developer Tools usage. |
| 592 | |
| 593 | Args: |
| 594 | et_record: Path to where the `ETRecord` file will be saved to. |
| 595 | edge_dialect_program: `EdgeProgramManager` for this model returned by the call to to_edge() |
| 596 | executorch_program: The ExecuTorch program for this model returned by the call to `to_executorch()` or the `BundledProgram` of this model |
| 597 | exported_program: Optional graph module for this model returned by the call to `torch.export` from nn.Module. |
| 598 | extra_recorded_export_modules [Optional]: **Should be ignored by OSS users**. A dictionary of graph modules with the key being the user provided name and the |
| 599 | value being the corresponding exported module. The exported graph modules can be either the |
| 600 | output of `torch.export()` or `exir.to_edge()`. |
| 601 | |
| 602 | Returns: |
| 603 | None |
| 604 | """ |
| 605 | etrecord = ETRecord() |
| 606 | etrecord.add_exported_program(exported_program) |
| 607 | etrecord.add_edge_dialect_program(edge_dialect_program) |
| 608 | etrecord.add_executorch_program(executorch_program) |
| 609 | |
| 610 | # Add extra export modules if user provided |
| 611 | if extra_recorded_export_modules is not None: |
| 612 | etrecord.add_extra_export_modules(extra_recorded_export_modules) |
| 613 | |
| 614 | etrecord.save(et_record) |
| 615 | |
| 616 | |
| 617 | def _process_exported_program( |