Skip to content

Commit

Permalink
[MO] Fix issue in nncf version verification (#19347)
Browse files Browse the repository at this point in the history
* Return deleted nncf import

* Remove try-except, it hides exception

* Get version visout importing nncf module
  • Loading branch information
mvafin authored Aug 23, 2023
1 parent 1d0d00b commit e11e8ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
21 changes: 12 additions & 9 deletions tools/mo/openvino/tools/mo/moc_frontend/pytorch_frontend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ def get_pytorch_decoder(model, input_shape, example_inputs, args):
except Exception as e:
log.error("PyTorch frontend loading failed")
raise e
try:
if 'nncf' in sys.modules:
from nncf.torch.nncf_network import NNCFNetwork # pylint: disable=undefined-variable
from packaging import version
if 'nncf' in sys.modules:
is_good_version = True
try:
from nncf.torch.nncf_network import NNCFNetwork

if isinstance(model, NNCFNetwork):
if version.parse(nncf.__version__) < version.parse("2.6"): # pylint: disable=undefined-variable
raise RuntimeError(
"NNCF models produced by nncf<2.6 are not supported directly. Please upgrade nncf or export to ONNX first.")
except:
pass
from packaging import version
if version.parse(sys.modules['nncf'].__version__) < version.parse("2.6"):
is_good_version = False
except:
pass
if not is_good_version:
raise RuntimeError(
"NNCF models produced by nncf<2.6 are not supported directly. Please upgrade nncf or export to ONNX first.")
inputs = prepare_torch_inputs(example_inputs)
decoder = TorchScriptPythonDecoder(model, example_input=inputs, shared_memory=args.get("share_weights", True))
args['input_model'] = decoder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ def get_pytorch_decoder(model, example_inputs, args):
except Exception as e:
log.error("PyTorch frontend loading failed")
raise e
try:
if 'nncf' in sys.modules:
from nncf.torch.nncf_network import NNCFNetwork # pylint: disable=undefined-variable
from packaging import version
if 'nncf' in sys.modules:
is_good_version = True
try:
from nncf.torch.nncf_network import NNCFNetwork

if isinstance(model, NNCFNetwork):
if version.parse(nncf.__version__) <= version.parse("2.6"): # pylint: disable=undefined-variable
raise RuntimeError(
"NNCF models produced by nncf<2.6 are not supported directly. Please upgrade nncf or export to ONNX first.")
except:
pass
from packaging import version
if version.parse(sys.modules['nncf'].__version__) < version.parse("2.6"):
is_good_version = False
except:
pass
if not is_good_version:
raise RuntimeError(
"NNCF models produced by nncf<2.6 are not supported directly. Please upgrade nncf or export to ONNX first.")
inputs = prepare_torch_inputs(example_inputs)
decoder = TorchScriptPythonDecoder(model, example_input=inputs, shared_memory=args.get("share_weights", True))
args['input_model'] = decoder
Expand Down

0 comments on commit e11e8ed

Please sign in to comment.