mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: prevent false GPU detection when CUDA image runs without GPU
The STIRLING_GPU=true env var was baked into the :cuda Dockerfile,
which made gpu_available() return True without checking actual
hardware. On machines without a GPU, this would crash upscale.py
(torch.device("cuda") fails) and ocr.py (PaddleOCR use_gpu=True).
Fix: the env var can only disable GPU (set to false/0), never
force-enable it. Hardware detection always runs. Removed the
baked env var from the Dockerfile since it adds no value now.
This commit is contained in:
@@ -6,10 +6,15 @@ import os
|
||||
@functools.lru_cache(maxsize=1)
|
||||
def gpu_available():
|
||||
"""Return True if a usable CUDA GPU is present at runtime."""
|
||||
# Allow explicit disable via env var (set to "false" or "0")
|
||||
override = os.environ.get("STIRLING_GPU")
|
||||
if override is not None:
|
||||
return override.lower() in ("1", "true", "yes")
|
||||
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():
|
||||
|
||||
Reference in New Issue
Block a user