Docker安裝分布式vLLM的實現(xiàn)步驟
1 介紹
vLLM是一個快速且易于使用的LLM推理和服務庫,適合用于生產(chǎn)環(huán)境。單主機部署會遇到顯存不足的問題,因此需要分布式部署。
分布式安裝方法
https://docs.vllm.ai/en/latest/serving/distributed_serving.html
2 安裝方法
?? 注意:前期一定要把docker環(huán)境、運行時和GPU安裝好。
CUDA Version: 12.4
vllm:v0.7.2
2.1 下載鏡像
# 下載鏡像,鏡像比較大 docker pull vllm/vllm-openai:v0.7.2
下載分布式部署的腳本
https://github.com/vllm-project/vllm/blob/main/examples/online_serving/run_cluster.sh
run_cluster.sh文件
#!/bin/bash
# Check for minimum number of required arguments
if [ $# -lt 4 ]; then
echo "Usage: $0 docker_image head_node_address --head|--worker path_to_hf_home [additional_args...]"
exit 1
fi
# Assign the first three arguments and shift them away
DOCKER_IMAGE="$1"
HEAD_NODE_ADDRESS="$2"
NODE_TYPE="$3" # Should be --head or --worker
PATH_TO_HF_HOME="$4"
shift 4
# Additional arguments are passed directly to the Docker command
ADDITIONAL_ARGS=("$@")
# Validate node type
if [ "${NODE_TYPE}" != "--head" ] && [ "${NODE_TYPE}" != "--worker" ]; then
echo "Error: Node type must be --head or --worker"
exit 1
fi
# Define a function to cleanup on EXIT signal
cleanup() {
docker stop node
docker rm node
}
trap cleanup EXIT
# Command setup for head or worker node
RAY_START_CMD="ray start --block"
if [ "${NODE_TYPE}" == "--head" ]; then
RAY_START_CMD+=" --head --port=6379"
else
RAY_START_CMD+=" --address=${HEAD_NODE_ADDRESS}:6379"
fi
# Run the docker command with the user specified parameters and additional arguments
docker run \
--entrypoint /bin/bash \
--network host \
--name node \
--shm-size 10.24g \
--gpus all \
-v "${PATH_TO_HF_HOME}:/root/.cache/huggingface" \
"${ADDITIONAL_ARGS[@]}" \
"${DOCKER_IMAGE}" -c "${RAY_START_CMD}"
2.2 創(chuàng)建容器
兩臺主機的IP如下,主節(jié)點宿主機IP:192.168.108.100,工作節(jié)點宿主機IP:192.168.108.101。
主節(jié)點(head節(jié)點)運行分布式vLLM腳本
官網(wǎng)的說明
# ip_of_head_node:主節(jié)點容器所在宿主機的IP地址
# /path/to/the/huggingface/home/in/this/node: 映射到到容器中的路徑
# ip_of_this_node:當前節(jié)點所在宿主機的IP地址
# --head:表示主節(jié)點
bash run_cluster.sh \
vllm/vllm-openai \
ip_of_head_node \
--head \
/path/to/the/huggingface/home/in/this/node \
-e VLLM_HOST_IP=ip_of_this_node
本機執(zhí)行
bash run_cluster.sh \
vllm/vllm-openai:v0.7.2 \
192.168.108.100 \
--head \
/home/vllm \
-e VLLM_HOST_IP=192.168.108.100 \
> nohup.log 2>&1 &
工作節(jié)點(worker節(jié)點)運行分布式vLLM腳本
官網(wǎng)的說明
# ip_of_head_node:主節(jié)點容器所在宿主機的IP地址
# /path/to/the/huggingface/home/in/this/node: 映射到到容器中的路徑
# ip_of_this_node:當前節(jié)點所在宿主機的IP地址
# --worker:表示工作節(jié)點
bash run_cluster.sh \
vllm/vllm-openai \
ip_of_head_node \
--worker \
/path/to/the/huggingface/home/in/this/node \
-e VLLM_HOST_IP=ip_of_this_node
本機執(zhí)行
bash run_cluster.sh \
vllm/vllm-openai:v0.7.2 \
192.168.108.100 \
--worker \
/home/vllm \
-e VLLM_HOST_IP192.168.108.101 \
> nohup.log 2>&1 &
查看集群的信息
# 進入容器 docker exec -it node /bin/bash # 查看集群信息 ray status # 返回值中有GPU數(shù)量、CPU配置和內(nèi)存大小等 ======== Autoscaler status: 2025-02-13 20:18:13.886242 ======== Node status --------------------------------------------------------------- Active: 1 node_89c804d654976b3c606850c461e8dc5c6366de5e0ccdb360fcaa1b1c 1 node_4b794efd101bc393da41f0a45bd72eeb3fb78e8e507d72b5fdfb4c1b Pending: (no pending nodes) Recent failures: (no failures) Resources --------------------------------------------------------------- Usage: 0.0/128.0 CPU 0.0/4.0 GPU 0B/20 GiB memory 0B/19.46GiB object_store_memory Demands: (no resource demands)
3 安裝模型
?? 本地有4張GPU卡。
官網(wǎng)說明
# 啟動模型服務,可根據(jù)情況設置模型參數(shù)
# /path/to/the/model/in/the/container:模型路徑
# tensor-parallel-size:張量并行數(shù)量,模型層內(nèi)拆分后并行計算;
# pipeline-parallel-size:管道并行數(shù)量,模型不同層拆分后并行計算,在單個顯存不夠時可以設置此參數(shù)
vllm serve /path/to/the/model/in/the/container \
--tensor-parallel-size 8 \
--pipeline-parallel-size 2
本機執(zhí)行
將下載好的Qwen2.5-7B-Instruct模型,放在“/home/vllm”目錄下
# 進入節(jié)點,主節(jié)點和工作節(jié)點都可以
docker exec -it node /bin/bash
# 執(zhí)行命令參數(shù)
nohup vllm serve /root/.cache/huggingface/Qwen2.5-7B-Instruct \
--served-model-name qwen2.5-7b \
--tensor-parallel-size 2 \
--pipeline-parallel-size 2 \
> nohup.log 2>&1 &
在宿主機上調(diào)用參數(shù)
curl http://localhost:8000/v1/chat/completions \
-X POST \
-H "Content-Type: application/json" \
-d '{
"model": "qwen2.5-7b",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "介紹一下中國,不少于10000字"}
],
"stream": true
}'到此這篇關于Docker安裝分布式vLLM的實現(xiàn)步驟的文章就介紹到這了,更多相關Docker安裝分布式vLLM內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

