Skip to content

Commit 418824e

Browse files
JacobSzwejbkafacebook-github-bot
authored andcommitted
save api
Summary: Tired of writing out this python boilerplate Differential Revision: D66523473
1 parent 1c7d94e commit 418824e

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
@@ -1497,3 +1497,17 @@ def write_to_file(self, open_file: io.BufferedIOBase) -> None:
14971497
reducing the peak memory usage.
14981498
"""
14991499
self._pte_data.write_to_file(open_file)
1500+
1501+
def save(self, path: str) -> None:
1502+
"""
1503+
Saves the serialized ExecuTorch binary to the file at `path`.
1504+
"""
1505+
if path[-4:] != ".pte":
1506+
logging.error(f"Path {path} does not end with .pte")
1507+
raise ValueError(f"Path {path} does not end with .pte")
1508+
try:
1509+
with open(path, "wb") as file:
1510+
self.write_to_file(file)
1511+
logging.info(f"Saved exported program to {path}")
1512+
except Exception as e:
1513+
logging.error(f"Error while saving to {path}: {e}")

0 commit comments

Comments
 (0)