From 1f961f903ceb9619650b932899f49594e839c4ad Mon Sep 17 00:00:00 2001 From: Anastasiia Pnevskaia Date: Tue, 31 Oct 2023 10:05:54 +0100 Subject: [PATCH] Fixed info logs in OVC (#20586) * Corrected memory consumption log, removed unused log_level info. * Minor correction. * Trace memory only if verbose is set. * Use get_traced_memory(). --- tools/ovc/openvino/tools/ovc/cli_parser.py | 1 - tools/ovc/openvino/tools/ovc/convert_impl.py | 44 +++++++++++--------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/tools/ovc/openvino/tools/ovc/cli_parser.py b/tools/ovc/openvino/tools/ovc/cli_parser.py index 87fc0225206fa5..7e0a626db8099c 100644 --- a/tools/ovc/openvino/tools/ovc/cli_parser.py +++ b/tools/ovc/openvino/tools/ovc/cli_parser.py @@ -420,7 +420,6 @@ def get_common_cli_options(argv, is_python_api_used): if not is_python_api_used: model_name = get_model_name_from_args(argv) d['output_model'] = ['- IR output name', lambda _: model_name] - d['log_level'] = '- Log level' d['input'] = ['- Input layers', lambda x: x if x else 'Not specified, inherited from the model'] d['output'] = ['- Output layers', lambda x: x if x else 'Not specified, inherited from the model'] return d diff --git a/tools/ovc/openvino/tools/ovc/convert_impl.py b/tools/ovc/openvino/tools/ovc/convert_impl.py index cf09a2abfe26d0..3a746f646d8730 100644 --- a/tools/ovc/openvino/tools/ovc/convert_impl.py +++ b/tools/ovc/openvino/tools/ovc/convert_impl.py @@ -7,6 +7,7 @@ import os import sys import traceback +import tracemalloc from collections import OrderedDict from pathlib import Path from typing import Iterable, Callable @@ -39,7 +40,7 @@ from openvino.frontend import FrontEndManager, OpConversionFailure, TelemetryExtension from openvino.runtime import get_version as get_rt_version from openvino.runtime import Type, PartialShape -import re + try: from openvino.frontend.tensorflow.utils import create_tf_graph_iterator, type_supported_by_tf_fe, \ @@ -221,29 +222,13 @@ def check_model_object(argv): def driver(argv: argparse.Namespace, non_default_params: dict): - if not hasattr(argv, 'log_level'): - argv.log_level = 'ERROR' - init_logger(argv.log_level.upper(), argv.verbose) + init_logger('ERROR', argv.verbose) # Log dictionary with non-default cli parameters where complex classes are excluded. log.debug(str(non_default_params)) - start_time = datetime.datetime.now() - ov_model = moc_emit_ir(prepare_ir(argv), argv) - if argv.verbose: - elapsed_time = datetime.datetime.now() - start_time - print('[ SUCCESS ] Total execution time: {:.2f} seconds. '.format(elapsed_time.total_seconds())) - try: - import resource - mem_usage = round(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024) - if sys.platform == 'darwin': - mem_usage = round(mem_usage / 1024) - print('[ SUCCESS ] Memory consumed: {} MB. '.format(mem_usage)) - except ImportError: - pass - return ov_model def get_non_default_params(argv, cli_parser): @@ -416,11 +401,21 @@ def pack_params_to_args_namespace(args: dict, cli_parser: argparse.ArgumentParse return argv -def is_verbose(argv: argparse.Namespace): - return argv is not None and hasattr(argv, 'verbose') and argv.verbose +def is_verbose(argv, args=None): + if argv is not None and hasattr(argv, 'verbose') and argv.verbose: + return True + if args is not None and 'verbose' in args and args['verbose']: + return True + if '--verbose' in sys.argv: + return True + return False def _convert(cli_parser: argparse.ArgumentParser, args, python_api_used): + start_time = datetime.datetime.now() + if is_verbose(None, args): + tracemalloc.start() + simplified_ie_version = VersionChecker().get_ie_simplified_version() telemetry = init_mo_telemetry() telemetry.start_session('ovc') @@ -500,6 +495,15 @@ def _convert(cli_parser: argparse.ArgumentParser, args, python_api_used): print(ov_update_message) send_conversion_result('success') + + if is_verbose(argv): + elapsed_time = datetime.datetime.now() - start_time + print('[ SUCCESS ] Total execution time: {:.2f} seconds. '.format(elapsed_time.total_seconds())) + + _, peak_size = tracemalloc.get_traced_memory() + print("[ SUCCESS ] Peak memory consumption (includes only memory allocated in Python): {:.2f} MB. ".format(peak_size / (1024 * 1024))) + tracemalloc.stop() + return ov_model, argv except Exception as e: