Skip to content

Commit efdaa7c

Browse files
committed
+ tests
1 parent f9b317c commit efdaa7c

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

tests/python_tests/samples/test_tools_llm_benchmark.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
{"steps": 30, "width": 64, "height": 128, "guidance_scale": 1.0, "strength": "0.8", "media": "cat.png", "prompt": image_generation_i2i_prompt},
2828
]
2929

30+
# @pytest.fixture(scope="module")
31+
# def real_video(pytestconfig):
32+
# spinning_earth_url = TEST_VIDEO_URLS["spinning-earth-480"]
33+
# video = from_cache_or_download(pytestconfig, spinning_earth_url, "spinning-earth-480.mp4")
34+
# return video
35+
3036
class TestBenchmarkLLM:
3137
@pytest.mark.samples
3238
@pytest.mark.parametrize(

tools/llm_bench/benchmark.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def get_argprser():
231231
parser.add_argument("--vocoder_path", type=str, default=None,
232232
help="Path to vocoder for text to speech scenarios")
233233
parser.add_argument("-vf", "--video_frames", type=int, default=None,
234-
help="controller of video frames to process (required frame number or decymation factor if negative)")
234+
help="controller of video frames to process (required frame number if positive or decymation factor if negative)")
235235
return parser.parse_args()
236236

237237

@@ -316,10 +316,6 @@ def main():
316316
iter_data_list, pretrain_time, iter_timestamp = CASE_TO_BENCH[model_args['use_case'].task](
317317
model_path, framework, args.device, args.tokens_len, args.streaming, model_args,
318318
args.num_iters, memory_data_collector)
319-
elif model_args['use_case'].task == "visual_text_gen":
320-
iter_data_list, pretrain_time, iter_timestamp = CASE_TO_BENCH[model_args['use_case'].task](
321-
model_path, framework, args.device, model_args, args.num_iters,
322-
memory_data_collector, decym_frames=args.video_frames)
323319
else:
324320
iter_data_list, pretrain_time, iter_timestamp = CASE_TO_BENCH[model_args['use_case'].task](
325321
model_path, framework, args.device, model_args, args.num_iters, memory_data_collector)

tools/llm_bench/llm_bench_utils/model_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def analyze_args(args):
142142
model_args["rerank_texts"] = args.texts
143143
model_args["rerank_texts_file"] = args.texts_file
144144
model_args["apply_chat_template"] = args.apply_chat_template
145-
145+
model_args["video_frames"] = args.video_frames
146146
optimum = args.optimum
147147

148148
if optimum and args.genai:

tools/llm_bench/llm_bench_utils/prompt_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .parse_json_data import parse_vlm_json_data
1616
from pathlib import Path
1717
import openvino as ov
18+
import math
1819

1920

2021
def get_text_prompt(args):
@@ -87,15 +88,20 @@ def make_video_tensor(video_path, decym_frames=None):
8788
return output_frames
8889

8990
# decymation procedure
90-
# decym_fames is required max frame number if positive
91+
# decym_frames is required max frame number if positive
9192
# or decymation factor if negative
93+
# e.g if input frames number is 100 and decym_fames = 5:
94+
# then number of processed frames are: 0, 20, 40, 60, 80
95+
# if input frames number is 100 and decym_fames = -5:
96+
# then number of processed frames are: 0, 5, 10, 15, 20, ...
9297

9398
decym_frames = int(decym_frames)
9499
if decym_frames > 0:
95100
if len(output_frames) <= decym_frames:
96101
log.info(f"Video decym: too short to decym: crop: {decym_frames}")
97102
return list(output_frames[:decym_frames])
98-
decym_factor = 1 + int(len(output_frames) / decym_frames)
103+
decym_factor_f = float(len(output_frames)) / decym_frames
104+
decym_factor = int(math.ceil(decym_factor_f))
99105
else:
100106
decym_factor = -decym_frames
101107
log.info(f"Video decym factor: {decym_factor}")

tools/llm_bench/task/visual_language_generation.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727

2828
def run_visual_language_generation_optimum(
2929
inputs, num, model, processor, args, iter_data_list, md5_list, prompt_index,
30-
bench_hook, model_precision, proc_id, mem_consumption, decym_frames=None):
30+
bench_hook, model_precision, proc_id, mem_consumption):
3131
from optimum.intel.utils.import_utils import is_transformers_version
3232
set_seed(args['seed'])
3333
if args['batch_size'] != 1:
3434
log.warning("Only batch size 1 available for benchmarking")
3535
args["batch_size"] = 1
3636

37+
decym_frames = args["video_frames"]
3738
prompts, images, videos = extract_prompt_issues(inputs, decym_frames, False)
3839
if args["output_dir"] is not None and num == 0:
3940
for bs_index, in_text in enumerate(prompts):
@@ -180,12 +181,13 @@ def run_visual_language_generation_optimum(
180181

181182

182183
def run_visual_language_generation_genai(
183-
inputs, num, model, processor, args, iter_data_list, md5_list, prompt_index,
184-
streamer, model_precision, proc_id, mem_consumption, decym_frames=None):
184+
inputs, num, model, processor, args, iter_data_list, md5_list,
185+
prompt_index, streamer, model_precision, proc_id, mem_consumption):
185186
if args['batch_size'] != 1:
186187
log.warning("Only batch size 1 available for benchmarking")
187188
args["batch_size"] = 1
188189

190+
decym_frames = args["video_frames"]
189191
prompts, images, videos = extract_prompt_issues(inputs, decym_frames, True)
190192
if args["output_dir"] is not None and num == 0:
191193
for bs_index, in_text in enumerate(prompts):
@@ -294,9 +296,7 @@ def run_visual_language_generation_genai(
294296
metrics_print.print_generated(num, warm_up=(num == 0), generated=generated_text[0], prompt_idx=prompt_index)
295297

296298

297-
def run_visual_language_generation_benchmark(
298-
model_path, framework, device, args, num_iters,
299-
mem_consumption, decym_frames=None):
299+
def run_visual_language_generation_benchmark(model_path, framework, device, args, num_iters, mem_consumption):
300300
outs = FW_UTILS[framework].create_image_text_gen_model(model_path, device, mem_consumption, **args)
301301
model, processor, pretrain_time, bench_hook, use_genai = outs
302302
model_precision = model_utils.get_model_precision(model_path.parts)
@@ -335,7 +335,7 @@ def run_visual_language_generation_benchmark(
335335
iter_timestamp[num][p_idx]['start'] = datetime.datetime.now().isoformat()
336336
gen_fn(
337337
input_text, num, model, processor, args, iter_data_list, md5_list,
338-
p_idx, bench_hook, model_precision, proc_id, mem_consumption, decym_frames)
338+
p_idx, bench_hook, model_precision, proc_id, mem_consumption)
339339
iter_timestamp[num][p_idx]['end'] = datetime.datetime.now().isoformat()
340340
prefix = f"[warm-up][P{p_idx}]" if num == 0 else f"[{num}][P{p_idx}]"
341341
log.info(f"{prefix} start: {iter_timestamp[num][p_idx]['start']}, end: {iter_timestamp[num][p_idx]['end']}")
@@ -348,8 +348,8 @@ def run_visual_language_generation_benchmark(
348348
metrics_print.print_unicode(prefix, max_output=metrics_print.MAX_INPUT_TXT_IN_LOG)
349349
iter_timestamp[num][p_idx]['start'] = datetime.datetime.now().isoformat()
350350
gen_fn(
351-
input_text, num, model, processor, args, iter_data_list, md5_list, prompt_idx_list[idx],
352-
bench_hook, model_precision, proc_id, mem_consumption, decym_frames)
351+
input_text, num, model, processor, args, iter_data_list, md5_list,
352+
prompt_idx_list[idx], bench_hook, model_precision, proc_id, mem_consumption)
353353
iter_timestamp[num][p_idx]['end'] = datetime.datetime.now().isoformat()
354354
prefix = f"[warm-up][P{p_idx}]" if num == 0 else f"[{num}][P{p_idx}]"
355355
log.info(f"{prefix} start: {iter_timestamp[num][p_idx]['start']}, end: {iter_timestamp[num][p_idx]['end']}")

0 commit comments

Comments
 (0)