Skip to content

Commit e449350

Browse files
committed
add generate_etdump
1 parent 79bb43f commit e449350

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

Diff for: devtools/test/test_end2end.py

+42-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
from executorch.devtools.bundled_program.serialize import (
2525
serialize_from_bundled_program_to_flatbuffer,
2626
)
27+
from executorch.extension.pybindings.portable_lib import (
28+
_load_for_executorch_from_bundled_program,
29+
_load_bundled_program_from_buffer
30+
)
2731

2832
# 定义一个简单的模型用于测试
2933
class SimpleAddModel(torch.nn.Module):
@@ -34,9 +38,9 @@ def forward(self, x, y):
3438
return x + y
3539

3640

37-
class TestDevtoolsEndToEnd(unittest.TestCase):
38-
def setUp(self):
39-
self.tmp_dir = tempfile.mkdtemp()
41+
class TestDevtoolsEndToEnd():
42+
def __init__(self):
43+
self.tmp_dir = "./"
4044
self.etrecord_path = os.path.join(self.tmp_dir, "etrecord.bin")
4145
self.etdump_path = os.path.join(self.tmp_dir, "etdump.bin")
4246

@@ -45,10 +49,10 @@ def setUp(self):
4549
def tearDown(self):
4650
shutil.rmtree(self.tmp_dir)
4751

48-
def generate_etrecord(self):
52+
def generate_etrecord_(self):
4953
aten_model: ExportedProgram = export(
5054
self.model,
51-
(torch.randn(1, 1, 32, 32),),
55+
(torch.randn(1, 1, 32, 32), torch.randn(1, 1, 32, 32)),
5256
)
5357
edge_program_manager = to_edge(
5458
aten_model,
@@ -64,13 +68,13 @@ def generate_etrecord(self):
6468

6569
def generate_bundled_program(self):
6670
method_name = "forward"
67-
method_graphs = {method_name: export(self.model, (torch.randn(1, 1, 32, 32),))}
71+
method_graphs = {method_name: export(self.model, (torch.randn(1, 1, 32, 32), torch.randn(1, 1, 32, 32)))}
6872

69-
inputs = [torch.randn(1, 1, 32, 32)]
73+
inputs = [(torch.randn(1, 1, 32, 32), torch.randn(1, 1, 32, 32))]
7074
method_test_suites = [
7175
MethodTestSuite(
7276
method_name=method_name,
73-
test_cases=[MethodTestCase(inputs=inp, expected_outputs=self.model(inp)) for inp in inputs],
77+
test_cases=[MethodTestCase(inputs=inp, expected_outputs=self.model(*inp)) for inp in inputs],
7478
)
7579
]
7680

@@ -80,4 +84,33 @@ def generate_bundled_program(self):
8084
method_test_suites=method_test_suites,
8185
)
8286

83-
return bundled_program
87+
return bundled_program
88+
89+
def generate_etdump(self):
90+
bundled_program_py = self.generate_bundled_program()
91+
92+
bundled_program_bytes = serialize_from_bundled_program_to_flatbuffer(
93+
bundled_program_py
94+
)
95+
96+
bundled_program_cpp = _load_bundled_program_from_buffer(bundled_program_bytes)
97+
98+
program = _load_for_executorch_from_bundled_program(
99+
bundled_program_cpp,
100+
enable_etdump=True
101+
)
102+
103+
example_inputs = (torch.randn(1, 1, 32, 32), torch.randn(1, 1, 32, 32))
104+
program.forward(example_inputs)
105+
106+
program.write_etdump_result_to_file(self.etdump_path)
107+
108+
def test_profile(self):
109+
pass
110+
111+
112+
if __name__ == "__main__":
113+
tester = TestDevtoolsEndToEnd()
114+
tester.generate_etrecord_()
115+
tester.generate_bundled_program()
116+
tester.generate_etdump()

0 commit comments

Comments
 (0)