Skip to content

Commit

Permalink
Import ModuleExtension under try-except in OVC (openvinotoolkit#23663)
Browse files Browse the repository at this point in the history
### Details:
 - *Import ModuleExtension under try-except*

### Tickets:
 - *ticket-id*
  • Loading branch information
mvafin authored and alvoron committed Apr 29, 2024
1 parent 5a04b7e commit d0a8ec2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
18 changes: 14 additions & 4 deletions tools/ovc/openvino/tools/ovc/convert_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d0a8ec2

Please sign in to comment.