在Kubernetes上摆设DeepSeek-R1举行高效AI推理

打印 上一主题 下一主题

主题 1031|帖子 1031|积分 3093

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
在本篇文章中,我们将先容如何使用亚马逊云科技的Kubernetes服务Amazon EKS Auto Mode,在亚马逊云科技上摆设DeepSeek模型。Amazon EKS Auto Mode提供了更强的灵活性和可扩展性,同时无需管理Kubernetes控制节点、盘算、存储和网络组件,大大简化了摆设流程。



为什么要在Amazon EKS上摆设DeepSeek?



  • 开源与开放性:DeepSeek采用开源方式,让更多企业和开辟人员可以访问和使用其先辈的语言模型,推动AI发展。
  • 增强推理能力:DeepSeek-R1采用Chain of Thought (CoT) 推理,使模型可以将复杂题目拆解为多个可管理的步骤,提升其解决数学题目、逻辑推理等使命的能力。
  • 简化Amazon EKS上的托管:通过Amazon EKS Auto Mode托管DeepSeek,无需管理底层Kubernetes基础设施,让各人专注于摆设和使用模型。


在Amazon EKS Auto Mode上摆设DeepSeek-R1

在本教程中,我们将使用DeepSeek-R1-Distill-Llama-8B模型,这是一个DeepSeek的轻量级蒸馏版本,相比完整的DeepSeek-R1(671B参数)模型,它占用更少的盘算资源(如GPU),但性能稍逊于完整版本。如果各人盼望摆设完整的DeepSeek-R1模型,可以在vLLM设置中替换蒸馏版模型。


安装前置所需依靠

本教程使用亚马逊云科技CloudShell来简化安装过程。


  1. # Installing kubectl
  2. curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
  3. sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
  4. # Install Terraform
  5. sudo yum install -y yum-utils
  6. sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
  7. sudo yum -y install terraform
复制代码


使用Terraform创建Amazon EKS Auto Mode集群

接下来我们将使用Terraform快速创建云基础架构,包括:


  • VPC(虚拟私有云)
  • ECR(Elastic Container Registry)镜像堆栈
  • 启用Auto Mode的EKS集群
  1. # Clone the GitHub repo with the manifests
  2. git clone -b v0.1 https://github.com/aws-samples/deepseek-using-vllm-on-eks
  3. cd deepseek-using-vllm-on-eks
  4. # Apply the Terraform configuration
  5. terraform init
  6. terraform apply -auto-approve
  7. # After Terraform finishes, configure kubectl with the new EKS cluster
  8. $(terraform output configure_kubectl | jq -r)
复制代码

创建EKS Auto Mode NodePool

为了启用模型的GPU支持,需要创建自界说NodePool。
  1. # Create a custom NodePool with GPU support
  2. kubectl apply -f manifests/gpu-nodepool.yaml
  3. # Check if the NodePool is in 'Ready' state
  4. kubectl get nodepool/gpu-nodepool
复制代码

摆设DeepSeek模型

我们将使用vLLM摆设DeepSeek-R1-Distill-Llama-8B模型。为简化流程,我们提供了一个sed下令,方便各人快速设置模型名称和参数。
  1. # Use the sed command to replace the placeholder with the model name and configuration parameters
  2. sed -i "s|__MODEL_NAME_AND_PARAMETERS__|deepseek-ai/DeepSeek-R1-Distill-Llama-8B --max_model 2048|g" manifests/deepseek-deployment-gpu.yaml
  3. # Deploy the DeepSeek model on Kubernetes
  4. kubectl apply -f manifests/deepseek-deployment-gpu.yaml
  5. # Check the pods in the 'deepseek' namespace
  6. kubectl get po -n deepseek
复制代码


  • 摆设完成后,Pod大概会短暂处于Pending状态,由于EKS Auto Mode需要自动设置EC2实例,并安装必要的GPU驱动。
  • 如果Pod在Pending状态停留较长时间,请检查AWS账户的GPU实例可创建的额度,确保可以或许启动所需的GPU实例。
  • 可以在亚马逊云科技EC2实例配额文档中查看具体信息。
  • 注意:这些配额基于vCPU,而非实例的数量,因此申请云资源额度时需要按vCPU数量举行调解。
  1. # Wait for the pod to reach the 'Running' state
  2. watch -n 1 kubectl get po -n deepseek
  3. # Verify that a new Node has been created
  4. kubectl get nodes -l owner=data-engineer
  5. # Check the logs to confirm that vLLM has started
  6. kubectl logs deployment.apps/deepseek-deployment -n deepseek
复制代码
当摆设准备就绪后,日记记载中会表现提示:Application startup complete


与DeepSeek LLM交互

接下来,我们可以创建本地署理,然后使用curl哀求与模型交互。
  1. # Set up a proxy to forward the service port to your local terminal
  2. kubectl port-forward svc/deepseek-svc -n deepseek 8080:80 > port-forward.log 2>&1 &
  3. # Send a curl request to the model
  4. curl -X POST "http://localhost:8080/v1/chat/completions" -H "Content-Type: application/json" --data '{
  5. "model": "deepseek-ai/DeepSeek-R1-Distill-Llama-8B",
  6. "messages": [
  7. {
  8. "role": "user",
  9. "content": "What is Kubernetes?"
  10. }
  11. ]
  12. }'
复制代码


  • 响应时间大概会根据模型的盘算复杂度有所不同,一样平常需要几秒钟。
  • 可以通过deepseek-deployment日记来监控模型的执行环境。


为模型构建Chatbot UI

尽管我们可以通过API直接发送哀求调用EKS上的模型,但我们也可以构建一个更方便交互的Chatbot UI界面,以便用户能更方便地与模型交互。UI的源代码已经在GitHub堆栈中提供。
  1. # Retrieve the ECR repository URI created by Terraform
  2. export ECR_REPO=$(terraform output ecr_repository_uri | jq -r)
  3. # Build the container image for the Chatbot UI
  4. docker build -t $ECR_REPO:0.1 chatbot-ui/application/.
  5. # Login to ECR and push the image
  6. aws ecr get-login-password | docker login --username AWS --password-stdin $ECR_REPO
  7. docker push $ECR_REPO:0.1
  8. # Update the deployment manifest to use the image
  9. sed -i "s#__IMAGE_DEEPSEEK_CHATBOT__#$ECR_REPO:0.1#g" chatbot-ui/manifests/deployment.yaml
  10. # Generate a random password for the Chatbot UI login
  11. sed -i "s|__PASSWORD__|$(openssl rand -base64 12 | tr -dc A-Za-z0-9 | head -c 16)|" chatbot-ui/manifests/deployment.yaml
  12. # Deploy the UI and create the ingress class required for load balancers
  13. kubectl apply -f chatbot-ui/manifests/ingress-class.yaml
  14. kubectl apply -f chatbot-ui/manifests/deployment.yaml
  15. # Get the URL for the load balancer to access the application
  16. echo http://$(kubectl get ingress/deepseek-chatbot-ingress -n deepseek -o json | jq -r '.status.loadBalancer.ingress[0].hostname')
复制代码


  • 等候几秒钟,让负载均衡器(Load Balancer)完成摆设。
  • 访问Chatbot UI时,需要输入存储在Kubernetes Secret中的用户名和暗码。
  1. echo -e "Username=$(kubectl get secret deepseek-chatbot-secrets -n deepseek -o jsonpath='{.data.admin-username}' | base64 --decode)\nPassword=$(kubectl get secret deepseek-chatbot-secrets -n deepseek -o jsonpath='{.data.admin-password}' | base64 --decode)"
复制代码


  • 登录后,各人将在界面中看到我们的Chatbot UI界面,在这里可直接与模型交互!




总结

通过本教程,各人可以高效地在Amazon EKS上摆设DeepSeek R1模型,使用其灵活的扩展选项和精致化盘算资源控制,在优化成本的同时保持高性能。该方案充实使用了Kubernetes的原生功能,联合Amazon EKS的Auto Mode特性,提供了一种高度自界说的摆设方式,可以根据具体的运营需求和预算举行精确调解。
如果各人盼望进一步探索其他摆设模式(如使用Neuron或开源Karpenter举行摆设),可以访问GitHub堆栈deepseek-using-vllm-on-eks,获取更多代码示例。


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

道家人

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表