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

Method test_inspect_node

exir/tests/test_print_program.py:16–54  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

14
15class TestPrintProgram(unittest.TestCase):
16 def test_inspect_node(self) -> None:
17 class TestModel(torch.nn.Module):
18 def __init__(self):
19 super().__init__()
20 self.conv1 = torch.nn.Conv2d(32, 32, 1)
21 self.conv2 = torch.nn.Conv2d(32, 32, 1)
22 self.conv3 = torch.nn.Conv2d(32, 32, 1)
23 self.gelu = torch.nn.GELU()
24
25 def forward(self, x: torch.Tensor):
26 a = self.conv1(x)
27 b = self.conv2(a)
28 c = self.conv3(a + b)
29 return self.gelu(c)
30
31 class WrapModule(torch.nn.Module):
32 def __init__(self):
33 super().__init__()
34 self.test_model = TestModel()
35
36 def forward(self, x):
37 return self.test_model(x)
38
39 warp_model = WrapModule()
40 example_inputs = (torch.rand(1, 32, 16, 16),)
41
42 exir_exported_program = to_edge(export(warp_model, example_inputs, strict=True))
43 number_of_stack_trace = 0
44 for node in exir_exported_program.exported_program().graph.nodes:
45 node_info = inspect_node(
46 exir_exported_program.exported_program().graph, node
47 )
48 self.assertRegex(node_info, r".*-->.*")
49 if "stack_trace" in node.meta:
50 self.assertRegex(
51 node_info, r".*Traceback \(most recent call last\)\:.*"
52 )
53 number_of_stack_trace = number_of_stack_trace + 1
54 self.assertGreaterEqual(number_of_stack_trace, 1)

Callers

nothing calls this directly

Calls 5

to_edgeFunction · 0.90
exportFunction · 0.90
inspect_nodeFunction · 0.90
WrapModuleClass · 0.85
exported_programMethod · 0.45

Tested by

no test coverage detected