Fix is_onnx_available (#440)
* Fix is_onnx_available Fix: If user install onnxruntime-gpu, is_onnx_available() will return False. * add more onnxruntime candidates * Run `make style` Co-authored-by: anton-l <anton@huggingface.co>
This commit is contained in:
parent
214520c66a
commit
37c9d789aa
|
@ -137,11 +137,19 @@ except importlib_metadata.PackageNotFoundError:
|
||||||
|
|
||||||
|
|
||||||
_onnx_available = importlib.util.find_spec("onnxruntime") is not None
|
_onnx_available = importlib.util.find_spec("onnxruntime") is not None
|
||||||
try:
|
if _onnx_available:
|
||||||
_onnxruntime_version = importlib_metadata.version("onnxruntime")
|
candidates = ("onnxruntime", "onnxruntime-gpu", "onnxruntime-directml", "onnxruntime-openvino")
|
||||||
logger.debug(f"Successfully imported onnxruntime version {_onnxruntime_version}")
|
_onnxruntime_version = None
|
||||||
except importlib_metadata.PackageNotFoundError:
|
# For the metadata, we have to look for both onnxruntime and onnxruntime-gpu
|
||||||
_onnx_available = False
|
for pkg in candidates:
|
||||||
|
try:
|
||||||
|
_onnxruntime_version = importlib_metadata.version(pkg)
|
||||||
|
break
|
||||||
|
except importlib_metadata.PackageNotFoundError:
|
||||||
|
pass
|
||||||
|
_onnx_available = _onnxruntime_version is not None
|
||||||
|
if _onnx_available:
|
||||||
|
logger.debug(f"Successfully imported onnxruntime version {_onnxruntime_version}")
|
||||||
|
|
||||||
|
|
||||||
_scipy_available = importlib.util.find_spec("scipy") is not None
|
_scipy_available = importlib.util.find_spec("scipy") is not None
|
||||||
|
|
Loading…
Reference in New Issue