From ff6795e2396c94c9f6605cd03ddb42284e363df3 Mon Sep 17 00:00:00 2001 From: Anastasiia Pnevskaia Date: Thu, 1 Feb 2024 15:47:23 +0100 Subject: [PATCH] OVC pylint fix (#22558) * Test change. * PyLint fix. * Small fix. * Separated MO and OVC workflows. * Corrected ovc workflow. * Fixed error. * Fixed error. * PyLint fix. * PyLint fix. * Removed not needed change. * Temporarily removed changes from OVC. * Returned changes. * Returned changes. * Added merge_group. * Update tools/ovc/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py Co-authored-by: Roman Kazantsev --------- Co-authored-by: Roman Kazantsev --- .github/workflows/mo.yml | 6 +-- .github/workflows/ovc.yml | 54 +++++++++++++++++++ tools/mo/openvino/tools/mo/front/tf/loader.py | 6 +-- tools/ovc/openvino/tools/ovc/logger.py | 2 +- .../moc_frontend/pytorch_frontend_utils.py | 2 +- .../tools/ovc/moc_frontend/shape_utils.py | 4 +- .../tools/ovc/moc_frontend/type_utils.py | 4 +- 7 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/ovc.yml diff --git a/.github/workflows/mo.yml b/.github/workflows/mo.yml index 57208552556..b59df07a21b 100644 --- a/.github/workflows/mo.yml +++ b/.github/workflows/mo.yml @@ -53,8 +53,4 @@ jobs: - name: Pylint-MO run: pylint -d C,R,W openvino/tools/mo - working-directory: tools/mo - - - name: Pylint-OVC - run: pylint -d C,R,W openvino/tools/ovc - working-directory: tools/ovc \ No newline at end of file + working-directory: tools/mo \ No newline at end of file diff --git a/.github/workflows/ovc.yml b/.github/workflows/ovc.yml new file mode 100644 index 00000000000..74d891f8262 --- /dev/null +++ b/.github/workflows/ovc.yml @@ -0,0 +1,54 @@ +name: OVC +on: + merge_group: + push: + paths: + - 'tools/ovc/**' + - '.github/workflows/ovc.yml' + branches: + - 'master' + - 'releases/**' + pull_request: + paths: + - 'tools/ovc/**' + - '.github/workflows/ovc.yml' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + Pylint-UT: + runs-on: ubuntu-22.04 + steps: + - name: Clone OpenVINO + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('src/bindings/python/requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools + # For UT + pip install unittest-xml-reporting==3.0.2 + pip install pylint>=2.7.0 + pip install pyenchant>=3.0.0 + + pip install -r requirements.txt + working-directory: src/bindings/python/ + + - name: Pylint-OVC + run: pylint -d C,R,W openvino/tools/ovc + working-directory: tools/ovc \ No newline at end of file diff --git a/tools/mo/openvino/tools/mo/front/tf/loader.py b/tools/mo/openvino/tools/mo/front/tf/loader.py index 310cb08f129..9bcf87cfa23 100644 --- a/tools/mo/openvino/tools/mo/front/tf/loader.py +++ b/tools/mo/openvino/tools/mo/front/tf/loader.py @@ -207,7 +207,7 @@ def prepare_graph_def(model): for node in nodes_to_clear_device: node.device = "" return model, {}, "tf", None - if isinstance(model, tf.keras.Model): + if isinstance(model, tf.keras.Model): # pylint: disable=no-member assert hasattr(model, "inputs") and model.inputs is not None, "Model inputs specification is required." @@ -215,7 +215,7 @@ def prepare_graph_def(model): for inp in model.inputs: if isinstance(inp, tf.Tensor): model_inputs.append(inp) - elif tf.keras.backend.is_keras_tensor(inp): + elif tf.keras.backend.is_keras_tensor(inp): # pylint: disable=no-member model_inputs.append(inp.type_spec) else: raise Error("Unknown input tensor type {}".format(type(input))) @@ -308,7 +308,7 @@ def load_tf_graph_def(graph_file_name: str = "", is_binary: bool = True, checkpo # Code to extract Keras model. # tf.keras.models.load_model function throws TypeError,KeyError or IndexError # for TF 1.x SavedModel format in case TF 1.x installed - imported = tf.keras.models.load_model(model_dir, compile=False) + imported = tf.keras.models.load_model(model_dir, compile=False) # pylint: disable=no-member except: imported = tf.saved_model.load(model_dir, saved_model_tags) # pylint: disable=E1120 diff --git a/tools/ovc/openvino/tools/ovc/logger.py b/tools/ovc/openvino/tools/ovc/logger.py index cda6b40085e..0b96b44672f 100644 --- a/tools/ovc/openvino/tools/ovc/logger.py +++ b/tools/ovc/openvino/tools/ovc/logger.py @@ -10,7 +10,7 @@ from copy import copy # WA for abseil bug that affects logging while importing TF starting 1.14 version # Link to original issue: https://github.com/abseil/abseil-py/issues/99 if importlib.util.find_spec('absl') is not None: - import absl.logging + import absl.logging # pylint: disable=import-error log.root.removeHandler(absl.logging._absl_handler) diff --git a/tools/ovc/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py b/tools/ovc/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py index 138e9a55420..21af74862a7 100644 --- a/tools/ovc/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py +++ b/tools/ovc/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py @@ -35,7 +35,7 @@ def get_pytorch_decoder(model, example_inputs, args): inputs = prepare_torch_inputs(example_inputs) if not isinstance(model, (TorchScriptPythonDecoder, TorchFXPythonDecoder)): if isinstance(model, torch.export.ExportedProgram): - raise RuntimeException("Models recieved from torch.export are not yet supported by convert_model.") + raise RuntimeError("Models received from torch.export are not yet supported by convert_model.") else: decoder = TorchScriptPythonDecoder(model, example_input=inputs, shared_memory=args.get("share_weights", True)) else: diff --git a/tools/ovc/openvino/tools/ovc/moc_frontend/shape_utils.py b/tools/ovc/openvino/tools/ovc/moc_frontend/shape_utils.py index f80157fc4a9..2c746ef384e 100644 --- a/tools/ovc/openvino/tools/ovc/moc_frontend/shape_utils.py +++ b/tools/ovc/openvino/tools/ovc/moc_frontend/shape_utils.py @@ -76,7 +76,7 @@ def tensor_to_int_list(tensor): def to_partial_shape(shape): if 'tensorflow' in sys.modules: - import tensorflow as tf + import tensorflow as tf # pylint: disable=import-error if isinstance(shape, tf.Tensor): return PartialShape(tensor_to_int_list(shape)) if isinstance(shape, tf.TensorShape): @@ -92,7 +92,7 @@ def is_shape_type(value): if isinstance(value, PartialShape): return True if 'tensorflow' in sys.modules: - import tensorflow as tf + import tensorflow as tf # pylint: disable=import-error if isinstance(value, (tf.TensorShape, tf.Tensor)): return True if 'paddle' in sys.modules: diff --git a/tools/ovc/openvino/tools/ovc/moc_frontend/type_utils.py b/tools/ovc/openvino/tools/ovc/moc_frontend/type_utils.py index fba47fa4c06..372dd425429 100644 --- a/tools/ovc/openvino/tools/ovc/moc_frontend/type_utils.py +++ b/tools/ovc/openvino/tools/ovc/moc_frontend/type_utils.py @@ -11,7 +11,7 @@ def is_type(val): if isinstance(val, (type, Type)): return True if 'tensorflow' in sys.modules: - import tensorflow as tf + import tensorflow as tf # pylint: disable=import-error if isinstance(val, tf.dtypes.DType): return True if 'torch' in sys.modules: @@ -31,7 +31,7 @@ def to_ov_type(val): if isinstance(val, type): return Type(val) if 'tensorflow' in sys.modules: - import tensorflow as tf + import tensorflow as tf # pylint: disable=import-error if isinstance(val, tf.dtypes.DType): return Type(val.as_numpy_dtype()) if 'torch' in sys.modules: