深度解析:通過 AIBrix 多節點部署 DeepSeek-R1 671B 模型
本文詳細介紹了如何通過 AIBrix 分布式推理平臺實現 DeepSeek-R1 671B 的多節點部署。DeepSeek-R1 通過漸進式訓練框架展現出優秀的邏輯推理能力 —— 在 6710 億總參數量中,其動態激活的 370 億參數與 128k 上下文窗口,使其在復雜任務處理中表現卓越。然而,如此龐大的模型規模對部署環境提出了嚴苛挑戰,尤其是分布式推理的資源調度與性能優化。AIBrix 通過自主研發的容器化編排技術,實現了:
- 多節點 GPU 資源的智能分配
- 分布式推理服務的無縫管理
- 基于 RDMA 的高性能網絡通信
- 自動化彈性伸縮策略
通過與 AIBrix 的結合,使得原本需要數周的超大規模模型部署周期縮短至小時級。接下來,我們將從集群配置、鏡像優化、存儲方案等關鍵環節展開,為您呈現完整的技術實現路徑。
Reference: https://huggingface.co/deepseek-ai/DeepSeek-R1/resolve/main/figures/benchmark.jpg
01、前置準備
在 AIBrix 部署 DeepSeek-R1 前,需完成以下準備工作:將模型權重下載至對象存儲或共享文件系統,并配置定制化容器鏡像。本文將聚焦關鍵步驟,更多細節請參考我們的代碼示例與教程:https://github.com/vllm-project/aibrix/tree/main/samples/deepseek-r1
集群配置
DeepSeek-R1 671B 需要 16 塊 顯存 80+GB GPU。測試使用的實例規格如下,您可根據實際環境選擇類似配置
- 云平臺:火山引擎
- 實例:ecs.ebmhpcpni3l.48xlarge * 2
- CPU: 192 vCPU
- 內存:2048GiB DRAM
- GPU: 96GB*8
- 網絡:400 Gbps * 8 RDMA + 96 Gbps
- 磁盤:本地 NVME 3576GiB * 4
vLLM 鏡像
本次部署使用的鏡像是 aibrix/vllm-openai:v0.7.3.self.post1,這是由 AIBrix 定制構建的鏡像。選擇該鏡像主要有兩個原因:
- 在 v0.7.3 的上游版本中,存在一個與舊版 NCCL 版本相關的問題:https://aibrix.github.io/posts/2025-03-10-deepseek-r1/,該問題會導致系統偶爾掛起。我們通過將 nvidia-nccl-cu12==2.25.1 進行升級,以增強通信的穩定性。
- 在 v0.7.3 版本中,出現了一個與 Ray 相關的回歸問題,我們之前在 vLLM 中的修改被覆蓋了。為了緩解這個問題,我們重新引入了 ray[default,adag],以便為高可用性和故障檢測提供更好的探測支持。
如果你想自己構建鏡像,可以使用以下 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 [""]
注意:對于中國的用戶,從我們的鏡像倉庫拉取鏡像時,可能需要在鏡像名稱前加上 aibrix-container-registry-cn-beijing.cr.volces.com/。例如,不要只使用 aibrix/vllm-openai:v0.7.3.self.post1,而應該使用 aibrix-container-registry-cn-beijing.cr.volces.com/aibrix/vllm-openai:v0.7.3.self.post1。同樣的規則也適用于 aibrix/runtime:v0.2.1。
模型權重
用戶可以根據自己的云服務提供商,為模型權重
https://huggingface.co/deepseek-ai/DeepSeek-R1選擇不同的存儲選項。這里,我們將討論四種常見的場景:
- HuggingFace:一個 Pod 可以直接從 HuggingFace 檢索模型權重。然而,需要注意的是,不建議對 DeepSeek R1 從 HuggingFace 獲取權重。這是因為張量大小各不相同,會導致大量的隨機讀取,從而顯著降低網絡和 I/O 效率。
- 持久卷(Persistent Volume):像 AWS(使用 Lustre)或谷歌云這樣的云服務提供商,通過其容器存儲接口(CSI)
https://kubernetes-csi.github.io/docs/提供持久磁盤。用戶可以輕松地將持久卷聲明(PVC)
https://kubernetes.io/docs/concepts/storage/persistent-volumes/掛載到 Pod 上,從而能夠無縫訪問存儲在這些持久磁盤上的模型權重。 - 結合 AI 運行時的對象存儲:用戶可以選擇將模型權重存儲在對象存儲服務中,如亞馬遜 S3 或谷歌云存儲(GCS)。在這種情況下,AIBrix AI 運行時將自動將模型下載到主機卷上。這種方法利用了對象存儲在存儲大量數據方面的優勢,提供了靈活性和可擴展性。
- 本地磁盤:對于本地磁盤存儲,需要額外的過程將模型權重下載到本地磁盤上。我們假設存在一個可用的本地卷,并且可以成功地掛載到 Pod 上。這種選擇可能適用于本地存儲能帶來性能優勢的環境,或者當存在特定的安全或延遲要求時。
存儲選項 | 描述 | 示例文件 |
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 |
高性能網絡
為了利用 RDMA 在網絡通信中實現最佳性能,我們需要配置 Pod 配置以使用 RDMA。在注解中配置 k8s.volcengine.com/pod-networks,如下所示,并且在 Pod 資源級別需要 vke.volcengine.com/rdma:"8"。這只是火山引擎云上的一個示例,你需要根據自己的云環境進行相應的更改。
k8s.volcengine.com/pod-networks: |
[
{
"cniConf":{
"name":"rdma"
}
},
....
{
"cniConf":{
"name":"rdma"
}
}
]
此外,我們還需要 IPC_LOCK 和共享內存支持。
securityContext:
capabilities:
add:
- IPC_LOCK
02、安裝
多節點部署需要 AIBrix v0.2.1https://github.com/vllm-project/aibrix/releases/tag/v0.2.1版本。在部署 AIBrix 時,需要注意的是,AIBrix 鏡像主要托管在 Dockerhub 上,在對 Dockerhub 訪問有限制的環境中進行部署可能具有挑戰性。為了克服這個問題,請查看我們的教程,使用你自己的鏡像倉庫覆蓋控制平面鏡像,從而實現定制化 AIBrix 的順利部署。
需要強調的是,可能存在一些與云環境相關的方面,例如 ReadWriteMany 卷提供程序、本地磁盤 等。我們這里以火山引擎https://www.volcengine.com/為例,但建議用戶檢查自己的云基礎設施。雖然我們可以提供一些一般性的建議,但由于資源有限,我們無法對所有云平臺進行全面測試。我們鼓勵社區通過提交拉取請求(PR)來提供幫助,以改進我們對不同云平臺的支持。
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 模型的部署中起著至關重要的作用。它提供了一個全面的平臺,支持分布式編排、高效的流量路由以及智能的縮放功能。這些特性對于處理 Deepseek-r1 671B 模型的大規模和資源密集型特性至關重要。
在開始部署之前,我們將簡要介紹與本案例相關的 RayClusterFleet、網關插件 和 自動縮放器 的功能。
RayClusterFleet 在管理分布式推理編排方面發揮著關鍵作用。它調配 Pod 并構建一個 Ray 集群,在該集群中啟動 vLLM 服務器。因此,每個小型 Ray 集群都構成一個推理副本。
在多節點環境中,vLLM HTTP 服務器在頭節點上啟動。其余的 GPU 節點充當工作節點,這些節點上不運行 HTTP 服務。相應地,AIBrix 路由器僅將請求路由到頭節點。同樣,自動縮放器僅從服務 Pod 中獲取指標。這種分布式配置確保了編排、路由和自動縮放機制能夠有效地運行。通過以類似于單節點操作的方式管理多節點設置,它簡化了像 Deepseek-r1 這樣的超大型模型的整體部署過程。
04、模型部署
首先,確保你更改了網絡和對象存儲配置,例如使用 s3:https://aibrix.readthedocs.io/latest/features/runtime.html#download-from-s3。對于 Deepseek-r1,DOWNLOADER_ALLOW_FILE_SUFFIX 必須為 json、safetensors、py。
然后運行以下命令來部署模型以及相關的基于 kv 緩存的自動縮放策略。請注意,這確實取決于計算節點與對象存儲之間的網絡速度,部署可能需要長達 20 分鐘。
kubectl apply -f deepseek-r1-ai-runtime.yaml
kubectl apply -f deepseek-r1-autoscaling.yaml
過一會兒,你應該會看到類似于以下的正在運行的 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、發送請求
通過以下命令暴露Endpoint進行調用。
# 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?"}
]
}'
注意:如果你想使用默認的 Kubernetes 路由策略,可以刪除 -H "routing-strategy: least-request" 標頭。
你應該會看到類似以下的響應:
{"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、監控
我們假設你已經在集群中設置了 Prometheus:https://prometheus.io/,然后你可以部署 ServiceMonitor,以便它能夠從 Deepseek 部署中獲取指標。
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
你可以使用我們自己構建的儀表盤https://github.com/vllm-project/aibrix/blob/main/samples/deepseek-r1/static/AIBrix%20Engine%20Dashboard%20(vLLM)-1741078999667.json來查看模型的性能。
注意:在 Grafana 中導入儀表盤后,由于 Prometheus 的設置不同,你可能需要對 PromQL 中的一些內容(如標簽)進行細微的更改。
07、更多疑問
如果你有任何問題,請隨時在 Slack 頻道 #AIBrix:https://vllm-dev.slack.com/?redir=%2Farchives%2FC08EQ883CSV%3Fname%3DC08EQ883CSV中與我們聯系。我們很樂意支持你的使用情況!
相關鏈接
項目地址:
- GitHub 倉庫:vllm-project/aibrix:https://github.com/vllm-project/aibrix
- Github 問題頁面:Issues:https://github.com/vllm-project/aibrix/issues
- Slack 頻道:#AIBrix:https://aibrix.slack.com/?redir=%2Farchives%2FC123456%3Fname%3DC123456