11import subprocess # nosec B404
22import os
3+ import json
34import pytest
45import shutil
56import logging
8990 "name" : "Qwen/Qwen2-VL-2B-Instruct" ,
9091 "convert_args" : ['--trust-remote-code' ]
9192 },
93+ "tiny-dummy-qwen2" : {
94+ "name" : "fxmarty/tiny-dummy-qwen2" ,
95+ "convert_args" : ['--trust-remote-code' ]
96+ },
97+ "tiny-random-qwen2" : {
98+ "name" : "fxmarty/tiny-dummy-qwen2" ,
99+ "convert_args" : ["--task" , "text-generation-with-past" , "--weight-format" , "fp16" ]
100+ },
101+ "tiny-random-qwen2-int8" : {
102+ "name" : "fxmarty/tiny-dummy-qwen2" ,
103+ "convert_args" : ["--task" , "text-generation-with-past" , "--weight-format" , "int8" ]
104+ },
105+ "tiny-random-latent-consistency" : {
106+ "name" : "echarlaix/tiny-random-latent-consistency" ,
107+ "convert_args" : ['--trust-remote-code' , '--weight-format' , 'fp16' ]
108+ },
109+ "tiny-random-latent-consistency-lora" : {
110+ "name" : "katuni4ka/tiny-random-latent-consistency-lora" ,
111+ "convert_args" : []
112+ },
113+ "tiny-random-llava" : {
114+ "name" : "katuni4ka/tiny-random-llava" ,
115+ "convert_args" : ["--trust-remote-code" , "--task" , "image-text-to-text" ]
116+ },
92117}
93118
94119TEST_FILES = {
99124 "ShareGPT_V3_unfiltered_cleaned_split.json" : "https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfiltered/resolve/main/ShareGPT_V3_unfiltered_cleaned_split.json" ,
100125 "images/image.png" : "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png" ,
101126 "mask_image.png" : "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png" ,
127+ "overture-creations.png" : "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png" ,
128+ "overture-creations-mask.png" : "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png" ,
129+ "cat.png" : "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png" ,
130+ "cat" : "https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/d5fbbd1a-d484-415c-88cb-9986625b7b11" ,
131+ "3283_1447_000.tar.gz" : "https://huggingface.co/datasets/facebook/multilingual_librispeech/resolve/main/data/mls_polish/train/audio/3283_1447_000.tar.gz"
102132}
103133
104134SAMPLES_PY_DIR = os .environ .get ("SAMPLES_PY_DIR" , os .path .abspath (os .path .join (os .path .dirname (__file__ ), "../../../samples/python" )))
@@ -196,13 +226,14 @@ def download_model(request):
196226
197227@pytest .fixture (scope = "session" )
198228def download_test_content (request ):
199- """Download the test content from the given URL and return the file path."""
229+ """Download the test content from the given URL and return the file path or extracted folder ."""
200230
201231 test_data = request .config .cache .get ("TEST_DATA" , None )
202232
203233 file_name = request .param
204234 file_url = TEST_FILES [file_name ]
205235 file_path = os .path .join (test_data , file_name )
236+
206237 if not os .path .exists (file_path ):
207238 logger .info (f"Downloading test content from { file_url } to { file_path } ..." )
208239 os .makedirs (os .path .dirname (file_path ), exist_ok = True )
@@ -214,9 +245,26 @@ def download_test_content(request):
214245 logger .info (f"Downloaded test content to { file_path } " )
215246 else :
216247 logger .info (f"Test content already exists at { file_path } " )
217- yield file_path
248+
249+ # If the file is a tarball, extract it
250+ extracted_dir = None
251+ if file_name .endswith (".tar.gz" ):
252+ extracted_dir = os .path .join (test_data , os .path .splitext (file_name )[0 ])
253+ if not os .path .exists (extracted_dir ):
254+ os .makedirs (extracted_dir , exist_ok = True )
255+ shutil .unpack_archive (file_path , extracted_dir )
256+ logger .info (f"Extracted tarball to { extracted_dir } " )
257+ else :
258+ logger .info (f"Extracted folder already exists at { extracted_dir } " )
259+ yield extracted_dir
260+ else :
261+ yield file_path
262+
218263 # Cleanup the test content after tests
219264 if os .environ .get ("CLEANUP_CACHE" , "false" ).lower () == "true" :
265+ if extracted_dir and os .path .exists (extracted_dir ):
266+ logger .info (f"Removing extracted folder: { extracted_dir } " )
267+ shutil .rmtree (extracted_dir )
220268 if os .path .exists (file_path ):
221269 logger .info (f"Removing test content: { file_path } " )
222270 os .remove (file_path )
@@ -250,6 +298,32 @@ def generate_test_content(request):
250298 logger .info (f"Removing test content: { file_path } " )
251299 os .remove (file_path )
252300
301+ @pytest .fixture (scope = "session" )
302+ def generate_image_generation_jsonl (request ):
303+ """Generate a JSONL file for image generation prompts."""
304+
305+ test_data = request .config .cache .get ("TEST_DATA" , None )
306+ file_name , json_entries = request .param
307+ file_path = os .path .join (test_data , file_name )
308+
309+ if not os .path .exists (file_path ):
310+ os .makedirs (os .path .dirname (file_path ), exist_ok = True )
311+
312+ with open (file_path , "w" ) as f :
313+ for entry in json_entries :
314+ f .write (json .dumps (entry ) + "\n " )
315+
316+ logger .info (f"Generated image generation JSONL file at { file_path } " )
317+ else :
318+ logger .info (f"Image generation JSONL file already exists at { file_path } " )
319+
320+ yield file_path
321+
322+ # Cleanup the JSONL file after tests
323+ if os .environ .get ("CLEANUP_CACHE" , "false" ).lower () == "true" :
324+ if os .path .exists (file_path ):
325+ logger .info (f"Removing JSONL file: { file_path } " )
326+ os .remove (file_path )
253327
254328@pytest .fixture (scope = "module" , autouse = True )
255329def run_gc_after_test ():
0 commit comments