Skip to content

Commit 34e0570

Browse files
authored
executorch/exir/program/test
Differential Revision: D67383235 Pull Request resolved: #7397
1 parent c947fed commit 34e0570

File tree

72 files changed

+396
-587
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+396
-587
lines changed

backends/apple/coreml/runtime/test/export_stateful_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def main() -> None:
4747
torch.randn((1, embedding_dim)),
4848
torch.tensor([0]),
4949
)
50-
exported_model = export(model, example_inputs)
50+
exported_model = export(model, example_inputs, strict=True)
5151
edge_program_manager = exir.to_edge(exported_model)
5252
compile_specs = CoreMLBackend.generate_compile_specs(
5353
compute_precision=ct.precision.FLOAT16,

backends/apple/coreml/test/test_coreml_partitioner.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717

1818
class TestCoreMLPartitioner(unittest.TestCase):
19-
2019
# TODO(T182928844): Delegate dim order op to backend.
2120
edge_compile_config = executorch.exir.EdgeCompileConfig(_skip_dim_order=True)
2221

@@ -34,7 +33,7 @@ def forward(self, a, x, b):
3433
model.eval()
3534

3635
example_inputs = (torch.randn(2, 2), torch.randn(2, 2), torch.randn(2, 2))
37-
exir_program_aten = torch.export.export(model, example_inputs)
36+
exir_program_aten = torch.export.export(model, example_inputs, strict=True)
3837

3938
edge_program_manager = executorch.exir.to_edge(
4039
exir_program_aten, compile_config=self.edge_compile_config
@@ -61,7 +60,7 @@ def test_vit_skip_conv(self):
6160
model.eval()
6261

6362
example_inputs = (torch.randn(1, 3, 224, 224),)
64-
exir_program_aten = torch.export.export(model, example_inputs)
63+
exir_program_aten = torch.export.export(model, example_inputs, strict=True)
6564
edge_program_manager = executorch.exir.to_edge(
6665
exir_program_aten, compile_config=self.edge_compile_config
6766
)
@@ -106,7 +105,7 @@ def forward(self, q, k_val, input_pos):
106105
k_val = torch.randn((1, embedding_dim))
107106
input_pos = torch.tensor([0])
108107
example_inputs = (q, k_val, input_pos)
109-
exir_program_aten = torch.export.export(model, example_inputs)
108+
exir_program_aten = torch.export.export(model, example_inputs, strict=True)
110109

111110
compile_specs = CoreMLBackend.generate_compile_specs(
112111
minimum_deployment_target=ct.target.iOS18

backends/apple/mps/test/test_mps_utils.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,7 @@ def lower_module_and_test_output(
247247
)
248248

249249
executorch_program = to_edge(
250-
export(
251-
delegated_program,
252-
sample_inputs,
253-
),
250+
export(delegated_program, sample_inputs, strict=True),
254251
compile_config=exir.EdgeCompileConfig(
255252
_check_ir_validity=False,
256253
_skip_dim_order=True, # TODO(T182928844): Delegate dim order op to backend.

backends/cadence/aot/compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def export_program(
176176
torch._C._set_mkldnn_enabled(False)
177177

178178
# else: capture the model and return it.
179-
expo_program = export(model, inputs)
179+
expo_program = export(model, inputs, strict=True)
180180

181181
if dump_graphs:
182182
logging.info("Exported graph:")

backends/example/test_example_delegate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def get_example_inputs():
6060

6161
quantized_gm = m
6262
exported_program = to_edge(
63-
export(quantized_gm, copy.deepcopy(example_inputs)),
63+
export(quantized_gm, copy.deepcopy(example_inputs), strict=True),
6464
compile_config=EDGE_COMPILE_CONFIG,
6565
)
6666

@@ -92,7 +92,7 @@ def test_delegate_mobilenet_v2(self):
9292

9393
quantized_gm = m
9494
exported_program = to_edge(
95-
export(quantized_gm, copy.deepcopy(example_inputs)),
95+
export(quantized_gm, copy.deepcopy(example_inputs), strict=True),
9696
compile_config=EDGE_COMPILE_CONFIG,
9797
)
9898

backends/qualcomm/tests/test_qnn_delegate.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ def test_qnn_backend_multi_contexts_composite(self):
16171617
)
16181618
sample_input = module.get_random_input()
16191619
edge_prog = to_edge(
1620-
torch.export.export(module, sample_input),
1620+
torch.export.export(module, sample_input, strict=True),
16211621
)
16221622
update_spill_fill_size(edge_prog.exported_program())
16231623
exec_prog = edge_prog.to_executorch()
@@ -1957,7 +1957,7 @@ def calibrator(gm):
19571957
self.assertEqual(len(exported_progs), 1)
19581958
# lower all graph again, the skipped operators will be left in CPU
19591959
exec_prog = to_edge(
1960-
torch.export.export(graph_module, sample_input),
1960+
torch.export.export(graph_module, sample_input, strict=True),
19611961
).to_executorch()
19621962
self.verify_output(module, sample_input, exec_prog)
19631963

@@ -2004,7 +2004,7 @@ def calibrator(gm):
20042004
self.assertEqual(len(exported_progs), 2)
20052005
# lower all graph again, the skipped operators will be left in CPU
20062006
exec_prog = exec_prog = to_edge(
2007-
torch.export.export(graph_module, sample_input),
2007+
torch.export.export(graph_module, sample_input, strict=True),
20082008
).to_executorch()
20092009
self.verify_output(module, sample_input, exec_prog)
20102010

@@ -2041,7 +2041,7 @@ def calibrator(gm):
20412041
self.assertEqual(len(exported_progs), 5)
20422042
# lower all graph again, the skipped operators will be delegated with fp16
20432043
exec_prog = to_edge(
2044-
torch.export.export(graph_module, sample_input),
2044+
torch.export.export(graph_module, sample_input, strict=True),
20452045
).to_executorch()
20462046
self.verify_output(module, sample_input, exec_prog)
20472047

@@ -2086,7 +2086,7 @@ def test_qnn_backend_multi_contexts_composite(self):
20862086
)
20872087
sample_input = module.get_random_input()
20882088
edge_prog = to_edge(
2089-
torch.export.export(module, sample_input),
2089+
torch.export.export(module, sample_input, strict=True),
20902090
)
20912091
update_spill_fill_size(edge_prog.exported_program())
20922092
exec_prog = edge_prog.to_executorch()
@@ -2721,7 +2721,6 @@ def test_ssd300_vgg16(self):
27212721

27222722

27232723
class TestExampleQaihubScript(TestQNN):
2724-
27252724
def required_envs(self, conditions=None) -> bool:
27262725
conditions = [] if conditions is None else conditions
27272726
return all(

backends/qualcomm/tests/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def get_qdq_module(
385385
custom_quant_annotations: Tuple[Callable] = (),
386386
quant_dtype: QuantDtype = QuantDtype.use_8a8w,
387387
) -> torch.fx.GraphModule:
388-
m = torch.export.export(module, inputs).module()
388+
m = torch.export.export(module, inputs, strict=True).module()
389389

390390
quantizer = QnnQuantizer()
391391
quantizer.add_custom_quant_annotations(custom_quant_annotations)

backends/qualcomm/utils/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def capture_program(
337337
inputs: Tuple[torch.Tensor],
338338
custom_pass_config: FrozenSet[str] = frozenset(),
339339
) -> exir.ExirExportedProgram:
340-
ep = torch.export.export(module, inputs)
340+
ep = torch.export.export(module, inputs, strict=True)
341341
decomposed_ep = ep.run_decompositions(get_decomp_table())
342342
# We choose call_operator by target in ConvertBinaryOpsWithScalar
343343
# because it is the same source_fn_stack for MultiheadAttention
@@ -551,7 +551,7 @@ def prepare_subgm(subgm, subgm_name):
551551

552552
fp_node_id_set = fp_node_id_set if fp_node_id_set is not None else set()
553553
fp_node_op_set = fp_node_op_set if fp_node_op_set is not None else set()
554-
graph_module = torch.export.export(nn_module, sample_input).module()
554+
graph_module = torch.export.export(nn_module, sample_input, strict=True).module()
555555
# define node support type
556556
capability_partitioner = CapabilityBasedPartitioner(
557557
graph_module,
@@ -664,7 +664,7 @@ def forward(self, *inputs):
664664
).default(inputs)
665665

666666
model = Model()
667-
prog = torch.export.export(model, tuple(inputs.values()))
667+
prog = torch.export.export(model, tuple(inputs.values()), strict=True)
668668
# bookkeeping for variables' life cycle
669669
return {
670670
"custom_op": custom_op,

backends/vulkan/test/test_vulkan_delegate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def run_test():
112112
model(*sample_inputs)
113113

114114
program: ExportedProgram = export(
115-
model, sample_inputs, dynamic_shapes=dynamic_shapes
115+
model, sample_inputs, dynamic_shapes=dynamic_shapes, strict=True
116116
)
117117

118118
edge_program = to_edge_transform_and_lower(

backends/xnnpack/partition/graphs/sdpa.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def forward(
7676
v,
7777
mask,
7878
),
79+
strict=True,
7980
),
8081
compile_config=get_xnnpack_edge_compile_config(),
8182
)

backends/xnnpack/test/tester/tester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def run(
194194
inputs: Tuple[torch.Tensor],
195195
) -> None:
196196
self.exported_program = export(
197-
artifact, inputs, dynamic_shapes=self.dynamic_shapes
197+
artifact, inputs, dynamic_shapes=self.dynamic_shapes, strict=True
198198
)
199199

200200
@property

build/packaging/smoke_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def export_linear_model() -> bytes:
6565

6666
# Export the pytorch model and process for ExecuTorch.
6767
print("Exporting program...")
68-
exported_program = export(LinearModel(), example_inputs)
68+
exported_program = export(LinearModel(), example_inputs, strict=True)
6969
print("Lowering to edge...")
7070
edge_program = to_edge(exported_program)
7171
print("Creating ExecuTorch program...")

devtools/backend_debug/tests/test_delegation_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def forward(self, a, x, b):
3131

3232
m = Model()
3333
inputs = (torch.randn(2, 2), torch.randn(2, 2), torch.randn(2, 2))
34-
edge = to_edge(torch.export.export(m, inputs)).to_backend(
34+
edge = to_edge(torch.export.export(m, inputs, strict=True)).to_backend(
3535
AddMulPartitionerDemo()
3636
)
3737
delegation_info = get_delegation_info(edge.exported_program().graph_module)

devtools/bundled_program/util/test_util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ def get_common_executorch_program() -> (
271271
m_name: export(
272272
StatefulWrapperModule(eager_model, getattr(eager_model, m_name)),
273273
capture_inputs[m_name],
274+
strict=True,
274275
)
275276
for m_name in eager_model.method_names
276277
}

devtools/etrecord/tests/etrecord_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def get_test_model_with_bundled_program(self):
6969

7070
def get_test_model_with_manager(self):
7171
f = models.BasicSinMax()
72-
aten_dialect = export(f, f.get_random_inputs())
72+
aten_dialect = export(f, f.get_random_inputs(), strict=True)
7373
edge_program: EdgeProgramManager = to_edge(
7474
aten_dialect, compile_config=EdgeCompileConfig(_check_ir_validity=False)
7575
)

docs/source/tutorials_source/devtools-integration-tutorial.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ def forward(self, x):
8989

9090
model = Net()
9191

92-
aten_model: ExportedProgram = export(
93-
model,
94-
(torch.randn(1, 1, 32, 32),),
95-
)
92+
aten_model: ExportedProgram = export(model, (torch.randn(1, 1, 32, 32),), strict=True)
9693

9794
edge_program_manager: EdgeProgramManager = to_edge(
9895
aten_model, compile_config=EdgeCompileConfig(_check_ir_validity=True)
@@ -141,7 +138,7 @@ def forward(self, x):
141138

142139
# Step 1: ExecuTorch Program Export
143140
m_name = "forward"
144-
method_graphs = {m_name: export(model, (torch.randn(1, 1, 32, 32),))}
141+
method_graphs = {m_name: export(model, (torch.randn(1, 1, 32, 32),), strict=True)}
145142

146143
# Step 2: Construct Method Test Suites
147144
inputs = [[torch.randn(1, 1, 32, 32)] for _ in range(2)]

docs/source/tutorials_source/export-to-executorch-tutorial.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
6666

6767

6868
example_args = (torch.randn(1, 3, 256, 256),)
69-
aten_dialect: ExportedProgram = export(SimpleConv(), example_args)
69+
aten_dialect: ExportedProgram = export(SimpleConv(), example_args, strict=True)
7070
print(aten_dialect)
7171

7272
######################################################################
@@ -101,7 +101,7 @@ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
101101

102102

103103
example_args = (torch.randn(3, 3), torch.randn(3, 3))
104-
aten_dialect: ExportedProgram = export(Basic(), example_args)
104+
aten_dialect: ExportedProgram = export(Basic(), example_args, strict=True)
105105

106106
# Works correctly
107107
print(aten_dialect.module()(torch.ones(3, 3), torch.ones(3, 3)))
@@ -131,7 +131,7 @@ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
131131
dim1_x = Dim("dim1_x", min=1, max=10)
132132
dynamic_shapes = {"x": {1: dim1_x}, "y": {1: dim1_x}}
133133
aten_dialect: ExportedProgram = export(
134-
Basic(), example_args, dynamic_shapes=dynamic_shapes
134+
Basic(), example_args, dynamic_shapes=dynamic_shapes, strict=True
135135
)
136136
print(aten_dialect)
137137

@@ -213,7 +213,7 @@ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
213213
print("Quantized Graph")
214214
print(converted_graph)
215215

216-
aten_dialect: ExportedProgram = export(converted_graph, example_args)
216+
aten_dialect: ExportedProgram = export(converted_graph, example_args, strict=True)
217217
print("ATen Dialect Graph")
218218
print(aten_dialect)
219219

@@ -243,7 +243,7 @@ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
243243
from executorch.exir import EdgeProgramManager, to_edge
244244

245245
example_args = (torch.randn(1, 3, 256, 256),)
246-
aten_dialect: ExportedProgram = export(SimpleConv(), example_args)
246+
aten_dialect: ExportedProgram = export(SimpleConv(), example_args, strict=True)
247247

248248
edge_program: EdgeProgramManager = to_edge(aten_dialect)
249249
print("Edge Dialect Graph")
@@ -267,10 +267,10 @@ def forward(self, x):
267267

268268

269269
encode_args = (torch.randn(1, 10),)
270-
aten_encode: ExportedProgram = export(Encode(), encode_args)
270+
aten_encode: ExportedProgram = export(Encode(), encode_args, strict=True)
271271

272272
decode_args = (torch.randn(1, 5),)
273-
aten_decode: ExportedProgram = export(Decode(), decode_args)
273+
aten_decode: ExportedProgram = export(Decode(), decode_args, strict=True)
274274

275275
edge_program: EdgeProgramManager = to_edge(
276276
{"encode": aten_encode, "decode": aten_decode}
@@ -291,7 +291,7 @@ def forward(self, x):
291291
# rather than the ``torch.ops.aten`` namespace.
292292

293293
example_args = (torch.randn(1, 3, 256, 256),)
294-
aten_dialect: ExportedProgram = export(SimpleConv(), example_args)
294+
aten_dialect: ExportedProgram = export(SimpleConv(), example_args, strict=True)
295295
edge_program: EdgeProgramManager = to_edge(aten_dialect)
296296
print("Edge Dialect Graph")
297297
print(edge_program.exported_program())
@@ -357,7 +357,7 @@ def forward(self, x):
357357

358358
# Export and lower the module to Edge Dialect
359359
example_args = (torch.ones(1),)
360-
aten_dialect: ExportedProgram = export(LowerableModule(), example_args)
360+
aten_dialect: ExportedProgram = export(LowerableModule(), example_args, strict=True)
361361
edge_program: EdgeProgramManager = to_edge(aten_dialect)
362362
to_be_lowered_module = edge_program.exported_program()
363363

@@ -423,7 +423,7 @@ def forward(self, x):
423423

424424

425425
example_args = (torch.ones(1),)
426-
aten_dialect: ExportedProgram = export(ComposedModule(), example_args)
426+
aten_dialect: ExportedProgram = export(ComposedModule(), example_args, strict=True)
427427
edge_program: EdgeProgramManager = to_edge(aten_dialect)
428428
exported_program = edge_program.exported_program()
429429
print("Edge Dialect graph")
@@ -461,7 +461,7 @@ def forward(self, a, x, b):
461461

462462

463463
example_args = (torch.randn(2, 2), torch.randn(2, 2), torch.randn(2, 2))
464-
aten_dialect: ExportedProgram = export(Foo(), example_args)
464+
aten_dialect: ExportedProgram = export(Foo(), example_args, strict=True)
465465
edge_program: EdgeProgramManager = to_edge(aten_dialect)
466466
exported_program = edge_program.exported_program()
467467
print("Edge Dialect graph")
@@ -495,7 +495,7 @@ def forward(self, a, x, b):
495495

496496

497497
example_args = (torch.randn(2, 2), torch.randn(2, 2), torch.randn(2, 2))
498-
aten_dialect: ExportedProgram = export(Foo(), example_args)
498+
aten_dialect: ExportedProgram = export(Foo(), example_args, strict=True)
499499
edge_program: EdgeProgramManager = to_edge(aten_dialect)
500500
exported_program = edge_program.exported_program()
501501
delegated_program = edge_program.to_backend(AddMulPartitionerDemo())
@@ -577,7 +577,9 @@ def forward(self, x):
577577
pre_autograd_aten_dialect = export_for_training(M(), example_args).module()
578578
# Optionally do quantization:
579579
# pre_autograd_aten_dialect = convert_pt2e(prepare_pt2e(pre_autograd_aten_dialect, CustomBackendQuantizer))
580-
aten_dialect: ExportedProgram = export(pre_autograd_aten_dialect, example_args)
580+
aten_dialect: ExportedProgram = export(
581+
pre_autograd_aten_dialect, example_args, strict=True
582+
)
581583
edge_program: exir.EdgeProgramManager = exir.to_edge(aten_dialect)
582584
# Optionally do delegation:
583585
# edge_program = edge_program.to_backend(CustomBackendPartitioner)

examples/apple/coreml/scripts/export.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ def partition_module_to_coreml(module):
8888

8989
def lower_module_to_coreml(module, compile_specs, example_inputs):
9090
module = module.eval()
91-
edge = to_edge(export(module, example_inputs), compile_config=_EDGE_COMPILE_CONFIG)
91+
edge = to_edge(
92+
export(module, example_inputs, strict=True), compile_config=_EDGE_COMPILE_CONFIG
93+
)
9294
# All of the subsequent calls on the edge_dialect_graph generated above (such as delegation or
9395
# to_executorch()) are done in place and the graph is also modified in place. For debugging purposes
9496
# we would like to keep a copy of the original edge dialect graph and hence we create a deepcopy of
@@ -107,7 +109,8 @@ def lower_module_to_coreml(module, compile_specs, example_inputs):
107109
def export_lowered_module_to_executorch_program(lowered_module, example_inputs):
108110
lowered_module(*example_inputs)
109111
exec_prog = to_edge(
110-
export(lowered_module, example_inputs), compile_config=_EDGE_COMPILE_CONFIG
112+
export(lowered_module, example_inputs, strict=True),
113+
compile_config=_EDGE_COMPILE_CONFIG,
111114
).to_executorch(config=exir.ExecutorchBackendConfig(extract_delegate_segments=True))
112115

113116
return exec_prog
@@ -170,7 +173,7 @@ def main():
170173

171174
if args.use_partitioner:
172175
model.eval()
173-
exir_program_aten = torch.export.export(model, example_inputs)
176+
exir_program_aten = torch.export.export(model, example_inputs, strict=True)
174177

175178
edge_program_manager = exir.to_edge(exir_program_aten)
176179
edge_copy = copy.deepcopy(edge_program_manager)

0 commit comments

Comments
 (0)