Skip to content

Commit 78ee5f2

Browse files
gmagogsfmfacebook-github-bot
authored andcommitted
executorch/exir/tests (#7396)
Summary: Pull Request resolved: #7396 Reviewed By: avikchaudhuri, ydwu4 Differential Revision: D67383351
1 parent c337bef commit 78ee5f2

15 files changed

+127
-298
lines changed

exir/tests/models.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,7 @@ def get_random_inputs(self) -> Tuple[Tensor, Tensor]:
173173

174174
delegated_m = DelegateAdd()
175175
edge_ir_m = to_edge(
176-
export(
177-
delegated_m,
178-
delegated_m.get_random_inputs(),
179-
)
176+
export(delegated_m, delegated_m.get_random_inputs(), strict=True)
180177
)
181178
lowered_module = LoweredBackendModule(
182179
edge_program=edge_ir_m.exported_program(),

exir/tests/test_arg_validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def forward(self, x):
3131

3232
m = TestModel()
3333
inputs = (torch.randn(1, 3, 100, 100).to(dtype=torch.int),)
34-
egm = to_edge(export(m, inputs)).exported_program().graph_module
34+
egm = to_edge(export(m, inputs, strict=True)).exported_program().graph_module
3535
validator = EdgeOpArgValidator(egm)
3636
validator.run(*inputs)
3737
self.assertEqual(len(validator.violating_ops), 0)
@@ -49,7 +49,7 @@ def forward(self, x):
4949
inputs = (torch.randn(1, 3, 100, 100).to(dtype=torch.bfloat16),)
5050
egm = (
5151
to_edge(
52-
export(M(), inputs),
52+
export(M(), inputs, strict=True),
5353
compile_config=EdgeCompileConfig(_check_ir_validity=False),
5454
)
5555
.exported_program()

exir/tests/test_delegate.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def g(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
4545
return x + y
4646

4747
inputs = (torch.ones(1, 3), torch.ones(1, 3))
48-
edge_ir_m = to_edge(export(WrapperModule(g), inputs))
48+
edge_ir_m = to_edge(export(WrapperModule(g), inputs, strict=True))
4949
lowered_module: LoweredBackendModule = LoweredBackendModule(
5050
edge_ir_m.exported_program(), "BackendWithCompilerDemo", b"moo", []
5151
)
@@ -54,10 +54,7 @@ def f(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
5454
return torch.ops.higher_order.executorch_call_delegate(lowered_module, x, y)
5555

5656
orig_res = f(*inputs)
57-
gm = export(
58-
WrapperModule(f),
59-
inputs,
60-
)
57+
gm = export(WrapperModule(f), inputs, strict=True)
6158
FileCheck().check("lowered_module_0").check(
6259
"torch.ops.higher_order.executorch_call_delegate"
6360
).run(gm.graph_module.code)
@@ -69,7 +66,7 @@ def test_to_backend(self) -> None:
6966
m = models.CompositeDelegateModule()
7067

7168
exec_prog = to_edge(
72-
export(m, m.get_random_inputs()),
69+
export(m, m.get_random_inputs(), strict=True),
7370
compile_config=EdgeCompileConfig(_check_ir_validity=False),
7471
).to_executorch() # TODO(larryliu): fix split_copy.Tensor
7572
graph_module = exec_prog.exported_program().graph_module
@@ -165,7 +162,7 @@ def forward(self, x, y):
165162
return x
166163

167164
orig_res = Model()(*inputs)
168-
prog = to_edge(export(Model(), inputs))
165+
prog = to_edge(export(Model(), inputs, strict=True))
169166
gm = prog.exported_program().graph_module
170167

171168
node_list = []
@@ -225,7 +222,7 @@ def forward(self, x, y):
225222
return x
226223

227224
orig_res = Model()(*inputs)
228-
prog = to_edge(export(Model(), inputs))
225+
prog = to_edge(export(Model(), inputs, strict=True))
229226
gm = prog.exported_program().graph_module
230227

231228
node_list = []
@@ -284,7 +281,7 @@ def forward(self, x, y):
284281
return x
285282

286283
orig_res = Model()(*inputs)
287-
prog = to_edge(export(Model(), inputs))
284+
prog = to_edge(export(Model(), inputs, strict=True))
288285
gm = prog.exported_program().graph_module
289286

290287
node_list = []

exir/tests/test_dynamic_shape_propagation.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ def test_repeat(self):
2222
inputs = inputs[0], inputs[1]
2323

2424
prog = to_edge(
25-
export(eager_model, inputs, dynamic_shapes=eager_model.get_dynamic_shape()),
25+
export(
26+
eager_model,
27+
inputs,
28+
dynamic_shapes=eager_model.get_dynamic_shape(),
29+
strict=True,
30+
),
2631
compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
2732
)
2833

@@ -48,7 +53,7 @@ def test_unbacked_symint(self):
4853
inputs = inputs[0], inputs[1]
4954

5055
prog = to_edge(
51-
export(eager_model, inputs, dynamic_shapes=None),
56+
export(eager_model, inputs, dynamic_shapes=None, strict=True),
5257
compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
5358
)
5459
new_prog = prog.transform([SpecPropPass(), HintBasedSymShapeEvalPass()])

exir/tests/test_memory_format_ops_pass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def call_operator(self, op, args, kwargs, meta):
269269
_to_dim_order_op_str = "executorch_exir_dialects_edge__ops_dim_order_ops__to_dim_order_copy_default"
270270

271271
before_epm = to_edge(
272-
export(toy_model, sample_input),
272+
export(toy_model, sample_input, strict=True),
273273
compile_config=EdgeCompileConfig(_skip_dim_order=False),
274274
)
275275

exir/tests/test_memory_format_ops_pass_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ class MemoryFormatOpsPassTestUtils:
104104
def memory_format_test_runner(
105105
test_class: unittest.TestCase, test_set: MemoryFormatTestSet
106106
):
107-
before = export(test_set.module, test_set.sample_input).run_decompositions({})
107+
before = export(
108+
test_set.module, test_set.sample_input, strict=True
109+
).run_decompositions({})
108110

109111
if test_set.use_xnnpack:
110112
epm = to_edge_transform_and_lower(

exir/tests/test_memory_planning.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,7 @@ def wrapper(self: "TestMemoryPlanning") -> None:
239239
# torch._tensor.Tensor]` is not a function.
240240
inputs = eager_module.get_random_inputs()
241241
graph_module = (
242-
to_edge(
243-
export(
244-
eager_module,
245-
inputs,
246-
)
247-
)
242+
to_edge(export(eager_module, inputs, strict=True))
248243
.exported_program()
249244
.graph_module
250245
)
@@ -491,10 +486,7 @@ def test_multiple_pools(
491486
expected_bufsizes: List[int],
492487
) -> None:
493488
edge_program = to_edge(
494-
export(
495-
MultiplePoolsToyModel(),
496-
(torch.ones(1),),
497-
)
489+
export(MultiplePoolsToyModel(), (torch.ones(1),), strict=True)
498490
)
499491

500492
edge_program.to_executorch(
@@ -538,7 +530,8 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
538530
return torch.nn.functional.sigmoid(self.linear(x) + self.constant + 1)
539531

540532
def count_planned_inputs(
541-
nodes: List[Node], graph_signature: Any # pyre-ignore
533+
nodes: List[Node],
534+
graph_signature: Any, # pyre-ignore
542535
) -> Tuple[int, int]:
543536
num_mem_planned_placeholders = 0
544537
num_placeholders = 0
@@ -555,7 +548,9 @@ def count_planned_inputs(
555548
model = Simple()
556549
inputs = (torch.randn(5, 5),)
557550

558-
ep_no_input_planning = to_edge(export(model, inputs)).to_executorch(
551+
ep_no_input_planning = to_edge(
552+
export(model, inputs, strict=True)
553+
).to_executorch(
559554
config=ExecutorchBackendConfig(
560555
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False),
561556
sym_shape_eval_pass=ConstraintBasedSymShapeEvalPass(),
@@ -575,7 +570,7 @@ def count_planned_inputs(
575570
5, # x, self.constant, linear weight, linear bias, '1' scalar promoted to tensor
576571
)
577572

578-
ep_input_planning = to_edge(export(model, inputs)).to_executorch(
573+
ep_input_planning = to_edge(export(model, inputs, strict=True)).to_executorch(
579574
config=ExecutorchBackendConfig(
580575
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=True),
581576
sym_shape_eval_pass=ConstraintBasedSymShapeEvalPass(),
@@ -609,7 +604,7 @@ def forward(self, a, b, x):
609604

610605
model = TestModel()
611606
example_inputs = (torch.rand(1, 6, 2), torch.rand(1, 6, 2), torch.randn(5, 5))
612-
exported_model = torch.export.export(model, example_inputs)
607+
exported_model = torch.export.export(model, example_inputs, strict=True)
613608
edge = to_edge(exported_model)
614609

615610
class TestPass(ExportPass):

0 commit comments

Comments
 (0)