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

Method test

exir/backend/test/test_backends_nested.py:218–258  ·  view source on GitHub ↗

Partitions the cond ops into the delegate

(self)

Source from the content-addressed store, hash-verified

216
217class TestNestedBackends(unittest.TestCase):
218 def test(self) -> None:
219 """
220 Partitions the cond ops into the delegate
221 """
222
223 m = M()
224 orig_res = m(*m.get_example_inputs())
225 orig = to_edge(
226 export(m, m.get_example_inputs(), strict=True),
227 compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
228 )
229
230 partitioned = orig
231 partitioned._edge_programs["forward"] = to_backend(
232 orig.exported_program(), Backend1PartitionerDemo()
233 )
234
235 new_res = partitioned.exported_program().module()(*m.get_example_inputs())[0]
236 self.assertTrue(torch.allclose(orig_res, new_res))
237
238 # The toplevel module should have lowered the cond and add op
239 toplevel_lowered = get_lowered_submodules(
240 partitioned.exported_program().graph_module
241 )
242 self.assertEqual(len(toplevel_lowered), 1)
243 toplevel_lowered = toplevel_lowered[0][1]
244 self.maxDiff = None
245 self.assertEqual(
246 str(toplevel_lowered.processed_bytes),
247 (
248 'b"Backend1::('
249 + "call_delegate(b'Backend2::aten.add.Tensor;');"
250 + "cond("
251 # True function of toplevel cond (nested cond)
252 + "cond(call_delegate(b'Backend2::aten.add.Tensor;aten.mm.default;');,call_delegate(b'Backend2::aten.mm.default;'););"
253 # True function of toplevel cond (delegated add)
254 + "call_delegate(b'Backend2::aten.add.Tensor;');,"
255 # False function of toplevel cond
256 + "call_delegate(b'Backend2::aten.mm.default;'););)\""
257 ),
258 )

Callers

nothing calls this directly

Calls 9

get_example_inputsMethod · 0.95
to_edgeFunction · 0.90
exportFunction · 0.90
to_backendFunction · 0.90
get_lowered_submodulesFunction · 0.90
moduleMethod · 0.80
MClass · 0.70
exported_programMethod · 0.45

Tested by

no test coverage detected