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

Method test_call_delegate

exir/tests/test_delegate.py:43–61  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

41 register_additional_test_aten_ops()
42
43 def test_call_delegate(self) -> None:
44 def g(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
45 return x + y
46
47 inputs = (torch.ones(1, 3), torch.ones(1, 3))
48 edge_ir_m = to_edge(export(WrapperModule(g), inputs, strict=True))
49 lowered_module: LoweredBackendModule = LoweredBackendModule(
50 edge_ir_m.exported_program(), "BackendWithCompilerDemo", b"moo", []
51 )
52
53 def f(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
54 return torch.ops.higher_order.executorch_call_delegate(lowered_module, x, y)
55
56 orig_res = f(*inputs)
57 gm = export(WrapperModule(f), inputs, strict=True)
58 FileCheck().check("lowered_module_0").check(
59 "torch.ops.higher_order.executorch_call_delegate"
60 ).run(gm.graph_module.code)
61 self.assertTrue(torch.allclose(orig_res, gm.module()(*inputs)))
62
63 def test_to_backend(self) -> None:
64 """Check if we have patched a lowered module correctly (for delegation)"""

Callers

nothing calls this directly

Calls 9

to_edgeFunction · 0.90
exportFunction · 0.90
onesMethod · 0.80
moduleMethod · 0.80
WrapperModuleClass · 0.70
exported_programMethod · 0.45
runMethod · 0.45
checkMethod · 0.45

Tested by

no test coverage detected