Skip to content

Commit

Permalink
[TF FE] Test TF Hugging Face models (#22970)
Browse files Browse the repository at this point in the history
### Details:
 - TF Hugging face tests

### Tickets:
 - 132904

---------

Co-authored-by: Roman Kazantsev <[email protected]>
  • Loading branch information
popovaan and rkazants authored Feb 26, 2024
1 parent a68c820 commit a819605
Show file tree
Hide file tree
Showing 37 changed files with 541 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
/tests/layer_tests/tensorflow_tests @openvinotoolkit/openvino-tf-frontend-maintainers
/tests/layer_tests/jax_tests @openvinotoolkit/openvino-tf-frontend-maintainers
/tests/model_hub_tests @openvinotoolkit/openvino-tf-frontend-maintainers
/tests/model_hub_tests/torch_tests @openvinotoolkit/openvino-pytorch-frontend-maintainers
/tests/model_hub_tests/pytorch @openvinotoolkit/openvino-pytorch-frontend-maintainers

# Tools:
/tools/ @openvinotoolkit/openvino-tools-maintainers
Expand Down
4 changes: 2 additions & 2 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
- 'tests/layer_tests/tensorflow2_keras_tests/**/*'
- 'tests/layer_tests/jax_tests/**/*'
- any: ['tests/model_hub_tests/**',
'!tests/model_hub_tests/torch_tests/**/*']
'!tests/model_hub_tests/pytorch/**/*']

'category: TFL FE':
- 'src/frontends/tensorflow_lite/**/*'
Expand All @@ -156,7 +156,7 @@
- 'tests/layer_tests/py_frontend_tests/test_torch_decoder.py'
- 'tests/layer_tests/py_frontend_tests/test_torch_frontend.py'
- any: ['tests/model_hub_tests/**',
'!tests/model_hub_tests/tf_hub_tests/**/*']
'!tests/model_hub_tests/tensorflow/**/*']

'category: tools':
- any: ['tools/**',
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/job_pytorch_models_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ jobs:
- name: Install PyTorch tests requirements
run: |
python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/torch_tests/requirements.txt
python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/torch_tests/requirements_secondary.txt
python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/requirements.txt
python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/requirements_secondary.txt
echo "Available storage:"
df -h
env:
Expand All @@ -121,7 +121,7 @@ jobs:
- name: PyTorch Models Tests
run: |
export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/torch_tests -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-torch_model_tests.html --self-contained-html -v
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-torch_model_tests.html --self-contained-html -v
env:
TYPE: ${{ inputs.event == 'schedule' && 'nightly' || 'precommit'}}
TEST_DEVICE: CPU
Expand All @@ -131,7 +131,7 @@ jobs:
- name: Reformat unsupported ops file
if: '!cancelled()'
run: |
python3 ${MODEL_HUB_TESTS_INSTALL_DIR}/torch_tests/scripts/process_op_report.py ${INSTALL_TEST_DIR}/TEST-torch_unsupported_ops.log
python3 ${MODEL_HUB_TESTS_INSTALL_DIR}/pytorch/scripts/process_op_report.py ${INSTALL_TEST_DIR}/TEST-torch_unsupported_ops.log
- name: Available storage after tests
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: TensorFlow Hub Models tests
name: TensorFlow Models tests

on:
workflow_call:
Expand Down Expand Up @@ -109,12 +109,12 @@ jobs:
python3 -m pip install ${INSTALL_DIR}/openvino_tokenizers-*
- name: Install TF Hub tests requirements
run: python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/tf_hub_tests/requirements.txt
run: python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/tensorflow/requirements.txt

- name: TensorFlow Hub Tests - TF FE
- name: TensorFlow Models Tests - TF FE
run: |
export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/tf_hub_tests/ -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-tf_hub_tf_fe.html --self-contained-html -v
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/tensorflow/ -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-tf_hub_tf_fe.html --self-contained-html -v
env:
TYPE: ${{ inputs.event == 'schedule' && 'nightly' || 'precommit'}}
TEST_DEVICE: CPU
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,12 @@ jobs:
# image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04
# volumes:
# - /mount:/mount
TensorFlow_Hub_Models_Tests:
name: TensorFlow Hub Models tests
TensorFlow_Models_Tests:
name: TensorFlow Models tests
if: fromJSON(needs.smart_ci.outputs.affected_components).TF_FE.test ||
fromJSON(needs.smart_ci.outputs.affected_components).TFL_FE.test
needs: [ Build, Smart_CI, Openvino_tokenizers ]
uses: ./.github/workflows/job_tensorflow_hub_models_tests.yml
uses: ./.github/workflows/job_tensorflow_models_tests.yml
with:
runner: ${{ github.event_name == 'schedule' && 'ubuntu-20.04-16-cores' || 'ubuntu-20.04-8-cores' }}
event: ${{ github.event_name }}
Expand Down Expand Up @@ -755,7 +755,7 @@ jobs:
Overall_Status:
name: ci/gha_overall_status
needs: [Smart_CI, Build, Debian_Packages, Samples, Conformance, ONNX_Runtime, CXX_Unit_Tests, Python_Unit_Tests,
CPU_Functional_Tests, TensorFlow_Hub_Models_Tests, PyTorch_Models_Tests, NVIDIA_Plugin, Openvino_tokenizers]
CPU_Functional_Tests, TensorFlow_Models_Tests, PyTorch_Models_Tests, NVIDIA_Plugin, Openvino_tokenizers]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/linux_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ jobs:
runner: 'aks-linux-16-cores-arm'
image: 'openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04'

TensorFlow_Hub_Models_Tests:
name: TensorFlow Hub Models tests
TensorFlow_Models_Tests:
name: TensorFlow Models tests
if: ${{ 'false' }} # TODO: Enable once the dependencies are ready for arm (no tensorflow-text available for arm from PyPI)
# if: fromJSON(needs.smart_ci.outputs.affected_components).TF_FE.test ||
# fromJSON(needs.smart_ci.outputs.affected_components).TFL_FE.test
needs: [ Build, Smart_CI ]
uses: ./.github/workflows/job_tensorflow_hub_models_tests.yml
uses: ./.github/workflows/job_tensorflow_models_tests.yml
with:
runner: 'aks-linux-16-cores-arm'
container: '{"image": "openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04"}'
Expand All @@ -387,7 +387,7 @@ jobs:
Overall_Status:
name: ci/gha_overall_status_linux_arm64
needs: [Smart_CI, Build, Debian_Packages, Samples, ONNX_Runtime, CXX_Unit_Tests, Python_Unit_Tests, CPU_Functional_Tests,
TensorFlow_Hub_Models_Tests, PyTorch_Models_Tests]
TensorFlow_Models_Tests, PyTorch_Models_Tests]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
Expand Down
27 changes: 21 additions & 6 deletions src/bindings/python/src/openvino/frontend/tensorflow/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,28 @@ def get_concrete_func(tf_function, example_input, input_needs_packing, error_mes
return concrete_func


def get_signature_from_input(keras_model):
if not hasattr(keras_model, 'input') or getattr(keras_model, 'input') is None:
return None
return getattr(keras_model, 'input')


def get_signature_from_input_signature(keras_model):
if not hasattr(keras_model, 'input_signature') or getattr(keras_model, 'input_signature') is None:
return None
return getattr(keras_model, 'input_signature')


def create_generic_function_from_keras_model(keras_model):
import tensorflow as tf
assert isinstance(keras_model, tf.keras.Model), \
"[TensorFlow Frontend] internal error: the input model must be of Keras model type"
if not hasattr(keras_model, 'input') or getattr(keras_model, 'input') is None:
assert isinstance(keras_model, (tf.keras.Model, tf.Module)), \
"[TensorFlow Frontend] internal error: the input model must be of tf.keras.Model or tf.Module model type"

keras_input_signature = get_signature_from_input(keras_model)
if keras_input_signature is None:
keras_input_signature = get_signature_from_input_signature(keras_model)
if keras_input_signature is None:
return None
keras_input_signature = getattr(keras_model, 'input')
tf_input_signature = None
wrapper_function = None
if isinstance(keras_input_signature, dict):
Expand Down Expand Up @@ -218,7 +233,7 @@ def trace_tf_model(model, input_shapes, input_types, example_input):
elif isinstance(model, tf.types.experimental.GenericFunction):
tf_function = model
input_needs_packing = False
elif isinstance(model, tf.keras.Model):
elif isinstance(model, (tf.keras.Model, tf.Module)):
tf_function = create_generic_function_from_keras_model(model)
if tf_function is not None:
input_needs_packing = False
Expand Down Expand Up @@ -380,7 +395,7 @@ def extract_model_graph(argv):
argv["input_model"] = model.graph
return True
if Version(env_setup["tensorflow"]) >= parse("2.6.0") and isinstance(model, (tf.types.experimental.GenericFunction,
tf.types.experimental.ConcreteFunction)):
tf.types.experimental.ConcreteFunction)):
return True
if isinstance(model, tf.train.Checkpoint):
if isinstance(model.root, tf.keras.Model):
Expand Down
4 changes: 3 additions & 1 deletion tests/model_hub_tests/models_hub_common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
'''
runtime_heat_duration = os.environ.get('RUNTIME_HEAT_DURATION', '5')


tf_hub_cache_dir = os.environ.get('TFHUB_CACHE_DIR',
os.path.join(tempfile.gettempdir(), "tfhub_modules"))
hf_cache_dir = os.environ.get('HF_HUB_CACHE',
os.path.join(tempfile.gettempdir(), "hugging_face"))
os.environ['TFHUB_CACHE_DIR'] = tf_hub_cache_dir
os.environ['HF_HUB_CACHE'] = hf_cache_dir

no_clean_cache_dir = False
hf_hub_cache_dir = tempfile.gettempdir()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
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")
metafunc.parametrize(test_gen_attrs_names, params, scope="function")
Loading

0 comments on commit a819605

Please sign in to comment.