This repository was archived by the owner on Apr 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 249
This repository was archived by the owner on Apr 8, 2025. It is now read-only.
ONNXAdaptiveModel causes NameError: name 'onnxruntime' is not defined #847
Copy link
Copy link
Closed
Description
When trying to load an ONNX model:
File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/haystack/reader/farm.py", line 103, in __init__
strict=False)
File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/farm/infer.py", line 252, in load
model = BaseAdaptiveModel.load(load_dir=model_name_or_path, device=device, strict=strict)
File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/farm/modeling/adaptive_model.py", line 51, in load
model = cls.subclasses["ONNXAdaptiveModel"].load(**kwargs)
File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/farm/modeling/adaptive_model.py", line 670, in load
return cls(onnx_session, language_model_class, language, prediction_heads, device)
File "/home/ubuntu/anaconda3/envs/pytorch_latest_p37/lib/python3.7/site-packages/farm/modeling/adaptive_model.py", line 634, in __init__
if str(device) == "cuda" and onnxruntime.get_device() != "GPU":
NameError: name 'onnxruntime' is not defined
Looks like ONNXAdaptiveModel.__init__ is perhaps just missing a local import onnxruntime, as is done in ONNXAdaptiveModel.load.
FARM/farm/modeling/adaptive_model.py
Lines 638 to 643 in 77530ab
| """ | |
| def __init__(self, onnx_session, language_model_class, language, prediction_heads, device): | |
| if str(device) == "cuda" and onnxruntime.get_device() != "GPU": | |
| raise Exception(f"Device {device} not available for Inference. For CPU, run pip install onnxruntime and" | |
| f"for GPU run pip install onnxruntime-gpu") | |
| self.onnx_session = onnx_session |
I've manually worked around it by adding the import, after which everything else seems to work fine. Can create a PR with this change if you like...
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Timoeller commentedon Nov 12, 2021
It seems we havent really worked much with ONNX models... 😄
If you could create a PR fixing this that would be great!
ONNXAdaptiveModel causes NameError: name 'onnxruntime' is not defined
ONNXAdaptiveModel causes NameError: name 'onnxruntime' is not defined (…