跳到内容

DeepSeek-V3 (R1) 使用指南

本指南介绍了如何使用原生的 FP8 或 FP4 来运行 DeepSeek-V3 或 DeepSeek-R1。在本指南中,我们以 DeepSeek-R1 为例,但由于 DeepSeek-V3 拥有相同的模型架构,因此本指南同样适用于 DeepSeek-V3。

安装 vLLM

uv venv
source .venv/bin/activate
uv pip install -U vllm --torch-backend auto

在 8xH200 上使用 FP8 运行 DeepSeek-R1

有两种方法可以在多个 GPU 上并行化模型:(1) 张量并行或 (2) 数据并行。每种方法都有其自身的优点,其中张量并行通常更有利于低延迟/低负载场景,而数据并行更适用于数据量大且负载重的情况。

对于 Blackwell 架构,首先启用 flashinfer 环境变量

export VLLM_ATTENTION_BACKEND=CUTLASS_MLA
export VLLM_USE_FLASHINFER_MOE_FP8=1

然后,像这样运行张量并行

# Start server with FP8 model on 8 GPUs
vllm serve deepseek-ai/DeepSeek-R1-0528 \
  --trust-remote-code \
  --tensor-parallel-size 8 \
  --enable-expert-parallel

或者像这样运行数据并行

# Start server with FP8 model on 8 GPUs
vllm serve deepseek-ai/DeepSeek-R1-0528 \
  --trust-remote-code \
  --data-parallel-size 8 \
  --enable-expert-parallel

请注意,在两种情况下,我们也启用了专家并行,因此第一次运行是我们称之为 TP+EP,第二次运行是 DP+EP。

附加标志

  • 对于非 flashinfer 运行,可以使用 VLLM_USE_DEEP_GEMM 和 VLLM_ALL2ALL_BACKEND。例如
    export VLLM_USE_DEEP_GEMM=1 
    export VLLM_ALL2ALL_BACKEND="deepep_high_throughput" # or "deepep_low_latency"
    
  • 您可以设置 --max-model-len 以节省内存。--max-model-len=65536 通常适用于大多数场景。
  • 您可以设置 --max-num-batched-tokens 来平衡吞吐量和延迟,数值越高意味着吞吐量越高但延迟也越高。--max-num-batched-tokens=32768 通常适用于提示密集型工作负载。但您可以将其减少到 16k 和 8k 以减少激活内存使用并降低延迟。
  • vLLM 保守地使用 90% 的 GPU 内存,您可以设置 --gpu-memory-utilization=0.95 来最大化 KVCache。

在 4xB200 上使用 FP4 运行 DeepSeek-R1

对于 Blackwell GPU,在运行前添加这些环境变量

export VLLM_ATTENTION_BACKEND=CUTLASS_MLA
export VLLM_USE_FLASHINFER_MOE_FP4=1

然后运行张量并行

# The model is runnable on 4 or 8 GPUs, here we show usage of 4.
CUDA_VISIBLE_DEVICES=0,1,2,3 vllm serve nvidia/DeepSeek-R1-FP4 \
  --trust-remote-code \
  --tensor-parallel-size 4 \
  --enable-expert-parallel

或者,数据并行

# The model is runnable on 4 or 8 GPUs, here we show usage of 4.
CUDA_VISIBLE_DEVICES=0,1,2,3 vllm serve nvidia/DeepSeek-R1-FP4 \
  --trust-remote-code \
  --data-parallel-size 4 \
  --enable-expert-parallel

基准测试

对于基准测试,通过向服务器命令添加 --no-enable-prefix-caching 来禁用前缀缓存。

FP8 基准测试

# Prompt-heavy benchmark (8k/1k)
vllm bench serve \
  --model deepseek-ai/DeepSeek-R1-0528 \
  --dataset-name random \
  --random-input-len 8000 \
  --random-output-len 1000 \
  --request-rate 10000 \
  --num-prompts 16 \
  --ignore-eos

FP4 基准测试

# Prompt-heavy benchmark (8k/1k)
vllm bench serve \
  --model nvidia/DeepSeek-R1-FP4 \
  --dataset-name random \
  --random-input-len 8000 \
  --random-output-len 1000 \
  --request-rate 10000 \
  --num-prompts 16 \
  --ignore-eos

基准测试配置

通过调整输入/输出长度测试不同的工作负载

  • 提示密集型:8000 输入 / 1000 输出
  • 解码密集型:1000 输入 / 8000 输出
  • 平衡型:1000 输入 / 1000 输出

通过更改 --num-prompts 测试不同的批处理大小

  • 批处理大小:1、16、32、64、128、256、512

预期输出

============ Serving Benchmark Result ============
Successful requests:                     1         
Benchmark duration (s):                  16.39     
Total input tokens:                      7902      
Total generated tokens:                  1000      
Request throughput (req/s):              0.06      
Output token throughput (tok/s):         61.00     
Total Token throughput (tok/s):          543.06    
---------------Time to First Token----------------
Mean TTFT (ms):                          560.00    
Median TTFT (ms):                        560.00    
P99 TTFT (ms):                           560.00    
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          15.85     
Median TPOT (ms):                        15.85     
P99 TPOT (ms):                           15.85     
---------------Inter-token Latency----------------
Mean ITL (ms):                           15.85     
Median ITL (ms):                         15.85     
P99 ITL (ms):                            16.15     
==================================================