|
16 | 16 | from utils.generation_config import get_greedy, get_beam_search
|
17 | 17 | from utils.constants import get_default_llm_properties
|
18 | 18 | from utils.hugging_face import convert_models, get_hugging_face_models, run_hugging_face
|
| 19 | +from utils.comparation import compare_generation_results |
19 | 20 |
|
20 | 21 | TESTS_ROOT = Path(__file__).parent
|
21 | 22 |
|
@@ -155,34 +156,6 @@ def run_llm_pipeline(
|
155 | 156 | return generation_results
|
156 | 157 |
|
157 | 158 |
|
158 |
| -def compare_generation_result(hf_result: GenerationResult, ov_result: GenerationResult, generation_config: GenerationConfig): |
159 |
| - if generation_config.is_beam_search(): |
160 |
| - assert len(hf_result.m_scores) == len(ov_result.m_scores) |
161 |
| - for hf_score, ov_score in zip(hf_result.m_scores, ov_result.m_scores): |
162 |
| - # Note, that for fp32 / fp16 models scores are different less than 0.001 |
163 |
| - assert abs(hf_score - ov_score) < 0.02 |
164 |
| - |
165 |
| - if not generation_config.include_stop_str_in_output and len(generation_config.stop_strings) > 0: |
166 |
| - assert len(hf_result.m_generation_ids) >= len(ov_result.m_generation_ids) |
167 |
| - for hf_text, ov_text in zip(hf_result.m_generation_ids, ov_result.m_generation_ids): |
168 |
| - assert ov_text in hf_text |
169 |
| - else: |
170 |
| - assert len(hf_result.m_generation_ids) == len(ov_result.m_generation_ids) |
171 |
| - for hf_text, ov_text in zip(hf_result.m_generation_ids, ov_result.m_generation_ids): |
172 |
| - assert hf_text == ov_text |
173 |
| - |
174 |
| - |
175 |
| -def compare_generation_results(prompts: List[str], hf_results: List[GenerationResult], ov_results: List[GenerationResult], generation_configs: List[GenerationConfig] | GenerationConfig): |
176 |
| - if type(generation_configs) is not list: |
177 |
| - generation_configs = [generation_configs] |
178 |
| - |
179 |
| - assert len(prompts) == len(hf_results) |
180 |
| - assert len(prompts) == len(ov_results) |
181 |
| - |
182 |
| - for prompt, ref_result, ov_result, generation_config in zip(prompts, hf_results, ov_results, generation_configs): |
183 |
| - print(f"Prompt = {prompt}\nReference result = {ref_result}\nOpenVINO result = {ov_result.m_generation_ids}") |
184 |
| - compare_generation_result(ref_result, ov_result, generation_config) |
185 |
| - |
186 | 159 | def run_llm_pipeline_with_ref(model_id: str,
|
187 | 160 | prompts: List[str],
|
188 | 161 | generation_config: GenerationConfig | dict,
|
@@ -238,20 +211,6 @@ def generate_and_compare_with_reference_text(models_path: Path, prompts: List[st
|
238 | 211 | for ref_text, ov_text in zip(ref_texts_for_this_prompt, ov_result.m_generation_ids):
|
239 | 212 | assert ref_text == ov_text
|
240 | 213 |
|
241 |
| - |
242 |
| -def get_image_by_link(link): |
243 |
| - from PIL import Image |
244 |
| - import requests |
245 |
| - from openvino import Tensor |
246 |
| - import numpy as np |
247 |
| - |
248 |
| - image = Image.open(requests.get(link, stream=True).raw) |
249 |
| - if image.mode != 'RGB': |
250 |
| - image = image.convert('RGB') |
251 |
| - image_data = np.array((np.array(image.getdata()) - 128).astype(np.byte)).reshape(1, image.size[1], image.size[0], 3) |
252 |
| - return Tensor(image_data) |
253 |
| - |
254 |
| - |
255 | 214 | """rt_info has the highest priority. Delete it to respect configs."""
|
256 | 215 | def delete_rt_info(configs: List[Tuple], temp_path):
|
257 | 216 | core = openvino.Core()
|
|
0 commit comments