mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: verify CUDAExecutionProvider in onnxruntime before returning CUDA providers
gpu.onnx_providers() trusted gpu_available() which returns True via torch.cuda without checking whether onnxruntime actually has CUDAExecutionProvider compiled in. When onnxruntime (CPU-only) is installed, this caused silent fallback to CPU in every ONNX-based tool. Now verifies onnxruntime.get_available_providers() directly and emits a diagnostic warning when torch sees CUDA but onnxruntime does not. Closes #104
This commit is contained in:
@@ -60,10 +60,18 @@ def onnx_providers():
|
||||
"""Return (providers, device) tuple.
|
||||
|
||||
providers: ONNX Runtime execution providers in priority order.
|
||||
device: "cuda" or "cpu" — reflects which hardware will actually be used.
|
||||
device: "cuda" or "cpu" -- reflects which hardware will actually be used.
|
||||
"""
|
||||
if gpu_available():
|
||||
return (["CUDAExecutionProvider", "CPUExecutionProvider"], "cuda")
|
||||
try:
|
||||
import onnxruntime as _ort
|
||||
available = _ort.get_available_providers()
|
||||
if "CUDAExecutionProvider" in available:
|
||||
return (["CUDAExecutionProvider", "CPUExecutionProvider"], "cuda")
|
||||
emit_info("GPU detected by torch but CUDAExecutionProvider not available in onnxruntime "
|
||||
"-- install onnxruntime-gpu for GPU acceleration")
|
||||
except ImportError:
|
||||
emit_info("onnxruntime not installed, cannot check CUDA provider")
|
||||
emit_info("No GPU detected, processing on CPU")
|
||||
return (["CPUExecutionProvider"], "cpu")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user