11import pytest
22import logging
33from pathlib import Path
4- import subprocess # nosec B404
54import sys
65
76from conftest import convert_model , run_wwb
@@ -89,62 +88,6 @@ def run_test(model_id, model_type, optimum_threshold, genai_threshold, tmp_path)
8988 ])
9089
9190
92- def _download_hf_files_to_cache (repo_id : str , cache_dir : Path , filenames : list [str ]):
93- from ov_utils import AtomicDownloadManager , retry_request
94-
95- dest_dir = Path (cache_dir )
96-
97- def download_to_local_dir (local_dir : Path ) -> None :
98- for filename in filenames :
99- command = [
100- "huggingface-cli" ,
101- "download" ,
102- repo_id ,
103- filename ,
104- "--local-dir" ,
105- str (local_dir ),
106- ]
107-
108- def _run_download () -> None :
109- subprocess .run (command , check = True , text = True , capture_output = True )
110-
111- retry_request (_run_download )
112-
113- # If destination exists (e.g. shared CI cache), make sure all required files are present.
114- # This test previously cached only adapter_model.safetensors, but peft also requires
115- # adapter_config.json next to it.
116- if dest_dir .exists ():
117- dest_dir .mkdir (parents = True , exist_ok = True )
118- missing = [name for name in filenames if not (dest_dir / name ).exists ()]
119- if missing :
120- import shutil
121- import uuid
122-
123- temp_dir = dest_dir .parent / f".tmp_{ dest_dir .name } _{ uuid .uuid4 ().hex [:8 ]} "
124- temp_dir .mkdir (parents = True , exist_ok = True )
125- try :
126- download_to_local_dir (temp_dir )
127- for filename in missing :
128- src = temp_dir / filename
129- if not src .exists ():
130- raise AssertionError (f"Download failed: { src } " )
131- dst = dest_dir / filename
132- dst .parent .mkdir (parents = True , exist_ok = True )
133- src .replace (dst )
134- finally :
135- shutil .rmtree (temp_dir , ignore_errors = True )
136- else :
137- manager = AtomicDownloadManager (dest_dir )
138- manager .execute (download_to_local_dir )
139-
140- for filename in filenames :
141- downloaded = dest_dir / filename
142- if not downloaded .exists ():
143- raise AssertionError (f"Download failed: { downloaded } " )
144-
145- return dest_dir
146-
147-
14891def run_test_with_lora (
14992 model_id : str ,
15093 model_type : str ,
@@ -165,10 +108,11 @@ def run_test_with_lora(
165108 model_path = convert_model (model_id )
166109
167110 from ov_utils import get_ov_cache_dir
111+ from ov_utils import download_hf_files_to_cache
168112
169113 lora_filenames = ["adapter_model.safetensors" , "adapter_config.json" ]
170114 lora_cache_dir = get_ov_cache_dir () / "test_data" / lora_cache_subdir
171- lora_adapter_dir = _download_hf_files_to_cache (lora_repo_id , lora_cache_dir , lora_filenames )
115+ lora_adapter_dir = download_hf_files_to_cache (lora_repo_id , lora_cache_dir , lora_filenames )
172116 lora_adapter_file = lora_adapter_dir / "adapter_model.safetensors"
173117 assert lora_adapter_file .exists (), f"LoRA adapter wasn't downloaded: { lora_adapter_file } "
174118
0 commit comments