Skip to content

Commit

Permalink
[OV] Add caching of OMZ models (#2214)
Browse files Browse the repository at this point in the history
### Changes

Added cache_dir for OMZ models

### Reason for changes

* Сhanges made according to the requirements of the validation team

### Related tickets

<!--- Post the numerical ID of the ticket, if available -->

### Tests

<!--- How was the correctness of changes tested and whether new tests
were added -->
  • Loading branch information
l-bat authored Oct 25, 2023
1 parent 8c10eea commit 9cc57c0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
12 changes: 11 additions & 1 deletion tests/openvino/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ def data(request):
return Path(option)


@pytest.fixture(name="omz_cache_dir")
def models(request):
option = request.config.getoption("--data")
if option is None:
return Path(MODELS_PATH)
return Path(option)


# Custom markers specifying tests to be run only if a specific option
# is present on the pytest command line must be registered here.
MARKS_VS_OPTIONS = {**COMMON_SCOPE_MARKS_VS_OPTIONS}
Expand All @@ -46,4 +54,6 @@ def pytest_collection_modifyitems(config, items):
OPENVINO_NATIVE_TEST_ROOT = OPENVINO_TEST_ROOT / "native"
AC_CONFIGS_DIR = OPENVINO_TEST_ROOT / "data" / "ac_configs"
OPENVINO_DATASET_DEFINITIONS_PATH = OPENVINO_TEST_ROOT / "data" / "ov_dataset_definitions.yml"
DATASET_PATH = "~/.cache/nncf/datasets"
NNCF_CACHE_PATH = Path("~/.cache/nncf")
DATASET_PATH = NNCF_CACHE_PATH / "datasets"
MODELS_PATH = NNCF_CACHE_PATH / "models"
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def test_overflow_fix_scales(overflow_fix):
ids=[QuantizationPreset.PERFORMANCE.value, QuantizationPreset.MIXED.value],
)
@pytest.mark.parametrize("model_name", OMZ_MODELS)
def test_omz_models_fq_scales(model_name, preset, inplace_statistics, tmp_path):
download_model(model_name, tmp_path)
def test_omz_models_fq_scales(model_name, preset, inplace_statistics, tmp_path, omz_cache_dir):
download_model(model_name, tmp_path, omz_cache_dir)
convert_model(model_name, tmp_path)
model_path = tmp_path / "public" / model_name / "FP32" / f"{model_name}.xml"
model = ov.Core().read_model(model_path)
Expand Down
8 changes: 4 additions & 4 deletions tests/openvino/native/quantization/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def test_depthwise_models_fq_placement(model_creator_func):


@pytest.mark.parametrize("model_name_params", OMZ_MODELS_QUANTIZE_PARAMS.items(), ids=list(OMZ_MODELS_QUANTIZE_PARAMS))
def test_omz_models_fq_placement(model_name_params, tmp_path):
def test_omz_models_fq_placement(model_name_params, tmp_path, omz_cache_dir):
model_name, q_params = model_name_params
params_str = "_".join([param.value for param in q_params.values()])
q_params.update({"inplace_statistics": True})
download_model(model_name, tmp_path)
download_model(model_name, tmp_path, omz_cache_dir)
convert_model(model_name, tmp_path)
model_path = tmp_path / "public" / model_name / "FP32" / f"{model_name}.xml"
model = ov.Core().read_model(model_path)
Expand Down Expand Up @@ -116,10 +116,10 @@ def test_transformer_models_fq_placement(model_creator_func, tmp_path):


@pytest.mark.parametrize("model_name_params", OMZ_MODELS_SQ_PARAMS.items(), ids=list(OMZ_MODELS_SQ_PARAMS))
def test_omz_models_sq_placement(model_name_params, tmp_path):
def test_omz_models_sq_placement(model_name_params, tmp_path, omz_cache_dir):
model_name, q_params = model_name_params
q_params.update({"inplace_statistics": True})
download_model(model_name, tmp_path)
download_model(model_name, tmp_path, omz_cache_dir)
convert_model(model_name, tmp_path)
model_path = tmp_path / "public" / model_name / "FP32" / f"{model_name}.xml"
model = ov.Core().read_model(model_path)
Expand Down
4 changes: 2 additions & 2 deletions tests/openvino/native/quantization/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
@pytest.mark.parametrize(
"model, dataset, ref_metrics, advanced_params", OMZ_MODELS, ids=[model[0] for model in OMZ_MODELS]
)
def test_compression(data_dir, tmp_path, model, dataset, ref_metrics, advanced_params):
def test_compression(data_dir, tmp_path, model, dataset, ref_metrics, advanced_params, omz_cache_dir):
extracted_data_dir = os.path.dirname(get_dataset_for_test(dataset, data_dir))
config_path = AC_CONFIGS_DIR / f"{model}.yml"

download_model(model, tmp_path)
download_model(model, tmp_path, omz_cache_dir)
convert_model(model, tmp_path)
model_path = tmp_path / "public" / model / "FP32" / f"{model}.xml"

Expand Down
4 changes: 2 additions & 2 deletions tests/openvino/native/test_nncf_graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def test_compare_nncf_graph_synthetic_models(model_cls_to_test):


@pytest.mark.parametrize("model_name", OMZ_MODELS)
def test_compare_nncf_graph_omz_models(tmp_path, model_name):
download_model(model_name, tmp_path)
def test_compare_nncf_graph_omz_models(tmp_path, omz_cache_dir, model_name):
download_model(model_name, tmp_path, omz_cache_dir)
convert_model(model_name, tmp_path)
model_path = tmp_path / "public" / model_name / "FP32" / f"{model_name}.xml"
model = ov.Core().read_model(model_path)
Expand Down
4 changes: 2 additions & 2 deletions tests/openvino/omz_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def run_command(command: List[str]):
return cmd_output


def download_model(name, path):
com_line = ["omz_downloader", "--name", name, "-o", str(path)]
def download_model(name, path, omz_cache_dir):
com_line = ["omz_downloader", "--name", name, "-o", str(path), "--cache_dir", str(omz_cache_dir)]
_ = run_command(com_line)


Expand Down
4 changes: 2 additions & 2 deletions tests/openvino/pot/quantization/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@


@pytest.mark.parametrize("model, dataset, ref_metrics", OMZ_MODELS, ids=[model[0] for model in OMZ_MODELS])
def test_compression(data_dir, tmp_path, model, dataset, ref_metrics):
def test_compression(data_dir, tmp_path, omz_cache_dir, model, dataset, ref_metrics):
extracted_data_dir = os.path.dirname(get_dataset_for_test(dataset, data_dir))
config_path = AC_CONFIGS_DIR / f"{model}.yml"

download_model(model, tmp_path)
download_model(model, tmp_path, omz_cache_dir)
convert_model(model, tmp_path)
model_path = tmp_path / "public" / model / "FP32" / f"{model}.xml"

Expand Down

0 comments on commit 9cc57c0

Please sign in to comment.