Skip to content

Commit

Permalink
Fixed info logs in OVC (openvinotoolkit#20586)
Browse files Browse the repository at this point in the history
* Corrected memory consumption log, removed unused log_level info.

* Minor correction.

* Trace memory only if verbose is set.

* Use get_traced_memory().
  • Loading branch information
popovaan authored Oct 31, 2023
1 parent 38b6092 commit 1f961f9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
1 change: 0 additions & 1 deletion tools/ovc/openvino/tools/ovc/cli_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 24 additions & 20 deletions tools/ovc/openvino/tools/ovc/convert_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, \
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1f961f9

Please sign in to comment.