fix: use torch.cuda for GPU detection instead of onnxruntime providers

onnxruntime-gpu reports CUDAExecutionProvider as "available" just
because the library was compiled with CUDA support, even on machines
with no GPU. This made gpu_available() return True incorrectly,
causing upscale.py to try torch.device("cuda") and fall back to
Lanczos instead of running Real-ESRGAN on CPU.

torch.cuda.is_available() actually probes the hardware. Use it as
the single source of truth for GPU detection.

Verified: CUDA image on Apple Silicon (no GPU) now correctly reports
gpu: false and all AI tools run on CPU without crashes.
This commit is contained in:
Siddharth Kumar Sah
2026-04-05 22:24:16 +08:00
parent e8572358e9
commit 8d2f401512
+4 -13
View File
@@ -11,21 +11,12 @@ def gpu_available():
if override is not None and override.lower() in ("0", "false", "no"):
return False
# Always check actual hardware, even if STIRLING_GPU=true.
# The env var can disable GPU but never force-enable it,
# because the :cuda image bakes STIRLING_GPU=true and we
# still need to handle "no GPU attached" gracefully.
try:
import onnxruntime
if "CUDAExecutionProvider" in onnxruntime.get_available_providers():
return True
except ImportError:
pass
# Use torch.cuda as the source of truth. It actually probes
# the hardware. onnxruntime's get_available_providers() only
# reports compiled-in backends, not whether a GPU exists.
try:
import torch
if torch.cuda.is_available():
return True
return torch.cuda.is_available()
except ImportError:
pass