Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

Collect more data about ONNX Models Tests sporadic issue at tests collection (#26053)

Andrey Babushkinb9c38201873a
diff --git a/.github/workflows/job_onnx_models_tests.yml b/.github/workflows/job_onnx_models_tests.yml
index 9f0e3252286..f35b5772383 100644
--- a/.github/workflows/job_onnx_models_tests.yml
+++ b/.github/workflows/job_onnx_models_tests.yml
@@ -57,6 +57,7 @@ jobs:
echo "INSTALL_TEST_DIR=$GITHUB_WORKSPACE/install/tests" >> "$GITHUB_ENV"
echo "MODELS_SHARE_PATH=/mount/testdata$((GITHUB_RUN_NUMBER % NUMBER_OF_REPLICAS))" >> "$GITHUB_ENV"
echo $MODELS_SHARE_PATH
+ echo "LOGS_FOLDER=$GITHUB_WORKSPACE/onnx_models_tests_logs" >> "$GITHUB_ENV"
- name: Extract OpenVINO packages
run: |
@@ -68,16 +69,20 @@ jobs:
tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR}
popd
- - name: Fetch model_zoo_preprocess script
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- with:
- sparse-checkout: |
- src/frontends/onnx/tests/tests_python/model_zoo_preprocess.sh
- sparse-checkout-cone-mode: false
- path: 'openvino'
+ # Issue 148922
+ # Can be a possible root cause for the bug
+ # Uncomment only when there's a need
+ # to update the models on the shared drive
+ # - name: Fetch model_zoo_preprocess script
+ # uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
+ # with:
+ # sparse-checkout: |
+ # src/frontends/onnx/tests/tests_python/model_zoo_preprocess.sh
+ # sparse-checkout-cone-mode: false
+ # path: 'openvino'
- - name: Update Models
- run: bash ${OPENVINO_REPO}/src/frontends/onnx/tests/tests_python/model_zoo_preprocess.sh -d ${MODELS_SHARE_PATH} -o -s "${{ env.ONNX_MODEL_ZOO_SHA }}"
+ # - name: Update Models
+ # run: bash ${OPENVINO_REPO}/src/frontends/onnx/tests/tests_python/model_zoo_preprocess.sh -d ${MODELS_SHARE_PATH} -o -s "${{ env.ONNX_MODEL_ZOO_SHA }}"
- name: Install OpenVINO Python wheels
run: |
@@ -95,7 +100,24 @@ jobs:
- name: Install Python tests dependencies
run: |
# To enable pytest parallel features
- python3 -m pip install pytest-xdist[psutil] pytest-forked pytest-randomly
+ python3 -m pip install pytest-xdist[psutil] pytest-forked
+
+ - name: Find ONNX models
+ run: |
+ find ${MODELS_SHARE_PATH} -depth -type f -name "*.onnx" -print
+
+ - name: Collect ONNX Models tests
+ run: |
+ python3 -m pytest --backend="CPU" --model_zoo_dir="${MODELS_SHARE_PATH}" ${INSTALL_TEST_DIR}/onnx/tests/tests_python/test_zoo_models.py -v -n 1 -k 'not _cuda' --model_zoo_xfail --collect-only
- name: ONNX Models Tests
- run: python3 -m pytest --backend="CPU" --model_zoo_dir="${MODELS_SHARE_PATH}" ${INSTALL_TEST_DIR}/onnx/tests/tests_python/test_zoo_models.py -v -n 4 --forked -k 'not _cuda' --model_zoo_xfail
+ run: |
+ python3 -m pytest --backend="CPU" --model_zoo_dir="${MODELS_SHARE_PATH}" ${INSTALL_TEST_DIR}/onnx/tests/tests_python/test_zoo_models.py -v -n auto --forked -k 'not _cuda' --model_zoo_xfail
+
+ - name: Upload logs from pytest
+ uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
+ if: always()
+ with:
+ name: onnx_models_tests_logs
+ path: ${{ env.LOGS_FOLDER }}
+ if-no-files-found: 'ignore'
diff --git a/src/frontends/onnx/tests/conftest.py b/src/frontends/onnx/tests/conftest.py
index d5d6244ae63..10a404b63ba 100644
--- a/src/frontends/onnx/tests/conftest.py
+++ b/src/frontends/onnx/tests/conftest.py
@@ -3,9 +3,11 @@
# SPDX-License-Identifier: Apache-2.0
import os
+import sys
import pytest
import tests
+import logging
from pathlib import Path
@@ -49,6 +51,41 @@ def pytest_configure(config):
config.addinivalue_line("markers", "template_plugin")
config.addinivalue_line("markers", "dynamic_library: Runs tests only in dynamic libraries case")
+ # Issue 148922: trying to print what models
+ # were found to debug test cases generation issue
+ # Credits to https://stackoverflow.com/questions/36726461/how-to-print-output-when-using-pytest-with-xdist
+
+ # Determine pytest-xdist worker id
+ # Also see: https://pytest-xdist.readthedocs.io/en/latest/how-to.html#creating-one-log-file-for-each-worker
+ worker_id = os.environ.get("PYTEST_XDIST_WORKER", default="gw0")
+
+ # Create logs folder
+ logs_folder = os.environ.get("LOGS_FOLDER", default="logs_folder")
+ os.makedirs(logs_folder, exist_ok=True)
+
+ # Create file handler to output logs into corresponding worker file
+ file_handler = logging.FileHandler(f"{logs_folder}/logs_worker_{worker_id}.log", mode="w")
+ file_handler.setFormatter(
+ logging.Formatter(
+ fmt="{asctime} {levelname}:{name}:{lineno}:{message}",
+ style="{",
+ )
+ )
+
+ # Create stream handler to output logs on console
+ # This is a workaround for a known limitation:
+ # https://pytest-xdist.readthedocs.io/en/latest/known-limitations.html
+ console_handler = logging.StreamHandler(sys.stderr) # pytest only prints error logs
+ console_handler.setFormatter(
+ logging.Formatter(
+ # Include worker id in log messages, \r is needed to separate lines in console
+ fmt="\r{asctime} " + worker_id + ":{levelname}:{name}:{lineno}:{message}",
+ style="{",
+ )
+ )
+
+ # Configure logging
+ logging.basicConfig(level=logging.INFO, handlers=[console_handler, file_handler])
def pytest_collection_modifyitems(config, items):
backend_name = config.getvalue("backend")
diff --git a/src/frontends/onnx/tests/tests_python/test_zoo_models.py b/src/frontends/onnx/tests/tests_python/test_zoo_models.py
index 06f8f920157..b5cb6084870 100644
--- a/src/frontends/onnx/tests/tests_python/test_zoo_models.py
+++ b/src/frontends/onnx/tests/tests_python/test_zoo_models.py
@@ -2,6 +2,8 @@
# SPDX-License-Identifier: Apache-2.0
import tests
+import logging
+import pprint
from operator import itemgetter
from pathlib import Path
from typing import Sequence, Any
@@ -25,6 +27,8 @@ from tests import (
xfail_issue_onnx_models_140,
skip_issue_127649)
+logger = logging.getLogger()
+
MODELS_ROOT_DIR = tests.MODEL_ZOO_DIR
def yolov3_post_processing(outputs : Sequence[Any]) -> Sequence[Any]:
@@ -133,24 +137,30 @@ for path in Path(MODELS_ROOT_DIR).rglob("*.onnx"):
file_name = path.name
if path.is_file() and not file_name.startswith("."):
model = {"model_name": path, "model_file": file_name, "dir": mdir}
+ logger.info("Found model: %s", pprint.pformat(model))
basedir = mdir.stem
if basedir in tolerance_map:
# updated model looks now:
# {"model_name": path, "model_file": file, "dir": mdir, "atol": ..., "rtol": ...}
model.update(tolerance_map[basedir])
+ logger.info("Update model with a tolerance map: %s", pprint.pformat(model))
else:
# some models have the same stem, have to check if any of the keys from tolerance_map
# is found in the full model path
model_key = tolerance_map_key_in_model_path(str(path))
if model_key is not None:
model.update(tolerance_map[model_key])
+ logger.info("Update model with tolerance map with model_key: %s", pprint.pformat(model))
if basedir in post_processing:
model.update(post_processing[basedir])
+ logger.info("Update model with post_processing: %s", pprint.pformat(model))
zoo_models.append(model)
if len(zoo_models) > 0:
zoo_models = sorted(zoo_models, key=itemgetter("model_name"))
+ logger.info("Sorted zoo_models list of dictionaries: %s", pprint.pformat(zoo_models))
+
# Set backend device name to be used instead of hardcoded by ONNX BackendTest class ones.
OpenVinoOnnxBackend.backend_name = tests.BACKEND_NAME
# import all test cases at global scope to make them visible to pytest
@@ -169,6 +179,7 @@ if len(zoo_models) > 0:
xfail, test_name = test_case
xfail(getattr(test_cases, test_name))
+ logger.info("Test cases before first deletion: %s", pprint.pformat(test_cases))
del test_cases
test_cases = backend_test.test_cases["OnnxBackendModelExecutionTest"]
@@ -205,6 +216,11 @@ if len(zoo_models) > 0:
xfail, test_name = test_case
xfail(getattr(test_cases, test_name))
+ logger.info("Test cases before second deletion: %s", pprint.pformat(test_cases))
del test_cases
+ logger.info("Test cases before adding to globals: %s",
+ pprint.pformat(backend_test.enable_report().test_cases))
globals().update(backend_test.enable_report().test_cases)
+
+ logger.info("Globals: %s", pprint.pformat(globals()))