[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:
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
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.")
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

View File

@ -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
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.")
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