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

Function _export_and_execute

runtime/test/test_runtime_xnnpack.py:28–49  ·  view source on GitHub ↗

Export *model* with XNNPACK, save to a temp .pte, and run it via Runtime.

(
    model: torch.nn.Module, example_inputs: tuple[torch.Tensor, ...]
)

Source from the content-addressed store, hash-verified

26
27
28def _export_and_execute(
29 model: torch.nn.Module, example_inputs: tuple[torch.Tensor, ...]
30):
31 """Export *model* with XNNPACK, save to a temp .pte, and run it via Runtime."""
32 with tempfile.TemporaryDirectory() as temp_dir, torch.no_grad():
33 model.eval()
34 aten = export(model, example_inputs, strict=True)
35 edge = to_edge_transform_and_lower(
36 aten,
37 compile_config=EdgeCompileConfig(_check_ir_validity=False),
38 partitioner=[XnnpackPartitioner()],
39 )
40 et = edge.to_executorch()
41
42 pte_path = Path(temp_dir) / "xnnpack_runtime_test.pte"
43 et.save(str(pte_path))
44
45 runtime = Runtime.get()
46 program = runtime.load_program(pte_path, verification=Verification.Minimal)
47 method = program.load_method("forward")
48 assert method is not None, "forward method should exist in exported program"
49 return method.execute(example_inputs)
50
51
52@unittest.skipUnless(

Callers 7

test_addMethod · 0.85
test_linearMethod · 0.85
test_conv2d_reluMethod · 0.85
test_mlpMethod · 0.85
test_conv_bnMethod · 0.85
test_classifier_headMethod · 0.85

Calls 10

exportFunction · 0.90
EdgeCompileConfigClass · 0.90
XnnpackPartitionerClass · 0.90
load_programMethod · 0.80
load_methodMethod · 0.80
to_executorchMethod · 0.45
saveMethod · 0.45
getMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected