【AIGC魔童】DeepSeek v3推理部署:vLLM/SGLang/LMDeploy

(1)使用vLLM推理部署DeepSeek

在这里插入图片描述

GitHub地址https://github.com/vllm-project/vllm

vLLMv0.6.6 支持在 NVIDIA 和 AMD GPU 上对 FP8 和 BF16 模式进行 DeepSeek-V3 推理。除了标准技术之外,vLLM 还提供管道并行性,允许您在通过网络连接的多台机器上运行此模型。

有关详细指导,请参阅 vLLM 说明。也请随时遵循增强计划

pip install vllm

DeepSeek R1调用

目前vLLM已支持DeepSeek R1模型调用,可以在模型支持列表中查看模型关键字:https://docs.vllm.ai/en/latest/models/supported_models.html

在这里插入图片描述

使用python调用DeepSeek:

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

在这里插入图片描述

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

pip install "sglang[all]>=0.4.1.post5" --find-links https://flashinfer.ai/whl/cu124/torch2.4/flashinfer

调用DeepSeek R1

python3 -m sglang.launch_server --model deepseek-ai/DeepSeek-R1 --tp 8 --trust remote-code

此时服务将在30000端口启动。接下来即可使用OpenAI风格API来调用DeepSeek R1模型了:

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

在这里插入图片描述

GitHub地址https://github.com/InternLM/lmdeploy

LMDeploy 是一个为大型语言模型量身定制的灵活、高性能的推理和服务框架,现在支持 DeepSeek-V3。它提供离线管道处理和在线部署功能,与基于 PyTorch 的工作流无缝集成。

有关使用 LMDeploy 运行 DeepSeek-V3 的全面分步说明,请参阅此处:InternLM/lmdeploy#2960

安装LMDeploy

git clone -b support-dsv3 https://github.com/InternLM/lmdeploy.git
cd lmdeploy
pip install -e .

单任务推理,编写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)

在线服务调用

# run
lmdeploy serve api_server deepseek-ai/DeepSeek-R1-FP8 --tp 8 --backend pytorch

接下来即可在23333端口调用DeepSeek R1模型:

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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值