DeepSeek Model Optimizations#

SGLang provides several optimizations specifically designed for the DeepSeek model to boost its inference speed. This document outlines current optimizations for DeepSeek. Additionally, the SGLang team is actively developing enhancements for DeepSeek-V3.

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.

  • Triton Decoding Kernel Optimization: In the MLA decoding kernel, there is only one KV head. This optimization reduces memory access to the KV cache by processing multiple query heads within one block, accelerating the decoding process.

  • 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.

Overall, with these optimizations, we have achieved up to a 7x acceleration in output throughput compared to the previous version.

Multi-head Latent Attention for DeepSeek Series Models

Usage: MLA optimization is enabled by defalut, to disable, use --disable-mla.

Reference: Check Blog and Slides for more details.

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.

Data Parallelism Attention for DeepSeek Series Models

Usage: This optimization is aimed at improving throughput and should be used for scenarios with high QPS (Queries Per Second). Data Parallelism Attention optimization can be enabeld by --enable-dp-attention for DeepSeek Series Models.

Reference: Check Blog.

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.

Usage: turn on by default for DeepSeek V3 models.