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