Support Matrix
The support matrix is split into two parts: MHA (standard attention) and MLA (multi-head latent attention). For an explanation of the key differences between MHA and MLA, please see the SGLang documentation on DeepSeek MLA and the original DeepSeek MLA paper.MHA Backends
| Backend | Page Size > 1 (native) | FP8 KV Cache | FP4 KV Cache | Spec topk=1 | Spec topk>1 | Sliding Window | MultiModal |
|---|---|---|---|---|---|---|---|
| FlashInfer | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ |
| FA3 (FlashAttention 3) | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ |
| FA4 (FlashAttention 4) | 128 | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Triton | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Torch Native (SDPA) | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
| FlexAttention (PyTorch) | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
| TRTLLM MHA | 16, 32, 64 or 128 | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ |
| HPC-Ops | 64 | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| AITER (ROCm) | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ |
| Wave (ROCm) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Ascend (NPU) | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ | ✅ |
| Intel XPU | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ |
| Intel AMX (CPU) | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
MLA Backends
| Backend | Native Page Sizes | FP8 KV Cache | FP4 KV Cache | Chunked Prefix Cache | Spec topk=1 | Spec topk>1 |
|---|---|---|---|---|---|---|
| FlashInfer MLA | 1 | ❌ | ✅ | ✅ | ✅ | ❌ |
| FlashMLA | 64 | ✅ | ✅ | ✅ | ✅ | ❌ |
| TRTLLM MLA (Blackwell) | 32 or 64 | ✅ | ✅ | ✅ | ✅ | ❌ |
| CuteDSL MLA (Blackwell) | 32 or 64 | ✅ | ❌ | ✅ | ✅ | ❌ |
| FA3 (FlashAttention 3) | n/a | ❌ | ❌ | ✅ | ✅ | ⚠️ (page_size=1 only) |
| Triton | n/a | ❌ | ❌ | ❌ | ✅ | ⚠️ (page_size=1 only) |
| FA4 | 1 | ❌ | ✅ | ✅ | ❌ | ❌ |
| Ascend MLA (NPU) | 128 | ❌ | ❌ | ❌ | ❌ | ❌ |
Multimodal attention is selected by
--mm-attention-backend. The “MultiModal” column indicates whether a corresponding multimodal implementation exists for that backend family.- DSA is specifically designed for DeepSeek V3.2. See the DSA Attention Backend section and DeepSeek V3.2 deployment guide for details.
For the KV4 FA4 scenario, FA4 requires using a different —decode-attention-backend to run. Except for trtllm_mha being incompatible with FA4, all other decode backends behave as shown in the table.
page_size > 1 at the wrapper layer by expanding page tables to per-token indices. The “Page Size > 1 (native)” column indicates true in-kernel paging. Some backends require fixed native page sizes and cannot be reduced/emulated differently: TRTLLM MHA (16/32/64/128), TRTLLM MLA (32/64), CuteDSL MLA (32/64), FlashMLA (64), Ascend (128), HPC-Ops (64).
MLA page-size constraints:
- FlashInfer MLA: page_size = 1.
- FlashMLA: page_size = 64.
- TRTLLM MLA: page_size ∈ {32, 64}.
- CuteDSL MLA: page_size ∈ {32, 64} (decode-only; prefill falls back to
trtllm_mlawhen unset).
GDN Attention Backends
GDN (Gated Delta Network) is a linear attention mechanism with O(n) complexity, used in hybrid models that alternate GDN linear attention layers with standard full attention layers. GDN is not selected via--attention-backend; it is automatically activated when the model architecture requires it (e.g., Qwen 3.5, Qwen 3 Next, Jet Nemotron, Jet VLM).
The GDN linear attention layers have their own kernel backends, selected via --linear-attn-backend (default: triton). You can override the kernel per phase with --linear-attn-decode-backend and --linear-attn-prefill-backend.
On SM100/SM103 with CUDA 13+, SGLang automatically selects FlashInfer for GDN prefill when the per-phase override is unset, the base linear-attention backend is Triton, recurrent state is BF16, key/value head dimensions are 128, dynamic chunking and page-major KV layout are disabled, and --chunked-prefill-size is between 1 and 8192. Radix caching may be disabled or use no_buffer, extra_buffer, or extra_buffer_lazy; the extra-buffer paths use state checkpoints.
| Backend | Decode | Prefill / Extend | Spec Decoding (Target Verify) |
|---|---|---|---|
| Triton (CUDA) | ✅ | ✅ | ✅ |
| Triton (AMD/ROCm) | ✅ | ✅ | ✅ |
| Triton (NPU) | ✅ | ✅ | ❌ |
| Triton (CPU) | ✅ | ✅ | ❌ |
| CuTe DSL (CUDA only) | ✅ | ❌ | ❌ |
| FlashInfer (CUDA, SM90/SM100/SM103) | ✅ | ✅ | ✅ linear chain; tree falls back to Triton |
Linear-attention state dtype and FlashInfer
The recurrent (SSM) state of GDN, KDA and lightning layers is stored in one dtype per model, taken from the first of:--mamba-ssm-dtype;- the
SGLANG_MAMBA_SSM_DTYPEenvironment variable; - for GDN models only, the checkpoint config’s
mamba_ssm_dtype(KDA and lightning models ignore it); float32.
bfloat16 state. An explicit --linear-attn-decode-backend flashinfer (or verify backend) is accepted when the effective state dtype above is bfloat16, whichever source sets it, and rejected at launch otherwise. The generic automatic default (used by GDN models) is narrower: on SM100, decode (and verify, which follows decode) defaults to FlashInfer only when --mamba-ssm-dtype bfloat16 is passed and no decode backend is chosen; a bfloat16 state from the environment variable or the checkpoint keeps the Triton default. The automatic prefill choice described above uses the effective state dtype. Model-specific defaults take precedence: for KimiLinearForCausalLM, KimiK3ForConditionalGeneration and KimiK31ForConditionalGeneration, decode defaults to Triton under the same condition, and with speculative decoding verify defaults to nv_cutedsl on SM100 and Triton elsewhere.
ReplaySSM changes both choices: --enable-linear-replayssm decodes on Triton (or Helion), so no FlashInfer decode default is applied; --enable-linear-replayssm-spec sets the state dtype to float32 unless --mamba-ssm-dtype is given, before any default or check, so on compute capability 10.x and newer an explicit FlashInfer decode or verify with a bfloat16 checkpoint or environment variable is rejected at launch.
DSA Attention Backend
DSA (DeepSeek Sparse Attention) is a native sparse attention mechanism used by DeepSeek V3.2. It is activated automatically when the model architecture requires it and is selected via--attention-backend dsa. The old name nsa was removed in SGLang 1.0.
Internally, the DSA backend dispatches to different sub-backends for prefill and decode phases. You can override these with --dsa-prefill-backend and --dsa-decode-backend:
| Sub-backend | Prefill | Decode | Notes |
|---|---|---|---|
| flashmla_sparse | ✅ | ✅ | Default prefill on Hopper and Blackwell (BF16) |
| flashmla_sparse_q8 | ✅ | ❌ | Native FP8 (q8×kv8) sparse prefill on Hopper (SM90); BF16 or FP8 KV cache |
| triton_sparse_mla | ✅ | ❌ | Fused Triton sparse prefill that works on the post-TP head count instead of padding heads to 64/128; opt-in. CUDA SM90+ (tiles tuned on SM90 and SM120; other architectures run an untuned tile and log a warning at startup), at most 32 query heads per rank, not with index_kpool. —dsa-triton-union 2|4 lets adjacent query tokens share one gathered index set (exact; num_q_heads * union must be a power of two in [16, 32]) |
| flashmla_kv | ✅ | ✅ | Default for FP8 on Hopper (prefill + decode) |
| flashmla_auto | ✅ | ❌ | Picks flashmla_sparse or flashmla_kv by KV cache dtype |
| fa3 | ✅ | ✅ | Default decode on Hopper (BF16) |
| trtllm | ✅ | ✅ | Default decode on Blackwell (BF16); default for FP8 on Blackwell (prefill + decode) |
| prims_ts | ✅ | ✅ | FlashInfer Prims-TS sparse MLA on the trtllm route (same raw FP8 KV layout, no head padding); opt-in. SM100/SM103/SM107, D576 MLA, —kv-cache-dtype fp8_e4m3; —dcp-size > 1 only with Kimi-K3.1’s sharded index-K. Kimi-K3.1 needs it for both phases (an unset phase follows the set one); other models can pair it with trtllm |
| triton | ✅ | ✅ | Default on AMD (ROCm) |
| tilelang | ✅ | ✅ | Default on AMD (ROCm) when HiSparse is enabled |
| aiter | ✅ | ✅ | AMD-specific kernel library (requires aiter package) |
Gemma 4 on aiter (ROCm)
Gemma 4’s hybrid attention mixes sliding-window layers (head_dim 256) with
full-attention layers (head_dim 512) and shares KV across layers. The aiter
backend supports this and is allow-listed for Gemma 4, so you can serve it with
--attention-backend aiter on MI300X/MI350X. Under the hood aiter routes the
head_dim-512 prefill through the Triton unified_attention kernel (the CK
batch-prefill path caps head_dim at 256), honors each layer’s softmax scale,
and resolves the sliding-window KV pool for speculative-decode draft workers.
Non–sliding-window models (head_dim ≤ 256) are unaffected and keep using the
CK path.
For deployment examples, see the DeepSeek V3.2 deployment guide.
Hybrid attention (different backends for prefill vs decode) (Experimental)
You can mix-and-match attention backends for prefill and decode. This is useful when one backend excels at prefill and another excels at decode. For the implementation details, please seepython/sglang/srt/layers/attention/hybrid_attn_backend.py.
Command
Speculative decoding with hybrid attention
Hybrid attention also works with speculative decoding. The backend used for draft decoding and target verification depends on--speculative-attention-mode:
--speculative-attention-mode decode(recommended): draft/verify use the decode backend.--speculative-attention-mode prefill(default): draft/verify use the prefill backend.
- If any attention backend is
trtllm_mha, speculative decoding supports only--speculative-eagle-topk 1. - For paged MHA backends with
--page-size > 1and--speculative-eagle-topk > 1, onlyflashinferis supported. - CUDA Graph: the decode backend is always captured; the prefill backend is captured only when
--speculative-attention-mode prefill.
Attention Backend Selection Guide (CUDA)
If the--attention-backend argument is not specified, SGLang automatically selects the best backend based on the hardware (CUDA) and model architecture.
Automatic Selection Logic
1. MHA Models (e.g., Llama, Qwen)- Hopper (e.g., H100, H200): Defaults to
fa3if using CUDA 12.3+ and the model configuration is supported. - Blackwell (e.g., B200): Defaults to
trtllm_mha, unless using speculative decoding withtopk > 1. Models whose head dimstrtllm_mhahas no kernels for (anything other than 64, 128, 256 or 512 with equal K/V dims, e.g. Phi-3-mini at 96) default tofa4, or totritoniffa4does not support them either. - Other Architectures (Ampere, Ada, etc.): Defaults to
flashinferif available and its FA2 prefill supports the model’s head dims (multiples of 64); otherwise falls back totriton.
- Hopper: Defaults to
fa3(requires CUDA 12.3+). - Blackwell: Defaults to
flashinfer;trtllm_mlais auto-selected for DeepSeek V3 models specifically. - Other Architectures: Defaults to
triton.
User Guide
Launch Command for Different Attention Backends
- FlashInfer (Default for Non-Hopper Machines, e.g., A100, A40)
Command
- FlashAttention 3 (Default for Hopper Machines, e.g., H100, H200, H20)
Command
- Triton
Command
- FlashMLA
Command
- TRTLLM MLA (Optimized for Blackwell Architecture, e.g., B200)
Command
- TRTLLM MLA with FP8 KV Cache (Higher concurrency, lower memory footprint)
Command
- TRTLLM MHA (Optimized for Blackwell Architecture, e.g., B200)
Command
- TRTLLM MHA (XQA backend) (Optimized for SM90 and SM120, e.g., H20, H200, 5090) Note that TRTLLM XQA backend only works well for pagesize 64.
Command
- HPC-Ops (MHA kernels from HPC-Ops by the Tencent Hunyuan AI Infra team; Hopper (SM90) only, requires installing the
hpcpackage from source, page size 64, bf16 or fp8_e4m3 KV cache, head_dim 128, q/kv head group 4 or 8)
Command
- FlashAttention 4 (MHA & MLA)
Command
- Ascend
Command
- Intel XPU
Command
- Wave
Command
- FlexAttention
Command
- Torch Native
Command
Steps to add a new attention backend
To add a new attention backend, you can learn from the existing backends (python/sglang/srt/layers/attention/triton_backend.py, python/sglang/srt/layers/attention/flashattention_backend.py)
and follow the steps below.
Linear attention kernel backends (GDN, KDA) follow a different pattern. They implement
LinearAttnKernelBase in python/sglang/srt/layers/attention/linear/kernels/ and are dispatched by GDNKernelDispatcher / KDAKernelDispatcher rather than registered via @register_attention_backend.- Run without cuda graph. Support the two forward functions
- forward_extend
- Will be used for prefill, prefill with KV cache, and target verification
- It will be called once per layer
- forward_decode
- Will be used for normal decode, and draft decode
- It will be called once per layer
- init_forward_metadata
- Initialize the class and common metadata shared by all layers
- Call the plan function for optimizations like split_kv
- It will be called once per forward
- forward_extend
- Run with cuda graph. It has two phases (capture and replay) and you need to implement three functions
- init_cuda_graph_state
- It will be called once during life time
- Create all common shared buffers
- init_forward_metadata_capture_cuda_graph
- It will be called before capturing a cuda graph
- It is similar to init_forward_metadata but write the medatada to some pre-defined buffers
- init_forward_metadata_replay_cuda_graph
- It will be called before replaying a cuda graph
- This function is in the critical path and needs to be fast
- init_cuda_graph_state
