PaddlePaddle / PaddleOCR

Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)
https://paddlepaddle.github.io/PaddleOCR/
Apache License 2.0
43.05k stars 7.72k forks source link

The API call failed because the CUDA driver and runtime could not be initialized #9155

Closed wenxuezhang closed 1 year ago

wenxuezhang commented 1 year ago
LDOUBLEV commented 1 year ago

检查paddle是否正确安装

import paddle paddle.utils.run_check()

# Running verify PaddlePaddle program ...
# W1010 07:21:14.972093  8321 device_context.cc:338] Please NOTE: device: 0, CUDA Capability: 70, Driver API Version: 11.0, Runtime API Version: 10.1
# W1010 07:21:14.979770  8321 device_context.cc:346] device: 0, cuDNN Version: 7.6.
# PaddlePaddle works well on 1 GPU.
# PaddlePaddle works well on 8 GPUs.
# PaddlePaddle is installed successfully! Let's start deep learning with PaddlePaddle now.
wenxuezhang commented 1 year ago

这个问题百度解决的太慢了,大家都卡在这里用不了了

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

nilyang commented 4 months ago

我是在 Celery 异步队列中执行 PaddleOCR版面分析出现这个错误的,单独执行没有这个错误,后来是调用Celery命令参数影响:

  1. 服务器配置
    Python 3.10.14 (main, May  6 2024, 19:42:50) [GCC 11.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import paddle
    WARNING: OMP_NUM_THREADS set to 12, not 1. The computation speed will not be optimized if you use data parallel. It will fail if this PaddlePaddle binary is compiled with OpenBlas since OpenBlas does not support multi-threads.
    PLEASE USE OMP_NUM_THREADS WISELY.
    >>> paddle.utils.run_check()
    Running verify PaddlePaddle program ... 
    I0527 16:23:39.928263 743940 program_interpreter.cc:212] New Executor is Running.
    W0527 16:23:39.928719 743940 gpu_resources.cc:119] Please NOTE: device: 0, GPU Compute Capability: 8.6, Driver API Version: 12.2, Runtime API Version: 11.8
    W0527 16:23:39.954921 743940 gpu_resources.cc:164] device: 0, cuDNN Version: 8.6.
    I0527 16:23:40.123919 743940 interpreter_util.cc:624] Standalone Executor is Used.
    PaddlePaddle works well on 1 GPU.
    PaddlePaddle is installed successfully! Let's start deep learning with PaddlePaddle now.
  2. 出现错误的情况
OMP_NUM_THREADS=1 && celery -A celery_tasks.main worker -l INFO -c 4

此时会在table_engine = PPStructure(...) 这个对象创建时报错:

Traceback (most recent call last):
  File "/root/miniconda3/envs/paddle/lib/python3.10/site-packages/celery/app/trace.py", line 453, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/root/miniconda3/envs/paddle/lib/python3.10/site-packages/celery/app/trace.py", line 736, in __protected_call__
    return self.run(*args, **kwargs)
  File "/root/autodl-tmp/projects/pdfocr/celery_tasks/ocr/tasks.py", line 117, in step3_ocr_charts
    pp_layout.save_pdf_charts(pdf_info=pdf_info)
  File "/root/autodl-tmp/projects/pdfocr/celery_tasks/../paddle_ocr/pp_layout.py", line 48, in save_pdf_charts
    table_engine = PPStructure(show_log=pp_show_log,
  File "/root/autodl-tmp/projects/pdfocr/paddle_ocr/paddleocr.py", line 778, in __init__
    super().__init__(params)
  File "/root/autodl-tmp/projects/pdfocr/celery_tasks/../paddle_ocr/ppstructure/predict_system.py", line 67, in __init__
    self.layout_predictor = LayoutPredictor(args)
  File "/root/autodl-tmp/projects/pdfocr/celery_tasks/../paddle_ocr/ppstructure/layout/predict_layout.py", line 68, in __init__
    utility.create_predictor(args, 'layout', logger)
  File "/root/autodl-tmp/projects/pdfocr/paddle_ocr/tools/infer/utility.py", line 293, in create_predictor
    predictor = inference.create_predictor(config)
OSError: (External) CUDA error(3), initialization error. 
  [Hint: 'cudaErrorInitializationError'. The API call failed because the CUDA driver and runtime could not be initialized. ] (at /paddle/paddle/phi/backends/gpu/cuda/cuda_info.cc:256)
  1. 恢复正常的方法

Celery 在指定多线程池配置-P gevent参数后,就正常了

OMP_NUM_THREADS=1 && celery -A celery_tasks.main worker -l INFO -c 4 -P gevent