fix: handle paddlepaddle-gpu CUDA import at build time gracefully

paddlepaddle-gpu requires libcuda.so.1 at import time, but no CUDA
driver exists during Docker build. The download script now catches
this ImportError and skips PaddleOCR model pre-download on amd64.
Models will download on first use at runtime when the CUDA driver
is available via nvidia-container-toolkit.

On arm64 (CPU paddlepaddle), models are still pre-downloaded at build
time as before.

Also reverted CI to amd64-only Docker build test for speed. Multi-arch
build is tested on release via the release workflow.
This commit is contained in:
Siddharth Kumar Sah
2026-04-10 12:22:11 +08:00
parent d31d66556e
commit 0083a741a9
3 changed files with 22 additions and 19 deletions
-3
View File
@@ -87,14 +87,11 @@ jobs:
- uses: docker/setup-buildx-action@v3
- uses: docker/setup-qemu-action@v3
- uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile
push: false
platforms: linux/amd64,linux/arm64
tags: stirling-image:ci
cache-from: type=gha,scope=unified
cache-to: type=gha,mode=max,scope=unified
+3 -9
View File
@@ -118,16 +118,10 @@ RUN if [ "$TARGETARCH" = "amd64" ]; then \
RUN /opt/venv/bin/pip install seam-carving==1.1.0
# Install CUDA forward-compat stubs for build-time model downloads.
# paddlepaddle-gpu needs libcuda.so.1 to import, but the real driver is
# only injected at runtime by nvidia-container-toolkit. The compat package
# provides a stub that satisfies the dlopen without a real GPU.
RUN if [ "$TARGETARCH" = "amd64" ]; then \
apt-get update && apt-get install -y --no-install-recommends cuda-compat-12-6 && \
rm -rf /var/lib/apt/lists/* \
; fi
# Pre-download and verify all ML models
# Note: on amd64, paddlepaddle-gpu can't import without the CUDA driver (only
# available at runtime). The download script gracefully skips PaddleOCR model
# pre-download in this case; models download on first use at runtime instead.
COPY docker/download_models.py /tmp/download_models.py
RUN /opt/venv/bin/python3 /tmp/download_models.py && rm -f /tmp/download_models.py
+19 -7
View File
@@ -63,11 +63,16 @@ def download_realesrgan_model():
def download_paddleocr_models():
"""Pre-download PaddleOCR models for all supported languages."""
print("=== Downloading PaddleOCR models ===")
os.environ["PADDLE_PDX_DISABLE_MODEL_SOURCE_CHECK"] = "True"
# Force CPU mode during build - no GPU driver available at build time
os.environ["PADDLE_DEVICE"] = "cpu"
os.environ["FLAGS_use_cuda"] = "0"
from paddleocr import PaddleOCR
try:
from paddleocr import PaddleOCR
except ImportError as e:
if "libcuda" in str(e):
# paddlepaddle-gpu can't import without CUDA driver at build time.
# Models will be downloaded on first use at runtime instead.
print(f" Skipping PaddleOCR model pre-download (no CUDA driver at build time)")
print(f" Models will download on first use at runtime.\n")
return
raise
for lang in PADDLEOCR_LANGUAGES:
print(f" Downloading models for lang={lang}...")
@@ -100,13 +105,20 @@ def smoke_test():
is_amd64 = platform.machine() in ("x86_64", "amd64")
from rembg import new_session
from paddleocr import PaddleOCR
import mediapipe as mp
import cv2
import numpy
from PIL import Image
import seam_carving
print(" Core imports OK")
try:
from paddleocr import PaddleOCR
print(" Core imports OK (including PaddleOCR)")
except ImportError as e:
if "libcuda" in str(e):
print(" Core imports OK (PaddleOCR skipped - no CUDA driver at build time)")
else:
raise
# RealESRGAN/basicsr has a known torchvision compat issue on arm64.
# On amd64 we verify the full import chain; on arm64 we just check the model file.