|

楼主 |
发表于 2025-2-28 06:06:18
|
显示全部楼层
docker部署ray集群-多机单卡启动vllm-qwen2
JasonZhu
JasonZhu
AIGC工程化
​关注
13 人赞同了该文章
​
目录
收起
运行环境:
安装:
部署集群:
遇到的问题:
docker 的 ray 集群中部署 vllm,两个机器 使用的是不同型号显卡
运行环境:
硬件:
head node: A800 * 1
worker node: Quadro RTX 6000 * 1
软件环境
vllm==0.5.5
ray==2.21.0
安装:
vllm 环境:vllm 环境的安装可以参考 vllm 官网,镜像是自己封装的,可以使用官网的 vllm 对应的镜像
模型文件:可以提前封装在镜像里,也可以通过挂载的方式实现,我这里是直接封装的镜像内部,所以没有挂载,也可以进行挂载。
部署集群:
在两台机器上分别启动两个容器,一个容器为 head 节点,一个为 worker 节点
1)ray集群启动脚本如下:
head 和 worker 节点都需要执行:根据自己的需要修改相关的参数,-e 参数参考问题答疑部分-显卡通信问题
# head + worker
docker run -it \
--privileged \
--entrypoint /bin/bash \
--network host \
--name ray_header5.6 \
--shm-size 10.24g \
--gpus all \
-e NCCL_SOCKET_IFNAME=^lo,eno2,eth1,eth2,eth3,docker0,flannel.1,cni0,veth,br- \
-e NCCL_DEBUG=TRACE \
-v "/data/home/llm_models/gpu/qwen:/home/Models" \
vllm-0.5.5-ray-release:v13
# 如果需要挂载,挂载到容器内的/home/Models目录下
-v "/home/zhuzs/projects/gitlab/vllm_server/Models:/home/Models"
分别进入两个节点的容器内,手动执行,根据自己的 ip 地址进行修改,将 node1 换为对应的节点的 ip,如:127.0.0.1
# head节点
ray start --head --port=6379 --dashboard-host='0.0.0.0'
# worker节点
ray start --address='node1:6379'
dashboard 是 ray 查看集群状态的接口,设置为 0.0.0.0,可以通过主机:端口访问,默认端口是 8265,ray 命令相关的参数,可以通过 ray --help查看
2)集群正常启动日志如下:
# head 节点
root@:/home# ray start --head --port=6379 --dashboard-host='0.0.0.0'
Usage stats collection is enabled. To disable this, add `--disable-usage-stats` to the command that starts the cluster, or run the following command: `ray disable-usage-stats` before starting the cluster. See https://docs.ray.io/en/master/cluster/usage-stats.html for more details.
--------------------
Ray runtime started.
--------------------
Next steps
To add another node to this Ray cluster, run
ray start --address='nodeip:6379'
To connect to this Ray cluster:
import ray
ray.init()
To submit a Ray job using the Ray Jobs CLI:
RAY_ADDRESS='http://nodeip:8265' ray job submit --working-dir . -- python my_script.py
See https://docs.ray.io/en/latest/cl ... bmission/index.html
for more information on submitting Ray jobs to the Ray cluster.
To terminate the Ray runtime, run
ray stop
To view the status of the cluster, use
ray status
To monitor and debug Ray, view the dashboard at
nodeip:8265
If connection to the dashboard fails, check your firewall settings and network configuration.
# worker节点
root@:/home# ray start --address='headnodeip:6379'
Local node IP: worknodeip
[2024-09-23 10:35:14,900 W 7358 7358] global_state_accessor.cc:459: Retrying to get node with node ID b9e82c8a305dbf307bc4a0915dd0c5b27add6f9df6747305c652b45d
--------------------
Ray runtime started.
--------------------
To terminate the Ray runtime, run
ray stop
3)集群状态查看,在任意节点的容器内上执行 ray status,可以看到集群中的状态
root@gpu6959:/home# ray status
======== Autoscaler status: 2024-09-23 10:35:48.208468 ========
Node status
---------------------------------------------------------------
Active:
1 node_7ef076c140177f676448e42588af50b528a13b7de328ccac1a30c151
1 node_b9e82c8a305dbf307bc4a0915dd0c5b27add6f9df6747305c652b45d
Pending:
(no pending nodes)
Recent failures:
(no failures)
Resources
---------------------------------------------------------------
Usage:
0.0/88.0 CPU
0.0/2.0 GPU
0B/724.51GiB memory
0B/19.46GiB object_store_memory
Demands:
(no resource demands)
可视化界面:web上输入headip:8265
ray集群的deashboard界面
4)启动模型:使用 vllm serve 启动
模型文件可以提前封装在镜像里,也可以通过挂载的方式实现,我这里
vllm serve /home/Qwen2-7B-Instruct-GPTQ-Int4 \
--tensor-parallel-size 2 \
--gpu-memory-utilization 0.4 \
--quantization gptq \
--max-model-len 128 \
--max-num-seqs 1 \
--served_model_name qwen-base \
--trust-remote-code \
--port 8009
启动成功结果
启动模型成功日志
curl请求测试可用,使用 openai 的接口模式, mode是启动时配置的model_name
curl http://10.1.68.67:8009/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-base",
"messages": [
{
"role": "user",
"content": "Hello!"
}
]
请求结果
{"id":"chat-4d6cfe70695b464081ab55548d3e7860","object":"chat.completion","created":1724922331,"model":"qwen-base","choices":[{"index":0,"message":{"role":"assistant","content":"Hello there! How can I assist you today?","tool_calls":[]},"logprobs":null,"finish_reason":"stop","stop_reason":null}],"usage":{"prompt_tokens":20,"total_tokens":31,"completion_tokens":11}}
遇到的问题:
1) 同一台机器启动两个容器
每个容器一张卡,不允许这样执行,容器能启动,分布式状态正确,但是无法启动模型,其实也正常,同一台机器直接使用 vllm 单独启动即可,不用集群
查看了NCCL的详细日志说是不能这样执行
使用环境变量追踪日志,可以定位详细的错误问题,当出现WARN时可能会有问题,也可以在容器启动时配置环境变量:
# 容器启动时配置
-e NCCL_DEBUG=TRACE
# 手动配置
export NCCL_DEBUG=TRACE
2)网络通信问题
通过 ray status 查看集群状态正常,打开nccl日志追踪
https://www.w3xue.com/exp/article/20244/89111.html
查找相关的文档说是要过滤掉虚拟网卡的ip
解决方案:
正确的应该是用^后面过滤掉所有不用的,两台机器的都写在里面,比如我想用 eth0,也就是节点上的物理网卡名字是这个,
两边都需要配置环境变量,在启动docker时添加环境变量
# docker启动
-e NCCL_SOCKET_IFNAME=^lo,eno2,eth1,eth2,eth3,docker0,flannel.1,cni0,veth,br-
# 手动
export NCCL_SOCKET_IFNAME=^lo,eno2,eth1,eth2,eth3,docker0,flannel.1,cni0,veth,br-
比如在 node 上执行 ifconfig,会显示很多网卡,下面截取了一部分
docker0 Link encap:Ethernet HWaddr
inet addr: Bcast: Mask:
inet6 addr:
eth0 Link encap:Ethernet HWaddr
inet addr: Bcast: Mask:
inet6 addr:
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1984235723 errors:0 dropped:2320 overruns:31638 frame:0
eth1 Link encap:Ethernet HWaddr
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
比如想用 eth0,节点的物理网卡,就把其他网卡全部屏蔽掉,只留下需要的export NCCL_SOCKET_IFNAME=^lo,eth1,docker0
由于我的服务器上 tmp 不一定够,可能会出现tmp不足的问题,会影响性能,但不影响运行
但只要显存够,能正常启动
3)vllm serve 启动时卡柱,一直在加载,未出现 Uvicorn running 字样
tensor-parallel-size=2 改成 pipeline-parallel-size=2,能正常启动,可能是由于我这里使用的是两张不同的显卡,会导致卡主
参考目录:
vllm 分布式:Distributed Inference and Serving — vLLM
vllm 启动 openai 的接口:OpenAI Compatible Server — vLLM
分布式网卡通信问题:deepspeed 训练多机多卡报错 ncclSystemError Last error - 技术经验 - W3xue
发布于 2024-09-23 11: |
|