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

Method test_constant_buffer

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

Source from the content-addressed store, hash-verified

30
31class TestVerification(unittest.TestCase):
32 def test_constant_buffer(self) -> None:
33 def f(x: torch.Tensor) -> torch.Tensor:
34 return torch.ones(2) + x + torch.ones(2)
35
36 # Generate program
37 program = (
38 to_edge(export(WrapperModule(f), (torch.randn(2),), strict=True))
39 .transform(
40 [
41 ConstPropPass(),
42 ]
43 )
44 .to_executorch()
45 ._emitter_output.program
46 )
47
48 test = Interpreter(program)
49 for val_idx in range(len(test.execution_plan.values)):
50 val = test.execution_plan.values[val_idx].val
51 if not (
52 isinstance(val, Tensor) and val.data_buffer_idx == 0
53 ) and not isinstance(val, TensorList):
54 test.load_value(val_idx)
55 vlist = test.get_value_list()
56 for e in vlist:
57 if isinstance(e, torch.Tensor):
58 self.assertTrue(torch.allclose(e, torch.ones(2)))
59
60 # asserting only 2 constant Tensors exist in value list
61 self.assertEqual(len([e for e in vlist if isinstance(e, torch.Tensor)]), 2)
62
63 def test_operator_list(self) -> None:
64 class Op1(torch.nn.Module):

Callers

nothing calls this directly

Calls 10

load_valueMethod · 0.95
get_value_listMethod · 0.95
to_edgeFunction · 0.90
exportFunction · 0.90
ConstPropPassClass · 0.90
InterpreterClass · 0.90
onesMethod · 0.80
WrapperModuleClass · 0.70
to_executorchMethod · 0.45
transformMethod · 0.45

Tested by

no test coverage detected