Launch DeepSeek V3.1/V3/R1 with SGLang
To run DeepSeek V3.1/V3/R1 models, the recommended settings are as follows:| Weight Type | Configuration |
|---|---|
| Full precision FP8 | |
| (recommended) | 8 x H200 |
| 8 x B200 | |
| 8 x MI300X | |
| 2 x 8 x H100/800/20 | |
| Xeon 6980P CPU | |
| Full precision (BF16) (upcast from original FP8) | 2 x 8 x H200 |
| 2 x 8 x MI300X | |
| 4 x 8 x H100/800/20 | |
| 4 x 8 x A100/A800 | |
| Quantized weights (INT8) | 16 x A100/800 |
| 32 x L40S | |
| Xeon 6980P CPU | |
| 4 x Atlas 800I A3 | |
| Quantized weights (W4A8) | 8 x H20/100, 4 x H200 |
| Quantized weights (AWQ) | 8 x H100/800/20 |
| 8 x A100/A800 | |
| Quantized weights (MXFP4) | 8, 4 x MI355X/350X |
| Quantized weights (NVFP4) | 8, 4 x B200 |
The official DeepSeek V3 is already in FP8 format, so you should not run it with any quantization arguments like
--quantization fp8.- 8 x H200
- 4 x B200, 8 x B200
- 8 x MI300X
- 2 x 8 x H200
- 4 x 8 x A100
- 8 x A100 (AWQ)
- 16 x A100 (INT8)
- 32 x L40S (INT8)
- Xeon 6980P CPU
- 4 x Atlas 800I A3 (int8)
Download Weights
If you encounter errors when starting the server, ensure the weights have finished downloading. It’s recommended to download them beforehand or restart multiple times until all weights are downloaded. Please refer to DeepSeek V3 official guide to download the weights.Launch with one node of 8 x H200
Please refer to the example.Running examples on Multi-Node
- Deploying DeepSeek on GB200 NVL72 with PD and Large Scale EP (Part I, Part II) - Comprehensive guide on GB200 optimizations.
- Deploying DeepSeek with PD Disaggregation and Large-Scale Expert Parallelism on 96 H100 GPUs - Guide on PD disaggregation and large-scale EP.
- Serving with two H20*8 nodes.
- Best Practices for Serving DeepSeek-R1 on H20 - Comprehensive guide on H20 optimizations, deployment and performance.
- Serving with two H200*8 nodes and docker.
- Serving with four A100*8 nodes.
Optimizations
Multi-head Latent Attention (MLA) Throughput Optimizations
Description: MLA is an innovative attention mechanism introduced by the DeepSeek team, aimed at improving inference efficiency. SGLang has implemented specific optimizations for this, including:- Weight Absorption: By applying the associative law of matrix multiplication to reorder computation steps, this method balances computation and memory access and improves efficiency in the decoding phase.
- MLA Attention Backends: Currently SGLang supports different optimized MLA attention backends, including FlashAttention3, Flashinfer, FlashMLA, CutlassMLA, TRTLLM MLA (optimized for Blackwell architecture), and Triton backends. The default FA3 provides good performance across wide workloads.
- FP8 Quantization: W8A8 FP8 and KV Cache FP8 quantization enables efficient FP8 inference. Additionally, we have implemented Batched Matrix Multiplication (BMM) operator to facilitate FP8 inference in MLA with weight absorption.
- CUDA Graph & Torch.compile: Both MLA and Mixture of Experts (MoE) are compatible with CUDA Graph and Torch.compile, which reduces latency and accelerates decoding speed for small batch sizes.
- Chunked Prefix Cache: Chunked prefix cache optimization can increase throughput by cutting prefix cache into chunks, processing them with multi-head attention and merging their states. Its improvement can be significant when doing chunked prefill on long sequences. Currently this optimization is only available for FlashAttention3 backend.
Data Parallelism Attention
Description: This optimization involves data parallelism (DP) for the MLA attention mechanism of DeepSeek Series Models, which allows for a significant reduction in the KV cache size, enabling larger batch sizes. Each DP worker independently handles different types of batches (prefill, decode, idle), which are then synchronized before and after processing through the Mixture-of-Experts (MoE) layer. If you do not use DP attention, KV cache will be duplicated among all TP ranks.- Append
--enable-dp-attention --tp 8 --dp 8to the server arguments when using 8 H200 GPUs. This optimization improves peak throughput in high batch size scenarios where the server is limited by KV cache capacity. - DP and TP attention can be flexibly combined. For example, to deploy DeepSeek-V3/R1 on 2 nodes with 8 H100 GPUs each, you can specify
--enable-dp-attention --tp 16 --dp 2. This configuration runs attention with 2 DP groups, each containing 8 TP GPUs.
Multi-Node Tensor Parallelism
Description: For users with limited memory on a single node, SGLang supports serving DeepSeek Series Models, including DeepSeek V3, across multiple nodes using tensor parallelism. This approach partitions the model parameters across multiple GPUs or nodes to handle models that are too large for one node’s memory. Usage: Check here for usage examples.Block-wise FP8
Description: SGLang implements block-wise FP8 quantization with two key optimizations:- Activation: E4M3 format using per-token-per-128-channel sub-vector scales with online casting.
- Weight: Per-128x128-block quantization for better numerical stability.
- DeepGEMM: The DeepGEMM kernel library optimized for FP8 matrix multiplications.
SGLANG_ENABLE_JIT_DEEPGEMM=0.
Multi-token Prediction
Description: SGLang implements DeepSeek V3 Multi-Token Prediction (MTP) based on EAGLE speculative decoding. With this optimization, the decoding speed can be improved by 1.8x for batch size 1 and 1.5x for batch size 32 respectively on H200 TP8 setting. Usage: Add--speculative-algorithm EAGLE. Other flags, like --speculative-num-steps, --speculative-eagle-topk and --speculative-num-draft-tokens are optional. For example:
- The default configuration for DeepSeek models is
--speculative-num-steps 3 --speculative-eagle-topk 1 --speculative-num-draft-tokens 4. The best configuration for--speculative-num-steps,--speculative-eagle-topkand--speculative-num-draft-tokenscan be searched with bench_speculative.py script for given batch size. The minimum configuration is--speculative-num-steps 1 --speculative-eagle-topk 1 --speculative-num-draft-tokens 2, which can achieve speedup for larger batch sizes. - Most MLA attention backends fully support MTP usage. See MLA Backends for details.
To enable DeepSeek MTP for large batch sizes (>48), you need to adjust some parameters (Reference this discussion):
- Adjust
--max-running-requeststo a larger number. The default value is48for MTP. For larger batch sizes, you should increase this value beyond the default value. - Set
--cuda-graph-bs. It’s a list of batch sizes for cuda graph capture. The default captured batch sizes for speculative decoding is 48. You can customize this by including more batch sizes.
Reasoning Content for DeepSeek R1 & V3.1
See Reasoning Parser and Thinking Parameter for DeepSeek V3.1.Function calling for DeepSeek Models
Add arguments--tool-call-parser deepseekv3 and --chat-template ./examples/chat_template/tool_chat_template_deepseekv3.jinja(recommended) to enable this feature. For example (running on 1 * H20 node):
- Use a lower
"temperature"value for better results. - To receive more consistent tool call results, it is recommended to use
--chat-template examples/chat_template/tool_chat_template_deepseekv3.jinja. It provides an improved unified prompt.
Thinking Budget for DeepSeek R1
In SGLang, we can implement thinking budget withCustomLogitProcessor.
Launch a server with --enable-custom-logit-processor flag on.
FAQ
Q: Model loading is taking too long, and I’m encountering an NCCL timeout. What should I do? A: If you’re experiencing extended model loading times and an NCCL timeout, you can try increasing the timeout duration. Add the argument--dist-timeout 3600 when launching your model. This will set the timeout to one hour, which often resolves the issue.