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

Function main

examples/portable/scripts/export.py:31–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29
30
31def main() -> None:
32 parser = argparse.ArgumentParser()
33 parser.add_argument(
34 "-m",
35 "--model_name",
36 required=True,
37 help=f"provide a model name. Valid ones: {list(MODEL_NAME_TO_MODEL.keys())}",
38 )
39
40 parser.add_argument(
41 "-s",
42 "--strict",
43 action=argparse.BooleanOptionalAction,
44 help="whether to export with strict mode. Default is True",
45 )
46
47 parser.add_argument(
48 "-a",
49 "--segment_alignment",
50 required=False,
51 help="specify segment alignment in hex. Default is 0x1000. Use 0x4000 for iOS",
52 )
53
54 parser.add_argument(
55 "-e",
56 "--external_constants",
57 action=argparse.BooleanOptionalAction,
58 default=False,
59 help="Save constants in external .ptd file. Default is False",
60 )
61
62 parser.add_argument("-o", "--output_dir", default=".", help="output directory")
63
64 args = parser.parse_args()
65
66 if args.model_name not in MODEL_NAME_TO_MODEL:
67 raise RuntimeError(
68 f"Model {args.model_name} is not a valid name. "
69 f"Available models are {list(MODEL_NAME_TO_MODEL.keys())}."
70 )
71
72 model, example_inputs, _, dynamic_shapes = EagerModelFactory.create_model(
73 *MODEL_NAME_TO_MODEL[args.model_name]
74 )
75
76 backend_config = ExecutorchBackendConfig(external_constants=args.external_constants)
77 if args.segment_alignment is not None:
78 backend_config.segment_alignment = int(args.segment_alignment, 16)
79 if dynamic_shapes is not None:
80 edge_manager = export_to_edge(
81 model,
82 example_inputs,
83 dynamic_shapes=dynamic_shapes,
84 edge_compile_config=EdgeCompileConfig(
85 _check_ir_validity=False,
86 ),
87 strict=args.strict,
88 )

Callers 1

export.pyFile · 0.70

Calls 8

export_to_edgeFunction · 0.90
EdgeCompileConfigClass · 0.90
export_to_exec_progFunction · 0.90
save_pte_programFunction · 0.90
keysMethod · 0.80
create_modelMethod · 0.45
to_executorchMethod · 0.45

Tested by

no test coverage detected