Skip to content

Commit 3f637cc

Browse files
cccclaifacebook-github-bot
authored andcommitted
refactor the transform as a standalone function
Summary: Move the transform passes to a standalone function so it's easy to reuse. Reviewed By: mergennachin Differential Revision: D55230973
1 parent a6aefc0 commit 3f637cc

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

backends/qualcomm/utils/utils.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,10 @@ def canonicalize_program(prog: ExportedProgram):
8585
QNN_COMPILE_SPEC, convert_to_flatbuffer(options)
8686
)
8787

88-
89-
def capture_program(
90-
module: torch.nn.Module,
91-
inputs: Tuple[torch.Tensor],
92-
) -> exir.ExirExportedProgram:
93-
# TODO: should switch to torch.export.export & custom deomposition
94-
# to reduce maintaining effort.
95-
exir_exported_program = exir.capture(
96-
module,
97-
inputs,
98-
qnn_capture_config(),
99-
)
100-
# We choose call_operator by target in ConvertBinaryOpsWithScalar
101-
# because it is the same source_fn_stack for MultiheadAttention
102-
exir_exported_program.transform(ConvertBinaryOpsWithScalar())
103-
ex_prog = exir_exported_program.to_edge(qnn_edge_config())
104-
88+
def _transform(edge_program: ExportedProgram) -> None:
10589
# currently ExirExportedProgram.transform does not accept
10690
# changes of input number which was caused by FoldQDQ
10791
# apply passes one by one here to avoid IR capture failure
108-
edge_program = ex_prog.exported_program
10992
graph_module = edge_program.graph_module
11093
RemoveClone()(graph_module)
11194
RecomposePixelShuffle()(graph_module)
@@ -121,6 +104,23 @@ def capture_program(
121104
FoldQDQ()(graph_module)
122105
InsertRequantize(edge_program)(graph_module)
123106
LayoutTransform(edge_program)(graph_module)
107+
108+
def capture_program(
109+
module: torch.nn.Module,
110+
inputs: Tuple[torch.Tensor],
111+
) -> exir.ExirExportedProgram:
112+
# TODO: should switch to torch.export.export & custom deomposition
113+
# to reduce maintaining effort.
114+
exir_exported_program = exir.capture(
115+
module,
116+
inputs,
117+
qnn_capture_config(),
118+
)
119+
# We choose call_operator by target in ConvertBinaryOpsWithScalar
120+
# because it is the same source_fn_stack for MultiheadAttention
121+
exir_exported_program.transform(ConvertBinaryOpsWithScalar())
122+
ex_prog = exir_exported_program.to_edge(qnn_edge_config())
123+
_transform(ex_prog.exported_program)
124124
return ex_prog
125125

126126

0 commit comments

Comments
 (0)