Added test validating inference results after conditional compilation (#4840)
This commit is contained in:
parent
0fcb6d0464
commit
070201feee
@ -8,20 +8,18 @@
|
|||||||
""" Pytest configuration for compilation tests.
|
""" Pytest configuration for compilation tests.
|
||||||
|
|
||||||
Sample usage:
|
Sample usage:
|
||||||
python3 -m pytest --artifacts ./compiled --test_conf=<path to test config> \
|
python3 -m pytest --test_conf=<path to test config> \
|
||||||
--sea_runtool=./IntelSEAPI/runtool/sea_runtool.py \
|
--sea_runtool=./thirdparty/itt_collector/runtool/sea_runtool.py --artifacts ./compiled test_collect.py \
|
||||||
--benchmark_app=./bin/benchmark_app test_collect.py
|
--collector_dir=./bin/intel64/Release --artifacts=<path to directory where tests write output or read input> \
|
||||||
|
--openvino_ref=<Path to root directory with installed OpenVINO>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import pytest
|
import pytest
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from inspect import getsourcefile
|
from inspect import getsourcefile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from tests_utils import write_session_info, SESSION_INFO_FILE
|
|
||||||
|
|
||||||
# add ../lib to imports
|
# add ../lib to imports
|
||||||
sys.path.insert(0, str((Path(getsourcefile(lambda: 0)) / ".." / ".." / "lib").resolve(strict=True)))
|
sys.path.insert(0, str((Path(getsourcefile(lambda: 0)) / ".." / ".." / "lib").resolve(strict=True)))
|
||||||
|
|
||||||
@ -41,11 +39,6 @@ def pytest_addoption(parser):
|
|||||||
type=Path,
|
type=Path,
|
||||||
help="Path to sea_runtool.py"
|
help="Path to sea_runtool.py"
|
||||||
)
|
)
|
||||||
parser.addoption(
|
|
||||||
"--benchmark_app",
|
|
||||||
type=Path,
|
|
||||||
help="Path to the benchmark_app tool",
|
|
||||||
)
|
|
||||||
parser.addoption(
|
parser.addoption(
|
||||||
"--collector_dir",
|
"--collector_dir",
|
||||||
type=Path,
|
type=Path,
|
||||||
@ -85,37 +78,12 @@ def pytest_generate_tests(metafunc):
|
|||||||
metafunc.parametrize("test_id, model", params, ids=ids)
|
metafunc.parametrize("test_id, model", params, ids=ids)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
|
||||||
def test_info(request, pytestconfig):
|
|
||||||
"""Fixture function for getting the additional attributes of the current test."""
|
|
||||||
setattr(request.node._request, "test_info", {})
|
|
||||||
if not hasattr(pytestconfig, "session_info"):
|
|
||||||
setattr(pytestconfig, "session_info", [])
|
|
||||||
|
|
||||||
yield request.node._request.test_info
|
|
||||||
|
|
||||||
pytestconfig.session_info.append(request.node._request.test_info)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session", autouse=True)
|
|
||||||
def save_session_info(pytestconfig, artifacts):
|
|
||||||
"""Fixture function for saving additional attributes to configuration file."""
|
|
||||||
yield
|
|
||||||
write_session_info(path=artifacts / SESSION_INFO_FILE, data=pytestconfig.session_info)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def sea_runtool(request):
|
def sea_runtool(request):
|
||||||
"""Fixture function for command-line option."""
|
"""Fixture function for command-line option."""
|
||||||
return request.config.getoption("sea_runtool")
|
return request.config.getoption("sea_runtool")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
|
||||||
def benchmark_app(request):
|
|
||||||
"""Fixture function for command-line option."""
|
|
||||||
return request.config.getoption("benchmark_app")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def collector_dir(request):
|
def collector_dir(request):
|
||||||
"""Fixture function for command-line option."""
|
"""Fixture function for command-line option."""
|
||||||
|
@ -9,11 +9,32 @@
|
|||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import pytest
|
||||||
|
|
||||||
from proc_utils import cmd_exec # pylint: disable=import-error
|
from proc_utils import cmd_exec # pylint: disable=import-error
|
||||||
|
from tests_utils import write_session_info, SESSION_INFO_FILE, infer_tool
|
||||||
|
|
||||||
|
|
||||||
def test_cc_collect(test_id, model, sea_runtool, benchmark_app, collector_dir, artifacts, test_info):
|
@pytest.fixture(scope="function")
|
||||||
|
def test_info(request, pytestconfig):
|
||||||
|
"""Fixture function for getting the additional attributes of the current test."""
|
||||||
|
setattr(request.node._request, "test_info", {})
|
||||||
|
if not hasattr(pytestconfig, "session_info"):
|
||||||
|
setattr(pytestconfig, "session_info", [])
|
||||||
|
|
||||||
|
yield request.node._request.test_info
|
||||||
|
|
||||||
|
pytestconfig.session_info.append(request.node._request.test_info)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session")
|
||||||
|
def save_session_info(pytestconfig, artifacts):
|
||||||
|
"""Fixture function for saving additional attributes to configuration file."""
|
||||||
|
yield
|
||||||
|
write_session_info(path=artifacts / SESSION_INFO_FILE, data=pytestconfig.session_info)
|
||||||
|
|
||||||
|
|
||||||
|
def test_cc_collect(test_id, model, sea_runtool, collector_dir, artifacts, test_info, save_session_info):
|
||||||
""" Test conditional compilation statistics collection
|
""" Test conditional compilation statistics collection
|
||||||
:param test_info: custom `test_info` field of built-in `request` pytest fixture.
|
:param test_info: custom `test_info` field of built-in `request` pytest fixture.
|
||||||
contain a dictionary to store test metadata.
|
contain a dictionary to store test metadata.
|
||||||
@ -25,19 +46,20 @@ def test_cc_collect(test_id, model, sea_runtool, benchmark_app, collector_dir, a
|
|||||||
for path in prev_result:
|
for path in prev_result:
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
# run use case
|
# run use case
|
||||||
|
sys_executable = os.path.join(sys.prefix, 'python.exe') if sys.platform == "win32" \
|
||||||
|
else os.path.join(sys.prefix, 'bin', 'python')
|
||||||
return_code, output = cmd_exec(
|
return_code, output = cmd_exec(
|
||||||
[
|
[
|
||||||
sys.executable,
|
sys_executable,
|
||||||
str(sea_runtool),
|
str(sea_runtool),
|
||||||
f"--output={out}",
|
f"--output={out}",
|
||||||
f"--bindir={collector_dir}",
|
f"--bindir={collector_dir}",
|
||||||
"--app_status",
|
|
||||||
"!",
|
"!",
|
||||||
str(benchmark_app),
|
sys_executable,
|
||||||
"-d=CPU",
|
infer_tool,
|
||||||
f"-m={model}",
|
f"-m={model}",
|
||||||
"-niter=1",
|
"-d=CPU",
|
||||||
"-nireq=1",
|
f"-r={out}",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
out_csv = glob.glob(f"{out}.pid*.csv")
|
out_csv = glob.glob(f"{out}.pid*.csv")
|
||||||
|
@ -5,19 +5,14 @@
|
|||||||
|
|
||||||
""" Test inference with conditional compiled binaries.
|
""" Test inference with conditional compiled binaries.
|
||||||
"""
|
"""
|
||||||
import sys
|
|
||||||
from proc_utils import cmd_exec # pylint: disable=import-error
|
from tests_utils import run_infer
|
||||||
from install_pkg import get_openvino_environment # pylint: disable=import-error
|
|
||||||
|
|
||||||
|
|
||||||
def test_infer(test_id, model, artifacts):
|
def test_infer(test_id, model, artifacts):
|
||||||
""" Test inference with conditional compiled binaries
|
""" Test inference with conditional compiled binaries
|
||||||
"""
|
"""
|
||||||
install_prefix = artifacts / test_id / "install_pkg"
|
install_prefix = artifacts / test_id / "install_pkg"
|
||||||
exe_suffix = ".exe" if sys.platform == "win32" else ""
|
out = artifacts / test_id
|
||||||
benchmark_app = install_prefix / "bin" / f"benchmark_app{exe_suffix}"
|
returncode, output = run_infer(model, f"{out}_cc.npz", install_prefix)
|
||||||
returncode, _ = cmd_exec(
|
assert returncode == 0, f"Command exited with non-zero status {returncode}:\n {output}"
|
||||||
[str(benchmark_app), "-d=CPU", f"-m={model}", "-niter=1", "-nireq=1"],
|
|
||||||
env=get_openvino_environment(install_prefix),
|
|
||||||
)
|
|
||||||
assert returncode == 0, f"Command exited with non-zero status {returncode}"
|
|
||||||
|
29
tests/conditional_compilation/test_verify.py
Normal file
29
tests/conditional_compilation/test_verify.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# Copyright (C) 2021 Intel Corporation
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
""" Test to verify inference results.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from tests_utils import run_infer
|
||||||
|
|
||||||
|
|
||||||
|
def test_verify(test_id, model, artifacts, openvino_root_dir, tolerance=1e-6): # pylint: disable=too-many-arguments
|
||||||
|
""" Test verifying that inference results are equal
|
||||||
|
"""
|
||||||
|
out = artifacts / test_id
|
||||||
|
install_prefix = artifacts / test_id / "install_pkg"
|
||||||
|
out_file = f"{out}.npz"
|
||||||
|
out_file_cc = f"{out}_cc.npz"
|
||||||
|
returncode, output = run_infer(model, out_file, openvino_root_dir)
|
||||||
|
assert returncode == 0, f"Command exited with non-zero status {returncode}:\n {output}"
|
||||||
|
returncode, output = run_infer(model, out_file_cc, install_prefix)
|
||||||
|
assert returncode == 0, f"Command exited with non-zero status {returncode}:\n {output}"
|
||||||
|
reference_results = dict(np.load(out_file))
|
||||||
|
inference_results = dict(np.load(out_file_cc))
|
||||||
|
assert sorted(reference_results.keys()) == sorted(inference_results.keys()), \
|
||||||
|
"Results have different number of layers"
|
||||||
|
for layer in reference_results.keys():
|
||||||
|
assert np.allclose(reference_results[layer], inference_results[layer], tolerance), \
|
||||||
|
"Reference and inference results differ"
|
@ -4,13 +4,16 @@
|
|||||||
|
|
||||||
""" Utility functions for work with json test configuration file.
|
""" Utility functions for work with json test configuration file.
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
from inspect import getsourcefile
|
from inspect import getsourcefile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from proc_utils import cmd_exec # pylint: disable=import-error
|
||||||
|
from install_pkg import get_openvino_environment # pylint: disable=import-error
|
||||||
|
|
||||||
SESSION_INFO_FILE = "cc_tests.json"
|
SESSION_INFO_FILE = "cc_tests.json"
|
||||||
|
infer_tool = str((Path(getsourcefile(lambda: 0)) / ".." / "tools" / "infer_tool.py").resolve())
|
||||||
|
|
||||||
|
|
||||||
def read_session_info(path: Path = Path(getsourcefile(lambda: 0)).parent / SESSION_INFO_FILE):
|
def read_session_info(path: Path = Path(getsourcefile(lambda: 0)).parent / SESSION_INFO_FILE):
|
||||||
@ -23,3 +26,18 @@ def write_session_info(path: Path = Path(getsourcefile(lambda: 0)).parent / SESS
|
|||||||
data: dict = None):
|
data: dict = None):
|
||||||
with open(path, "w") as json_file:
|
with open(path, "w") as json_file:
|
||||||
json.dump(data, json_file, indent=4)
|
json.dump(data, json_file, indent=4)
|
||||||
|
|
||||||
|
|
||||||
|
def run_infer(model, out_file, install_dir):
|
||||||
|
""" Function running inference
|
||||||
|
"""
|
||||||
|
sys_executable = os.path.join(sys.prefix, 'python.exe') if sys.platform == "win32" \
|
||||||
|
else os.path.join(sys.prefix, 'bin', 'python')
|
||||||
|
returncode, output = cmd_exec(
|
||||||
|
[sys_executable,
|
||||||
|
infer_tool,
|
||||||
|
"-d=CPU", f"-m={model}", f"-r={out_file}"
|
||||||
|
],
|
||||||
|
env=get_openvino_environment(install_dir),
|
||||||
|
)
|
||||||
|
return returncode, output
|
||||||
|
Loading…
Reference in New Issue
Block a user