Skip to content

Commit 37c9d78

Browse files
SkyTNTanton-l
andauthored
Fix is_onnx_available (huggingface#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 <[email protected]>
1 parent 214520c commit 37c9d78

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/diffusers/utils/import_utils.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,19 @@
137137

138138

139139
_onnx_available = importlib.util.find_spec("onnxruntime") is not None
140-
try:
141-
_onnxruntime_version = importlib_metadata.version("onnxruntime")
142-
logger.debug(f"Successfully imported onnxruntime version {_onnxruntime_version}")
143-
except importlib_metadata.PackageNotFoundError:
144-
_onnx_available = False
140+
if _onnx_available:
141+
candidates = ("onnxruntime", "onnxruntime-gpu", "onnxruntime-directml", "onnxruntime-openvino")
142+
_onnxruntime_version = None
143+
# For the metadata, we have to look for both onnxruntime and onnxruntime-gpu
144+
for pkg in candidates:
145+
try:
146+
_onnxruntime_version = importlib_metadata.version(pkg)
147+
break
148+
except importlib_metadata.PackageNotFoundError:
149+
pass
150+
_onnx_available = _onnxruntime_version is not None
151+
if _onnx_available:
152+
logger.debug(f"Successfully imported onnxruntime version {_onnxruntime_version}")
145153

146154

147155
_scipy_available = importlib.util.find_spec("scipy") is not None

0 commit comments

Comments
 (0)