[MO] Fix issue in nncf version verification (#19347)

* Return deleted nncf import

* Remove try-except, it hides exception

* Get version visout importing nncf module
This commit is contained in:
Maxim Vafin 2023-08-23 21:16:26 +02:00 committed by GitHub
parent 1d0d00bf22
commit e11e8ede1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 18 deletions

View File

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

View File

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