MCPcopy Create free account
hub / github.com/pytorch/executorch / preprocess

Method preprocess

exir/backend/test/test_backends_nested.py:131–158  ·  view source on GitHub ↗
(
        edge_program: ExportedProgram,
        compile_specs: List[CompileSpec],
    )

Source from the content-addressed store, hash-verified

129class Backend1Demo(BackendDetails):
130 @staticmethod
131 def preprocess(
132 edge_program: ExportedProgram,
133 compile_specs: List[CompileSpec],
134 ) -> PreprocessResult:
135 assert isinstance(edge_program, ExportedProgram)
136 partitioned_module = to_backend(edge_program, Backend2PartitionerDemo())
137
138 def process(gm):
139 processed_bytes = ""
140 for node in gm.graph.nodes:
141 if node.op == "call_function":
142 if node.target is torch.ops.higher_order.cond:
143 _, true_gm, _ = _get_submodule(gm, node, 1)
144 _, false_gm, _ = _get_submodule(gm, node, 2)
145 processed_bytes += f"{node.target.__name__}({process(true_gm)},{process(false_gm)});"
146 elif node.target is operator.getitem:
147 continue
148 elif node.target is executorch_call_delegate:
149 _, lowered, _ = _get_submodule(gm, node, 0)
150 processed_bytes += f"call_delegate({lowered.processed_bytes});"
151 else:
152 processed_bytes += f"{node.target.__name__};"
153 return processed_bytes
154
155 processed_bytes = f"Backend1::({process(partitioned_module.graph_module)})"
156 return PreprocessResult(
157 processed_bytes=bytes(processed_bytes, encoding="utf8"),
158 )
159
160
161class CondOperatorSupport(OperatorSupportBase):

Callers

nothing calls this directly

Calls 3

to_backendFunction · 0.90
PreprocessResultClass · 0.90

Tested by

no test coverage detected