Skip to content

Commit b04fec2

Browse files
cccclaifacebook-github-bot
authored andcommitted
Update the example flow to include emit program directly from lowered module (#134)
Summary: Pull Request resolved: #134 As title, we can emit the program directly from lowered module Reviewed By: mergennachin, chakriu, digantdesai, larryliu0820 Differential Revision: D47855787 fbshipit-source-id: ffdfbba74bfda6445c9653c59d67775f454dbdac
1 parent 98c1ec9 commit b04fec2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

examples/export/export_and_delegate.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import argparse
1010

11-
import executorch.exir as exir
1211
import torch
1312
from executorch.exir.backend.backend_api import to_backend
1413
from executorch.exir.backend.test.backend_with_compiler_demo import (
@@ -157,11 +156,17 @@ def export_and_lower_the_whole_graph():
157156

158157
# Lower AddMulModule to the demo backend
159158
print("Lowering to the demo backend...")
160-
_ = to_backend(
161-
BackendWithCompilerDemo.__name__, edge.exported_program, m.get_compile_spec()
159+
lowered_module = to_backend(
160+
BackendWithCompilerDemo.__name__, edge, m.get_compile_spec()
162161
)
163162

164-
# TODO(chenlai): emit the lowered graph
163+
buffer = lowered_module.buffer()
164+
165+
model_name = "whole"
166+
filename = f"{model_name}.pte"
167+
print(f"Saving exported program to {filename}")
168+
with open(filename, "wb") as file:
169+
file.write(buffer)
165170

166171

167172
OPTIONS_TO_LOWER = {

0 commit comments

Comments
 (0)