From 1b5172da70533bec5d6c0970506f7f9bdc8544bb Mon Sep 17 00:00:00 2001 From: meiyang-intel Date: Mon, 4 Mar 2024 06:25:26 -0500 Subject: [PATCH 1/8] Update Paddle API for ovc tools --- tools/ovc/openvino/tools/ovc/convert.py | 6 ++-- tools/ovc/openvino/tools/ovc/convert_impl.py | 7 ++--- .../ovc/moc_frontend/paddle_frontend_utils.py | 31 ++++++++++++++----- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/tools/ovc/openvino/tools/ovc/convert.py b/tools/ovc/openvino/tools/ovc/convert.py index 782fa25ab2d..1dfec30c4d6 100644 --- a/tools/ovc/openvino/tools/ovc/convert.py +++ b/tools/ovc/openvino/tools/ovc/convert.py @@ -51,8 +51,10 @@ def convert_model( PaddlePaddle paddle.hapi.model.Model - paddle.fluid.dygraph.layers.Layer - paddle.fluid.executor.Executor + paddle.nn.layer.layers.Layer + paddle.fluid.dygraph.layers.Layer # deprecated since v2.5 + paddle.base.Executor + paddle.fluid.executor.Executor # deprecated since v2.6 :param input: Information of model input required for model conversion. diff --git a/tools/ovc/openvino/tools/ovc/convert_impl.py b/tools/ovc/openvino/tools/ovc/convert_impl.py index 95682c706bb..418ecb0ff2e 100644 --- a/tools/ovc/openvino/tools/ovc/convert_impl.py +++ b/tools/ovc/openvino/tools/ovc/convert_impl.py @@ -35,7 +35,7 @@ from openvino.tools.ovc.logger import init_logger from openvino.tools.ovc.telemetry_utils import send_params_info, send_conversion_result, \ init_mo_telemetry from openvino.tools.ovc.moc_frontend.pytorch_frontend_utils import get_pytorch_decoder, extract_input_info_from_example -from openvino.tools.ovc.moc_frontend.paddle_frontend_utils import paddle_frontend_converter +from openvino.tools.ovc.moc_frontend.paddle_frontend_utils import paddle_frontend_converter, paddle_model_check_instance # pylint: disable=no-name-in-module,import-error from openvino.frontend import FrontEndManager, OpConversionFailure, TelemetryExtension @@ -223,10 +223,7 @@ def check_model_object(argv): return 'onnx' if 'paddle' in sys.modules: - import paddle - if isinstance(model, paddle.hapi.model.Model) or isinstance(model, - paddle.fluid.dygraph.layers.Layer) or isinstance( - model, paddle.fluid.executor.Executor): + if paddle_model_check_instance(model, "paddle.hapi.model.Model") or paddle_model_check_instance(model, "paddle.nn.layer.layers.Layer") or paddle_model_check_instance(model, "paddle.fluid.dygraph.layers.Layer") or paddle_model_check_instance(model, "paddle.base.Executor") or paddle_model_check_instance(model, "paddle.fluid.executor.Executor"): return "paddle" raise Error('Unknown model type: {}'.format(type(model))) diff --git a/tools/ovc/openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py b/tools/ovc/openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py index d3e2ae24c46..cf8cf76cb9d 100644 --- a/tools/ovc/openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py +++ b/tools/ovc/openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py @@ -5,6 +5,20 @@ import os import sys import tempfile +import paddle # pylint: disable=import-error +def paddle_class_check(class_str): + try: + return eval(class_str) + except: + return None + +def paddle_model_check_instance(model, class_str): + cls = paddle_class_check(class_str) + if cls and isinstance(model, cls): + return True + else: + return False + class paddle_frontend_converter: def __init__(self, model, inputs=None, outputs=None): @@ -49,18 +63,21 @@ class paddle_frontend_converter: self.pdiparams = "{}.pdiparams".format(self.model_name) self.pdiparams_info = "{}.pdiparams.info".format(self.model_name) - import paddle # pylint: disable=import-error - if isinstance(self.model, paddle.hapi.model.Model): + if paddle_model_check_instance(self.model, "paddle.hapi.model.Model"): self.model.save(self.model_name, False) else: if self.inputs is None: raise RuntimeError( "Saving inference model needs 'inputs' before saving. Please specify 'example_input'" ) - if isinstance(self.model, paddle.fluid.dygraph.layers.Layer): - with paddle.fluid.framework._dygraph_guard(None): - paddle.jit.save(self.model, self.model_name, input_spec=self.inputs, output_spec=self.outputs) - elif isinstance(self.model, paddle.fluid.executor.Executor): + if paddle_model_check_instance(self.model, "paddle.nn.layer.layers.Layer") or paddle_model_check_instance(self.model, "paddle.fluid.dygraph.layers.Layer"): + if paddle_class_check("paddle.base.framework._dygraph_guard"): + with paddle.base.framework._dygraph_guard(None): + paddle.jit.save(self.model, self.model_name, input_spec=self.inputs, output_spec=self.outputs) + else: + with paddle.fluid.framework._dygraph_guard(None): + paddle.jit.save(self.model, self.model_name, input_spec=self.inputs, output_spec=self.outputs) + elif paddle_model_check_instance(self.model, "paddle.base.Executor") or paddle_model_check_instance(self.model, "paddle.fluid.executor.Executor"): if self.outputs is None: raise RuntimeError( "Model is static. Saving inference model needs 'outputs' before saving. Please specify 'output' for this model" @@ -68,7 +85,7 @@ class paddle_frontend_converter: paddle.static.save_inference_model(self.model_name, self.inputs, self.outputs, self.model) else: raise RuntimeError( - "Conversion just support paddle.hapi.model.Model, paddle.fluid.dygraph.layers.Layer and paddle.fluid.executor.Executor" + "Conversion just support paddle.hapi.model.Model, paddle.nn.layer.layers.Layer, paddle.fluid.dygraph.layers.Layer, paddle.base.Executor and paddle.fluid.executor.Executor" ) if not os.path.exists(self.pdmodel): From b8ad4339d7fdb6c919fa23adf94ec8e1686215ac Mon Sep 17 00:00:00 2001 From: meiyang-intel Date: Mon, 4 Mar 2024 19:40:07 -0500 Subject: [PATCH 2/8] import paddle in runtime --- .../openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/ovc/openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py b/tools/ovc/openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py index cf8cf76cb9d..cfb17653cee 100644 --- a/tools/ovc/openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py +++ b/tools/ovc/openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py @@ -4,10 +4,11 @@ import os import sys import tempfile +# pylint: disable=no-name-in-module,import-error -import paddle # pylint: disable=import-error def paddle_class_check(class_str): try: + import paddle return eval(class_str) except: return None @@ -63,6 +64,7 @@ class paddle_frontend_converter: self.pdiparams = "{}.pdiparams".format(self.model_name) self.pdiparams_info = "{}.pdiparams.info".format(self.model_name) + import paddle if paddle_model_check_instance(self.model, "paddle.hapi.model.Model"): self.model.save(self.model_name, False) else: From 98ee966937488c1f494944a9e4c39e4f53d35306 Mon Sep 17 00:00:00 2001 From: "mei, yang" Date: Thu, 7 Mar 2024 09:12:30 +0800 Subject: [PATCH 3/8] Update tools/ovc/openvino/tools/ovc/convert.py Co-authored-by: Anastasiia Pnevskaia --- tools/ovc/openvino/tools/ovc/convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ovc/openvino/tools/ovc/convert.py b/tools/ovc/openvino/tools/ovc/convert.py index 1dfec30c4d6..619d8e3ed4d 100644 --- a/tools/ovc/openvino/tools/ovc/convert.py +++ b/tools/ovc/openvino/tools/ovc/convert.py @@ -52,7 +52,7 @@ def convert_model( PaddlePaddle paddle.hapi.model.Model paddle.nn.layer.layers.Layer - paddle.fluid.dygraph.layers.Layer # deprecated since v2.5 + paddle.fluid.dygraph.layers.Layer # deprecated since paddle v2.5 paddle.base.Executor paddle.fluid.executor.Executor # deprecated since v2.6 From e6cc4fa118927ec54a4d664bc25ba07cb4ce03a7 Mon Sep 17 00:00:00 2001 From: "mei, yang" Date: Thu, 7 Mar 2024 09:12:37 +0800 Subject: [PATCH 4/8] Update tools/ovc/openvino/tools/ovc/convert.py Co-authored-by: Anastasiia Pnevskaia --- tools/ovc/openvino/tools/ovc/convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ovc/openvino/tools/ovc/convert.py b/tools/ovc/openvino/tools/ovc/convert.py index 619d8e3ed4d..e546cd643fb 100644 --- a/tools/ovc/openvino/tools/ovc/convert.py +++ b/tools/ovc/openvino/tools/ovc/convert.py @@ -54,7 +54,7 @@ def convert_model( paddle.nn.layer.layers.Layer paddle.fluid.dygraph.layers.Layer # deprecated since paddle v2.5 paddle.base.Executor - paddle.fluid.executor.Executor # deprecated since v2.6 + paddle.fluid.executor.Executor # deprecated since paddle v2.6 :param input: Information of model input required for model conversion. From ed0d7b2284f0ed29efb751c3820bbf2dbf154d88 Mon Sep 17 00:00:00 2001 From: meiyang-intel Date: Thu, 7 Mar 2024 22:08:05 -0500 Subject: [PATCH 5/8] fix for comments --- tools/ovc/openvino/tools/ovc/convert_impl.py | 7 +++---- .../tools/ovc/moc_frontend/paddle_frontend_utils.py | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/ovc/openvino/tools/ovc/convert_impl.py b/tools/ovc/openvino/tools/ovc/convert_impl.py index 418ecb0ff2e..5d981d4bfdb 100644 --- a/tools/ovc/openvino/tools/ovc/convert_impl.py +++ b/tools/ovc/openvino/tools/ovc/convert_impl.py @@ -35,7 +35,7 @@ from openvino.tools.ovc.logger import init_logger from openvino.tools.ovc.telemetry_utils import send_params_info, send_conversion_result, \ init_mo_telemetry from openvino.tools.ovc.moc_frontend.pytorch_frontend_utils import get_pytorch_decoder, extract_input_info_from_example -from openvino.tools.ovc.moc_frontend.paddle_frontend_utils import paddle_frontend_converter, paddle_model_check_instance +from openvino.tools.ovc.moc_frontend.paddle_frontend_utils import paddle_frontend_converter, is_paddle_model # pylint: disable=no-name-in-module,import-error from openvino.frontend import FrontEndManager, OpConversionFailure, TelemetryExtension @@ -222,9 +222,8 @@ def check_model_object(argv): if isinstance(model, io.BytesIO): return 'onnx' - if 'paddle' in sys.modules: - if paddle_model_check_instance(model, "paddle.hapi.model.Model") or paddle_model_check_instance(model, "paddle.nn.layer.layers.Layer") or paddle_model_check_instance(model, "paddle.fluid.dygraph.layers.Layer") or paddle_model_check_instance(model, "paddle.base.Executor") or paddle_model_check_instance(model, "paddle.fluid.executor.Executor"): - return "paddle" + if 'paddle' in sys.modules and is_paddle_model(model): + return "paddle" raise Error('Unknown model type: {}'.format(type(model))) diff --git a/tools/ovc/openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py b/tools/ovc/openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py index cfb17653cee..993fbcf2a2b 100644 --- a/tools/ovc/openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py +++ b/tools/ovc/openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py @@ -20,6 +20,10 @@ def paddle_model_check_instance(model, class_str): else: return False +def is_paddle_model(model): + possible_instances = ["paddle.hapi.model.Model", "paddle.nn.layer.layers.Layer", "paddle.fluid.dygraph.layers.Layer", "paddle.base.Executor", "paddle.fluid.executor.Executor"] + is_instance = [paddle_model_check_instance(model, possible_instance) for possible_instance in possible_instances] + return any(is_instance) class paddle_frontend_converter: def __init__(self, model, inputs=None, outputs=None): From e85e52b211edc8d39779f60e5ae2431fc5734b8f Mon Sep 17 00:00:00 2001 From: meiyang-intel Date: Tue, 14 May 2024 00:17:19 -0400 Subject: [PATCH 6/8] re-enable ovc import paddle from memory test --- tests/layer_tests/ovc_python_api_tests/test_paddle.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/layer_tests/ovc_python_api_tests/test_paddle.py b/tests/layer_tests/ovc_python_api_tests/test_paddle.py index de468a264d8..3b284ccfa44 100644 --- a/tests/layer_tests/ovc_python_api_tests/test_paddle.py +++ b/tests/layer_tests/ovc_python_api_tests/test_paddle.py @@ -92,7 +92,6 @@ class TestMoConvertPaddle(CommonMOConvertTest): create_paddle_static_module, create_paddle_hapi_module ] - @pytest.mark.skip(reason="Paddlepaddle has incompatible protobuf. Ticket: 95904") @pytest.mark.parametrize("create_model", test_data) def test_mo_import_from_memory_paddle_fe(self, create_model, ie_device, precision, ir_version, temp_dir): From 51ecaff662157b9b48913e81a11284b3520c77a9 Mon Sep 17 00:00:00 2001 From: meiyang-intel Date: Tue, 14 May 2024 01:47:50 -0400 Subject: [PATCH 7/8] add paddlepaddle in layer_tests dependancy --- tests/constraints.txt | 2 +- tests/layer_tests/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/constraints.txt b/tests/constraints.txt index 7d7ae43ce6f..6a36b56d6e5 100644 --- a/tests/constraints.txt +++ b/tests/constraints.txt @@ -16,7 +16,7 @@ tensorflow>=2.5,<2.17.0 test-generator==0.1.2 requests>=2.25.1 opencv-python>=4.5 -paddlepaddle==2.5.0 +paddlepaddle==2.6.0 protobuf>=3.18.1,<4.0.0 py>=1.9.0 pytest>=5.0,<7.5 diff --git a/tests/layer_tests/requirements.txt b/tests/layer_tests/requirements.txt index 6799b32036d..12a3f8ad852 100644 --- a/tests/layer_tests/requirements.txt +++ b/tests/layer_tests/requirements.txt @@ -1,5 +1,5 @@ -c ../constraints.txt -# paddlepaddle # ticket 95904 +paddlepaddle numpy onnxruntime requests From 251f6712b798340b21d812add15c60c87e90d18c Mon Sep 17 00:00:00 2001 From: meiyang-intel Date: Tue, 14 May 2024 07:50:51 -0400 Subject: [PATCH 8/8] find gomp lib --- .github/workflows/job_python_unit_tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/job_python_unit_tests.yml b/.github/workflows/job_python_unit_tests.yml index 4efd95d5122..b7b06d37daf 100644 --- a/.github/workflows/job_python_unit_tests.yml +++ b/.github/workflows/job_python_unit_tests.yml @@ -194,7 +194,8 @@ jobs: if [[ "${{ runner.os }}" == "Linux" ]] && [[ "${{ runner.arch }}" == "ARM64" ]]; then # Find gomp lib GOMP_LIB=$(find "${PIP_INSTALL_PATH}/torch/lib/../../torch.libs/" -name '*libgomp-*so*') - export LD_PRELOAD=${GOMP_LIB} + GOMP_LIB_GLOBAL=$(ldconfig -p | grep libgomp | grep AArch64 | awk '{print $4}') + export LD_PRELOAD=${GOMP_LIB}:${GOMP_LIB_GLOBAL} fi python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/ovc_python_api_tests --junitxml=${INSTALL_TEST_DIR}/TEST-test_ovc_convert.xml