forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JAX FE][GHA] Add JAX/Flax Model Hub tests into GHA (openvinotoolkit#…
…26542) **Details:** Add JAX Model Hub tests into GHA **Ticket:** 142882 --------- Signed-off-by: Kazantsev, Roman <[email protected]>
- Loading branch information
Showing
12 changed files
with
333 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
name: JAX/Flax Models tests | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
runner: | ||
description: 'Machine on which the tests would run' | ||
type: string | ||
required: true | ||
container: | ||
description: 'JSON to be converted to the value of the "container" configuration for the job' | ||
type: string | ||
required: false | ||
default: '{"image": null}' | ||
model_scope: | ||
description: 'Scope of models for testing.' | ||
type: string | ||
required: true | ||
|
||
permissions: read-all | ||
|
||
jobs: | ||
JAX_Models_Tests: | ||
name: JAX/Flax Models tests | ||
timeout-minutes: ${{ inputs.model_scope == 'precommit' && 35 || 35 }} | ||
runs-on: ${{ inputs.runner }} | ||
container: ${{ fromJSON(inputs.container) }} | ||
defaults: | ||
run: | ||
shell: bash | ||
env: | ||
DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input | ||
OPENVINO_REPO: ${{ github.workspace }}/openvino | ||
INSTALL_DIR: ${{ github.workspace }}/install | ||
INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests | ||
MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests | ||
steps: | ||
- name: Download OpenVINO package | ||
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 | ||
with: | ||
name: openvino_package | ||
path: ${{ env.INSTALL_DIR }} | ||
|
||
- name: Download OpenVINO tokenizers extension | ||
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 | ||
with: | ||
name: openvino_tokenizers_wheel | ||
path: ${{ env.INSTALL_DIR }} | ||
|
||
- name: Download OpenVINO tests package | ||
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 | ||
with: | ||
name: openvino_tests | ||
path: ${{ env.INSTALL_TEST_DIR }} | ||
|
||
# Needed as ${{ github.workspace }} is not working correctly when using Docker | ||
- name: Setup Variables | ||
run: | | ||
echo "OPENVINO_REPO=$GITHUB_WORKSPACE/openvino" >> "$GITHUB_ENV" | ||
echo "INSTALL_DIR=$GITHUB_WORKSPACE/install" >> "$GITHUB_ENV" | ||
echo "INSTALL_TEST_DIR=$GITHUB_WORKSPACE/install/tests" >> "$GITHUB_ENV" | ||
echo "MODEL_HUB_TESTS_INSTALL_DIR=$GITHUB_WORKSPACE/install/tests/model_hub_tests" >> "$GITHUB_ENV" | ||
- name: Extract OpenVINO packages | ||
run: | | ||
pushd ${INSTALL_DIR} | ||
tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} | ||
popd | ||
pushd ${INSTALL_TEST_DIR} | ||
tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} | ||
popd | ||
- name: Fetch setup_python action | ||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
with: | ||
sparse-checkout: | | ||
.github/actions/setup_python/action.yml | ||
sparse-checkout-cone-mode: false | ||
path: 'openvino' | ||
|
||
- name: Setup Python 3.11 | ||
uses: ./openvino/.github/actions/setup_python | ||
with: | ||
version: '3.11' | ||
should-setup-pip-paths: 'false' | ||
self-hosted-runner: ${{ contains(inputs.runner, 'aks') }} | ||
|
||
- name: Install OpenVINO Python wheels | ||
run: | | ||
# To enable pytest parallel features | ||
python3 -m pip install pytest-xdist[psutil] | ||
python3 -m pip install ${INSTALL_DIR}/tools/openvino-* | ||
python3 -m pip install ${INSTALL_DIR}/openvino_tokenizers-* | ||
- name: Install JAX tests requirements for precommit | ||
run: | | ||
python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/jax/requirements.txt | ||
- name: JAX/Flax Models Tests from Hugging Face | ||
if: ${{ inputs.model_scope == 'precommit' || inputs.model_scope == 'nightly' }} | ||
run: | | ||
export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH | ||
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/jax/ -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-jax_model_${{ inputs.model_scope }}_tests.html --self-contained-html -v | ||
env: | ||
TYPE: ${{ inputs.model_scope == 'precommit' && 'precommit' || 'nightly' }} | ||
TEST_DEVICE: CPU | ||
|
||
- name: Upload Test Results | ||
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 | ||
if: ${{ !cancelled() }} | ||
with: | ||
name: test-results-jax-models-${{ inputs.model_scope }} | ||
path: | | ||
${{ env.INSTALL_TEST_DIR }}/TEST*.html | ||
if-no-files-found: 'error' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (C) 2018-2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import jax | ||
import numpy as np | ||
import pytest | ||
from jax import numpy as jnp | ||
|
||
from jax_layer_test_class import JaxLayerTest | ||
|
||
rng = np.random.default_rng(109734) | ||
|
||
|
||
class TestErf(JaxLayerTest): | ||
def _prepare_input(self): | ||
# erf are mostly changing in a range [-4, 4] | ||
x = rng.uniform(-4.0, 4.0, self.input_shape).astype(self.input_type) | ||
|
||
x = jnp.array(x) | ||
return [x] | ||
|
||
def create_model(self, input_shape, input_type): | ||
self.input_shape = input_shape | ||
self.input_type = input_type | ||
|
||
def jax_erf(x): | ||
return jax.lax.erf(x) | ||
|
||
return jax_erf, None, 'erf' | ||
|
||
@pytest.mark.parametrize("input_shape", [[2], [3, 4]]) | ||
@pytest.mark.parametrize("input_type", [np.float16, np.float32, np.float64]) | ||
@pytest.mark.nightly | ||
@pytest.mark.precommit | ||
@pytest.mark.precommit_jax_fe | ||
def test_erf(self, ie_device, precision, ir_version, input_shape, input_type): | ||
self._test(*self.create_model(input_shape, input_type), | ||
ie_device, precision, | ||
ir_version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright (C) 2018-2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import inspect | ||
|
||
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# type,name,mark,reason | ||
# top transformers from https://huggingface.co/docs/transformers/index | ||
vit-base,google/vit-base-patch16-224-in21k | ||
albert-base-v2,albert/albert-base-v2,skip,No conversion rule found for iota pjit select_n | ||
bart-base,facebook/bart-base,skip,No conversion rule found for and eq ge gt iota ne pjit scatter select_n | ||
clip-vit-base-patch32,openai/clip-vit-base-patch32,skip,No conversion rule found for and argmax gather ge gt iota logistic lt ne pjit select_n | ||
Mistral-tiny,ksmcg/Mistral-tiny,skip,No conversion rule found for and gather ge gt iota lt ne neg pjit select_n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (C) 2018-2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import flax | ||
import jax | ||
import numpy as np | ||
from models_hub_common.test_convert_model import TestConvertModel | ||
from openvino import convert_model | ||
|
||
|
||
def flattenize_pytree(outputs): | ||
leaves, _ = jax.tree_util.tree_flatten(outputs) | ||
return [np.array(i) if isinstance(i, jax.Array) else i for i in leaves] | ||
|
||
|
||
class TestJaxConvertModel(TestConvertModel): | ||
def get_inputs_info(self, _): | ||
return None | ||
|
||
def prepare_inputs(self, _): | ||
inputs = getattr(self, 'inputs', self.example) | ||
return inputs | ||
|
||
def convert_model(self, model_obj): | ||
if isinstance(model_obj, flax.linen.Module): | ||
ov_model = convert_model(model_obj, example_input=self.example, verbose=True) | ||
else: | ||
# create JAXpr object | ||
jaxpr = jax.make_jaxpr(model_obj)(**self.example) | ||
ov_model = convert_model(jaxpr, verbose=True) | ||
return ov_model | ||
|
||
def infer_fw_model(self, model_obj, inputs): | ||
if isinstance(inputs, dict): | ||
fw_outputs = model_obj(**inputs) | ||
elif isinstance(inputs, list): | ||
fw_outputs = model_obj(*inputs) | ||
else: | ||
fw_outputs = model_obj(inputs) | ||
return flattenize_pytree(fw_outputs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-c ../../constraints.txt | ||
numpy | ||
pytest | ||
pytest-html | ||
transformers | ||
requests | ||
jax | ||
jaxlib | ||
flax | ||
pillow |
Oops, something went wrong.