Skip to content

Commit 90098dc

Browse files
committed
[llm_bench] Fix way with relative path of media for json prompts
1 parent 53ff595 commit 90098dc

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

tools/llm_bench/llm_bench_utils/model_utils.py

+9
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,12 @@ def init_timestamp(num_iters, prompt_list, prompt_idx_list):
312312
p_idx = prompt_idx_list[idx]
313313
iter_timestamp[num][p_idx] = {}
314314
return iter_timestamp
315+
316+
317+
def resolve_media_file_path(file_path, prompt_file_path):
318+
if not file_path:
319+
return file_path
320+
if not (file_path.startswith("http://") or file_path.startswith("https://")):
321+
return os.path.join(os.path.dirname(prompt_file_path), file_path.replace("./", ""))
322+
return file_path
323+

tools/llm_bench/task/image_generation.py

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ def read_image(image_path: str, ov_tensor=True):
3737
return pil_image
3838

3939

40+
def load_image_genai(image_path):
41+
pil_image = load_image(image_path)
42+
image_data = np.array(pil_image)[None]
43+
return ov.Tensor(image_data)
44+
4045
def collects_input_args(image_param, model_type, model_name, infer_count=None, height=None, width=None, callback=None, image_as_ov_tensor=True):
4146
input_args = {}
4247
input_args["width"] = image_param.get('width', width or DEFAULT_IMAGE_WIDTH)
@@ -277,6 +282,9 @@ def get_image_prompt(args):
277282
image_param_list = parse_json_data.parse_image_json_data(output_data_list)
278283
if len(image_param_list) > 0:
279284
for image_data in image_param_list:
285+
if args['prompt_file'] is not None and len(args['prompt_file']) > 0:
286+
image_data['media'] = model_utils.resolve_media_file_path(image_data.get("media"), args['prompt_file'][0])
287+
image_data['mask_image'] = model_utils.resolve_media_file_path(image_data.get("mask_image"), args['prompt_file'][0])
280288
input_image_list.append(image_data)
281289
else:
282290
input_image_list.append(output_data_list[0])

tools/llm_bench/task/visual_language_generation.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,7 @@ def get_image_text_prompt(args):
366366
if len(vlm_param_list) > 0:
367367
for vlm_file in vlm_param_list:
368368
if args['prompt_file'] is not None and len(args['prompt_file']) > 0:
369-
media_path = vlm_file["media"]
370-
if not (media_path.startswith("http://") or media_path.startswith("https://")):
371-
media_path = os.path.join(os.path.dirname(args['prompt_file'][0]), media_path.replace("./", ""))
372-
vlm_file['media'] = media_path
369+
vlm_file['media'] = model_utils.resolve_media_file_path(vlm_file.get("media"), args['prompt_file'][0])
373370
vlm_file_list.append(vlm_file)
374371
else:
375372
vlm_file_list.append(output_data_list)

0 commit comments

Comments
 (0)