From 7852dc51b090edae84497b32f49fdad755d08b3e Mon Sep 17 00:00:00 2001 From: fxmarty <9808326+fxmarty@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:02:03 +0100 Subject: [PATCH] Fix ORT detection (#1636) do not use metadata.version --- optimum/utils/import_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/optimum/utils/import_utils.py b/optimum/utils/import_utils.py index 0894a3b4902..2bf66718fd4 100644 --- a/optimum/utils/import_utils.py +++ b/optimum/utils/import_utils.py @@ -59,7 +59,10 @@ def _is_package_available(pkg_name: str, return_version: bool = False) -> Union[ _onnx_available = _is_package_available("onnx") -_onnxruntime_available = _is_package_available("onnxruntime") + +# importlib.metadata.version seem to not be robust with the ONNX Runtime extensions (`onnxruntime-gpu`, etc.) +_onnxruntime_available = importlib.util.find_spec("onnxruntime") is not None + _pydantic_available = _is_package_available("pydantic") _accelerate_available = _is_package_available("accelerate") _diffusers_available = _is_package_available("diffusers")