Skip to content

Commit fa4d935

Browse files
pytorchbotlucylq
andauthored
[retake] Use extension module for pybind (#14029)
This PR was created by the merge bot to help merge the original PR into the main branch. ghstack PR number: #14024 by @lucylq ^ Please use this as the source of truth for the PR details, comments, and reviews ghstack PR base: https://github.com/pytorch/executorch/tree/gh/lucylq/106/base ghstack PR head: https://github.com/pytorch/executorch/tree/gh/lucylq/106/head Merge bot PR base: https://github.com/pytorch/executorch/tree/main Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/lucylq/106/orig @diff-train-skip-merge --------- Co-authored-by: lucylq <[email protected]>
1 parent d3e19eb commit fa4d935

File tree

5 files changed

+142
-318
lines changed

5 files changed

+142
-318
lines changed

exir/backend/test/test_backends.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ def forward(self, a, x, b):
266266

267267
executorch_module = _load_for_executorch_from_buffer(buff)
268268

269-
# pyre-fixme[16]: Module `pytree` has no attribute `tree_flatten`.
270269
inputs_flattened, _ = tree_flatten(model_inputs)
271270
model_output = executorch_module.run_method("forward", tuple(inputs_flattened))
272271
ref_output = add_mul_module(*model_inputs)
@@ -319,16 +318,17 @@ def forward(self, x):
319318
)
320319

321320
buff = exec_prog.buffer
322-
321+
executorch_module = _load_for_executorch_from_buffer(buff)
323322
# This line should raise an exception like
324323
# RuntimeError: failed with error 0x12
325-
_load_for_executorch_from_buffer(buff)
324+
inputs_flattened, _ = tree_flatten(model_inputs)
325+
executorch_module.run_method("forward", tuple(inputs_flattened))
326326

327327
@vary_segments
328328
def test_backend_with_compiler_out_of_range(self, extract_delegate_segments: bool):
329329
with self.assertRaisesRegex(
330330
RuntimeError,
331-
"loading method forward failed with error 0x12",
331+
"Failed to execute method forward, error: 0x12",
332332
):
333333
self.run_model_in_unsupported_backend(
334334
extract_delegate_segments=extract_delegate_segments
@@ -876,7 +876,6 @@ def forward(self, a, x, b):
876876
self.assertEqual(counter, 2)
877877

878878
executorch_module = _load_for_executorch_from_buffer(executorch_prog.buffer)
879-
# pyre-fixme[16]: Module `pytree` has no attribute `tree_flatten`.
880879
inputs_flattened, _ = tree_flatten(inputs)
881880
model_output = executorch_module.run_method("forward", tuple(inputs_flattened))
882881
ref_output = m(*inputs)

exir/backend/test/test_backends_lifted.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ def forward(self, a, x, b):
297297

298298
executorch_module = _load_for_executorch_from_buffer(buff)
299299

300-
# pyre-fixme[16]: Module `pytree` has no attribute `tree_flatten`.
301300
inputs_flattened, _ = tree_flatten(model_inputs)
302301
model_output = executorch_module.run_method("forward", tuple(inputs_flattened))
303302
ref_output = add_mul_module(*model_inputs)
@@ -347,15 +346,17 @@ def forward(self, x):
347346

348347
buff = exec_prog.buffer
349348

349+
executorch_module = _load_for_executorch_from_buffer(buff)
350350
# This line should raise an exception like
351351
# RuntimeError: failed with error 0x12
352-
_load_for_executorch_from_buffer(buff)
352+
inputs_flattened, _ = tree_flatten(model_inputs)
353+
executorch_module.run_method("forward", tuple(inputs_flattened))
353354

354355
@vary_segments
355356
def test_backend_with_compiler_out_of_range(self, extract_delegate_segments: bool):
356357
with self.assertRaisesRegex(
357358
RuntimeError,
358-
"loading method forward failed with error 0x12",
359+
"Failed to execute method forward, error: 0x12",
359360
):
360361
self.run_model_in_unsupported_backend(
361362
extract_delegate_segments=extract_delegate_segments
@@ -887,7 +888,6 @@ def forward(self, a, x, b):
887888
self.assertEqual(counter, 2)
888889

889890
executorch_module = _load_for_executorch_from_buffer(executorch_prog.buffer)
890-
# pyre-fixme[16]: Module `pytree` has no attribute `tree_flatten`.
891891
inputs_flattened, _ = tree_flatten(inputs)
892892
model_output = executorch_module.run_method("forward", tuple(inputs_flattened))
893893
ref_output = m(*inputs)

exir/backend/test/test_compatibility.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ def forward(self, x):
6262
)
6363
)
6464

65+
executorch_module = _load_for_executorch_from_buffer(buff)
6566
# Throw runtime error with error code 0x30, meaning delegate is incompatible.
6667
with self.assertRaisesRegex(
6768
RuntimeError,
68-
"loading method forward failed with error 0x30",
69+
"Failed to execute method forward, error: 0x30",
6970
):
70-
executorch_module = _load_for_executorch_from_buffer(buff)
71+
executorch_module.run_method("forward")
7172

7273
def test_compatibility_in_runtime_edge_program_manager(self):
7374
class SinModule(torch.nn.Module):
@@ -108,9 +109,10 @@ def forward(self, x):
108109
)
109110
)
110111

112+
executorch_module = _load_for_executorch_from_buffer(buff)
111113
# Throw runtime error with error code 0x30, meaning delegate is incompatible.
112114
with self.assertRaisesRegex(
113115
RuntimeError,
114-
"loading method forward failed with error 0x30",
116+
"Failed to execute method forward, error: 0x30",
115117
):
116-
executorch_module = _load_for_executorch_from_buffer(buff)
118+
executorch_module.run_method("forward")

0 commit comments

Comments
 (0)