Skip to content

Introduce missing APIs to lower ExportedProgram objects directly #8909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions backends/cadence/aot/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,14 @@ def export_program(
return expo_program


# Export the model and lower it to an EdgeProgramManager (in edge IR).
def export_to_edge(
model: torch.nn.Module,
inputs: tuple[object, ...],
def lower_ep_to_edge(
expo_program: ExportedProgram,
dump_graphs: bool = False,
constant_methods: Optional[dict[str, object]] = None,
) -> EdgeProgramManager:
assert isinstance(model, torch.nn.Module), "model should be an nn.Module"

# Export the model into an ExportedProgram.
expo_program = export_program(model, inputs)

"""
Lower an ExportedProgram to an EdgeProgramManager (in edge IR).
"""
# Call to_edge to convert the graph to edge IR.
# Note: dim_order is skipped (https://github.com./pytorch/executorch/issues/3704)
edge_prog_manager = to_edge(
Expand All @@ -215,6 +211,23 @@ def export_to_edge(
logging.info(
edge_prog_manager.exported_program().graph_module.graph.print_tabular()
)
return edge_prog_manager


# Export the model and lower it to an EdgeProgramManager (in edge IR).
def export_to_edge(
model: torch.nn.Module,
inputs: tuple[object, ...],
dump_graphs: bool = False,
constant_methods: Optional[dict[str, object]] = None,
) -> EdgeProgramManager:
assert isinstance(model, torch.nn.Module), "model should be an nn.Module"

# Export the model into an ExportedProgram.
expo_program = export_program(model, inputs)

# Lower the model to edge IR.
edge_prog_manager = lower_ep_to_edge(expo_program, dump_graphs, constant_methods)

return edge_prog_manager

Expand Down
Loading