Implements renaming of tf_fe lib (#12684)

* tf_fe lib renaming to switch to new fe

* Apply suggestions from code review

* 1. implements renaming for win os
2. --api_2 key is equal to True by default

* --ir_version key is equal to '11' by default

* resolves merge conflicts

* check if file to rename exists

Co-authored-by: Evgenya Stepyreva <eva.my.link@gmail.com>
This commit is contained in:
Ruslan Nugmanov 2022-08-30 13:51:03 +04:00 committed by GitHub
parent 98a23a5c6f
commit 5a1fc67131
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 67 additions and 11 deletions

View File

@ -16,15 +16,13 @@ This folder layer tests framework code and test files.
```
* Set up environment variables for layer tests:
```bash
export MO_ROOT=PATH_TO_MO
export PYTHONPATH="path_to_openvino"/tests/layer_tests/:"path_to_openvino"/tools/mo:"path to python api"
```
To parametrize tests by device and precision (optional)
```bash
export PYTHONPATH="path_to_openvino"/tests/layer_tests/:$PYTHONPATH
export TEST_DEVICE="CPU;GPU"
export TEST_PRECISION="FP32;FP16"
```
```bash
export IE_APP_PATH="path_to_IE"
```
* Add IE dependencies in LD_LIBRARY_PATH.
## Run tests
```bash

View File

@ -7,7 +7,6 @@ import os
import re
import warnings
import xml.etree.ElementTree as ET
from openvino.tools.mo.utils.ir_engine.ir_engine import IREngine
from pathlib import Path
import numpy as np

View File

@ -1,6 +1,5 @@
# Copyright (C) 2018-2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import subprocess
import sys

View File

@ -2,12 +2,13 @@
# SPDX-License-Identifier: Apache-2.0
import logging
import os
import subprocess
import sys
from pathlib import Path
from openvino.tools.mo import mo
import numpy as np
from openvino.tools.mo import mo
logger = logging.getLogger(__name__)
@ -85,3 +86,12 @@ def allclose(cur_array, ref_array, atol, rtol):
abs_diff = np.absolute(cur_array - ref_array)
max_val = np.maximum(np.absolute(cur_array), np.absolute(ref_array))
return ((abs_diff < atol) | (abs_diff < rtol * max_val)).all()
def rename_ov_lib(files_to_rename: list, lib_dir: Path):
for pair in files_to_rename:
current_lib_path = os.path.join(lib_dir, pair[0])
new_lib_path = os.path.join(lib_dir, pair[1])
if os.path.exists(current_lib_path):
logging.info('Renaming library from {} to {}'.format(current_lib_path, new_lib_path))
os.replace(current_lib_path, new_lib_path)

View File

@ -56,7 +56,7 @@ def pytest_addoption(parser):
"""Specify command-line options for all plugins"""
parser.addoption(
"--ir_version",
required=True,
default=11,
action="store",
help="Version of IR to generate by Model Optimizer")
parser.addoption(
@ -68,7 +68,7 @@ def pytest_addoption(parser):
"--api_2",
action="store_true",
help="Use new API 2.0 for model processing in Inference Engine",
default=False)
default=True)
@pytest.fixture(scope="session")

View File

@ -2,11 +2,61 @@
# SPDX-License-Identifier: Apache-2.0
import inspect
import os
import sys
import logging as log
from pathlib import Path
import pytest
from common.layer_test_class import get_params
from common.utils.common_utils import rename_ov_lib
def pytest_generate_tests(metafunc):
test_gen_attrs_names = list(inspect.signature(get_params).parameters)
params = get_params()
metafunc.parametrize(test_gen_attrs_names, params, scope="function")
@pytest.fixture(scope='session', autouse=True)
def rename_tf_fe_libs(request):
# code before 'yield' statement is equal to 'set_up' function
try:
import openvino.runtime as rt
except ImportError as err:
raise Exception("Please set PYTHONPATH to OpenVINO Python") from err
openvino_lib_path = Path(rt.__file__).parent.parent.parent.parent.parent
if sys.platform == 'win32':
tf_fe_lib_names = [('openvino_tensorflow_fe.dll', 'openvino_tensorflow_frontend.dll'),
('openvino_tensorflow_fe.lib', 'openvino_tensorflow_frontend.lib'),
('openvino_tensorflow_fe.exp', 'openvino_tensorflow_frontend.exp')]
else:
tf_fe_lib_names = [('libopenvino_tensorflow_fe.so', 'libopenvino_tensorflow_frontend.so')]
if request.config.getoption('use_new_frontend'):
log.info('Using new frontend...')
# check if all required files already have new names
if all([file_pair[1] in os.listdir(openvino_lib_path) for file_pair in tf_fe_lib_names]):
log.info('TF FE libraries already have new names, no renaming will be done')
else:
rename_ov_lib(tf_fe_lib_names, openvino_lib_path)
# code after 'yield' statement is equal to 'tear_down' function
yield
# check if all required files already have old names
if all([file_pair[0] in os.listdir(openvino_lib_path) for file_pair in tf_fe_lib_names]):
log.info('TF FE libraries already have old names, no renaming will be done')
else:
if sys.platform == 'win32':
tf_fe_lib_names = [('openvino_tensorflow_frontend.dll', 'openvino_tensorflow_fe.dll'),
('openvino_tensorflow_frontend.lib', 'openvino_tensorflow_fe.lib'),
('openvino_tensorflow_frontend.exp', 'openvino_tensorflow_fe.exp')]
else:
tf_fe_lib_names = [('libopenvino_tensorflow_frontend.so', 'libopenvino_tensorflow_fe.so')]
rename_ov_lib(tf_fe_lib_names, openvino_lib_path)