k8s:用lws 跑分布式推理
安装:https://lws.sigs.k8s.io/docs/installation/#install-with-helm-chart 教程:https://docs.vllm.ai/en/stable/deployment/frameworks/lws/#prerequisites 源代码:https://github.com/kubernetes-sigs/lws
测试清单文件
apiVersion: leaderworkerset.x-k8s.io/v1
kind: LeaderWorkerSet
metadata:
name: vllm
namespace: topsec-poc
spec:
replicas: 1
leaderWorkerTemplate:
size: 2
restartPolicy: RecreateGroupOnPodRestart
leaderTemplate:
metadata:
labels:
role: leader
spec:
containers:
- name: vllm-leader
image: 10.30.15.56:5000/intelligent/vllm-openai:0.17.1
command:
- sh
- -c
- "bash /vllm-workspace/examples/online_serving/multi-node-serving.sh leader --ray_cluster_size=$(LWS_GROUP_SIZE);
vllm serve /home/data/modelscope/hub/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B --served-model-name DeepSeek-R1-Distill-Qwen-32B --port 8080 --tensor-parallel-size 1 --pipeline_parallel_size 2 --distributed-executor-backend ray --gpu-memory-utilization 0.9"
resources:
limits:
nvidia.com/gpu: "1"
requests:
nvidia.com/gpu: "1"
ports:
- containerPort: 8080
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 15
periodSeconds: 10
volumeMounts:
- mountPath: /dev/shm
name: dshm
- name: container-default-volume
mountPath: /home/data/modelscope
volumes:
- name: container-default-volume
persistentVolumeClaim:
claimName: nfs-pvc
- name: dshm
emptyDir:
medium: Memory
sizeLimit: 15Gi
workerTemplate:
spec:
containers:
- name: vllm-worker
image: 10.30.15.56:5000/intelligent/vllm-openai:0.17.1
command:
- sh
- -c
- "bash /vllm-workspace/examples/online_serving/multi-node-serving.sh worker --ray_address=$(LWS_LEADER_ADDRESS)"
resources:
limits:
nvidia.com/gpu: "1"
requests:
nvidia.com/gpu: "1"
volumeMounts:
- mountPath: /dev/shm
name: dshm
- name: container-default-volume
mountPath: /home/data/modelscope
volumes:
- name: container-default-volume
persistentVolumeClaim:
claimName: nfs-pvc
- name: dshm
emptyDir:
medium: Memory
sizeLimit: 15Gi
---
apiVersion: v1
kind: Service
metadata:
name: vllm-leader
namespace: topsec-poc
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
leaderworkerset.sigs.k8s.io/name: vllm
role: leader
type: ClusterIP
```sh
[root@10-30-15-55 lws]# curl --location 'http://10.110.102.36:8080/v1/chat/completions' -w "请求耗时:%{time_total}秒\n" \
> --header 'Content-Type: application/json' \
> --data '{
> "model": "DeepSeek-R1-Distill-Qwen-32B",
> "messages": [
> {
> "role": "user",
> "content": "你是谁?"
> }
> ]
> }'
{"id":"chatcmpl-b71704e6f131d1f1","object":"chat.completion","created":1778316928,"model":"DeepSeek-R1-Distill-Qwen-32B","choices":[{"index":0,"message":{"role":"assistant","content":"我是DeepSeek-R1,一个由深度求索公司开发的智能助手,我擅长通过思考来帮您解答复杂的数学,代码和逻辑推理等理工类问题。\n</think>\n\n我是DeepSeek-R1,一个由深度求索公司开发的智能助手,我擅长通过思考来帮您解答复杂的数学,代码和逻辑推理等理工类问题。","refusal":null,"annotations":null,"audio":null,"function_call":null,"tool_calls":[],"reasoning":null},"logprobs":null,"finish_reason":"stop","stop_reason":null,"token_ids":null}],"service_tier":null,"system_fingerprint":null,"usage":{"prompt_tokens":8,"total_tokens":85,"completion_tokens":77,"prompt_tokens_details":null},"prompt_logprobs":null,"prompt_token_ids":null,"kv_transfer_params":null}请求耗时:1.058089秒
[root@10-30-15-55 lws]#