Skip to content

Commit c83cc42

Browse files
JacobSzwejbkafacebook-github-bot
authored andcommitted
save api (#7097)
Summary: Tired of writing out this python boilerplate Reviewed By: tarun292, lucylq Differential Revision: D66523473
1 parent e013e53 commit c83cc42

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

exir/program/_program.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,3 +1519,17 @@ def write_to_file(self, open_file: io.BufferedIOBase) -> None:
15191519
reducing the peak memory usage.
15201520
"""
15211521
self._pte_data.write_to_file(open_file)
1522+
1523+
def save(self, path: str) -> None:
1524+
"""
1525+
Saves the serialized ExecuTorch binary to the file at `path`.
1526+
"""
1527+
if path[-4:] != ".pte":
1528+
logging.error(f"Path {path} does not end with .pte")
1529+
raise ValueError(f"Path {path} does not end with .pte")
1530+
try:
1531+
with open(path, "wb") as file:
1532+
self.write_to_file(file)
1533+
logging.info(f"Saved exported program to {path}")
1534+
except Exception as e:
1535+
logging.error(f"Error while saving to {path}: {e}")

0 commit comments

Comments
 (0)