Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TF FE] Test TF Hugging Face models #22970

Merged
merged 29 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
665ca44
Hugging face tests.
popovaan Feb 19, 2024
c9dda25
Updated nightly list.
popovaan Feb 20, 2024
b30b3a0
Minor correction.
popovaan Feb 20, 2024
c34e92d
Moved tests to single folder, added scope param.
popovaan Feb 21, 2024
1d9a3e5
Minor correction.
popovaan Feb 21, 2024
b691b75
Tests correction.
popovaan Feb 21, 2024
aa89c79
Tests correction.
popovaan Feb 21, 2024
b5abcd2
Removed not needed code.
popovaan Feb 21, 2024
676ad90
Test correction.
popovaan Feb 22, 2024
c8e131c
Apply suggestions from code review
popovaan Feb 22, 2024
f3364bd
Renamed tf_tests->tensorflow folder.
popovaan Feb 22, 2024
fe4de9b
Merge remote-tracking branch 'upstream/master' into hugging_face_tests
popovaan Feb 22, 2024
65004be
Separated model lists,
popovaan Feb 22, 2024
8b4de00
Corrected name.
popovaan Feb 22, 2024
9a82a00
Tests correction.
popovaan Feb 22, 2024
44f3077
Clean up models cache.
popovaan Feb 23, 2024
628ddb8
Corrected workflow file.
popovaan Feb 23, 2024
35e8f3c
Renamed pytorch dir.
popovaan Feb 23, 2024
2abec9e
Apply suggestions from code review
popovaan Feb 23, 2024
252ee3b
Tmp dir changed.
popovaan Feb 23, 2024
5076278
Merge branch 'hugging_face_tests' of https://github.com/popovaan/open…
popovaan Feb 23, 2024
cc70866
Labeler fix.
popovaan Feb 23, 2024
df0df77
Merge branch 'master' into hugging_face_tests
popovaan Feb 23, 2024
3dda37e
Merge branch 'master' into hugging_face_tests
popovaan Feb 26, 2024
619d7e2
Removed scope option.
popovaan Feb 26, 2024
3772668
Removed not needed code.
popovaan Feb 26, 2024
b727d65
Removed not needed code.
popovaan Feb 26, 2024
73c34ce
Update tests/model_hub_tests/models_hub_common/constants.py
popovaan Feb 26, 2024
ca237ca
Merge branch 'master' into hugging_face_tests
rkazants Feb 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/tf_tests/**/*']
popovaan marked this conversation as resolved.
Show resolved Hide resolved

'category: TFL FE':
- 'src/frontends/tensorflow_lite/**/*'
Expand All @@ -156,7 +156,7 @@
- 'tests/layer_tests/py_frontend_tests/test_torch_decoder.py'
popovaan marked this conversation as resolved.
Show resolved Hide resolved
- '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/torch_tests/**/*']
popovaan marked this conversation as resolved.
Show resolved Hide resolved

'category: tools':
- any: ['tools/**',
Expand Down
22 changes: 19 additions & 3 deletions .github/workflows/job_tensorflow_hub_models_tests.yml
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 @@ -108,12 +108,28 @@ 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}/tf_tests/requirements.txt

- name: TensorFlow Hub 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}/tf_tests/ -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-tf_hub_tf_fe.html --self-contained-html -v --scope tf_hub
env:
TYPE: ${{ inputs.event == 'schedule' && 'nightly' || 'precommit'}}
TEST_DEVICE: CPU

- name: TensorFlow Hugging Face Tests - TF FE
run: |
export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/tf_tests/test_tf_convert_model.py -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-tf_hub_tf_fe.html --self-contained-html -v --scope hf
env:
TYPE: ${{ inputs.event == 'schedule' && 'nightly' || 'precommit'}}
TEST_DEVICE: CPU

- name: TensorFlow Other Tests (OMZ) - TF FE
run: |
export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/tf_tests/test_tf_convert_model.py -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-tf_hub_tf_fe.html --self-contained-html -v --scope others
rkazants marked this conversation as resolved.
Show resolved Hide resolved
env:
TYPE: ${{ inputs.event == 'schedule' && 'nightly' || 'precommit'}}
TEST_DEVICE: CPU
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 @@ -370,7 +385,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
24 changes: 23 additions & 1 deletion tests/model_hub_tests/models_hub_common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
import os
import shutil
import time
import sys

import numpy as np
from models_hub_common.constants import test_device

def is_tf_hub_link(link: str):
return "www.kaggle.com" in link or "tfhub.dev" in link

def is_hf_link(link: str):
return link.startswith("hf_")

def get_models_list(file_name: str):
scope = "all"
if "--scope" in sys.argv and len(sys.argv) >= sys.argv.index("--scope") + 1:
scope = sys.argv[sys.argv.index("--scope") + 1]
models = []
with open(file_name) as f:
for model_info in f:
Expand All @@ -20,14 +29,27 @@ def get_models_list(file_name: str):
continue
mark = None
reason = None
model_link = None
assert len(model_info.split(',')) == 2 or len(model_info.split(',')) == 4, \
"Incorrect model info `{}`. It must contain either 2 or 4 fields.".format(model_info)
if len(model_info.split(',')) == 2:
model_name, model_link = model_info.split(',')
elif len(model_info.split(',')) == 4:
model_name, model_link, mark, reason = model_info.split(',')
assert mark in ["skip", "xfail"], "Incorrect failure mark for model info {}".format(model_info)
models.append((model_name, model_link, mark, reason))
if scope == "all":
models.append((model_name, model_link, mark, reason))
elif scope == "hf":
if is_hf_link(model_link):
models.append((model_name, model_link, mark, reason))
elif scope == "tf_hub":
if is_tf_hub_link(model_link):
models.append((model_name, model_link, mark, reason))
elif scope == "others":
if not is_hf_link(model_link) and not is_tf_hub_link(model_link):
models.append((model_name, model_link, mark, reason))
else:
raise Exception("Unknown scope {}. Please select one of [all, hf, tf_hub, others].".format(scope))

return models

Expand Down
12 changes: 0 additions & 12 deletions tests/model_hub_tests/tf_hub_tests/conftest.py

This file was deleted.

27 changes: 27 additions & 0 deletions tests/model_hub_tests/tf_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import inspect

import pytest

from models_hub_common.utils import get_params


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")

def pytest_addoption(parser):
"""Specify command-line options"""
parser.addoption(
"--scope",
default="all",
action="store",
help="Models scope for testing. Select one of [all, tf_hub, hf, others]. Default: all.")

@pytest.fixture(scope="function")
def models_scope(request):
"""Fixture function for command-line option."""
return request.config.getoption('scope')
Loading
Loading