Skip to content

Commit 93d63f8

Browse files
mryzhovWovchena
andauthored
[GHA] Replaced isual_language_chat_sample-ubuntu-minicpm_v2_6 job (openvinotoolkit#1909)
Moved tests to Linux/Windows pipelines --------- Co-authored-by: Vladimir Zlobin <vladimir.zlobin@intel.com>
1 parent e8aaedf commit 93d63f8

File tree

7 files changed

+107
-112
lines changed

7 files changed

+107
-112
lines changed

.github/workflows/causal_lm_cpp.yml

Lines changed: 1 addition & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -89,100 +89,6 @@ jobs:
8989
diff pred2.txt ref.txt
9090
echo "Chat sample python" passed
9191
92-
visual_language_chat_sample-ubuntu-minicpm_v2_6:
93-
runs-on: ubuntu-22.04-16-cores
94-
steps:
95-
- uses: actions/checkout@v4
96-
with:
97-
submodules: recursive
98-
- uses: actions/setup-python@v4
99-
with:
100-
python-version: 3.11
101-
- uses: ./.github/actions/install_openvino
102-
with:
103-
ov_link: ${{ env.l_u22_ov_link }}
104-
- uses: ./.github/actions/build_app
105-
with:
106-
build_target: 'visual_language_chat benchmark_vlm py_openvino_genai'
107-
- uses: ./.github/actions/install_python_deps
108-
- name: Download and convert tiny-random-minicpmv-2_6 model and an image
109-
run: |
110-
source ./ov/setupvars.sh
111-
optimum-cli export openvino -m katuni4ka/tiny-random-minicpmv-2_6 tiny-random-minicpmv-2_6 --trust-remote-code --task image-text-to-text
112-
mkdir images
113-
- name: Generate images - tiny-random-minicpmv-2_6
114-
shell: python
115-
run: |
116-
from PIL import Image
117-
import numpy as np
118-
import requests
119-
res = 28, 28
120-
lines = np.arange(res[0] * res[1] * 3, dtype=np.uint8) % 255
121-
lines = lines.reshape([*res, 3])
122-
lines_image = Image.fromarray(lines)
123-
lines_image.save("images/lines.png")
124-
cat = Image.open(requests.get("https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/d5fbbd1a-d484-415c-88cb-9986625b7b11", stream=True).raw).convert('RGB')
125-
cat.save("images/cat.png")
126-
- name: Run visual_language_chat C++ sample - tiny-random-minicpmv-2_6
127-
run: >
128-
set -o pipefail
129-
&& source ./ov/setupvars.sh
130-
&& ./build/samples/cpp/visual_language_chat/visual_language_chat ./tiny-random-minicpmv-2_6/ ./images/
131-
<<< $'Describe the images?' | tee cpp.txt
132-
timeout-minutes: 2
133-
- name: Run benchmark_vlm C++ sample - tiny-random-minicpmv-2_6
134-
run: >
135-
set -o pipefail
136-
&& source ./ov/setupvars.sh
137-
&& ./build/samples/cpp/visual_language_chat/benchmark_vlm -m ./tiny-random-minicpmv-2_6/ -i ./images/cat.png -n 3
138-
timeout-minutes: 2
139-
- name: Run visual_language_chat Python sample - tiny-random-minicpmv-2_6
140-
run: >
141-
set -o pipefail
142-
&& source ./ov/setupvars.sh
143-
&& ./samples/python/visual_language_chat/visual_language_chat.py ./tiny-random-minicpmv-2_6/ ./images/
144-
<<< $'Describe the images?' | tee py.txt
145-
env:
146-
PYTHONPATH: "./build/"
147-
- name: Run benchmark_vlm Python sample - tiny-random-minicpmv-2_6
148-
run: >
149-
set -o pipefail
150-
&& source ./ov/setupvars.sh
151-
&& ./samples/python/visual_language_chat/benchmark_vlm.py -m ./tiny-random-minicpmv-2_6/ -i ./images/cat.png -n 3
152-
env:
153-
PYTHONPATH: "./build/"
154-
- name: Encode cpp.txt with Python encoding instead of terminal one
155-
shell: python
156-
run: |
157-
with open("cpp.txt", "rb") as f:
158-
content = f.read().decode("utf-8", "replace")
159-
with open("cpp.txt", "wb") as f:
160-
f.write(content.encode("utf-8"))
161-
- run: diff cpp.txt py.txt
162-
- name: Run visual_language_chat C++ sample with 2 prompts - tiny-random-minicpmv-2_6
163-
run: >
164-
set -o pipefail
165-
&& source ./ov/setupvars.sh
166-
&& ./build/samples/cpp/visual_language_chat/visual_language_chat ./tiny-random-minicpmv-2_6/ ./images/cat.png
167-
<<< $'What is unusual on this image?\nGo on.' | tee cpp2.txt
168-
timeout-minutes: 2
169-
- name: Run visual_language_chat Python sample with 2 prompts - tiny-random-minicpmv-2_6
170-
run: >
171-
set -o pipefail
172-
&& source ./ov/setupvars.sh
173-
&& ./samples/python/visual_language_chat/visual_language_chat.py ./tiny-random-minicpmv-2_6/ ./images/cat.png
174-
<<< $'What is unusual on this image?\nGo on.' | tee py2.txt
175-
env:
176-
PYTHONPATH: "./build/"
177-
- name: Encode cpp2.txt with Python encoding instead of terminal one
178-
shell: python
179-
run: |
180-
with open("cpp2.txt", "rb") as f:
181-
content = f.read().decode("utf-8", "replace")
182-
with open("cpp2.txt", "wb") as f:
183-
f.write(content.encode("utf-8"))
184-
- run: diff cpp2.txt py2.txt
185-
18692
cpp-continuous-batching-ubuntu:
18793
runs-on: ubuntu-22.04-8-cores
18894
defaults:
@@ -320,8 +226,7 @@ jobs:
320226
321227
Overall_Status:
322228
name: ci/gha_overall_status_causal_lm
323-
needs: [cpp-chat_sample-ubuntu, cpp-continuous-batching-ubuntu,
324-
visual_language_chat_sample-ubuntu-minicpm_v2_6, cpp-continuous-batching-windows, cpp-continuous-batching-macos]
229+
needs: [cpp-chat_sample-ubuntu, cpp-continuous-batching-ubuntu, cpp-continuous-batching-windows, cpp-continuous-batching-macos]
325230
if: ${{ always() }}
326231
runs-on: ubuntu-latest
327232
steps:

tests/python_tests/samples/conftest.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
"name": "OpenVINO/LCM_Dreamshaper_v7-int8-ov",
7878
"convert_args": []
7979
},
80+
"tiny-random-minicpmv-2_6": {
81+
"name": "katuni4ka/tiny-random-minicpmv-2_6",
82+
"convert_args": ['--trust-remote-code', "--task", "image-text-to-text"]
83+
},
8084
"InternVL2-1B": {
8185
"name": "OpenGVLab/InternVL2-1B",
8286
"convert_args": ['--trust-remote-code']
@@ -92,8 +96,8 @@
9296
"adapter_model.safetensors": "https://huggingface.co/smangrul/tinyllama_lora_sql/resolve/main/adapter_model.safetensors",
9397
"monalisa.jpg": "https://llava-vl.github.io/static/images/monalisa.jpg",
9498
"soulcard.safetensors": "https://civitai.com/api/download/models/72591",
95-
"image.png": "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png",
96-
"mask_image.png": "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
99+
"images/image.png": "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png",
100+
"mask_image.png": "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png",
97101
}
98102

99103
SAMPLES_PY_DIR = os.environ.get("SAMPLES_PY_DIR", os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../samples/python")))
@@ -198,7 +202,8 @@ def download_test_content(request):
198202
file_url = TEST_FILES[file_name]
199203
file_path = os.path.join(test_data, file_name)
200204
if not os.path.exists(file_path):
201-
logger.info(f"Downloading test content from {file_url}...")
205+
logger.info(f"Downloading test content from {file_url} to {file_path}...")
206+
os.makedirs(os.path.dirname(file_path), exist_ok=True)
202207
response = requests.get(file_url, stream=True)
203208
response.raise_for_status()
204209
with open(file_path, 'wb') as f:
@@ -215,6 +220,35 @@ def download_test_content(request):
215220
os.remove(file_path)
216221

217222

223+
@pytest.fixture(scope="session")
224+
def generate_test_content(request):
225+
"""Generate an image of lines and return the file path."""
226+
227+
test_data = request.config.cache.get("TEST_DATA", None)
228+
229+
file_name = request.param
230+
file_path = os.path.join(test_data, file_name)
231+
if not os.path.exists(file_path):
232+
os.makedirs(os.path.dirname(file_path), exist_ok=True)
233+
234+
from PIL import Image
235+
import numpy as np
236+
res = 28, 28
237+
lines = np.arange(res[0] * res[1] * 3, dtype=np.uint8) % 255
238+
lines = lines.reshape([*res, 3])
239+
lines_image = Image.fromarray(lines)
240+
lines_image.save(file_path)
241+
logger.info(f"Generated test content {file_path}")
242+
else:
243+
logger.info(f"Test content already exists at {file_path}")
244+
yield file_path
245+
# Cleanup the test content after tests
246+
if os.environ.get("CLEANUP_CACHE", "false").lower() == "true":
247+
if os.path.exists(file_path):
248+
logger.info(f"Removing test content: {file_path}")
249+
os.remove(file_path)
250+
251+
218252
@pytest.fixture(scope="module", autouse=True)
219253
def run_gc_after_test():
220254
"""

tests/python_tests/samples/test_benchmark_image_gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TestBenchmarkImageGen:
2323
@pytest.mark.parametrize(
2424
"download_test_content, download_mask_image",
2525
[
26-
pytest.param("image.png", "mask_image.png"),
26+
pytest.param("images/image.png", "mask_image.png"),
2727
], indirect=["download_test_content", "download_mask_image"],
2828
)
2929
def test_sample_benchmark_image_gen(self, download_model, pipeline_type, prompt, download_test_content, download_mask_image):
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (C) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
import os
5+
import pytest
6+
import sys
7+
8+
from conftest import SAMPLES_PY_DIR, SAMPLES_CPP_DIR
9+
from test_utils import run_sample
10+
11+
class TestBenchmarkVLM:
12+
@pytest.mark.vlm
13+
@pytest.mark.samples
14+
@pytest.mark.parametrize(
15+
"convert_model, download_test_content",
16+
[
17+
pytest.param("tiny-random-minicpmv-2_6", "images/image.png"),
18+
],
19+
indirect=["convert_model", "download_test_content"],
20+
)
21+
def test_sample_benchmark_vlm(self, convert_model, download_test_content):
22+
num_iter = "3"
23+
# Run C++ benchmark sample
24+
benchmark_sample = os.path.join(SAMPLES_CPP_DIR, 'benchmark_vlm')
25+
benchmark_cpp_command = [benchmark_sample, "-m" , convert_model, "-i", download_test_content, "-n", num_iter]
26+
run_sample(benchmark_cpp_command)
27+
28+
# Run Python benchmark sample
29+
benchmark_script = os.path.join(SAMPLES_PY_DIR, 'visual_language_chat/benchmark_vlm.py')
30+
benchmark_py_command = [sys.executable, benchmark_script, "-m" , convert_model, "-i", download_test_content, "-n", num_iter]
31+
run_sample(benchmark_py_command)

tests/python_tests/samples/test_image2image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TestImage2Image:
1818
],
1919
indirect=["download_model"],
2020
)
21-
@pytest.mark.parametrize("download_test_content", ["image.png"], indirect=True)
21+
@pytest.mark.parametrize("download_test_content", ["images/image.png"], indirect=True)
2222
def test_sample_image2image(self, download_model, prompt, download_test_content):
2323
# Run Python sample
2424
py_script = os.path.join(SAMPLES_PY_DIR, "image_generation/image2image.py")

tests/python_tests/samples/test_inpainting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TestInpainting:
2323
@pytest.mark.parametrize(
2424
"download_test_content, download_mask_image",
2525
[
26-
pytest.param("image.png", "mask_image.png"),
26+
pytest.param("images/image.png", "mask_image.png"),
2727
],
2828
indirect=["download_test_content", "download_mask_image"],
2929
)

tests/python_tests/samples/test_visual_language_chat.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,54 @@ class TestVisualLanguageChat:
1212
@pytest.mark.vlm
1313
@pytest.mark.samples
1414
@pytest.mark.parametrize(
15-
"convert_model, sample_args",
15+
"convert_model, download_test_content, questions",
1616
[
17-
pytest.param("llava-1.5-7b-hf", 'Who drew this painting?\nWhen did the painter live?'),
18-
pytest.param("llava-v1.6-mistral-7b-hf", 'Who drew this painting?\nWhen did the painter live?'),
19-
pytest.param("InternVL2-1B", 'Who drew this painting?\nWhen did the painter live?'),
20-
pytest.param("Qwen2-VL-2B-Instruct", 'Who drew this painting?\nWhen did the painter live?'),
17+
pytest.param("llava-1.5-7b-hf", "monalisa.jpg", 'Who drew this painting?\nWhen did the painter live?'),
18+
pytest.param("llava-v1.6-mistral-7b-hf", "monalisa.jpg", 'Who drew this painting?\nWhen did the painter live?'),
19+
pytest.param("InternVL2-1B", "monalisa.jpg", 'Who drew this painting?\nWhen did the painter live?'),
20+
pytest.param("Qwen2-VL-2B-Instruct", "monalisa.jpg", 'Who drew this painting?\nWhen did the painter live?'),
21+
pytest.param("tiny-random-minicpmv-2_6", "images/image.png", 'What is unusual on this image?\nGo on.')
2122
],
22-
indirect=["convert_model"],
23+
indirect=["convert_model", "download_test_content"],
2324
)
24-
@pytest.mark.parametrize("download_test_content", ["monalisa.jpg"], indirect=True)
25-
def test_sample_visual_language_chat(self, request, convert_model, download_test_content, sample_args):
25+
def test_sample_visual_language_chat(self, request, convert_model, download_test_content, questions):
2626
model_name = request.node.callspec.params['convert_model']
2727

2828
# Test Python sample
2929
py_script = os.path.join(SAMPLES_PY_DIR, "visual_language_chat/visual_language_chat.py")
3030
py_command = [sys.executable, py_script, convert_model, download_test_content]
31-
py_result = run_sample(py_command, sample_args)
31+
py_result = run_sample(py_command, questions)
3232

3333
# Test CPP sample
3434
cpp_sample = os.path.join(SAMPLES_CPP_DIR, 'visual_language_chat')
3535
cpp_command =[cpp_sample, convert_model, download_test_content]
36-
cpp_result = run_sample(cpp_command, sample_args)
36+
cpp_result = run_sample(cpp_command, questions)
3737

3838
# Compare results
3939
if model_name != "Qwen2-VL-2B-Instruct": # "Skipping result comparison for Qwen2-VL-2B-Instruct due to CVS-164144"
4040
assert py_result.stdout == cpp_result.stdout, f"Results should match"
41+
42+
@pytest.mark.vlm
43+
@pytest.mark.samples
44+
@pytest.mark.parametrize(
45+
"convert_model, questions",
46+
[
47+
pytest.param("tiny-random-minicpmv-2_6", 'Describe the images?'),
48+
],
49+
indirect=["convert_model"],
50+
)
51+
@pytest.mark.parametrize("download_test_content", ["images/image.png"], indirect=True)
52+
@pytest.mark.parametrize("generate_test_content", ["images/lines.png"], indirect=True)
53+
def test_sample_visual_language_chat_images(self, convert_model, download_test_content, generate_test_content, questions):
54+
# Test Python sample
55+
py_script = os.path.join(SAMPLES_PY_DIR, "visual_language_chat/visual_language_chat.py")
56+
py_command = [sys.executable, py_script, convert_model, os.path.dirname(generate_test_content)]
57+
py_result = run_sample(py_command, questions)
58+
59+
# Test CPP sample
60+
cpp_sample = os.path.join(SAMPLES_CPP_DIR, 'visual_language_chat')
61+
cpp_command =[cpp_sample, convert_model, os.path.dirname(generate_test_content)]
62+
cpp_result = run_sample(cpp_command, questions)
63+
64+
# Compare results
65+
assert py_result.stdout == cpp_result.stdout, f"Results should match"

0 commit comments

Comments
 (0)