【AIGC魔童】DeepSeek v3推理部署:vLLM/SGLang/LMDeploy
(1)使用vLLM推理部署DeepSeek
![](https://i-blog.csdnimg.cn/direct/7e1f7cf7ae364e658b4aa98dd37dc87b.png)
GitHub地址 :https://github.com/vllm-project/vllm
vLLMv0.6.6 支持在 NVIDIA 和 AMD GPU 上对 FP8 和 BF16 模式进行 DeepSeek-V3 推理。除了标准技术之外,vLLM 还提供管道并行性,允许您在通过网络连接的多台机器上运行此模型。
有关详细指导,请参阅 vLLM 说明。也请随时遵循增强计划。
shell
pip install vllm
DeepSeek R1调用
目前vLLM已支持DeepSeek R1模型调用,可以在模型支持列表中查看模型关键字:https://docs.vllm.ai/en/latest/models/supported_models.html
![](https://i-blog.csdnimg.cn/direct/0c48294cc2ea4723bfb6df33edf59e4e.png)
使用python调用DeepSeek:
python
from vllm import LLM
llm = LLM(model=deepseek-ai/DeepSeek-V3, task="generate")
output = llm.generate("Hello, my name is")
print(output)
(2)使用SGLang推理部署DeepSeek
![](https://i-blog.csdnimg.cn/direct/8c119b7e81bf4415acf80b0a9c31a002.png)
GitHub地址 :https://github.com/sgl-project/sglang
SGLang 目前支持 MLA 优化、DP Attention、FP8 (W8A8)、FP8 KV Cache 和 Torch Compile,在开源框架中提供最先进的延迟和吞吐量性能。
值得注意的是,SGLang v0.4.1 完全支持在 NVIDIA 和 AMD GPU 上运行 DeepSeek-V3,使其成为一个高度通用且强大的解决方案。
SGLang 还支持多节点张量并行性,使您能够在多台联网的计算机上运行此模型。
多Token预测 (MTP) 正在开发中,可以在优化计划中跟踪进度。
以下是 SGLang 团队的启动说明:https://github.com/sgl-project/sglang/tree/main/benchmark/deepseek_v3
安装SGLang
shell
pip install "sglang[all]>=0.4.1.post5" --find-links https://flashinfer.ai/whl/cu124/torch2.4/flashinfer
调用DeepSeek R1
shell
python3 -m sglang.launch_server --model deepseek-ai/DeepSeek-R1 --tp 8 --trust remote-code
此时服务将在30000端口启动。接下来即可使用OpenAI风格API来调用DeepSeek R1模型了:
python
import openai
client = openai.Client(base_url="http://127.0.0.1:30000/v1", api_key="EMPTY")
# Chat completion
response = client.chat.completions.create(
model="default",
messages=[
{"role": "system", "content": "You are a helpful AI assistant"},
{"role": "user", "content": "List 3 countries and their capitals."},],
temperature=0,
max_tokens=64,)
print(response)
(3)使用LMDeploy推理部署DeepSeek
![](https://i-blog.csdnimg.cn/direct/f9384992f1c24095bf315ac5466886db.png)
GitHub地址 :https://github.com/InternLM/lmdeploy
LMDeploy 是一个为大型语言模型量身定制的灵活、高性能的推理和服务框架,现在支持 DeepSeek-V3。它提供离线管道处理和在线部署功能,与基于 PyTorch 的工作流无缝集成。
有关使用 LMDeploy 运行 DeepSeek-V3 的全面分步说明,请参阅此处:InternLM/lmdeploy#2960
安装LMDeploy
shell
git clone -b support-dsv3 https://github.com/InternLM/lmdeploy.git
cd lmdeploy
pip install -e .
单任务推理,编写Python脚本执行
python
from lmdeploy import pipeline, PytorchEngineConfig
if __name__ == "__main__":
pipe = pipeline("deepseek-ai/DeepSeek-R1-FP8",
backend_config=PytorchEngineConfig(tp=8))
messages_list = [
[{"role": "user", "content": "Who are you?"}],
[{"role": "user", "content": "Translate the following content into Chinese directly: DeepSeek-V3 adopts innovative architectures to guarantee economical training and efficient inference."}],
[{"role": "user", "content": "Write a piece of quicksort code in C++."}],]
output = pipe(messages_list)
print(output)
在线服务调用
shell
# run
lmdeploy serve api_server deepseek-ai/DeepSeek-R1-FP8 --tp 8 --backend pytorch
接下来即可在23333端口调用DeepSeek R1模型:
python
from openai import OpenAI
client = OpenAI(
api_key='YOUR_API_KEY',
base_url="http://0.0.0.0:23333/v1")
model_name = client.models.list().data[0].id
response = client.chat.completions.create(
model=model_name,
messages=[
{"role": "user", "content": "Write a piece of quicksort code in C++."}],
temperature=0.8,
top_p=0.8)
print(response)