diff --git a/tools/ovc/openvino/tools/ovc/convert_impl.py b/tools/ovc/openvino/tools/ovc/convert_impl.py index 748cbe2b0453d9..ef937d0b1f595d 100644 --- a/tools/ovc/openvino/tools/ovc/convert_impl.py +++ b/tools/ovc/openvino/tools/ovc/convert_impl.py @@ -38,7 +38,6 @@ # pylint: disable=no-name-in-module,import-error from openvino.frontend import FrontEndManager, OpConversionFailure, TelemetryExtension -from openvino.frontend.pytorch.module_extension import ModuleExtension from openvino.runtime import get_version as get_rt_version from openvino.runtime import Type, PartialShape @@ -154,6 +153,18 @@ def get_moc_frontends(argv: argparse.Namespace): return moc_front_end, available_moc_front_ends +def filtered_extensions(extensions): + try: + new_extensions = [] + from openvino.frontend.pytorch.module_extension import ModuleExtension + for ext in extensions: + if not isinstance(ext, ModuleExtension): + new_extensions.append(ext) + return new_extensions + except: + return extensions + + def prepare_ir(argv: argparse.Namespace): argv = arguments_post_parsing(argv) t = tm.Telemetry() @@ -173,9 +184,8 @@ def prepare_ir(argv: argparse.Namespace): t.send_event("ovc", "conversion_method", moc_front_end.get_name() + "_frontend") moc_front_end.add_extension(TelemetryExtension("ovc", t.send_event, t.send_error, t.send_stack_trace)) if any_extensions_used(argv): - for extension in argv.extension: - if not isinstance(extension, ModuleExtension): - moc_front_end.add_extension(extension) + for extension in filtered_extensions(argv.extension): + moc_front_end.add_extension(extension) ov_model = moc_pipeline(argv, moc_front_end) return ov_model diff --git a/tools/ovc/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py b/tools/ovc/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py index 8e562cf21b8606..67eb07c1a25f64 100644 --- a/tools/ovc/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py +++ b/tools/ovc/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py @@ -8,24 +8,25 @@ # pylint: disable=no-name-in-module,import-error from openvino.runtime import Tensor, PartialShape from openvino.tools.ovc.error import Error -from openvino.frontend.pytorch.module_extension import ModuleExtension -def extract_module_extensions(args): - extensions = args.get('extension', []) - if not isinstance(extensions, (list, tuple)): - extensions = [extensions] - return {extension.module: extension for extension in extensions if isinstance(extension, ModuleExtension)} - def get_pytorch_decoder(model, example_inputs, args): try: from openvino.frontend.pytorch.ts_decoder import TorchScriptPythonDecoder from openvino.frontend.pytorch.fx_decoder import TorchFXPythonDecoder + from openvino.frontend.pytorch.module_extension import ModuleExtension import torch except Exception as e: log.error("PyTorch frontend loading failed") raise e + + def extract_module_extensions(args): + extensions = args.get('extension', []) or [] + if not isinstance(extensions, (list, tuple)): + extensions = [extensions] + return {extension.module: extension for extension in extensions if isinstance(extension, ModuleExtension)} + if 'nncf' in sys.modules: is_good_version = True try: