Skip to content

refactor the transform as a standalone function #2593

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

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 19 additions & 17 deletions backends/qualcomm/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,10 @@ def canonicalize_program(prog: ExportedProgram):
)


def capture_program(
module: torch.nn.Module,
inputs: Tuple[torch.Tensor],
) -> exir.ExirExportedProgram:
# TODO: should switch to torch.export.export & custom deomposition
# to reduce maintaining effort.
exir_exported_program = exir.capture(
module,
inputs,
qnn_capture_config(),
)
# We choose call_operator by target in ConvertBinaryOpsWithScalar
# because it is the same source_fn_stack for MultiheadAttention
exir_exported_program.transform(ConvertBinaryOpsWithScalar())
ex_prog = exir_exported_program.to_edge(qnn_edge_config())

def _transform(edge_program: ExportedProgram) -> None:
# currently ExirExportedProgram.transform does not accept
# changes of input number which was caused by FoldQDQ
# apply passes one by one here to avoid IR capture failure
edge_program = ex_prog.exported_program
graph_module = edge_program.graph_module
RemoveClone()(graph_module)
RecomposePixelShuffle()(graph_module)
Expand All @@ -121,6 +105,24 @@ def capture_program(
FoldQDQ()(graph_module)
InsertRequantize(edge_program)(graph_module)
LayoutTransform(edge_program)(graph_module)


def capture_program(
module: torch.nn.Module,
inputs: Tuple[torch.Tensor],
) -> exir.ExirExportedProgram:
# TODO: should switch to torch.export.export & custom deomposition
# to reduce maintaining effort.
exir_exported_program = exir.capture(
module,
inputs,
qnn_capture_config(),
)
# We choose call_operator by target in ConvertBinaryOpsWithScalar
# because it is the same source_fn_stack for MultiheadAttention
exir_exported_program.transform(ConvertBinaryOpsWithScalar())
ex_prog = exir_exported_program.to_edge(qnn_edge_config())
_transform(ex_prog.exported_program)
return ex_prog


Expand Down