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:
Siddharth Kumar Sah
2026-04-05 22:03:57 +08:00
parent 609fd57de8
commit a291d1fe0b
2 changed files with 8 additions and 4 deletions
+1 -2
View File
@@ -190,8 +190,7 @@ ENV PORT=1349 \
CONCURRENT_JOBS=3 \
MAX_MEGAPIXELS=100 \
RATE_LIMIT_PER_MIN=100 \
STIRLING_VARIANT=${VARIANT} \
STIRLING_GPU=${GPU}
STIRLING_VARIANT=${VARIANT}
# Create non-root user for runtime
RUN groupadd -r stirling && useradd -r -g stirling -d /app -s /sbin/nologin stirling
+7 -2
View File
@@ -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():