From 491e6fb5544fd9c96c88900b7fe2554e08c9c6a6 Mon Sep 17 00:00:00 2001 From: ashim-hq Date: Mon, 20 Apr 2026 22:13:07 +0800 Subject: [PATCH] fix: prevent PaddleOCR segfault on CPU-only Docker by setting CUDA env vars --- packages/ai/python/ocr.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/ai/python/ocr.py b/packages/ai/python/ocr.py index a0f061d3..6ad6390c 100644 --- a/packages/ai/python/ocr.py +++ b/packages/ai/python/ocr.py @@ -3,6 +3,17 @@ import sys import json import os +# Prevent PaddlePaddle C++ runtime from probing for CUDA on CPU-only systems. +# Without these, paddlepaddle-gpu can segfault during import on machines without +# a GPU, because the C++ layer attempts GPU initialization before Python-level +# device routing takes effect. Must run before any PaddleOCR import. +from gpu import gpu_available as _gpu_available +if not _gpu_available(): + if not os.environ.get("FLAGS_use_cuda"): + os.environ["FLAGS_use_cuda"] = "0" + if not os.environ.get("FLAGS_use_cudnn"): + os.environ["FLAGS_use_cudnn"] = "0" + # Lazy-loaded VLM instance (stays resident in dispatcher process) _paddleocr_vl_instance = None