From b07a587de50d3e02323ffc3dc133d07aed6c64de Mon Sep 17 00:00:00 2001 From: PRATHAM-SPS Date: Mon, 9 Oct 2023 22:37:08 +0530 Subject: [PATCH] revertback:- freeze_placeholder_test.py --- .../mo/utils/freeze_placeholder_test.py | 299 +++++++++--------- 1 file changed, 148 insertions(+), 151 deletions(-) diff --git a/tools/mo/unit_tests/mo/utils/freeze_placeholder_test.py b/tools/mo/unit_tests/mo/utils/freeze_placeholder_test.py index 7b247665b22740..6c9f25c86aa8b6 100644 --- a/tools/mo/unit_tests/mo/utils/freeze_placeholder_test.py +++ b/tools/mo/unit_tests/mo/utils/freeze_placeholder_test.py @@ -8,6 +8,7 @@ import numpy as np import onnx +from generator import generator, generate from onnx.helper import make_graph, make_model, make_tensor_value_info from openvino.frontend import ( @@ -51,7 +52,7 @@ def base_args_config(use_legacy_fe: bool = None, use_new_fe: bool = None): try: import openvino_telemetry as tm - + from openvino_telemetry.backend import backend_ga4 except ImportError: import openvino.tools.mo.utils.telemetry_stub as tm @@ -60,6 +61,7 @@ def get_test_default_frontends(): return {"onnx": "new", "tf": "legacy"} +@generator class TestMoFreezePlaceholder(unittest.TestCase): def setUp(self): tm.Telemetry.__init__ = Mock(return_value=None) @@ -122,185 +124,180 @@ def tearDown(self): for name in self.models.keys(): os.remove(name) - def test_freeze_placeholder_with_value_onnx_fe(self): - test_cases = [ + @generate( + *[ ( - "in1[1 4]{f32}->[1.0 2.0 3.0 4.0],in2[1 4]{f32}->[1.0 2.0 3.0 4.0]", - True, - {}, - np.array([2.0, 4.0, 6.0, 8.0]), - np.float32, + "in1[1 4]{f32}->[1.0 2.0 3.0 4.0],in2[1 4]{f32}->[1.0 2.0 3.0 4.0]", + True, + {}, + np.array([2.0, 4.0, 6.0, 8.0]), + np.float32, ), ( - "in2{f32}->[0.0 0.0 0.0 0.0]", - True, - {"in1": np.array([[1.0, 2.0], [3.0, 4.0]])}, - np.array([[1.0, 2.0], [3.0, 4.0]]), - np.float32, + "in2{f32}->[0.0 0.0 0.0 0.0]", + True, + {"in1": np.array([[1.0, 2.0], [3.0, 4.0]])}, + np.array([[1.0, 2.0], [3.0, 4.0]]), + np.float32, ), ( - "in2{f32}->[1.0 15.0 15.5 1.0]", - True, - {"in1": np.array([[2.0, 4.0], [12.0, 8.0]])}, - np.array([[3.0, 19.0], [27.5, 9.0]]), - np.float32, + "in2{f32}->[1.0 15.0 15.5 1.0]", + True, + {"in1": np.array([[2.0, 4.0], [12.0, 8.0]])}, + np.array([[3.0, 19.0], [27.5, 9.0]]), + np.float32, ), ( - "in1[1 4]{i32}->[1 2 3 4],in2[1 4]{i32}->[1 2 3 4]", - True, - {}, - np.array([2.0, 4.0, 6.0, 8.0]), - np.int32, + "in1[1 4]{i32}->[1 2 3 4],in2[1 4]{i32}->[1 2 3 4]", + True, + {}, + np.array([2.0, 4.0, 6.0, 8.0]), + np.int32, ), - ] - + ], + ) + def test_freeze_placeholder_with_value_onnx_fe(self, input_freezing_value, use_new_fe, inputs, expected, + dtype=None): with patch("openvino.tools.mo.convert_impl.get_default_frontends") as default_fe: default_fe.return_value = get_test_default_frontends() - - for idx, (input_freezing_value, use_new_fe, inputs, expected, dtype) in enumerate(test_cases): - with self.subTest(test_case_idx=idx): - args = base_args_config(use_new_fe=use_new_fe) - args.input_model = "test_model.onnx" - args.input = input_freezing_value - - _, model = prepare_ir(args) - - ie = Core() - exec_net = ie.compile_model(model, "CPU") - req = exec_net.create_infer_request() - results = req.infer(inputs) - values = list(results.values())[0] - if dtype is not None: - self.assertEqual(values.dtype, dtype) - self.assertTrue(np.allclose(values, expected)) - - def test_freeze_placeholder_with_value_mul(self): - test_cases = [ + args = base_args_config(use_new_fe=use_new_fe) + args.input_model = "test_model.onnx" + args.input = input_freezing_value + + _, model = prepare_ir(args) + + ie = Core() + exec_net = ie.compile_model(model, "CPU") + req = exec_net.create_infer_request() + results = req.infer(inputs) + values = list(results.values())[0] + if dtype is not None: + assert values.dtype == dtype + assert np.allclose(values, expected) + + @generate( + *[ ( - "in1{f32}->[1.0 15.0 1.0]", - True, - {"in2": np.array([2])}, - np.array([2.0, 30.0, 2.0]), - np.float32, + "in1{f32}->[1.0 15.0 1.0]", + True, + {"in2": np.array([2])}, + np.array([2.0, 30.0, 2.0]), + np.float32, ), ( - "in1{f32}->[7.0 11.0 -1.0],in2{f32}->3.0", - True, - {}, - np.array([21.0, 33.0, -3.0]), - np.float32, + "in1{f32}->[7.0 11.0 -1.0],in2{f32}->3.0", + True, + {}, + np.array([21.0, 33.0, -3.0]), + np.float32, ), ( - None, - True, - { - "in1": np.array([2.0, 2.0, 2.0]).reshape(1, 1, 3), - "in2": np.array([-1.0]), - }, - np.array([-2.0, -2.0, -2.0]), - np.float32, + None, + True, + { + "in1": np.array([2.0, 2.0, 2.0]).reshape(1, 1, 3), + "in2": np.array([-1.0]), + }, + np.array([-2.0, -2.0, -2.0]), + np.float32, ), ( - "in1[3 1]{f32}->[7.0 11.0 -1.0],in2{f32}->3.0", - True, - {}, - np.array([21.0, 33.0, -3.0]).reshape(3, 1), - np.float32, + "in1[3 1]{f32}->[7.0 11.0 -1.0],in2{f32}->3.0", + True, + {}, + np.array([21.0, 33.0, -3.0]).reshape(3, 1), + np.float32, ), ( - "in1[3 1]{f16}->[7.0 11.0 -1.0],in2{f16}->3.0", - True, - {}, - np.array([21.0, 33.0, -3.0]).reshape(3, 1), - np.float16, + "in1[3 1]{f16}->[7.0 11.0 -1.0],in2{f16}->3.0", + True, + {}, + np.array([21.0, 33.0, -3.0]).reshape(3, 1), + np.float16, ), ( - "in1[3 1]{i32}->[7 11 -1],in2{i32}->3.0", - True, - {}, - np.array([21, 33, -3]).reshape(3, 1), - np.int32, + "in1[3 1]{i32}->[7 11 -1],in2{i32}->3.0", + True, + {}, + np.array([21, 33, -3]).reshape(3, 1), + np.int32, ), - ] - + ], + ) + def test_freeze_placeholder_with_value_mul(self, input_freezing_value, use_new_fe, inputs, expected, dtype=None): with patch("openvino.tools.mo.convert_impl.get_default_frontends") as default_fe: default_fe.return_value = get_test_default_frontends() - - for idx, (input_freezing_value, use_new_fe, inputs, expected, dtype) in enumerate(test_cases): - with self.subTest(test_case_idx=idx): - args = base_args_config(use_new_fe=use_new_fe) - args.input_model = "test_model_2.onnx" - args.input = input_freezing_value - - _, model = prepare_ir(args) - - ie = Core() - exec_net = ie.compile_model(model, "CPU") - req = exec_net.create_infer_request() - results = req.infer(inputs) - values = list(results.values())[0] - if dtype is not None: - self.assertEqual(values.dtype, dtype) - self.assertTrue(np.allclose(values, expected)) - - def test_value_without_type(self): - test_cases = [ + args = base_args_config(use_new_fe=use_new_fe) + args.input_model = "test_model_2.onnx" + args.input = input_freezing_value + + _, model = prepare_ir(args) + + ie = Core() + exec_net = ie.compile_model(model, "CPU") + req = exec_net.create_infer_request() + results = req.infer(inputs) + values = list(results.values())[0] + if dtype is not None: + assert values.dtype == dtype + assert np.allclose(values, expected) + + @generate( + *[ ( - "in1->[1.0 15.0 1.0]", - True, - {"in2": np.array([2])}, - np.array([2.0, 30.0, 2.0]), - np.float32, + "in1->[1.0 15.0 1.0]", + True, + {"in2": np.array([2])}, + np.array([2.0, 30.0, 2.0]), + np.float32, ), - ] - + ], + ) + def test_value_without_type(self, input_freezing_value, use_new_fe, inputs, expected, + dtype=None): with patch("openvino.tools.mo.convert_impl.get_default_frontends") as default_fe: default_fe.return_value = get_test_default_frontends() - - for idx, (input_freezing_value, use_new_fe, inputs, expected, dtype) in enumerate(test_cases): - with self.subTest(test_case_idx=idx): - args = base_args_config(use_new_fe=use_new_fe) - args.input_model = "test_model_2.onnx" - args.input = input_freezing_value - - _, model = prepare_ir(args) - - ie = Core() - exec_net = ie.compile_model(model, "CPU") - req = exec_net.create_infer_request() - results = req.infer(inputs) - values = list(results.values())[0] - if dtype is not None: - self.assertEqual(values.dtype, dtype) - self.assertTrue(np.allclose(values, expected)) - - def test_value_without_type_int32(self): - test_cases = [ + args = base_args_config(use_new_fe=use_new_fe) + args.input_model = "test_model_2.onnx" + args.input = input_freezing_value + + _, model = prepare_ir(args) + + ie = Core() + exec_net = ie.compile_model(model, "CPU") + req = exec_net.create_infer_request() + results = req.infer(inputs) + values = list(results.values())[0] + if dtype is not None: + assert values.dtype == dtype + assert np.allclose(values, expected) + + @generate( + *[ ( - "in2->[3 2 5]", - True, - {"in1": np.array([[2, 1, 3], [1, 5, 6]], dtype=np.int32)}, - np.array([[6, 2, 15], [3, 10, 30]], dtype=np.int32), - np.int32, + "in2->[3 2 5]", + True, + {"in1": np.array([[2, 1, 3], [1, 5, 6]], dtype=np.int32)}, + np.array([[6, 2, 15], [3, 10, 30]], dtype=np.int32), + np.int32, ), - ] - + ], + ) + def test_value_without_type_int32(self, input_freezing_value, use_new_fe, inputs, expected, + dtype=None): with patch("openvino.tools.mo.convert_impl.get_default_frontends") as default_fe: default_fe.return_value = get_test_default_frontends() - - for idx, (input_freezing_value, use_new_fe, inputs, expected, dtype) in enumerate(test_cases): - with self.subTest(test_case_idx=idx): - args = base_args_config(use_new_fe=use_new_fe) - args.input_model = "test_model_int.onnx" - args.input = input_freezing_value - - _, model = prepare_ir(args) - - ie = Core() - exec_net = ie.compile_model(model, "CPU") - req = exec_net.create_infer_request() - results = req.infer(inputs) - values = list(results.values())[0] - if dtype is not None: - self.assertEqual(values.dtype, dtype) - self.assertTrue(np.allclose(values, expected)) + args = base_args_config(use_new_fe=use_new_fe) + args.input_model = "test_model_int.onnx" + args.input = input_freezing_value + + _, model = prepare_ir(args) + + ie = Core() + exec_net = ie.compile_model(model, "CPU") + req = exec_net.create_infer_request() + results = req.infer(inputs) + values = list(results.values())[0] + if dtype is not None: + assert values.dtype == dtype + assert np.allclose(values, expected)