深度学习部署实战 Ubuntu24.04单机多卡部署ERNIE-4.5-VL-28B-A3B-Paddle文心多模态大模型(详细教程)
目录
深度学习部署实战 Ubuntu24.04单机多卡部署ERNIE-4.5-VL-28B-A3B-Paddle文心多模态大模型(详细教程)
超实用的多模态大模型部署教程,助力深度学习研究!
1、前置环境准备(重要⭐⭐⭐)
查看gpu驱动版本
查看cuda版本
查看cudnn版本
查看系统版本
查看python版本
2、运行环境搭建
2.1 paddlepaddle安装
2.2 fastdeploy安装
2.3 环境检查
3、模型下载
4、启动服务(关键命令)
服务启动参数详细说明
5、模型调用示例
requests库调用方式---图像描述生成
6、参考资源链接
7、交流学习
深度学习部署实战 Ubuntu24.04单机多卡部署ERNIE-4.5-VL-28B-A3B-Paddle文心多模态大模型(详细教程)
超实用的多模态大模型部署教程,助力深度学习研究!
测试环境:
ubuntu24.04
cuda12.8
3090显卡(4x24G)
磁盘空间1T
1、前置环境准备(重要⭐⭐⭐)
在开始部署前,请确保你的硬件环境满足如下条件:
- • GPU驱动 >= 535
- • CUDA >= 12.3
- • CUDNN >= 9.5
- • Linux X86_64
- • Python >= 3.10
查看gpu驱动版本
nvidia-smi
查看cuda版本
nvcc -V
查看cudnn版本
dpkg -l | grep cudnn
查看系统版本
cat /etc/os-release
查看python版本
python --version
2、运行环境搭建
2.1 paddlepaddle安装
首先安装 paddlepaddle-gpu,cuda(版本12.8)向下兼容
可参考:https://www.paddlepaddle.org.cn/en/install/quick?docurl=/documentation/docs/en/develop/install/pip/linux-pip_en.html
python -m pip install paddlepaddle-gpu==3.1.1 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
2.2 fastdeploy安装
查看显卡型号算力
可参考:https://developer.nvidia.com/cuda-gpus#compute
算力版本 | 显卡型号版本 |
---|---|
8.0 | NVIDIA A100、NVIDIA A30 |
9.0 | NVIDIA GH200、NVIDIA H200、NVIDIA H100 |
8.6 | NVIDIA A40、NVIDIA A10、NVIDIA A16、NVIDIA A2、NVIDIA RTX A6000、NVIDIA RTX A5000、NVIDIA RTX A4000、NVIDIA RTX A3000、NVIDIA RTX A2000、GeForce RTX 3090 Ti、GeForce RTX 3090、GeForce RTX 3080 Ti、GeForce RTX 3080、GeForce RTX 3070 Ti、GeForce RTX 3070、GeForce RTX 3060 Ti、GeForce RTX 3060、GeForce RTX 3050 Ti、GeForce RTX 3050 |
8.9 | NVIDIA L4、NVIDIA L40、NVIDIA RTX 6000 Ada、NVIDIA RTX 5000 Ada、NVIDIA RTX 4500 Ada、NVIDIA RTX 4000 Ada、NVIDIA RTX 4000 SFF Ada、NVIDIA RTX 2000 Ada、GeForce RTX 4090、GeForce RTX 4080、GeForce RTX 4070 Ti、GeForce RTX 4070、GeForce RTX 4060 Ti、GeForce RTX 4060、GeForce RTX 4050 |
安装方式,可参考:https://paddlepaddle.github.io/FastDeploy/zh/get_started/installation/nvidia_gpu/
目前显卡为3090,选择算力为8.6的系列
# 安装稳定版本fastdeploy
python -m pip install fastdeploy-gpu -i https://www.paddlepaddle.org.cn/packages/stable/fastdeploy-gpu-86_89/ --extra-index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
2.3 环境检查
在安装 FastDeploy 后,通过如下 Python 代码检查环境的可用性
import paddle
from paddle.jit.marker import unified
# 检查GPU卡的可用性
paddle.utils.run_check()
# 检查FastDeploy自定义算子编译成功与否
from fastdeploy.model_executor.ops.gpu import beam_search_softmax
3、模型下载
模型下载地址,可参考:https://aistudio.baidu.com/modelsdetail/30648/intro
CLI命令行下载方式
# 首先请先安装aistudio-sdk库
# pip install --upgrade aistudio-sdk# 安装后获取帮助可输入:
aistudio download -h# 下载整个repo(到指定目录)
# 填写要下载的模型repo_id,在local_dir后指定下载路径,以下示例为下载到当前文件夹
aistudio download --model PaddlePaddle/ERNIE-4.5-VL-28B-A3B-Paddle --local_dir ./ERNIE-4.5-VL-28B-A3B-Paddle
目录结构展示
ERNIE-4.5-VL-28B-A3B-Paddle/├── LICENSE # 许可证文件├── README.md # 模型说明文档├── added_tokens.json # 新增token配置├── config.json # 模型配置文件├── generation_config.json # 生成配置文件├── model-00001-of-00012.safetensors # 模型参数文件(分片1/12)├── model-00002-of-00012.safetensors # 模型参数文件(分片2/12)├── model-00003-of-00012.safetensors # 模型参数文件(分片3/12)├── model-00004-of-00012.safetensors # 模型参数文件(分片4/12)├── model-00005-of-00012.safetensors # 模型参数文件(分片5/12)├── model-00006-of-00012.safetensors # 模型参数文件(分片6/12)├── model-00007-of-00012.safetensors # 模型参数文件(分片7/12)├── model-00008-of-00012.safetensors # 模型参数文件(分片8/12)├── model-00009-of-00012.safetensors # 模型参数文件(分片9/12)├── model-00010-of-00012.safetensors # 模型参数文件(分片10/12)├── model-00011-of-00012.safetensors # 模型参数文件(分片11/12)├── model-00012-of-00012.safetensors # 模型参数文件(分片12/12)├── model.safetensors.index.json # 模型分片索引文件├── preprocessor_config.json # 预处理器配置├── special_tokens_map.json # 特殊token映射├── tokenizer.model # 分词器模型文件└── tokenizer_config.json # 分词器配置文件
4、启动服务(关键命令)
新建start_server.sh脚本,写入如下内容:
CUDA_VISIBLE_DEVICES=0,1,2,3 python -m fastdeploy.entrypoints.openai.api_server \--model ./ERNIE-4.5-VL-28B-A3B-Paddle \--port 8180 \--metrics-port 8181 \--engine-worker-queue-port 8182 \--max-model-len 32768 \--max-num-seqs 32 \--tensor-parallel-size 4 \--quantization wint4 \--reasoning-parser ernie-45-vl \--enable-mm \--enable-chunked-prefill
服务启动参数详细说明
参数名称 | 参数说明 | 默认值 | 示例值 |
---|---|---|---|
--model | 模型文件路径,包含模型权重和配置文件的目录 | 必选 | ./ERNIE-4.5-VL-28B-A3B-Paddle |
--port | API服务监听端口,客户端通过此端口访问服务 | 8000 | 8180 |
--metrics-port | 监控指标服务端口,用于性能监控和健康检查 | 8001 | 8181 |
--engine-worker-queue-port | 引擎工作队列端口,用于内部任务调度 | 8002 | 8182 |
--max-model-len | 模型最大支持的序列长度(token数) | 2048 | 32768 |
--max-num-seqs | 最大并发序列数,控制批处理大小 | 256 | 32 |
--tensor-parallel-size | 张量并行大小(多GPU) | 1 | 4 |
--quantization | 模型量化策略,指定wint4或wint8时,支持无损在线4bit/8bit量化 | 无 | wint4 |
--enable-mm | 启用多模态功能(文本+图像处理) | False | 开启 |
--reasoning-parser | 推理解析器类型,指定模型的推理逻辑 | 无 | ernie-45-vl |
--enable_chunked_prefill | 动态分块处理长输入序列,显著提升GPU资源利用率 | False | 开启 |
5、模型调用示例
requests库调用方式---图像描述生成
import requests
import base64
import jsondef encode_image(image_path):with open(image_path, "rb") as image_file:return base64.b64encode(image_file.read()).decode('utf-8')url = "http://localhost:8180/v1/chat/completions"
headers = {"Content-Type": "application/json"}
payload = {"model":"null","messages":[{"role":"user","content":[{"type":"image_url","image_url":{"url":f"data:image/jpeg;base64,{encode_image('1.jpg')}"}},{"type":"text","text":"生成图片描述"}]}],"stream": True
}response = requests.post(url, headers=headers, json=payload, stream=True)for line in response.iter_lines():if line:line = line.decode('utf-8').replace('data: ', '')if line.strip() == '[DONE]':continuetry:data = json.loads(line)if 'choices' in data and len(data['choices']) > 0:delta = data['choices'][0].get('delta', {})content = delta.get('content', '')if content:print(content, end='', flush=True)except json.JSONDecodeError as e:print(f"Error decoding line: {line}")print(f"Error: {e}")print()
6、参考资源链接
- • https://paddlepaddle.github.io/FastDeploy/zh/get_started/quick_start_vl/
- • https://blog.csdn.net/cooldream2009/article/details/149292330
- • https://aistudio.baidu.com/projectdetail/9357717?channelType=0
7、交流学习
进一步交流学习,共同进步,可在下方回复联系!祝您前程似锦!
文章:Ubuntu24.04单机多卡部署ERNIE-4.5-VL-28B-A3B-Paddle文心多模态大模型(详细教程)