Skip to content

Commit f76e8cb

Browse files
authored
Base LLM pipeline testing refactoring and optimization (#2779)
## Description Ticket: Part of [CVS-173285](https://jira.devtools.intel.com/browse/CVS-173285)
1 parent 4c19821 commit f76e8cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2278
-1417
lines changed

tests/python_tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Argument `--model_ids` can be used to run tests selectively only for specific mo
3939
python -m pytest tests/python_tests/ -k "test_multibatch" --model_ids "TinyLlama/TinyLlama-1.1B-Chat-v1.0 Qwen/Qwen2-0.5B-Instruct"
4040
```
4141

42-
List of currently supported models can be found in tests/python_tests/models.py:get_models_list
42+
List of currently supported models can be found in tests/python_tests/data/models.py:get_models_list
4343

4444
## Test Samples
4545
To test samples, set the `SAMPLES_PY_DIR` and `SAMPLES_CPP_DIR` environment variables to the directories containing your Python samples and built C++ samples respectively. The `SAMPLES_CPP_DIR` should point to the folder with built C++ samples, which can be installed using `cmake --component samples_bin`. For example:

tests/python_tests/conftest.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import os
2+
import gc
23
import pytest
34
import shutil
45
import logging
5-
from utils.constants import get_ov_cache_models_dir
6+
from utils.constants import (
7+
get_ov_cache_dir,
8+
get_ov_cache_downloaded_models_dir,
9+
get_ov_cache_converted_models_dir,
10+
)
611

712
# Configure logging
813
logging.basicConfig(level=logging.INFO)
@@ -13,20 +18,23 @@
1318
def setup_and_teardown():
1419
"""Fixture to set up and tear down the temporary directories."""
1520

16-
ov_cache_models_dir = get_ov_cache_models_dir()
21+
ov_cache_dir = get_ov_cache_dir()
22+
ov_cache_downloaded_dir = get_ov_cache_downloaded_models_dir()
23+
ov_cache_converted_dir = get_ov_cache_converted_models_dir()
1724

18-
logger.info(f"Creating directory: {ov_cache_models_dir}")
19-
os.makedirs(ov_cache_models_dir, exist_ok=True)
25+
logger.info(f"Creating directories: {ov_cache_downloaded_dir}, {ov_cache_converted_dir}")
26+
ov_cache_downloaded_dir.mkdir(exist_ok=True, parents=True)
27+
ov_cache_converted_dir.mkdir(exist_ok=True, parents=True)
2028

2129
yield
2230

2331
if os.environ.get("CLEANUP_CACHE", "false").lower() != "false":
24-
if os.path.exists(ov_cache_models_dir):
25-
logger.info(f"Removing temporary directory: {ov_cache_models_dir}")
26-
shutil.rmtree(ov_cache_models_dir)
32+
if ov_cache_dir.exists():
33+
logger.info(f"Removing temporary directory: {ov_cache_dir}")
34+
shutil.rmtree(ov_cache_dir)
2735
else:
2836
logger.info(
29-
f"Skipped temporary directory cleanup because it doesn't exist: {ov_cache_models_dir}"
37+
f"Skipped temporary directory cleanup because it doesn't exist: {ov_cache_dir}"
3038
)
3139

3240

@@ -54,3 +62,14 @@ def pytest_addoption(parser):
5462

5563
def pytest_configure(config: pytest.Config):
5664
pytest.selected_model_ids = config.getoption("--model_ids", default=None)
65+
66+
67+
@pytest.fixture(scope="module", autouse=True)
68+
def run_gc_after_test():
69+
"""
70+
Fixture to run garbage collection after each test module.
71+
This is a workaround to minimize memory consumption during tests
72+
and allow the use of less powerful CI runners.
73+
"""
74+
yield
75+
gc.collect()

tests/python_tests/data/models.py

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,48 @@
11
# Copyright (C) 2024 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4-
from pathlib import Path
54
import pytest
6-
from os.path import sep
75

86

9-
def get_models_list():
10-
model_ids = [
7+
def get_models_list() -> tuple[str, ...]:
8+
model_ids: list[str] = [
119
"katuni4ka/tiny-random-phi3",
1210
]
1311
if pytest.selected_model_ids:
1412
model_ids = [model_id for model_id in model_ids if model_id in pytest.selected_model_ids.split(' ')]
1513

16-
return model_ids
14+
return tuple(model_ids)
1715

1816

19-
def get_chat_models_list():
20-
return [
21-
"Qwen/Qwen2-0.5B-Instruct",
22-
]
17+
CHAT_MODELS_LIST = (
18+
"Qwen/Qwen2-0.5B-Instruct",
19+
)
2320

2421

25-
def get_gguf_model_list():
26-
return [
22+
GGUF_MODEL_LIST = (
23+
{
24+
"hf_model_id": "HuggingFaceTB/SmolLM2-135M",
25+
"gguf_model_id": "prithivMLmods/SmolLM2-135M-GGUF",
26+
"gguf_filename": "SmolLM2-135M.F16.gguf",
27+
"dynamic_quantization_group_size": None,
28+
},
29+
{
30+
"gguf_model_id": "Qwen/Qwen2.5-0.5B-Instruct-GGUF",
31+
"gguf_filename": "qwen2.5-0.5b-instruct-q4_0.gguf",
32+
"dynamic_quantization_group_size": None,
33+
},
34+
pytest.param(
2735
{
2836
"hf_model_id": "HuggingFaceTB/SmolLM2-135M",
29-
"gguf_model_id": "prithivMLmods/SmolLM2-135M-GGUF",
30-
"gguf_filename": "SmolLM2-135M.F16.gguf",
31-
"dynamic_quantization_group_size": None,
32-
},
33-
{
34-
"gguf_model_id": "Qwen/Qwen2.5-0.5B-Instruct-GGUF",
35-
"gguf_filename": "qwen2.5-0.5b-instruct-q4_0.gguf",
37+
"gguf_model_id": "QuantFactory/SmolLM2-135M-GGUF",
38+
"gguf_filename": "SmolLM2-135M.Q4_1.gguf",
3639
"dynamic_quantization_group_size": None,
3740
},
38-
pytest.param(
39-
{
40-
"hf_model_id": "HuggingFaceTB/SmolLM2-135M",
41-
"gguf_model_id": "QuantFactory/SmolLM2-135M-GGUF",
42-
"gguf_filename": "SmolLM2-135M.Q4_1.gguf",
43-
"dynamic_quantization_group_size": None,
44-
},
45-
marks=pytest.mark.xfail(reason="Prediction mismatch. Ticket 172345", raises=AssertionError),
46-
),
47-
{
48-
"gguf_model_id": "sammysun0711/tiny-random-deepseek-distill-qwen-gguf",
49-
"gguf_filename": "tiny-random-deepseek-distill-qwen_q8_0.gguf",
50-
# Dummy gguf model accuracy is sensitive for dynamic quantization w/ small group size 32 (default), set group size as 64 explicitly instead
51-
"dynamic_quantization_group_size": "64",
52-
},
53-
]
41+
marks=pytest.mark.xfail(reason="Prediction mismatch. Ticket 172345", raises=AssertionError),
42+
),
43+
{
44+
"gguf_model_id": "sammysun0711/tiny-random-deepseek-distill-qwen-gguf",
45+
"gguf_filename": "tiny-random-deepseek-distill-qwen_q8_0.gguf",
46+
"dynamic_quantization_group_size": "64",
47+
},
48+
)

tests/python_tests/data/test_dataset.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
from openvino_genai import GenerationConfig
5-
from utils.generation_config import get_greedy, get_beam_search, get_multinomial_temperature
5+
from utils.generation_config import get_greedy, get_beam_search
66

77
def get_test_dataset() -> tuple[list[str], list[GenerationConfig]]:
88
prompts = [
@@ -11,10 +11,12 @@ def get_test_dataset() -> tuple[list[str], list[GenerationConfig]]:
1111
"What is your name?",
1212
"Tell me something about Canada"
1313
]
14+
1415
generation_configs = [
1516
get_greedy(),
1617
get_beam_search(),
1718
get_greedy(),
1819
get_beam_search(),
1920
]
21+
2022
return (prompts, generation_configs)

0 commit comments

Comments
 (0)