From 82cc7165e7d42ff8f31c2613f598fd577abb3085 Mon Sep 17 00:00:00 2001 From: Mateusz Bencer Date: Fri, 21 Jan 2022 14:46:59 +0100 Subject: [PATCH] Fall back to legacy path if input freezing feature is used (#9668) --- .../prepare_model/Model_Optimizer_FAQ.md | 5 ++- tools/mo/openvino/tools/mo/main.py | 3 +- .../tools/mo/moc_frontend/check_config.py | 5 +++ .../mo/utils/mo_fallback_test_actual.py | 42 +++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/docs/MO_DG/prepare_model/Model_Optimizer_FAQ.md b/docs/MO_DG/prepare_model/Model_Optimizer_FAQ.md index 5e9bbd8f4c0..2956376f9c5 100644 --- a/docs/MO_DG/prepare_model/Model_Optimizer_FAQ.md +++ b/docs/MO_DG/prepare_model/Model_Optimizer_FAQ.md @@ -626,13 +626,14 @@ The issue "SyntaxError: 'yield' inside list comprehension" might occur during co The following workarounds are suggested to resolve this issue: 1. Use Python 3.6/3.7 to convert MXNet\* models on Windows 2. Update MXNet: pip install mxnet=1.7.0.post2 -Note that you might have conflicts between previously installed PyPI dependencies.m +Note that you might have conflicts between previously installed PyPI dependencies. #### 105. What does the message "The IR preparation was executed by the legacy MO path. ..." mean? For the models in ONNX* format, there are two available paths of IR conversion. The old one is handled by the old Python* implementation, while the new one uses new C++ frontends. Starting from the 2022.1 version, the default IR conversion path for ONNX models is processed using the new ONNX frontend. -Certain features, such as `--extensions and` `--transformations_config`, are not yet fully supported on the new frontends. +Certain features, such as `--extensions` and `--transformations_config`, are not yet fully supported on the new frontends. For `--extensions`, the new frontends support only paths to shared libraries (.dll and .so). For `--transformations_config`, they support JSON configurations with defined library fields. +Inputs freezing (enabled by `--freeze_placeholder_with_value` or `--input` arguments) is not supported on the new frontends. The IR conversion falls back to the old path if a user does not select any expected path of conversion explicitly (by `--use_new_frontend` or `--use_legacy_frontend` MO arguments) and unsupported pre-defined scenario is detected on the new frontend path. \ No newline at end of file diff --git a/tools/mo/openvino/tools/mo/main.py b/tools/mo/openvino/tools/mo/main.py index c91b1db47aa..bc52728e581 100644 --- a/tools/mo/openvino/tools/mo/main.py +++ b/tools/mo/openvino/tools/mo/main.py @@ -20,7 +20,7 @@ except ImportError: from openvino.tools.mo.back.SpecialNodesFinalization import RemoveConstOps, CreateConstNodesReplacement, NormalizeTI from openvino.tools.mo.back.ie_ir_ver_2.emitter import append_ir_info from openvino.tools.mo.moc_frontend.check_config import legacy_extensions_used, legacy_transformations_config_used, \ - new_extensions_used, new_transformations_config_used + new_extensions_used, new_transformations_config_used, input_freezig_used from openvino.tools.mo.moc_frontend.pipeline import moc_pipeline from openvino.tools.mo.moc_frontend.serialize import moc_emit_ir from openvino.tools.mo.graph.graph import Graph @@ -340,6 +340,7 @@ def check_fallback(argv : argparse.Namespace): fallback_reasons['extensions'] = legacy_extensions_used fallback_reasons['transformations_config'] = legacy_transformations_config_used + fallback_reasons['input_freezing'] = input_freezig_used reasons = [reason for reason, is_applicable in fallback_reasons.items() if is_applicable(argv)] return reasons diff --git a/tools/mo/openvino/tools/mo/moc_frontend/check_config.py b/tools/mo/openvino/tools/mo/moc_frontend/check_config.py index 35ad2d77442..56fe627c84f 100644 --- a/tools/mo/openvino/tools/mo/moc_frontend/check_config.py +++ b/tools/mo/openvino/tools/mo/moc_frontend/check_config.py @@ -89,3 +89,8 @@ def legacy_transformations_config_used(argv: argparse.Namespace): if path != None: return not is_new_json_config(path) return False + + +def input_freezig_used(argv): + return hasattr(argv, 'freeze_placeholder_with_value') and argv.freeze_placeholder_with_value is not None \ + and len(argv.freeze_placeholder_with_value) > 0 diff --git a/tools/mo/unit_tests/mo/utils/mo_fallback_test_actual.py b/tools/mo/unit_tests/mo/utils/mo_fallback_test_actual.py index d2c2eb3f7aa..168c35a54ae 100644 --- a/tools/mo/unit_tests/mo/utils/mo_fallback_test_actual.py +++ b/tools/mo/unit_tests/mo/utils/mo_fallback_test_actual.py @@ -404,3 +404,45 @@ class TestMoFallback(unittest.TestCase): with pytest.raises(Error) as ex: # not called prepare_ir(args) assert str(ex) == 'Legacy transformations configuration is not supported for the new frontend' + + @generate(*[('in1->[5.0 5.0 7.0 8.0],in2->[1.0 2.0 3.0 4.0]', None, None, 'mo_legacy', 'input_freezing'), #fallback + ('in1,in2->[1.0 2.0 3.0 4.0]', None, None, 'mo_legacy', 'input_freezing'), #fallback + ('in1->[1.0 2.0 3.0 4.0],in2', True, None, 'onnx_frontend', None), + ('in1->[1.0 2.0 3.0 4.0],in2', None, True, 'mo_legacy', None), + ]) + def test_fallback_if_input_freezing_used(self, input, use_new_fe, use_legacy, conversion_method, fallback_reason): + with patch('openvino.tools.mo.main.get_default_frontends') as default_fe: + default_fe.return_value = get_test_default_frontends() + args = base_args_config(use_legacy, use_new_fe) + args.input_model = "test_model.onnx" + args.input = input + + prepare_ir(args) + + tm.Telemetry.send_event.assert_any_call('mo', 'conversion_method', conversion_method) + if fallback_reason: + tm.Telemetry.send_event.assert_any_call('mo', 'fallback_reason', fallback_reason) + else: + with pytest.raises(AssertionError): # not called + tm.Telemetry.send_event.assert_any_call('mo', 'fallback_reason', fallback_reason) + + + @generate(*[('in2->[1.0 2.0 3.0 4.0]', None, None, 'mo_legacy', 'input_freezing'), #fallback + ('in2->[1.0 2.0 3.0 4.0]', True, None, 'onnx_frontend', None), + ('in2->[1.0 2.0 3.0 4.0]', None, True, 'mo_legacy', None), + ]) + def test_fallback_if_input_freezing_used_in_deprecated_way(self, input_freezing_value, use_new_fe, use_legacy, conversion_method, fallback_reason): + with patch('openvino.tools.mo.main.get_default_frontends') as default_fe: + default_fe.return_value = get_test_default_frontends() + args = base_args_config(use_legacy, use_new_fe) + args.input_model = "test_model.onnx" + args.freeze_placeholder_with_value = input_freezing_value + + prepare_ir(args) + + tm.Telemetry.send_event.assert_any_call('mo', 'conversion_method', conversion_method) + if fallback_reason: + tm.Telemetry.send_event.assert_any_call('mo', 'fallback_reason', fallback_reason) + else: + with pytest.raises(AssertionError): # not called + tm.Telemetry.send_event.assert_any_call('mo', 'fallback_reason', fallback_reason)