vLLM DeepSeek Guide

Deploy DeepSeek with vLLM for production-grade inference. Performance optimization, batching configuration, and API server setup guide.

vLLM 部署指南

高性能推理引擎,适用于生产级部署

vLLM 部署方案

进阶

高性能推理引擎,适合生产级 DeepSeek 部署

环境要求

安装 vLLM

确保 CUDA 版本与 PyTorch 版本兼容。注意:V4.1-Flash 用的是全新的 Causal Encoder-Decoder 结构(config 里 model_type 为 deepseek_v41),能不能被 vLLM 直接加载要以 vLLM 自己的支持列表为准;官方仓库随权重附带的是一份可读的参考实现,不是服务引擎。

获取模型

使用 Hugging Face Hub 下载模型权重

命令行下载 (V4.1-Flash-1017)

# 安装 huggingface-cli pip install huggingface_hub # 下载 DeepSeek-V4.1-Flash-1017(552B 骨干参数,仓库约 510.3GB) huggingface-cli download \ deepseek-ai/DeepSeek-V4.1-Flash-1017 \ --local-dir ./models/DeepSeek-V4.1-Flash-1017 # 旧仓库 deepseek-ai/DeepSeek-V4.1-Flash 仍在,两者同为 MIT、体积一样 # 或下载较小的 R1 蒸馏模型以节省空间 huggingface-cli download \ deepseek-ai/DeepSeek-R1-Distill-Qwen-7B \ --local-dir ./models/deepseek-r1-7b

Python 下载

from huggingface_hub import snapshot_download # 下载 DeepSeek-R1 蒸馏模型 snapshot_download( repo_id="deepseek-ai/DeepSeek-R1-Distill-Qwen-7B", local_dir="./models/deepseek-r1-7b" )

启动服务

基础推理 (R1-7B)

from vllm import LLM, SamplingParams llm = LLM(model="./models/deepseek-r1-7b") sampling_params = SamplingParams( temperature=0.7, max_tokens=1024, top_p=0.95 ) outputs = llm.generate( ["用Python写一个Hello World:"], sampling_params ) for output in outputs: print(output.outputs[0].text)

API 服务器模式

python -m vllm.entrypoints.openai.api_server \ --model ./models/deepseek-r1-7b \ --served-model-name deepseek-r1 \ --port 8000 \ --gpu-memory-utilization 0.9

启动后可通过 http://localhost:8000/v1/chat/completions 使用 OpenAI 兼容客户端访问

本站全部页面