From 55c584954cdb19bed14a4825470f3da211b46d99 Mon Sep 17 00:00:00 2001 From: Yulong Wang <7679871+fs-eire@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:10:25 -0700 Subject: [PATCH] fix supports_device() in python interface (#22473) ### Description `get_device()` returns a string of hyphen connected device names, such as "GPU-DML". It's a problem that when CUDA is disabled but OpenVino GPU is enabled in the build, because in this case `get_device()` returns "CPU-OPENVINO_GPU", so `supports_device("CUDA")` will return `True` in this build. Splitting the value of `get_device()` by "-" and check if the input is in the list is not an option because it seems some code in the code base stores the value of `get_device()` and use the value to call `supports_device()`. Using this implementation will cause `supports_device("GPU-DML")` to return `False` for a build with `get_device() == "GPU-DML"` because `"GPU-DML" in ["GPU", "DML"]` is `False`. This change also helps to avoid further problems when "WebGPU" is introduced. --- onnxruntime/python/backend/backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/python/backend/backend.py b/onnxruntime/python/backend/backend.py index 97b7358f2a..67423fe9b5 100644 --- a/onnxruntime/python/backend/backend.py +++ b/onnxruntime/python/backend/backend.py @@ -87,7 +87,7 @@ class OnnxRuntimeBackend(Backend): """ if device == "CUDA": device = "GPU" - return device in get_device() + return "-" + device in get_device() or device + "-" in get_device() or device == get_device() @classmethod def prepare(cls, model, device=None, **kwargs):