深度解析:通過(guò) AIBrix 多節(jié)點(diǎn)部署 DeepSeek-R1 671B 模型
本文詳細(xì)介紹了如何通過(guò) AIBrix 分布式推理平臺(tái)實(shí)現(xiàn) DeepSeek-R1 671B 的多節(jié)點(diǎn)部署。DeepSeek-R1 通過(guò)漸進(jìn)式訓(xùn)練框架展現(xiàn)出優(yōu)秀的邏輯推理能力 —— 在 6710 億總參數(shù)量中,其動(dòng)態(tài)激活的 370 億參數(shù)與 128k 上下文窗口,使其在復(fù)雜任務(wù)處理中表現(xiàn)卓越。然而,如此龐大的模型規(guī)模對(duì)部署環(huán)境提出了嚴(yán)苛挑戰(zhàn),尤其是分布式推理的資源調(diào)度與性能優(yōu)化。AIBrix 通過(guò)自主研發(fā)的容器化編排技術(shù),實(shí)現(xiàn)了:
- 多節(jié)點(diǎn) GPU 資源的智能分配
- 分布式推理服務(wù)的無(wú)縫管理
- 基于 RDMA 的高性能網(wǎng)絡(luò)通信
- 自動(dòng)化彈性伸縮策略
通過(guò)與 AIBrix 的結(jié)合,使得原本需要數(shù)周的超大規(guī)模模型部署周期縮短至小時(shí)級(jí)。接下來(lái),我們將從集群配置、鏡像優(yōu)化、存儲(chǔ)方案等關(guān)鍵環(huán)節(jié)展開,為您呈現(xiàn)完整的技術(shù)實(shí)現(xiàn)路徑。
Reference: https://huggingface.co/deepseek-ai/DeepSeek-R1/resolve/main/figures/benchmark.jpg
01、前置準(zhǔn)備
在 AIBrix 部署 DeepSeek-R1 前,需完成以下準(zhǔn)備工作:將模型權(quán)重下載至對(duì)象存儲(chǔ)或共享文件系統(tǒng),并配置定制化容器鏡像。本文將聚焦關(guān)鍵步驟,更多細(xì)節(jié)請(qǐng)參考我們的代碼示例與教程:https://github.com/vllm-project/aibrix/tree/main/samples/deepseek-r1
集群配置
DeepSeek-R1 671B 需要 16 塊 顯存 80+GB GPU。測(cè)試使用的實(shí)例規(guī)格如下,您可根據(jù)實(shí)際環(huán)境選擇類似配置
- 云平臺(tái):火山引擎
- 實(shí)例:ecs.ebmhpcpni3l.48xlarge * 2
- CPU: 192 vCPU
- 內(nèi)存:2048GiB DRAM
- GPU: 96GB*8
- 網(wǎng)絡(luò):400 Gbps * 8 RDMA + 96 Gbps
- 磁盤:本地 NVME 3576GiB * 4
vLLM 鏡像
本次部署使用的鏡像是 aibrix/vllm-openai:v0.7.3.self.post1,這是由 AIBrix 定制構(gòu)建的鏡像。選擇該鏡像主要有兩個(gè)原因:
- 在 v0.7.3 的上游版本中,存在一個(gè)與舊版 NCCL 版本相關(guān)的問題:https://aibrix.github.io/posts/2025-03-10-deepseek-r1/,該問題會(huì)導(dǎo)致系統(tǒng)偶爾掛起。我們通過(guò)將 nvidia-nccl-cu12==2.25.1 進(jìn)行升級(jí),以增強(qiáng)通信的穩(wěn)定性。
- 在 v0.7.3 版本中,出現(xiàn)了一個(gè)與 Ray 相關(guān)的回歸問題,我們之前在 vLLM 中的修改被覆蓋了。為了緩解這個(gè)問題,我們重新引入了 ray[default,adag],以便為高可用性和故障檢測(cè)提供更好的探測(cè)支持。
如果你想自己構(gòu)建鏡像,可以使用以下 Dockerfile。
FROM vllm/vllm-openai:v0.7.3
RUN pip3 install -U ray[default,adag]==2.40.0
RUN pip3 install -U nvidia-nccl-cu12
ENTRYPOINT [""]
注意:對(duì)于中國(guó)的用戶,從我們的鏡像倉(cāng)庫(kù)拉取鏡像時(shí),可能需要在鏡像名稱前加上 aibrix-container-registry-cn-beijing.cr.volces.com/。例如,不要只使用 aibrix/vllm-openai:v0.7.3.self.post1,而應(yīng)該使用 aibrix-container-registry-cn-beijing.cr.volces.com/aibrix/vllm-openai:v0.7.3.self.post1。同樣的規(guī)則也適用于 aibrix/runtime:v0.2.1。
模型權(quán)重
用戶可以根據(jù)自己的云服務(wù)提供商,為模型權(quán)重
https://huggingface.co/deepseek-ai/DeepSeek-R1選擇不同的存儲(chǔ)選項(xiàng)。這里,我們將討論四種常見的場(chǎng)景:
- HuggingFace:一個(gè) Pod 可以直接從 HuggingFace 檢索模型權(quán)重。然而,需要注意的是,不建議對(duì) DeepSeek R1 從 HuggingFace 獲取權(quán)重。這是因?yàn)閺埩看笮「鞑幌嗤瑫?huì)導(dǎo)致大量的隨機(jī)讀取,從而顯著降低網(wǎng)絡(luò)和 I/O 效率。
- 持久卷(Persistent Volume):像 AWS(使用 Lustre)或谷歌云這樣的云服務(wù)提供商,通過(guò)其容器存儲(chǔ)接口(CSI)
https://kubernetes-csi.github.io/docs/提供持久磁盤。用戶可以輕松地將持久卷聲明(PVC)
https://kubernetes.io/docs/concepts/storage/persistent-volumes/掛載到 Pod 上,從而能夠無(wú)縫訪問存儲(chǔ)在這些持久磁盤上的模型權(quán)重。 - 結(jié)合 AI 運(yùn)行時(shí)的對(duì)象存儲(chǔ):用戶可以選擇將模型權(quán)重存儲(chǔ)在對(duì)象存儲(chǔ)服務(wù)中,如亞馬遜 S3 或谷歌云存儲(chǔ)(GCS)。在這種情況下,AIBrix AI 運(yùn)行時(shí)將自動(dòng)將模型下載到主機(jī)卷上。這種方法利用了對(duì)象存儲(chǔ)在存儲(chǔ)大量數(shù)據(jù)方面的優(yōu)勢(shì),提供了靈活性和可擴(kuò)展性。
- 本地磁盤:對(duì)于本地磁盤存儲(chǔ),需要額外的過(guò)程將模型權(quán)重下載到本地磁盤上。我們假設(shè)存在一個(gè)可用的本地卷,并且可以成功地掛載到 Pod 上。這種選擇可能適用于本地存儲(chǔ)能帶來(lái)性能優(yōu)勢(shì)的環(huán)境,或者當(dāng)存在特定的安全或延遲要求時(shí)。
存儲(chǔ)選項(xiàng) | 描述 | 示例文件 |
HuggingFace | no volume needed | https://github.com/vllm-project/aibrix/blob/main/samples/deepseek-r1/deepseek-r1-huggingface.yaml |
Persistent Volume | models volume, PVC | https://github.com/vllm-project/aibrix/blob/main/samples/deepseek-r1/deepseek-r1-pvc.yaml |
Object Storage(S3 / GCS) with AIBrix AI Runtime | models volume, HostPath | https://github.com/vllm-project/aibrix/blob/main/samples/deepseek-r1/deepseek-r1-ai-runtime.yaml |
Local Disk | models volume, HostPath + InitContainer | https://github.com/vllm-project/aibrix/blob/main/samples/deepseek-r1/deepseek-r1-local-nvme.yaml |
高性能網(wǎng)絡(luò)
為了利用 RDMA 在網(wǎng)絡(luò)通信中實(shí)現(xiàn)最佳性能,我們需要配置 Pod 配置以使用 RDMA。在注解中配置 k8s.volcengine.com/pod-networks,如下所示,并且在 Pod 資源級(jí)別需要 vke.volcengine.com/rdma:"8"。這只是火山引擎云上的一個(gè)示例,你需要根據(jù)自己的云環(huán)境進(jìn)行相應(yīng)的更改。
k8s.volcengine.com/pod-networks: |
[
{
"cniConf":{
"name":"rdma"
}
},
....
{
"cniConf":{
"name":"rdma"
}
}
]
此外,我們還需要 IPC_LOCK 和共享內(nèi)存支持。
securityContext:
capabilities:
add:
- IPC_LOCK
02、安裝
多節(jié)點(diǎn)部署需要 AIBrix v0.2.1https://github.com/vllm-project/aibrix/releases/tag/v0.2.1版本。在部署 AIBrix 時(shí),需要注意的是,AIBrix 鏡像主要托管在 Dockerhub 上,在對(duì) Dockerhub 訪問有限制的環(huán)境中進(jìn)行部署可能具有挑戰(zhàn)性。為了克服這個(gè)問題,請(qǐng)查看我們的教程,使用你自己的鏡像倉(cāng)庫(kù)覆蓋控制平面鏡像,從而實(shí)現(xiàn)定制化 AIBrix 的順利部署。
需要強(qiáng)調(diào)的是,可能存在一些與云環(huán)境相關(guān)的方面,例如 ReadWriteMany 卷提供程序、本地磁盤 等。我們這里以火山引擎https://www.volcengine.com/為例,但建議用戶檢查自己的云基礎(chǔ)設(shè)施。雖然我們可以提供一些一般性的建議,但由于資源有限,我們無(wú)法對(duì)所有云平臺(tái)進(jìn)行全面測(cè)試。我們鼓勵(lì)社區(qū)通過(guò)提交拉取請(qǐng)求(PR)來(lái)提供幫助,以改進(jìn)我們對(duì)不同云平臺(tái)的支持。
kubectl create -f https://github.com/vllm-project/aibrix/releases/download/v0.2.1/aibrix-dependency-v0.2.1.yaml
kubectl create -f https://github.com/vllm-project/aibrix/releases/download/v0.2.1/aibrix-core-v0.2.1.yaml
03、AIBrix 如何支持 DeepSeek-R1
AIBrix 在支持 Deepseek-r1 671B 模型的部署中起著至關(guān)重要的作用。它提供了一個(gè)全面的平臺(tái),支持分布式編排、高效的流量路由以及智能的縮放功能。這些特性對(duì)于處理 Deepseek-r1 671B 模型的大規(guī)模和資源密集型特性至關(guān)重要。
在開始部署之前,我們將簡(jiǎn)要介紹與本案例相關(guān)的 RayClusterFleet、網(wǎng)關(guān)插件 和 自動(dòng)縮放器 的功能。
RayClusterFleet 在管理分布式推理編排方面發(fā)揮著關(guān)鍵作用。它調(diào)配 Pod 并構(gòu)建一個(gè) Ray 集群,在該集群中啟動(dòng) vLLM 服務(wù)器。因此,每個(gè)小型 Ray 集群都構(gòu)成一個(gè)推理副本。
在多節(jié)點(diǎn)環(huán)境中,vLLM HTTP 服務(wù)器在頭節(jié)點(diǎn)上啟動(dòng)。其余的 GPU 節(jié)點(diǎn)充當(dāng)工作節(jié)點(diǎn),這些節(jié)點(diǎn)上不運(yùn)行 HTTP 服務(wù)。相應(yīng)地,AIBrix 路由器僅將請(qǐng)求路由到頭節(jié)點(diǎn)。同樣,自動(dòng)縮放器僅從服務(wù) Pod 中獲取指標(biāo)。這種分布式配置確保了編排、路由和自動(dòng)縮放機(jī)制能夠有效地運(yùn)行。通過(guò)以類似于單節(jié)點(diǎn)操作的方式管理多節(jié)點(diǎn)設(shè)置,它簡(jiǎn)化了像 Deepseek-r1 這樣的超大型模型的整體部署過(guò)程。
04、模型部署
首先,確保你更改了網(wǎng)絡(luò)和對(duì)象存儲(chǔ)配置,例如使用 s3:https://aibrix.readthedocs.io/latest/features/runtime.html#download-from-s3。對(duì)于 Deepseek-r1,DOWNLOADER_ALLOW_FILE_SUFFIX 必須為 json、safetensors、py。
然后運(yùn)行以下命令來(lái)部署模型以及相關(guān)的基于 kv 緩存的自動(dòng)縮放策略。請(qǐng)注意,這確實(shí)取決于計(jì)算節(jié)點(diǎn)與對(duì)象存儲(chǔ)之間的網(wǎng)絡(luò)速度,部署可能需要長(zhǎng)達(dá) 20 分鐘。
kubectl apply -f deepseek-r1-ai-runtime.yaml
kubectl apply -f deepseek-r1-autoscaling.yaml
過(guò)一會(huì)兒,你應(yīng)該會(huì)看到類似于以下的正在運(yùn)行的 Pod。
kubectl get pods
NAME READY STATUS RESTARTS AGE
deepseek-r1-671b-7ffb754f75-ggnzf-head-7xr6q 1/1 Running 0 25m
deepseek-r1-671b-7ffb754f75-ggnzf-worker-group-worker-gj456 1/1 Running 0 25m
05、發(fā)送請(qǐng)求
通過(guò)以下命令暴露Endpoint進(jìn)行調(diào)用。
# Option 1: Kubernetes cluster with LoadBalancer support
LB_IP=$(kubectl get svc/envoy-aibrix-system-aibrix-eg-903790dc -n envoy-gateway-system -o=jsnotallow='{.status.loadBalancer.ingress[0].ip}')
ENDPOINT="${LB_IP}:80"
# Option 2: Dev environment without LoadBalancer support. Use port forwarding way instead
kubectl -n envoy-gateway-system port-forward service/envoy-aibrix-system-aibrix-eg-903790dc 8888:80 &
ENDPOINT="localhost:8888"
curl http://${ENDPOINT}/v1/chat/completions \
-H "Content-Type: application/json" -H "routing-strategy: least-request" \
-d '{
"model": "deepseek-r1-671b",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"}
]
}'
注意:如果你想使用默認(rèn)的 Kubernetes 路由策略,可以刪除 -H "routing-strategy: least-request" 標(biāo)頭。
你應(yīng)該會(huì)看到類似以下的響應(yīng):
{"id":"chatcmpl-d26583d2-96e5-42c4-a322-133c7d0e505d","object":"chat.completion","created":1740967604,"model":"deepseek-r1-671b","choices":[{"index":0,"message":{"role":"assistant","reasoning_content":null,"content":"<think>\nOkay, the user is asking which team won the World Series in 2020. Let me recall, the World Series is the championship series of Major League Baseball (MLB) in the United States. I remember that 2020 was a unique year because of the COVID-19 pandemic, which affected the schedule and format of the season. The season was shortened, and there were some changes to the playoff structure.\n\nI think the Los Angeles Dodgers won the World Series around that time. Let me verify. The 2020 World Series was held at a neutral site, which was Globe Life Field in Arlington, Texas, to minimize travel and reduce the risk of COVID-19 spread. The Dodgers faced the Tampa Bay Rays. The Dodgers were led by players like Mookie Betts, Corey Seager, and Clayton Kershaw. They won the series in six games. The clinching game was Game 6, where the Dodgers beat the Rays 3-1. That victory gave the Dodgers their first title since 1988, ending a long drought.\n\nWait, let me make sure I got the opponent right. Was it the Rays or another team? Yes, I'm pretty confident it was the Rays because earlier in the playoffs, teams like the Braves and Dodgers were in the National League, while the Rays were the American League champions. The Rays had a strong team with players like Randy Arozarena, who had a standout postseason. But the Dodgers ultimately triumphed. So the answer should be the Los Angeles Dodgers. Let me double-check a reliable source if I'm unsure. Confirming now... yes, the Dodgers won the 2020 World Series against the Tampa Bay Rays in six games. So the user needs to know both the winner and maybe a bit of context, like it being in a neutral location. Okay, ready to provide a concise answer with those details.\n</think>\n\nThe Los Angeles Dodgers won the 2020 World Series, defeating the Tampa Bay Rays in six games. This championship marked the Dodgers' first title since 1988. Notably, the 2020 series was held at Globe Life Field in Arlington, Texas—a neutral site—due to COVID-19 health and safety protocols.","tool_calls":[]},"logprobs":null,"finish_reason":"stop","stop_reason":null}],"usage":{"prompt_tokens":19,"total_tokens":472,"completion_tokens":453,"prompt_tokens_details":null},"prompt_logprobs":null}%
06、監(jiān)控
我們假設(shè)你已經(jīng)在集群中設(shè)置了 Prometheus:https://prometheus.io/,然后你可以部署 ServiceMonitor,以便它能夠從 Deepseek 部署中獲取指標(biāo)。
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: deepseek-r1-svc-discover
namespace: default
labels:
volcengine.vmp: "true"
spec:
endpoints:
- port: service
namespaceSelector:
matchNames:
- default
selector:
matchLabels:
ray.io/node-type: head
你可以使用我們自己構(gòu)建的儀表盤https://github.com/vllm-project/aibrix/blob/main/samples/deepseek-r1/static/AIBrix%20Engine%20Dashboard%20(vLLM)-1741078999667.json來(lái)查看模型的性能。
注意:在 Grafana 中導(dǎo)入儀表盤后,由于 Prometheus 的設(shè)置不同,你可能需要對(duì) PromQL 中的一些內(nèi)容(如標(biāo)簽)進(jìn)行細(xì)微的更改。
07、更多疑問
如果你有任何問題,請(qǐng)隨時(shí)在 Slack 頻道 #AIBrix:https://vllm-dev.slack.com/?redir=%2Farchives%2FC08EQ883CSV%3Fname%3DC08EQ883CSV中與我們聯(lián)系。我們很樂意支持你的使用情況!
相關(guān)鏈接
項(xiàng)目地址:
- GitHub 倉(cāng)庫(kù):vllm-project/aibrix:https://github.com/vllm-project/aibrix
- Github 問題頁(yè)面:Issues:https://github.com/vllm-project/aibrix/issues
- Slack 頻道:#AIBrix:https://aibrix.slack.com/?redir=%2Farchives%2FC123456%3Fname%3DC123456