From c47ded63e6c280bc1f8a30be83f264f0aa2959e9 Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Fri, 2 Feb 2024 00:12:15 +0100 Subject: [PATCH] Fix issue with older torch (#22592) --- tools/ovc/openvino/tools/ovc/convert_impl.py | 2 +- .../openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/ovc/openvino/tools/ovc/convert_impl.py b/tools/ovc/openvino/tools/ovc/convert_impl.py index 8a25b73956799b..9594b3ae796078 100644 --- a/tools/ovc/openvino/tools/ovc/convert_impl.py +++ b/tools/ovc/openvino/tools/ovc/convert_impl.py @@ -190,7 +190,7 @@ def check_model_object(argv): return "tf" if 'torch' in sys.modules: import torch - if isinstance(model, (torch.nn.Module, torch.jit.ScriptFunction, torch.export.ExportedProgram)): + if isinstance(model, (torch.nn.Module, torch.jit.ScriptFunction)) or (hasattr(torch, "export") and isinstance(model, (torch.export.ExportedProgram))): return "pytorch" try: from openvino.frontend.pytorch.ts_decoder import TorchScriptPythonDecoder 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 21af74862a780d..fa669ba646690d 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 @@ -34,7 +34,7 @@ def get_pytorch_decoder(model, example_inputs, args): "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) if not isinstance(model, (TorchScriptPythonDecoder, TorchFXPythonDecoder)): - if isinstance(model, torch.export.ExportedProgram): + if hasattr(torch, "export") and isinstance(model, (torch.export.ExportedProgram)): raise RuntimeError("Models received from torch.export are not yet supported by convert_model.") else: decoder = TorchScriptPythonDecoder(model, example_input=inputs, shared_memory=args.get("share_weights", True))