Skip to content
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
12 changes: 10 additions & 2 deletions python/tvm/relax/frontend/torch/exported_program_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ def from_exported_program(
keep_params_as_input: bool = False,
unwrap_unit_return_tuple: bool = False,
no_bind_return_tuple: bool = False,
run_ep_decomposition: bool = False,
) -> tvm.IRModule:
"""Convert a PyTorch ExportedProgram to a Relax program

Expand All @@ -1216,6 +1217,12 @@ def from_exported_program(
A boolean flag indicating whether to bind the return tuple as a relax var.
If the flag is true and the return value is a tuple, it will not bind it to a var.

run_ep_decomposition : bool
A boolean flag indicating whether to run PyTorch's decomposition on the
exported program before translation. When True, high-level operators will
be decomposed into their constituent parts. Defaults to False for backward
compatibility.

Returns
-------
output : tvm.IRModule
Expand Down Expand Up @@ -1255,8 +1262,9 @@ def forward(self, input):
# Use the importer to import the ExportedProgram to Relax.
mod: tvm.IRModule = from_exported_program(exported_program)
"""
# decompose into Core ATen operators
exported_program.run_decompositions()
# Conditionally decompose into Core ATen operators
if run_ep_decomposition:
exported_program = exported_program.run_decompositions()
Comment on lines +1266 to +1267

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since this flag is temporary, it would be good practice to add a TODO comment here to track its future removal. This helps ensure the codebase is cleaned up after the migration is complete.

# TODO(user): Remove this flag and always run decomposition once all operators are supported.
if run_ep_decomposition:
    exported_program = exported_program.run_decompositions()

It would also be helpful to note the temporary nature of this flag in its docstring.


return ExportedProgramImporter().from_exported_program(
exported_program,
Expand Down
Loading