Parses an `ETRecord` file and returns an `ETRecord` object that contains the deserialized graph modules, program buffer, and a debug handle map. In the graph map in the returned `ETRecord` object if a model with multiple entry points was provided originally by the user during `ETRec
(etrecord_path: str)
| 742 | |
| 743 | |
| 744 | def parse_etrecord(etrecord_path: str) -> ETRecord: # noqa: C901 |
| 745 | """ |
| 746 | Parses an `ETRecord` file and returns an `ETRecord` object that contains the deserialized graph |
| 747 | modules, program buffer, and a debug handle map. |
| 748 | In the graph map in the returned `ETRecord` object if a model with multiple entry points was provided |
| 749 | originally by the user during `ETRecord` generation then each entry point will be stored as a separate |
| 750 | graph module in the `ETRecord` object with the name being `the original module name + "/" + the |
| 751 | name of the entry point`. |
| 752 | |
| 753 | Args: |
| 754 | etrecord_path: Path to the `ETRecord` file. |
| 755 | |
| 756 | Returns: |
| 757 | `ETRecord` object. |
| 758 | """ |
| 759 | |
| 760 | try: |
| 761 | etrecord_zip = ZipFile(etrecord_path, "r") |
| 762 | except BadZipFile: |
| 763 | raise RuntimeError("Invalid etrecord file passed in.") |
| 764 | |
| 765 | file_list = etrecord_zip.namelist() |
| 766 | |
| 767 | if ETRecordReservedFileNames.ETRECORD_IDENTIFIER not in file_list: |
| 768 | raise RuntimeError( |
| 769 | "ETRecord identifier missing from etrecord file passed in. Either an invalid file was passed in or the file is corrupt." |
| 770 | ) |
| 771 | |
| 772 | graph_map: Dict[str, ExportedProgram] = {} |
| 773 | edge_dialect_programs: Dict[str, ExportedProgram] = {} |
| 774 | debug_handle_map = None |
| 775 | delegate_map = None |
| 776 | instruction_id_to_num_outs_map = None |
| 777 | exported_program = None |
| 778 | edge_dialect_program: Optional[ |
| 779 | Union[ExportedProgram, Dict[str, ExportedProgram]] |
| 780 | ] = None |
| 781 | reference_outputs = None |
| 782 | representative_inputs = None |
| 783 | export_graph_id = 0 |
| 784 | |
| 785 | serialized_exported_program_files = set() |
| 786 | serialized_edge_dialect_program_files = set() |
| 787 | serialized_state_dict_files = set() |
| 788 | serialized_constants_files = set() |
| 789 | serialized_example_inputs_files = set() |
| 790 | |
| 791 | edge_dialect_prefix = f"{ETRecordReservedFileNames.EDGE_DIALECT_EXPORTED_PROGRAM}/" |
| 792 | |
| 793 | for entry in file_list: |
| 794 | if entry == ETRecordReservedFileNames.DEBUG_HANDLE_MAP_NAME: |
| 795 | debug_handle_map = json.loads( |
| 796 | etrecord_zip.read(ETRecordReservedFileNames.DEBUG_HANDLE_MAP_NAME) |
| 797 | ) |
| 798 | elif entry == ETRecordReservedFileNames.DELEGATE_MAP_NAME: |
| 799 | delegate_map = json.loads( |
| 800 | etrecord_zip.read(ETRecordReservedFileNames.DELEGATE_MAP_NAME) |
| 801 | ) |