{"record":{"id":"23ecb7d7c1deb4e2","repo":"PaddlePaddle/PaddleOCR","slug":"environment-variable-cuda-visible-devices-is-not-s-23ecb7","errorCode":null,"errorMessage":"Environment Variable CUDA_VISIBLE_DEVICES is not set correctly. If you wanna use gpu, please set CUDA_VISIBLE_DEVICES via export CUDA_VISIBLE_DEVICES=cuda_device_id.","messagePattern":"Environment Variable CUDA_VISIBLE_DEVICES is not set correctly\\. If you wanna use gpu, please set CUDA_VISIBLE_DEVICES via export CUDA_VISIBLE_DEVICES=cuda_device_id\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"deploy/hubserving/kie_ser_re/module.py","lineNumber":64,"sourceCode":"    type=\"cv/KIE_SER_RE\",\n)\nclass KIESerRE(hub.Module):\n    def _initialize(self, use_gpu=False, enable_mkldnn=False):\n        \"\"\"\n        initialize with the necessary elements\n        \"\"\"\n        cfg = self.merge_configs()\n\n        cfg.use_gpu = use_gpu\n        if use_gpu:\n            try:\n                _places = os.environ[\"CUDA_VISIBLE_DEVICES\"]\n                int(_places[0])\n                print(\"use gpu: \", use_gpu)\n                print(\"CUDA_VISIBLE_DEVICES: \", _places)\n                cfg.gpu_mem = 8000\n            except:\n                raise RuntimeError(\n                    \"Environment Variable CUDA_VISIBLE_DEVICES is not set correctly. If you wanna use gpu, please set CUDA_VISIBLE_DEVICES via export CUDA_VISIBLE_DEVICES=cuda_device_id.\"\n                )\n        cfg.ir_optim = True\n        cfg.enable_mkldnn = enable_mkldnn\n\n        self.ser_re_predictor = SerRePredictor(cfg)\n\n    def merge_configs(\n        self,\n    ):\n        # default cfg\n        backup_argv = copy.deepcopy(sys.argv)\n        sys.argv = sys.argv[:1]\n        cfg = parse_args()\n\n        update_cfg_map = vars(read_params())\n\n        for key in update_cfg_map:","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/deploy/hubserving/kie_ser_re/module.py#L46-L82","documentation":"Raised by the kie_ser_re (SER + RE chained) hub module at init when use_gpu=True and CUDA_VISIBLE_DEVICES is unset or its first character cannot be parsed as int. Like the kie_ser module, a bare except wraps both the env lookup and int(_places[0]), collapsing distinct failures (missing var, empty string, \"all\") into one message. Pure environment configuration error raised as RuntimeError before any predictor loads.","triggerScenarios":"Launching the kie_ser_re hub service with use_gpu=True in a shell/container where CUDA_VISIBLE_DEVICES was never exported; value set to \"\" (entrypoint script setting it empty); \"all\" or \"NoDevFiles\" on driver 450+/470+ where int() of the first char fails.","commonSituations":"GPU Docker deployments missing -e CUDA_VISIBLE_DEVICES=0; systemd units without Environment=; upgrading NVIDIA drivers which now advertise \"all\"; switching a CPU-validated deployment to GPU without revisiting env setup.","solutions":["export CUDA_VISIBLE_DEVICES=0 (or the desired GPU id) in the shell/service environment and restart","Add the env to the container/pod spec: docker run -e CUDA_VISIBLE_DEVICES=0 --gpus all ...","If running CPU-only, keep use_gpu=False","Use a numeric value (\"0\", \"0,1\") - not \"all\", \"\", or \"-1\""],"exampleFix":"# before\nhub serving start -m kie_ser_re --use_gpu true  # env unset -> RuntimeError\n\n# after\nexport CUDA_VISIBLE_DEVICES=0\nhub serving start -m kie_ser_re --use_gpu true","handlingStrategy":"validation","validationCode":"import os\n\ndef gpu_env_valid() -> bool:\n    v = os.environ.get(\"CUDA_VISIBLE_DEVICES\")\n    return v is not None and len(v) > 0 and v[0].isdigit()\n\nif USE_GPU and not gpu_env_valid():\n    raise SystemExit(\"export CUDA_VISIBLE_DEVICES=<gpu_id> before starting kie_ser_re with GPU\")","typeGuard":null,"tryCatchPattern":"try:\n    module = SerRePredictorModule(use_gpu=True)\nexcept RuntimeError as e:\n    if \"CUDA_VISIBLE_DEVICES\" in str(e):\n        raise SystemExit(\"Fix env: export CUDA_VISIBLE_DEVICES=0, then restart the service\")\n    raise","preventionTips":["Bake ENV CUDA_VISIBLE_DEVICES=0 into GPU Dockerfiles for hub modules","Add the variable to systemd/K8s service definitions","Use numeric GPU ids only (\"0\", \"0,1\")","Document the env requirement in the service runbook"],"tags":["gpu","environment","deployment","python","hubserving"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}