背景
PaddlePaddle这东西的适配性做得很差,运行环境对包版本经常很严格。我们今天要处理的问题是复现一份基于paddleocr的代码,要求支持cpu推理和gpu单卡推理。
情况摸排
- 根据项目其他依赖,选择使用3.8版本的python.
- 通过前置测试,确定代码依赖paddlepaddle=2.5.2, paddleocr=2.0.1,在此环境下cpu推理成功。因此,我们为GPU推理选择安装2.5.2版本的paddlepaddle-gpu.
注意,如果是从头开始开发,建议直接选取最新版本的paddle和paddleocr,然后在后续开发中保持版本不变。
- 运行环境是实体宿主机,cuda版本12.0,安装位置在
/usr/local/cuda/bin,nvcc -V显示正常。
安装方式
- 根据Paddle2.5官方文档,CUDA 工具包 12.0 配合 cuDNN v8.9.1. 这个链接同时提供了 CUDA12.0 包含 cuDNN 动态链接库的 PaddlePaddle安装方式。
pip install paddlepaddle-gpu==2.5.2.post120 -f https://www.paddlepaddle.org.cn/whl/linux/cudnnin/stable.html
- 按照这种方式安装paddlepaddle-gpu之后,
which python找到目前环境的python的位置,假如是anaconda_path/envs/env_name/bin/python,那么cuDNN 动态链接库的位置在anaconda_path/envs/env_name/lib/python3.8/site-packages/paddle/libs

- 路径配置,为了paddle能正常找到cuda和cudnn
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=anaconda_path/envs/env_name/lib/python3.8/site-packages/paddle/libs:$LD_LIBRARY_PATH
- 检测paddle环境正常:因为没有装nccl,所以此时运行
paddle.utils.run_check()是过不了的。但是没关系,我们运行paddle.utils.run_check()指令,观测到前面正常调用gpu+cudnn版本正确即可
$ python
Python 3.8.19 (default, Mar 20 2024, 19:58:24)
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import paddle
>>> paddle.utils.run_check()
Running verify PaddlePaddle program ...
I0521 09:57:48.455099 463860 interpretercore.cc:237] New Executor is Running.
W0521 09:57:48.455610 463860 gpu_resources.cc:96] The GPU architecture in your current machine is Pascal, which is not compatible with Paddle installation with arch: 70 75 80 86 , it is recommended to install the corresponding wheel package according to the installation information on the official Paddle website.
W0521 09:57:48.455624 463860 gpu_resources.cc:119] Please NOTE: device: 0, GPU Compute Capability: 6.1, Driver API Version: 12.0, Runtime API Version: 12.0
W0521 09:57:48.456411 463860 gpu_resources.cc:149] device: 0, cuDNN Version: 8.9.
I0521 09:57:48.978622 463860 interpreter_util.cc:518] Standalone Executor is Used.
PaddlePaddle works well on 1 GPU.
- 安装paddleocr
pip install paddleocr==2.0.1
- 测试GPU推理代码,输出预期结果并观测到gpu调用
意料外情况处理
报错找不到库文件,参考链接解决:安装新版本gcc
conda install -c conda-forge gcc=12
3661

被折叠的 条评论
为什么被折叠?



