Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llm bench] Move calculation of memory consumption to memory_monitor tool #1937

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions tools/llm_bench/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from openvino import get_version
import torch
import traceback
from llm_bench_utils.memory_profile import MemConsumption
from llm_bench_utils.memory_monitor import MemMonitorWrapper
import llm_bench_utils.output_csv
import llm_bench_utils.output_json
import task.visual_language_generation as bench_vlm
Expand All @@ -19,7 +19,7 @@
import task.speech_to_text_generation as bench_speech

DEFAULT_TORCH_THREAD_NUMS = 16
mem_consumption = MemConsumption()
memory_monitor = MemMonitorWrapper()


def num_iters_type(x):
Expand Down Expand Up @@ -87,11 +87,19 @@ def get_argprser():
)
parser.add_argument(
"--memory_consumption_delay",
default=0.5,
default=None,
required=False,
type=float,
help="delay for memory consumption check in seconds, smaller value will lead to more precised memory consumption, but may affects performance."
"It is not recommended to run memory consumption and performance benchmarking in the same time"
"It is not recommended to run memory consumption and performance benchmarking in the same time",
)
parser.add_argument(
'-mc_dir',
'--memory_consumption_dir',
default=None,
required=False,
type=str,
help='Path to store memory consamption logs and chart.',
)
parser.add_argument('-bs', '--batch_size', type=int, default=1, required=False, help='Batch size value')
parser.add_argument('--num_beams', type=int, default=1, help='Number of beams in the decoding strategy, activates beam_search if greater than 1')
Expand Down Expand Up @@ -233,22 +241,25 @@ def main():
if half_nums_of_torch_threads > DEFAULT_TORCH_THREAD_NUMS:
torch.set_num_threads(DEFAULT_TORCH_THREAD_NUMS)
else:
half_nums_of_torch_threads = int(half_nums_of_torch_threads) if int(half_nums_of_torch_threads) else 1
torch.set_num_threads(int(half_nums_of_torch_threads))
log.info(f"The num_beams is {model_args['num_beams']}, update Torch thread num from "
f'{original_torch_thread_nums} to {torch.get_num_threads()}, avoid to use the CPU cores for OpenVINO inference.')
log.info(out_str)
if args.memory_consumption:
mem_consumption.delay = args.memory_consumption_delay
mem_consumption.start_collect_mem_consumption_thread()
memory_monitor.create_monitors()
if args.memory_consumption_dir:
memory_monitor.set_dir(args.memory_consumption_dir)
if args.memory_consumption_delay:
memory_monitor.interval = args.memory_consumption_delay
try:
if model_args['use_case'] in ['text_gen', 'code_gen']:
iter_data_list, pretrain_time, iter_timestamp = CASE_TO_BENCH[model_args['use_case']](
model_path, framework, args.device, args.tokens_len, args.streaming, model_args,
args.num_iters, mem_consumption)
args.num_iters, memory_monitor)
else:
iter_data_list, pretrain_time, iter_timestamp = CASE_TO_BENCH[model_args['use_case']](
model_path, framework, args.device, model_args, args.num_iters,
mem_consumption)
model_path, framework, args.device, model_args, args.num_iters, memory_monitor)
if args.report is not None or args.report_json is not None:
model_precision = ''
if framework == 'ov':
Expand Down Expand Up @@ -289,7 +300,7 @@ def main():
exit(1)
finally:
if args.memory_consumption:
mem_consumption.end_collect_mem_consumption_thread()
memory_monitor.stop()


if __name__ == '__main__':
Expand Down
10 changes: 6 additions & 4 deletions tools/llm_bench/llm_bench_utils/gen_output_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def gen_iterate_data(
latency='',
res_md5='',
max_rss_mem='',
max_shared_mem='',
max_uss_mem='',
max_rss_mem_increase='',
max_sys_mem='',
max_sys_mem_increase='',
prompt_idx='',
tokenization_time=[],
mm_embeddings_preparation_time=''
Expand All @@ -31,8 +32,9 @@ def gen_iterate_data(
iter_data['first_token_infer_latency'] = -1
iter_data['other_tokens_infer_avg_latency'] = -1
iter_data['max_rss_mem_consumption'] = max_rss_mem
iter_data['max_shared_mem_consumption'] = max_shared_mem
iter_data['max_uss_mem_consumption'] = max_uss_mem
iter_data['max_rss_mem_increase'] = max_rss_mem_increase
iter_data['max_sys_mem_consumption'] = max_sys_mem
iter_data['max_sys_mem_increase'] = max_sys_mem_increase
iter_data['prompt_idx'] = prompt_idx
iter_data['tokenization_time'] = tokenization_time[0] if len(tokenization_time) > 0 else ''
iter_data['detokenization_time'] = tokenization_time[1] if len(tokenization_time) > 1 else ''
Expand Down
Loading
Loading