PaddleOCR-VL 模型部署实战:Docker 镜像与 vLLM 服务启动

记录用 PaddleOCR 官方 Docker 镜像快速启动 vLLM 推理服务、部署 PaddleOCR-VL-0.9B 的过程,包含 GPU 与网络参数配置、服务启动命令,以及官方流水线用法的参考链接。

https://www.paddleocr.ai/latest/version3.x/pipeline_usage/PaddleOCR-VL.html#31-vlm

模型部署

PaddleOCR 提供了 Docker 镜像,用于快速启动 vLLM 推理服务。可使用以下命令启动服务:

1
2
3
4
5
6
7
docker run \
-it \
--rm \
--gpus all \
--network host \
ccr-2vdh3abv-pub.cnc.bj.baidubce.com/paddlepaddle/paddlex-genai-vllm-server \
paddlex_genai_server --model_name PaddleOCR-VL-0.9B --host 0.0.0.0 --port 8118 --backend vllm --model_dir /data/models/PaddleOCR-VL-0.9B

本地环境安装

1
2
3
4
wget https://files.pythonhosted.org/packages/32/68/fb93a38c567291c3d8a336d3fdf8306a5d378dec3deeb23f2d732a71cf81/paddlepaddle-3.2.1-cp312-cp312-win_amd64.whl

pip install paddlepaddle-3.2.1-cp312-cp312-win_amd64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install paddleocr[all]==3.3.1 -i https://pypi.tuna.tsinghua.edu.cn/simple

Python API 调用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from pathlib import Path
from paddleocr import PaddleOCRVL

input_file = "./your_pdf_file.pdf"
output_path = Path("./output")

pipeline = PaddleOCRVL(vl_rec_backend="vllm-server", vl_rec_server_url="http://127.0.0.1:8118/v1")
output = pipeline.predict(input=input_file)

markdown_list = []
markdown_images = []

for res in output:
md_info = res.markdown
markdown_list.append(md_info)
markdown_images.append(md_info.get("markdown_images", {}))

markdown_texts = pipeline.concatenate_markdown_pages(markdown_list)

mkd_file_path = output_path / f"{Path(input_file).stem}.md"
mkd_file_path.parent.mkdir(parents=True, exist_ok=True)

with open(mkd_file_path, "w", encoding="utf-8") as f:
f.write(markdown_texts)

for item in markdown_images:
if item:
for path, image in item.items():
file_path = output_path / path
file_path.parent.mkdir(parents=True, exist_ok=True)
image.save(file_path)

参数调优

使用支持进程替换(process substitution)的 shell(如 Bash)

1
paddleocr genai_server --model_name PaddleOCR-VL-0.9B --backend vllm --backend_config <(echo -e 'gpu-memory-utilization: 0.3\nmax-num-seqs: 128')
本文结束 感谢您的阅读