Serialize and save the ETRecord to the specified path for use in Inspector. The ETRecord should contains at least edge dialect program and executorch program information for further analysis, otherwise it will raise an exception. Args: path: Path where t
(self, path: Union[str, os.PathLike, BinaryIO, IO[bytes]])
| 136 | self.__debug_handle_map = value |
| 137 | |
| 138 | def save(self, path: Union[str, os.PathLike, BinaryIO, IO[bytes]]) -> None: |
| 139 | """ |
| 140 | Serialize and save the ETRecord to the specified path for use in Inspector. The ETRecord |
| 141 | should contains at least edge dialect program and executorch program information for further |
| 142 | analysis, otherwise it will raise an exception. |
| 143 | |
| 144 | Args: |
| 145 | path: Path where the ETRecord file will be saved to. |
| 146 | |
| 147 | Raises: |
| 148 | RuntimeError: If the ETRecord does not contain essential information for Inpector. |
| 149 | """ |
| 150 | if isinstance(path, (str, os.PathLike)): |
| 151 | # pyre-ignore[6]: In call `os.fspath`, for 1st positional argument, expected `str` but got `Union[PathLike[typing.Any], str]` |
| 152 | path = os.fspath(path) |
| 153 | |
| 154 | if not (self.edge_dialect_program and self._debug_handle_map): |
| 155 | raise RuntimeError( |
| 156 | "ETRecord must contain edge dialect program and executorch program to be saved" |
| 157 | ) |
| 158 | |
| 159 | # Normalize edge_dialect_program to dict format for consistent handling |
| 160 | if isinstance(self.edge_dialect_program, ExportedProgram): |
| 161 | self._edge_dialect_programs_dict: Dict[str, ExportedProgram] = { |
| 162 | "forward": self.edge_dialect_program |
| 163 | } |
| 164 | else: |
| 165 | self._edge_dialect_programs_dict = self.edge_dialect_program |
| 166 | |
| 167 | etrecord_zip = ZipFile(path, "w") |
| 168 | |
| 169 | try: |
| 170 | self._write_identifier(etrecord_zip) |
| 171 | self._save_programs(etrecord_zip) |
| 172 | self._save_graph_map(etrecord_zip) |
| 173 | self._save_metadata(etrecord_zip) |
| 174 | finally: |
| 175 | etrecord_zip.close() |
| 176 | |
| 177 | def _write_identifier(self, etrecord_zip: ZipFile) -> None: |
| 178 | """Write the magic file identifier.""" |