diff --git a/.github/workflows/job_python_unit_tests.yml b/.github/workflows/job_python_unit_tests.yml index 2348e64a78a..b003dcc57f1 100644 --- a/.github/workflows/job_python_unit_tests.yml +++ b/.github/workflows/job_python_unit_tests.yml @@ -189,7 +189,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 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): 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 diff --git a/tools/ovc/openvino/tools/ovc/convert.py b/tools/ovc/openvino/tools/ovc/convert.py index 782fa25ab2d..e546cd643fb 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 paddle v2.5 + paddle.base.Executor + paddle.fluid.executor.Executor # deprecated since paddle 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..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 +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,12 +222,8 @@ def check_model_object(argv): if isinstance(model, io.BytesIO): 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): - 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 d3e2ae24c46..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 @@ -4,7 +4,26 @@ import os import sys import tempfile +# pylint: disable=no-name-in-module,import-error +def paddle_class_check(class_str): + try: + import paddle + 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 + +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): @@ -49,18 +68,22 @@ 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): + import paddle + 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 +91,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):