diff --git a/exir/tests/models.py b/exir/tests/models.py index d3b68485b9a..b4939ecfb09 100644 --- a/exir/tests/models.py +++ b/exir/tests/models.py @@ -173,10 +173,7 @@ def get_random_inputs(self) -> Tuple[Tensor, Tensor]: delegated_m = DelegateAdd() edge_ir_m = to_edge( - export( - delegated_m, - delegated_m.get_random_inputs(), - ) + export(delegated_m, delegated_m.get_random_inputs(), strict=True) ) lowered_module = LoweredBackendModule( edge_program=edge_ir_m.exported_program(), diff --git a/exir/tests/test_arg_validator.py b/exir/tests/test_arg_validator.py index a22544d37a5..d85ef81b90d 100644 --- a/exir/tests/test_arg_validator.py +++ b/exir/tests/test_arg_validator.py @@ -31,7 +31,7 @@ def forward(self, x): m = TestModel() inputs = (torch.randn(1, 3, 100, 100).to(dtype=torch.int),) - egm = to_edge(export(m, inputs)).exported_program().graph_module + egm = to_edge(export(m, inputs, strict=True)).exported_program().graph_module validator = EdgeOpArgValidator(egm) validator.run(*inputs) self.assertEqual(len(validator.violating_ops), 0) @@ -49,7 +49,7 @@ def forward(self, x): inputs = (torch.randn(1, 3, 100, 100).to(dtype=torch.bfloat16),) egm = ( to_edge( - export(M(), inputs), + export(M(), inputs, strict=True), compile_config=EdgeCompileConfig(_check_ir_validity=False), ) .exported_program() diff --git a/exir/tests/test_delegate.py b/exir/tests/test_delegate.py index 713e4b0941c..d89d3f2bbd8 100644 --- a/exir/tests/test_delegate.py +++ b/exir/tests/test_delegate.py @@ -45,7 +45,7 @@ def g(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: return x + y inputs = (torch.ones(1, 3), torch.ones(1, 3)) - edge_ir_m = to_edge(export(WrapperModule(g), inputs)) + edge_ir_m = to_edge(export(WrapperModule(g), inputs, strict=True)) lowered_module: LoweredBackendModule = LoweredBackendModule( edge_ir_m.exported_program(), "BackendWithCompilerDemo", b"moo", [] ) @@ -54,10 +54,7 @@ def f(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: return torch.ops.higher_order.executorch_call_delegate(lowered_module, x, y) orig_res = f(*inputs) - gm = export( - WrapperModule(f), - inputs, - ) + gm = export(WrapperModule(f), inputs, strict=True) FileCheck().check("lowered_module_0").check( "torch.ops.higher_order.executorch_call_delegate" ).run(gm.graph_module.code) @@ -69,7 +66,7 @@ def test_to_backend(self) -> None: m = models.CompositeDelegateModule() exec_prog = to_edge( - export(m, m.get_random_inputs()), + export(m, m.get_random_inputs(), strict=True), compile_config=EdgeCompileConfig(_check_ir_validity=False), ).to_executorch() # TODO(larryliu): fix split_copy.Tensor graph_module = exec_prog.exported_program().graph_module @@ -165,7 +162,7 @@ def forward(self, x, y): return x orig_res = Model()(*inputs) - prog = to_edge(export(Model(), inputs)) + prog = to_edge(export(Model(), inputs, strict=True)) gm = prog.exported_program().graph_module node_list = [] @@ -225,7 +222,7 @@ def forward(self, x, y): return x orig_res = Model()(*inputs) - prog = to_edge(export(Model(), inputs)) + prog = to_edge(export(Model(), inputs, strict=True)) gm = prog.exported_program().graph_module node_list = [] @@ -284,7 +281,7 @@ def forward(self, x, y): return x orig_res = Model()(*inputs) - prog = to_edge(export(Model(), inputs)) + prog = to_edge(export(Model(), inputs, strict=True)) gm = prog.exported_program().graph_module node_list = [] diff --git a/exir/tests/test_dynamic_shape_propagation.py b/exir/tests/test_dynamic_shape_propagation.py index 01c2f2b29a2..3dbdf0b5f4e 100644 --- a/exir/tests/test_dynamic_shape_propagation.py +++ b/exir/tests/test_dynamic_shape_propagation.py @@ -22,7 +22,12 @@ def test_repeat(self): inputs = inputs[0], inputs[1] prog = to_edge( - export(eager_model, inputs, dynamic_shapes=eager_model.get_dynamic_shape()), + export( + eager_model, + inputs, + dynamic_shapes=eager_model.get_dynamic_shape(), + strict=True, + ), compile_config=exir.EdgeCompileConfig(_check_ir_validity=False), ) @@ -48,7 +53,7 @@ def test_unbacked_symint(self): inputs = inputs[0], inputs[1] prog = to_edge( - export(eager_model, inputs, dynamic_shapes=None), + export(eager_model, inputs, dynamic_shapes=None, strict=True), compile_config=exir.EdgeCompileConfig(_check_ir_validity=False), ) new_prog = prog.transform([SpecPropPass(), HintBasedSymShapeEvalPass()]) diff --git a/exir/tests/test_memory_format_ops_pass.py b/exir/tests/test_memory_format_ops_pass.py index 0292cf98f50..76e994abdbf 100644 --- a/exir/tests/test_memory_format_ops_pass.py +++ b/exir/tests/test_memory_format_ops_pass.py @@ -269,7 +269,7 @@ def call_operator(self, op, args, kwargs, meta): _to_dim_order_op_str = "executorch_exir_dialects_edge__ops_dim_order_ops__to_dim_order_copy_default" before_epm = to_edge( - export(toy_model, sample_input), + export(toy_model, sample_input, strict=True), compile_config=EdgeCompileConfig(_skip_dim_order=False), ) diff --git a/exir/tests/test_memory_format_ops_pass_utils.py b/exir/tests/test_memory_format_ops_pass_utils.py index 3049f30a8cb..8bf810e847e 100644 --- a/exir/tests/test_memory_format_ops_pass_utils.py +++ b/exir/tests/test_memory_format_ops_pass_utils.py @@ -104,7 +104,9 @@ class MemoryFormatOpsPassTestUtils: def memory_format_test_runner( test_class: unittest.TestCase, test_set: MemoryFormatTestSet ): - before = export(test_set.module, test_set.sample_input).run_decompositions({}) + before = export( + test_set.module, test_set.sample_input, strict=True + ).run_decompositions({}) if test_set.use_xnnpack: epm = to_edge_transform_and_lower( diff --git a/exir/tests/test_memory_planning.py b/exir/tests/test_memory_planning.py index 5e4573a2bab..1f94f0341f1 100644 --- a/exir/tests/test_memory_planning.py +++ b/exir/tests/test_memory_planning.py @@ -239,12 +239,7 @@ def wrapper(self: "TestMemoryPlanning") -> None: # torch._tensor.Tensor]` is not a function. inputs = eager_module.get_random_inputs() graph_module = ( - to_edge( - export( - eager_module, - inputs, - ) - ) + to_edge(export(eager_module, inputs, strict=True)) .exported_program() .graph_module ) @@ -491,10 +486,7 @@ def test_multiple_pools( expected_bufsizes: List[int], ) -> None: edge_program = to_edge( - export( - MultiplePoolsToyModel(), - (torch.ones(1),), - ) + export(MultiplePoolsToyModel(), (torch.ones(1),), strict=True) ) edge_program.to_executorch( @@ -538,7 +530,8 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: return torch.nn.functional.sigmoid(self.linear(x) + self.constant + 1) def count_planned_inputs( - nodes: List[Node], graph_signature: Any # pyre-ignore + nodes: List[Node], + graph_signature: Any, # pyre-ignore ) -> Tuple[int, int]: num_mem_planned_placeholders = 0 num_placeholders = 0 @@ -555,7 +548,9 @@ def count_planned_inputs( model = Simple() inputs = (torch.randn(5, 5),) - ep_no_input_planning = to_edge(export(model, inputs)).to_executorch( + ep_no_input_planning = to_edge( + export(model, inputs, strict=True) + ).to_executorch( config=ExecutorchBackendConfig( memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False), sym_shape_eval_pass=ConstraintBasedSymShapeEvalPass(), @@ -575,7 +570,7 @@ def count_planned_inputs( 5, # x, self.constant, linear weight, linear bias, '1' scalar promoted to tensor ) - ep_input_planning = to_edge(export(model, inputs)).to_executorch( + ep_input_planning = to_edge(export(model, inputs, strict=True)).to_executorch( config=ExecutorchBackendConfig( memory_planning_pass=MemoryPlanningPass(alloc_graph_input=True), sym_shape_eval_pass=ConstraintBasedSymShapeEvalPass(), @@ -609,7 +604,7 @@ def forward(self, a, b, x): model = TestModel() example_inputs = (torch.rand(1, 6, 2), torch.rand(1, 6, 2), torch.randn(5, 5)) - exported_model = torch.export.export(model, example_inputs) + exported_model = torch.export.export(model, example_inputs, strict=True) edge = to_edge(exported_model) class TestPass(ExportPass): diff --git a/exir/tests/test_passes.py b/exir/tests/test_passes.py index 4d2c17086b1..fe063964cfe 100644 --- a/exir/tests/test_passes.py +++ b/exir/tests/test_passes.py @@ -133,12 +133,7 @@ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: int_tensor = torch.tensor([[1, 2, 3]]) float_tensor = torch.tensor([[1.0, 2.0, 3.0]]) - edge_prog = to_edge( - export( - add, - (int_tensor, float_tensor), - ) - ) + edge_prog = to_edge(export(add, (int_tensor, float_tensor), strict=True)) new_prog = edge_prog.transform([RemoveMixedTypeOperators()]) new_graph_module = new_prog.exported_program().graph_module @@ -161,7 +156,7 @@ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: double_tensor = torch.tensor([[1.0, 2.0, 3.0]]) double_tensor = double_tensor.to(torch.double) - double_prog = to_edge(export(add, (int_tensor, double_tensor))) + double_prog = to_edge(export(add, (int_tensor, double_tensor), strict=True)) double_prog.transform([RemoveMixedTypeOperators()]) new_graph_module_double = double_prog.exported_program().graph_module @@ -188,12 +183,7 @@ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: mult = Mult() float_tensor_vert = float_tensor.T - mult_prog = to_edge( - export( - mult, - (int_tensor, float_tensor_vert), - ) - ) + mult_prog = to_edge(export(mult, (int_tensor, float_tensor_vert), strict=True)) # graph_module_mult.graph.print_tabular() @@ -224,10 +214,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: # Turn off functionalization so that we can get the actual to.dtype op edge_prog = to_edge( - export( - foo, - (torch.ones(1, dtype=torch.float32),), - ) + export(foo, (torch.ones(1, dtype=torch.float32),), strict=True) ) edge_prog = edge_prog.transform([RemoveNoopPass()]) self.assertIsNotNone(edge_prog.exported_program().graph_module) @@ -257,36 +244,21 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: # Turn off functionalization so that we can get the actual to.dtype op x = torch.ones((3, 8, 8)) - prog = to_edge( - export( - foo_with_no_slice, - (x,), - ) - ) + prog = to_edge(export(foo_with_no_slice, (x,), strict=True)) prog = prog.transform([RemoveNoopPass()]) new_graph_module = prog.exported_program().graph_module FileCheck().check_count( "executorch_exir_dialects_edge__ops_aten_slice_copy_Tensor", 0, exactly=True ).run(new_graph_module.code) - prog = to_edge( - export( - foo_with_one_slice, - (x,), - ) - ) + prog = to_edge(export(foo_with_one_slice, (x,), strict=True)) prog = prog.transform([RemoveNoopPass()]) new_graph_module = prog.exported_program().graph_module FileCheck().check_count( "executorch_exir_dialects_edge__ops_aten_slice_copy_Tensor", 1, exactly=True ).run(new_graph_module.code) - prog = to_edge( - export( - foo_with_all_slices, - (x,), - ) - ) + prog = to_edge(export(foo_with_all_slices, (x,), strict=True)) prog = prog.transform([RemoveNoopPass()]) new_graph_module = prog.exported_program().graph_module FileCheck().check_count( @@ -302,12 +274,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: x = (torch.randn(2, 3),) - to_edge( - export( - f, - x, - ) - ).exported_program().graph_module + to_edge(export(f, x, strict=True)).exported_program().graph_module # TODO(angelayi): Add a utility function that verifies a model is in # the edge dialect @@ -335,12 +302,8 @@ def forward(self, x_raw, h, c): composite_m = CompositeModel(3) edge_prog = to_edge( - export( - composite_m, - inputs, - ) + export(composite_m, inputs, strict=True), # torch._ops.aten.t.default - , compile_config=exir.EdgeCompileConfig(_check_ir_validity=False), ) @@ -380,10 +343,7 @@ def get_random_inputs(self): model = MyModel() inputs = model.get_random_inputs() prog = to_edge( - export( - model, - inputs, - ), + export(model, inputs, strict=True), compile_config=EdgeCompileConfig(_check_ir_validity=False), ) # TODO(larryliu): fix split_copy new_gm_res = ToOutVarPass()(prog.exported_program().graph_module) @@ -415,10 +375,7 @@ def get_random_inputs(self): model = MyModel() inputs = model.get_random_inputs() prog = to_edge( - export( - model, - inputs, - ), + export(model, inputs, strict=True), compile_config=EdgeCompileConfig(_check_ir_validity=False), ) # TODO(larryliu): fix topk new_gm_res = ToOutVarPass()(prog.exported_program().graph_module) @@ -449,12 +406,7 @@ def forward(self, x): inputs = torch.tensor(1.0, dtype=torch.float) model_res = model(inputs) - edge_dialect = to_edge( - export( - model, - (inputs,), - ) - ) + edge_dialect = to_edge(export(model, (inputs,), strict=True)) edge_res = edge_dialect.exported_program().module()(inputs) self.assertTrue(torch.allclose(model_res, edge_res)) @@ -470,10 +422,7 @@ class NullPass(ExportPass): pass prog = to_edge( - export( - f, - (torch.ones(3, 2),), - ), + export(f, (torch.ones(3, 2),), strict=True), compile_config=EdgeCompileConfig(_check_ir_validity=False), ) # TODO(larryliu): fix cat new_prog = prog.transform([NullPass()]) @@ -502,10 +451,7 @@ class NullPass(ExportPass): pass prog = to_edge( - export( - f, - (torch.ones(3, 2),), - ), + export(f, (torch.ones(3, 2),), strict=True), compile_config=exir.EdgeCompileConfig(_check_ir_validity=False), ) new_prog = prog.transform([NullPass()]) @@ -529,7 +475,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: mul = Mul() - expo_prog = to_edge(export(mul, (torch.ones(1),))) + expo_prog = to_edge(export(mul, (torch.ones(1),), strict=True)) new_prog = expo_prog.transform([ScalarToTensorPass()]) self.assertIsNotNone(new_prog.exported_program().graph_module) new_graph_module = new_prog.exported_program().graph_module @@ -561,12 +507,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: example_inputs = (torch.randn(2, 3, 4, 5),) - gm = to_edge( - export( - f, - example_inputs, - ) - ) + gm = to_edge(export(f, example_inputs, strict=True)) new_gm = gm.transform( [ReplaceSymSizeOpPass(), ScalarToTensorPass(), RemoveMixedTypeOperators()] ) @@ -587,12 +528,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: f = Foo() gm = ( - to_edge( - export( - f, - (torch.ones(3, 2),), - ) - ) + to_edge(export(f, (torch.ones(3, 2),), strict=True)) .exported_program() .graph_module ) @@ -616,12 +552,7 @@ def forward(self, x: torch.Tensor) -> Tuple[torch.Tensor]: f = Foo() gm = ( - to_edge( - export( - f, - (torch.ones(3, 2),), - ) - ) + to_edge(export(f, (torch.ones(3, 2),), strict=True)) .exported_program() .graph_module ) @@ -655,10 +586,7 @@ def forward(self, inp: torch.Tensor) -> torch.Tensor: # ReplaceBrokenOpsWithFunctionalOpsPass is used in to_edge() prog = to_edge( - export( - f, - (x,), - ), + export(f, (x,), strict=True), compile_config=exir.EdgeCompileConfig(_check_ir_validity=False), ) gm = prog.exported_program().graph_module @@ -681,9 +609,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: prog = to_edge( export( - f, - (torch.ones(3, 2),), - dynamic_shapes={"x": {0: dim_x}}, + f, (torch.ones(3, 2),), dynamic_shapes={"x": {0: dim_x}}, strict=True ), compile_config=exir.EdgeCompileConfig(_check_ir_validity=False), ) @@ -703,10 +629,7 @@ def test_alloc_node_spec(self) -> None: eager_model = FTMapBasic() inputs = eager_model.get_random_inputs() prog = to_edge( - export( - eager_model, - inputs, - ), + export(eager_model, inputs, strict=True), compile_config=exir.EdgeCompileConfig(_check_ir_validity=False), ) passes = [ @@ -755,10 +678,7 @@ def test_debug_pass_file_log(self) -> None: def test_dce_recursive(self) -> None: eager_model = FTCondDeadCode() inputs = eager_model.get_random_inputs() - gm = export( - eager_model, - inputs, - ).graph_module + gm = export(eager_model, inputs, strict=True).graph_module self.assertTrue(torch.ops.aten.sub.Tensor in collect_ops(gm)) dead_code_elimination_pass(gm) @@ -776,10 +696,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: f = Foo() prog = to_edge( - export( - f, - (torch.rand(5),), - ), + export(f, (torch.rand(5),), strict=True), # missing dispatch key compile_config=exir.EdgeCompileConfig(_check_ir_validity=False), ).transform(propagate_dynamic_shape()) @@ -807,9 +724,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: dim_x = torch.export.Dim("dim_x", max=3) prog = to_edge( export( - f, - (torch.ones(3, 2),), - dynamic_shapes={"x": {0: dim_x}}, + f, (torch.ones(3, 2),), dynamic_shapes={"x": {0: dim_x}}, strict=True ), compile_config=exir.EdgeCompileConfig(_check_ir_validity=False), ) @@ -839,16 +754,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: f = Foo() - gm = ( - to_edge( - export( - f, - (x,), - ) - ) - .exported_program() - .graph_module - ) + gm = to_edge(export(f, (x,), strict=True)).exported_program().graph_module for node in gm.graph.nodes: if node.op == "call_function": self.assertEqual(type(node.target), EdgeOpOverload) @@ -871,6 +777,7 @@ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: torch.randn(2, 2), torch.randn(2, 2), ), + strict=True, ) # should look like: # graph(): @@ -934,6 +841,7 @@ def call_operator(self, op, args, kwargs, meta): torch.randn(2, 2), torch.randn(2, 2), ), + strict=True, ) ) # Retrace-able, the graph "promote" back to ATen dialect, showing up add and relu, which is expected. @@ -946,12 +854,7 @@ def test_debug_handle_generator_pass(self) -> None: inputs = eager_model.get_random_inputs() graph_module = ( - to_edge( - export( - eager_model, - inputs, - ) - ) + to_edge(export(eager_model, inputs, strict=True)) .exported_program() .graph_module ) @@ -965,12 +868,7 @@ def test_generate_missing_debug_handles(self) -> None: eager_model = MLP(2, output_size=4) inputs = eager_model.get_random_inputs() - ep = to_edge( - export( - eager_model, - inputs, - ) - ).exported_program() + ep = to_edge(export(eager_model, inputs, strict=True)).exported_program() list(ep.graph.nodes)[0].meta.pop("debug_handle") self.assertTrue(list(ep.graph.nodes)[0].meta.get("debug_handle") is None) @@ -1021,12 +919,7 @@ def forward( torch.ones(2, 2), ) - ep = to_edge( - export( - f, - inputs, - ) - ).exported_program() + ep = to_edge(export(f, inputs, strict=True)).exported_program() graph_module = ep.graph_module def check_debug_handle_metadata(graph_module: torch.fx.GraphModule) -> None: @@ -1061,9 +954,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: dim_x = torch.export.Dim("dim_x", max=3) prog = to_edge( export( - f, - (torch.ones(3, 2),), - dynamic_shapes={"x": {0: dim_x}}, + f, (torch.ones(3, 2),), dynamic_shapes={"x": {0: dim_x}}, strict=True ), compile_config=exir.EdgeCompileConfig(_check_ir_validity=False), ) @@ -1093,10 +984,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: f = Foo() gm = to_edge( - export( - f, - (torch.randn(5),), - ), + export(f, (torch.randn(5),), strict=True), compile_config=exir.EdgeCompileConfig(_check_ir_validity=False), ) new_gm = gm.transform([RemoveGraphAssertsPass()]) @@ -1117,12 +1005,7 @@ def __init__(self): def forward(self, x): return torch.arange(start=0, end=2) + x - _ = to_edge( - export( - M(), - (torch.randn(2),), - ) - ).to_executorch() + _ = to_edge(export(M(), (torch.randn(2),), strict=True)).to_executorch() def test_replace_slice(self) -> None: class M(torch.nn.Module): @@ -1134,12 +1017,7 @@ def forward(self, x): return self.a[:2] + x gm = ( - to_edge( - export( - M(), - (torch.randn(2),), - ) - ) + to_edge(export(M(), (torch.randn(2),), strict=True)) .exported_program() .graph_module ) @@ -1155,7 +1033,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: add = Add() edge = to_edge( - export(add, (torch.ones(1),)), + export(add, (torch.ones(1),), strict=True), compile_config=EdgeCompileConfig(_skip_dim_order=False), ) edge = edge.transform([ScalarToTensorPass(), RemoveMixedTypeOperators()]) @@ -1173,9 +1051,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: "_prop_tensor_constant0" ).check_not( "executorch_exir_dialects_edge__ops_dim_order_ops__to_dim_order_copy_default" - ).run( - new_ep.graph_module.code - ) + ).run(new_ep.graph_module.code) def test_constant_prop_pass_for_parameter(self) -> None: def count_additions(gm: torch.fx.GraphModule) -> int: @@ -1193,10 +1069,7 @@ def forward(self, x): c = torch.cat([self.a, b]) return (c + c) + x - aten = export( - M(), - (torch.zeros(2, 2, 3),), - ) + aten = export(M(), (torch.zeros(2, 2, 3),), strict=True) self.assertEqual(count_additions(aten.graph_module), 3) new_ep = constant_prop_pass(aten) self.assertEqual(count_additions(new_ep.graph_module), 1) @@ -1217,10 +1090,7 @@ def forward(self, x): c = torch.cat([self.a, b]) return (c + c) + x - aten = export( - M(), - (torch.zeros(2, 2, 3),), - ) + aten = export(M(), (torch.zeros(2, 2, 3),), strict=True) # Input signature will have two entries: # (1) parameter `a` and (2) user input `x`. self.assertEqual(len(aten.graph_signature.input_specs), 2) @@ -1298,7 +1168,7 @@ def forward(self, query, key, value): m = convert_pt2e(m) # export, perform constant propagation to make weights const - aten_prog = export(m, (query, key, value)) + aten_prog = export(m, (query, key, value), strict=True) aten_prog = constant_prop_pass(aten_prog) # lower to edge dialect @@ -1332,10 +1202,7 @@ def forward(self, x): slice_tensor = torch.slice_copy(self.a, dim=0, start=0, end=1) return torch.cat([x, slice_tensor]) - aten = export( - M(), - (torch.zeros(2, 2, 2),), - ) + aten = export(M(), (torch.zeros(2, 2, 2),), strict=True) self.assertIn("a", aten.state_dict) self.assertEqual(count_slice(aten.graph_module), 1) @@ -1360,10 +1227,7 @@ def forward(self, x, y): # y is unused. return x + self.a - aten = export( - M(), - (torch.zeros(3, 2, 4), torch.zeros(3, 2, 4)), - ) + aten = export(M(), (torch.zeros(3, 2, 4), torch.zeros(3, 2, 4)), strict=True) self.assertIn("a", aten.state_dict) self.assertEqual(count_placeholder(aten.graph_module), 3) @@ -1401,7 +1265,7 @@ def forward(self, pred, x): x = torch.randn([3, 3]) pred = torch.tensor(x[0][0].item() < 0) edge = to_edge( - export(mod, (pred, x)), + export(mod, (pred, x), strict=True), compile_config=exir.EdgeCompileConfig(_check_ir_validity=False), ) error_msg = r"constant_prop_pass for control flow is not supported yet." @@ -1429,12 +1293,7 @@ def forward(self, x): self.state.add_(1) return y - model = to_edge( - export( - MutableStateModule(), - (torch.zeros(1),), - ) - ) + model = to_edge(export(MutableStateModule(), (torch.zeros(1),), strict=True)) self.assertEqual(count_copies(model.exported_program().graph_module), 0) # Before # graph(): @@ -1516,7 +1375,7 @@ def quantize_model( quantizer.set_global(quantization_config) m = prepare_pt2e(m, quantizer) # pyre-fixme[6] m = convert_pt2e(m, fold_quantize=True) - ep = torch.export.export(m, example_inputs) + ep = torch.export.export(m, example_inputs, strict=True) dq_nodes_pre = count_dq_nodes(ep.graph_module) q_nodes_pre = count_q_nodes(ep.graph_module) edge = to_edge( @@ -1573,7 +1432,7 @@ def forward(self, x): model = TestDqQ() m_eager = model.eval() - ep = torch.export.export(m_eager, (torch.randn(9, 8),)) + ep = torch.export.export(m_eager, (torch.randn(9, 8),), strict=True) edge = to_edge(ep) # Check that the dq and q nodes are not touched by the RemoveNoopPass. self.assertTrue( @@ -1606,7 +1465,7 @@ def forward(self, x): model = TestDqQDifferentQParam() m_eager = model.eval() - ep = torch.export.export(m_eager, (torch.randn(9, 8),)) + ep = torch.export.export(m_eager, (torch.randn(9, 8),), strict=True) edge = to_edge(ep) print(edge.exported_program().graph_module.graph) # Check that the dq and q nodes are not touched by the RemoveNoopPass. @@ -1630,7 +1489,6 @@ def forward(self, x): ) def test_normalize_view_copy_base_pass(self) -> None: - class ViewChain(torch.nn.Module): def forward(self, x): x = torch.ops.aten.view_copy.default(x, [30, 1]) @@ -1645,7 +1503,7 @@ def is_view_copy(node: torch.fx.Node) -> bool: and node.target == torch.ops.aten.view_copy.default ) - gm = export(ViewChain(), (torch.ones(30),)).graph_module + gm = export(ViewChain(), (torch.ones(30),), strict=True).graph_module # Check before transformation n_view_copy_before = 0 @@ -1680,7 +1538,6 @@ def is_view_copy(node: torch.fx.Node) -> bool: self.assertEqual(n_view_copy_bases_after, 0) def test_replace_view_copy_with_view_pass(self) -> None: # noqa: C901 - # Helper functions def is_view_copy(node: torch.fx.Node) -> bool: return ( @@ -1704,10 +1561,7 @@ def forward(self, x): # a computation before the end of the graph. return torch.ops.aten.add.Tensor(o1, o2) - ep = torch.export.export( - TestViewCopies(), - args=(torch.ones(1),), - ) + ep = torch.export.export(TestViewCopies(), args=(torch.ones(1),), strict=True) for node in ep.graph.nodes: if node.op == "placeholder": node.meta["spec"] = TensorSpec.from_tensor(torch.empty(1)) @@ -1809,10 +1663,7 @@ def _do_checks( input = torch.randn([2, 3, 4, 5]).to(memory_format=torch.contiguous_format) # 1. vanilla export, no edge ops - ep = export( - m, - (input,), - ).run_decompositions({}) + ep = export(m, (input,), strict=True).run_decompositions({}) _do_checks( ep.graph_module.code, aten_op_str, diff --git a/exir/tests/test_print_program.py b/exir/tests/test_print_program.py index c53ca4c3765..9440450a9c2 100644 --- a/exir/tests/test_print_program.py +++ b/exir/tests/test_print_program.py @@ -39,7 +39,7 @@ def forward(self, x): warp_model = WrapModule() example_inputs = (torch.rand(1, 32, 16, 16),) - exir_exported_program = to_edge(export(warp_model, example_inputs)) + exir_exported_program = to_edge(export(warp_model, example_inputs, strict=True)) number_of_stack_trace = 0 for node in exir_exported_program.exported_program().graph.nodes: node_info = inspect_node( diff --git a/exir/tests/test_quant_fusion_pass.py b/exir/tests/test_quant_fusion_pass.py index d14e85b496e..26d17ca1394 100644 --- a/exir/tests/test_quant_fusion_pass.py +++ b/exir/tests/test_quant_fusion_pass.py @@ -57,7 +57,7 @@ def forward(self, x, y): ) m = _convert_to_reference_decomposed_fx(m) config = EdgeCompileConfig(_check_ir_validity=False) - m = to_edge(export(m, example_inputs), compile_config=config) + m = to_edge(export(m, example_inputs, strict=True), compile_config=config) # QuantFusionPass should be part of to_executorch() config, separating it out so that we can check the graph. m = m.transform([QuantFusionPass(_fix_node_meta_val=True)]) # check that we are using functional variant of q/dq/add @@ -67,9 +67,7 @@ def forward(self, x, y): "executorch_exir_dialects_edge__ops_quantized_decomposed_add_default" ).check( "executorch_exir_dialects_edge__ops_quantized_decomposed_dequantize_per_tensor_default" - ).run( - m.exported_program().graph_module.code - ) + ).run(m.exported_program().graph_module.code) m = m.to_executorch() # check that we are using out variant of q/dq/add FileCheck().check("torch.ops.quantized_decomposed.add.out").run( @@ -96,7 +94,7 @@ def forward(self, x, y): m(*example_inputs) m = _convert_to_reference_decomposed_fx(m) config = EdgeCompileConfig(_check_ir_validity=False) - m = to_edge(export(m, example_inputs), compile_config=config) + m = to_edge(export(m, example_inputs, strict=True), compile_config=config) # QuantFusionPass should be part of to_executorch() config, separating it out so that we can check the graph. m = m.transform([QuantFusionPass(_fix_node_meta_val=True)]) # check that we are using functional variant of q/dq/add/reshape @@ -114,9 +112,7 @@ def forward(self, x, y): "executorch_exir_dialects_edge__ops_quantized_decomposed_dequantize_per_tensor_default", 1, exactly=True, - ).run( - m.exported_program().graph_module.code - ) + ).run(m.exported_program().graph_module.code) m = m.to_executorch(exir.ExecutorchBackendConfig(remove_view_copy=False)) # check that we are using out variant of q/dq/add @@ -151,7 +147,7 @@ def forward(self, x, y): ) m = _convert_to_reference_decomposed_fx(m) config = EdgeCompileConfig(_check_ir_validity=False) - m = to_edge(export(m, example_inputs), compile_config=config) + m = to_edge(export(m, example_inputs, strict=True), compile_config=config) # QuantFusionPass should be part of to_executorch() config, separating it out so that we can check the graph. m = m.transform([QuantFusionPass(_fix_node_meta_val=True)]) # check that we are using functional variant of q/dq/add/slice @@ -163,15 +159,11 @@ def forward(self, x, y): exactly=True, ).check("executorch_exir_dialects_edge__ops_aten_slice_copy_Tensor").check( "executorch_exir_dialects_edge__ops_quantized_decomposed_quantize_per_tensor_default" - ).check( - "executorch_exir_dialects_edge__ops_aten_slice_copy_Tensor" - ).check( + ).check("executorch_exir_dialects_edge__ops_aten_slice_copy_Tensor").check( "executorch_exir_dialects_edge__ops_quantized_decomposed_add_default" ).check( "executorch_exir_dialects_edge__ops_quantized_decomposed_dequantize_per_tensor_default" - ).run( - m.exported_program().graph_module.code - ) + ).run(m.exported_program().graph_module.code) m = m.to_executorch() # check that we are using out variant of add and slice_copy @@ -198,7 +190,7 @@ def forward(self, x, y): m(*example_inputs) m = _convert_to_reference_decomposed_fx(m) config = EdgeCompileConfig(_check_ir_validity=False) - m = to_edge(export(m, example_inputs), compile_config=config) + m = to_edge(export(m, example_inputs, strict=True), compile_config=config) # QuantFusionPass should be part of to_executorch() config, separating it out so that we can check the graph. m = m.transform([QuantFusionPass()]) # check that we are using functional variant of q/dq/cat @@ -210,9 +202,7 @@ def forward(self, x, y): "executorch_exir_dialects_edge__ops_quantized_decomposed_dequantize_per_tensor_default", 1, exactly=True, - ).run( - m.exported_program().graph_module.code - ) + ).run(m.exported_program().graph_module.code) m = m.to_executorch() # Note: quantized add is not fused since the qparams are the same and current subgraph_rewriter @@ -224,9 +214,7 @@ def forward(self, x, y): "torch.ops.quantized_decomposed.quantize_per_tensor.out", 1, exactly=True ).check("torch.ops.aten.cat.out").check_count( "torch.ops.quantized_decomposed.dequantize_per_tensor.out", 1, exactly=True - ).run( - m.exported_program().graph_module.code - ) + ).run(m.exported_program().graph_module.code) def test_embedding_byte(self) -> None: class M(torch.nn.Module): @@ -293,7 +281,9 @@ def forward(self, indices): _check_ir_validity=False, _use_edge_ops=True, ) - m = to_edge(export(m, example_inputs), compile_config=compile_config) + m = to_edge( + export(m, example_inputs, strict=True), compile_config=compile_config + ) # QuantFusionPass should be part of to_executorch() config, separating it out so that we can check the graph. m = m.transform([QuantFusionPass(_fix_node_meta_val=True)]) # check that we are using functional variant of q/dq/cat @@ -301,9 +291,7 @@ def forward(self, indices): "executorch_exir_dialects_edge__ops_quantized_decomposed_quantize_per_channel_default", ).check( "executorch_exir_dialects_edge__ops_quantized_decomposed_embedding_byte_default" - ).run( - m.exported_program().graph_module.code - ) + ).run(m.exported_program().graph_module.code) # TODO: enable after the out variants of quantize_per_channel is supported # m = m.to_executorch() @@ -349,7 +337,9 @@ def forward(self, indices): _check_ir_validity=False, _use_edge_ops=True, ) - m = to_edge(export(m, example_inputs), compile_config=compile_config) + m = to_edge( + export(m, example_inputs, strict=True), compile_config=compile_config + ) # QuantFusionPass should be part of to_executorch() config, separating it out so that we can check the graph. m = m.transform([QuantFusionPass(_fix_node_meta_val=True)]) # check that we are using functional variant of q/dq/cat @@ -357,9 +347,7 @@ def forward(self, indices): "executorch_exir_dialects_edge__ops_quantized_decomposed_quantize_per_channel_default", ).check( "executorch_exir_dialects_edge__ops_quantized_decomposed_embedding_byte_default" - ).run( - m.exported_program().graph_module.code - ) + ).run(m.exported_program().graph_module.code) # TODO: enable after the out variants of quantize_per_channel is supported # m = m.to_executorch() diff --git a/exir/tests/test_quantization.py b/exir/tests/test_quantization.py index 269a9ee11bc..d3e385e7a16 100644 --- a/exir/tests/test_quantization.py +++ b/exir/tests/test_quantization.py @@ -71,7 +71,7 @@ def test_resnet(self) -> None: _check_ir_validity=False, ) m = to_edge( - export(m, example_inputs), compile_config=compile_config + export(m, example_inputs, strict=True), compile_config=compile_config ).transform([QuantFusionPass(), SpecPropPass()]) after_quant_result = m.exported_program().module()(*example_inputs)[0] @@ -79,9 +79,7 @@ def test_resnet(self) -> None: "executorch_exir_dialects_edge__ops_quantized_decomposed_quantize_per_tensor" ).check( "executorch_exir_dialects_edge__ops_quantized_decomposed_dequantize_per_tensor" - ).run( - m.exported_program().graph_module.code - ) + ).run(m.exported_program().graph_module.code) # after_quant_fusion_result = m(*example_inputs)[0] # TODO: implement torch.ops.quantized_decomposed.add_relu.out diff --git a/exir/tests/test_remove_view_copy.py b/exir/tests/test_remove_view_copy.py index 318dc085b45..b13fabede15 100644 --- a/exir/tests/test_remove_view_copy.py +++ b/exir/tests/test_remove_view_copy.py @@ -44,7 +44,7 @@ def test_disable(self) -> None: model = TestModel1() model.eval() example_inputs = model.get_example_inputs() - ep = torch.export.export(model, example_inputs) + ep = torch.export.export(model, example_inputs, strict=True) etpm = to_edge(ep).to_executorch( config=ExecutorchBackendConfig( remove_view_copy=False, @@ -59,7 +59,7 @@ def test_output_matches(self) -> None: model = TestModel1() model.eval() example_inputs = model.get_example_inputs() - ep = torch.export.export(model, example_inputs) + ep = torch.export.export(model, example_inputs, strict=True) epm_remove = to_edge(ep) epm_no_remove = copy.deepcopy( @@ -96,7 +96,7 @@ def test_spec(self) -> None: model = TestModel1() model.eval() example_inputs = model.get_example_inputs() - ep = torch.export.export(model, example_inputs) + ep = torch.export.export(model, example_inputs, strict=True) etpm = to_edge(ep).to_executorch( config=ExecutorchBackendConfig( diff --git a/exir/tests/test_serde.py b/exir/tests/test_serde.py index 2c68920ff34..5b09ddf07c1 100644 --- a/exir/tests/test_serde.py +++ b/exir/tests/test_serde.py @@ -49,7 +49,7 @@ def check_ep( # pyre-ignore def check_serde(self, m, inputs, check_executorch=True) -> None: - aten = export(m, inputs) + aten = export(m, inputs, strict=True) aten_new = deserialize(serialize(aten)) self.check_ep(aten, aten_new, inputs) @@ -135,7 +135,7 @@ def forward(self, x): sin_module = SinModule() model_inputs = (torch.ones(1),) - edgeir_m = to_edge(export(sin_module, model_inputs)) + edgeir_m = to_edge(export(sin_module, model_inputs, strict=True)) max_value = model_inputs[0].shape[0] compile_specs = [CompileSpec("max_value", bytes([max_value]))] lowered_sin_module = to_backend( @@ -155,7 +155,7 @@ def forward(self, x): composite_model(*model_inputs) - edge = to_edge(export(composite_model, model_inputs)) + edge = to_edge(export(composite_model, model_inputs, strict=True)) edge_new = deserialize(serialize(edge.exported_program())) self.check_ep(edge.exported_program(), edge_new, model_inputs) @@ -197,7 +197,7 @@ def forward(self, a, x, b): m = Model() inputs = (torch.randn(2, 2), torch.randn(2, 2), torch.randn(2, 2)) - ep = to_edge(export(m, inputs)) + ep = to_edge(export(m, inputs, strict=True)) edge = ep.to_backend(AddMulPartitionerDemo()) edge_new = deserialize(serialize(edge.exported_program())) self.check_ep(edge.exported_program(), edge_new, inputs) @@ -217,7 +217,7 @@ def forward(self, x): inputs = (torch.randn(1, 1, 32, 32),) metadata = () - edge = to_edge(export(m, inputs)) + edge = to_edge(export(m, inputs, strict=True)) for node in edge.exported_program().graph_module.graph.nodes: if "convolution" in str(node.target): metadata = ( diff --git a/exir/tests/test_tracer.py b/exir/tests/test_tracer.py index 415443c4c1e..3ed4feae23c 100644 --- a/exir/tests/test_tracer.py +++ b/exir/tests/test_tracer.py @@ -107,7 +107,10 @@ def forward(self, x): return x + y ep = torch.export.export( - M(), (torch.ones(3),), dynamic_shapes={"x": {0: torch.export.Dim("x")}} + M(), + (torch.ones(3),), + dynamic_shapes={"x": {0: torch.export.Dim("x")}}, + strict=True, ) exir.to_edge(ep) @@ -137,9 +140,8 @@ def get_random_inputs(self) -> Tuple[torch.Tensor, ...]: graph_module = ( exir.capture(model, model.get_random_inputs(), exir.CaptureConfig()) # torch._ops.aten.t.default - .to_edge( - exir.EdgeCompileConfig(_check_ir_validity=False) - ).exported_program.graph_module + .to_edge(exir.EdgeCompileConfig(_check_ir_validity=False)) + .exported_program.graph_module ) num_get_attr_node = 0 num_get_attr_node_with_tensorspec = 0 diff --git a/exir/tests/test_verification.py b/exir/tests/test_verification.py index c223e0ad844..f18e9d74b75 100644 --- a/exir/tests/test_verification.py +++ b/exir/tests/test_verification.py @@ -35,7 +35,7 @@ def f(x: torch.Tensor) -> torch.Tensor: # Generate program program = ( - to_edge(export(WrapperModule(f), (torch.randn(2),))) + to_edge(export(WrapperModule(f), (torch.randn(2),), strict=True)) .transform( [ ConstPropPass(), @@ -90,7 +90,9 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: model1 = Op1() inputs = (torch.ones(2, 2),) program = ( - to_edge(export(model1, inputs)).to_executorch()._emitter_output.program + to_edge(export(model1, inputs, strict=True)) + .to_executorch() + ._emitter_output.program ) # Initialize and test Interpreter -- assert that the operators are same as above @@ -104,7 +106,9 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: model2 = Op2() inputs = (torch.ones(2, 2),) program = ( - to_edge(export(model2, inputs)).to_executorch()._emitter_output.program + to_edge(export(model2, inputs, strict=True)) + .to_executorch() + ._emitter_output.program ) # Initialize and test Interpreter -- assert that the operators are same as above @@ -135,7 +139,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: # Generate a program with Op2's operations (remainder, div, add) model2 = Op2() inputs = torch.ones(2, 2) - exec_prog = to_edge(export(model2, (inputs,))).to_executorch() + exec_prog = to_edge(export(model2, (inputs,), strict=True)).to_executorch() exported_prog = exec_prog.exported_program() res = exported_prog.module()(inputs)[0] # noqa @@ -158,8 +162,7 @@ def forward(self, x): egm = ( to_edge( export( - m, - (torch.randn(1, 3, 100, 100).to(dtype=torch.int),), + m, (torch.randn(1, 3, 100, 100).to(dtype=torch.int),), strict=True ) ) .exported_program() @@ -184,6 +187,7 @@ def forward(self, x, weight, bias): export( m, (torch.rand(16, 8, 32, 32), torch.rand(8), torch.rand(8)), + strict=True, ) ) .exported_program() @@ -202,16 +206,7 @@ def forward(self, x): return torch._to_cpu(x) m = TestModel() - egm = ( - to_edge( - export( - m, - ([],), - ) - ) - .exported_program() - .graph_module - ) + egm = to_edge(export(m, ([],), strict=True)).exported_program().graph_module verifier = EXIREdgeDialectVerifier() verifier(egm) self.assertTrue(verifier.is_valid(egm)) @@ -228,8 +223,7 @@ def forward(self, x): m = TestModel() egm = export( - m, - (torch.randn(1, 3, 100, 100).to(dtype=torch.int),), + m, (torch.randn(1, 3, 100, 100).to(dtype=torch.int),), strict=True ).graph_module verifier = EXIREdgeDialectVerifier() with self.assertRaises(SpecViolationError): @@ -247,8 +241,7 @@ def forward(self, x): egm = ( to_edge( export( - m, - (torch.randn(1, 3, 100, 100).to(dtype=torch.int),), + m, (torch.randn(1, 3, 100, 100).to(dtype=torch.int),), strict=True ) ) .exported_program() @@ -267,6 +260,7 @@ def test_edge_sad_with_edge_ops(self) -> None: export( m, (torch.randn(1, 3, 100, 100).to(dtype=torch.bfloat16),), + strict=True, ) ) .exported_program()