Skip to main content
SGLang supports a wide variety of attention backends, each with different strengths and tradeoffs. Selecting an optimal attention backend is crucial for maximizing performance based on your model, hardware, and use case.
Different backends excel in various scenarios. Choose based on your model architecture, hardware platform, and workload characteristics. Not all backends are supported on all platforms and model architectures.

Automatic Backend Selection

If you don’t specify --attention-backend, SGLang makes a best effort to automatically select the most performant backend based on your hardware and model architecture.

MHA Models (e.g., Llama, Qwen)

  • Hopper (H100, H200): Defaults to fa3 if using CUDA 12.3+ and model configuration is supported
  • Blackwell (B200): Defaults to trtllm_mha, unless using speculative decoding with topk > 1
  • Other Architectures (Ampere, Ada): Defaults to flashinfer if available; otherwise falls back to triton

MLA Models (e.g., DeepSeek V3)

  • Hopper: Defaults to fa3 (requires CUDA 12.3+)
  • Blackwell: Defaults to trtllm_mla
  • Other Architectures: Defaults to triton

Backend Support Matrix

MHA (Multi-Head Attention) Backends

MLA (Multi-Head Latent Attention) Backends

Multimodal attention is selected by --mm-attention-backend. The “MultiModal” column indicates whether a corresponding multimodal implementation exists for that backend family.
Page Size and Prefix Cache: Page size controls how many tokens are grouped into a KV cache block. For the prefix cache to take effect, the number of tokens must fill at least one complete page. For example, if your prompt is only 32 tokens and page_size = 64, it won’t fill a complete page and cannot be matched in the prefix cache. Use page_size = 1 for maximum prefix reuse (token-level matching).

Backend Descriptions

FlashInfer

Best for: General-purpose MHA models on non-Hopper GPUs (A100, A40) High-performance attention implementation with broad feature support including FP8 KV cache, speculative decoding, and sliding window attention.

FlashAttention 3 (FA3)

Best for: Hopper GPUs (H100, H200, H20) Default backend for Hopper machines. Optimized for SM90 architecture with excellent performance for both MHA and MLA models.

FlashAttention 4 (FA4)

Best for: Blackwell GPUs (B200) and FP4 KV cache workloads Supports both prefill and decode on SM90 (Hopper) and SM100 (Blackwell). On Hopper, requires page_size = 128.
FA4 on Hopper (SM90): FA4 decode speed decreases as sequence length grows due to lack of SplitKV support. At batch=1 compared to FA3 on H100: ~-10% at 2K tokens, ~-18% at 4K, ~-31% at 8K, ~-49% at 16K. Larger batch sizes reduce the gap. Blackwell (SM100) is not affected.

FlashMLA

Best for: MLA models with FP8 KV cache on Hopper Specialized backend for MLA architecture with native support for FP8 and FP4 KV cache. Requires page_size = 64.

TRTLLM MLA

Best for: Blackwell architecture (B200) with MLA models Optimized for Blackwell GPUs with excellent performance for MLA models. Supports FP8 and FP4 KV cache.

TRTLLM MHA

Best for: Blackwell architecture (B200) with MHA models Optimized for Blackwell GPUs. Supports page_size of 16, 32, or 64.

Triton

Best for: Development, debugging, and FP4 KV cache Flexible Triton-based implementation supporting FP4 KV cache and various advanced features. Good fallback option for unsupported configurations.

Cutlass MLA

High-performance MLA backend using CUTLASS kernels. Requires page_size = 128.

Platform-Specific Backends

AMD ROCm

AITER: Recommended for ROCm platforms
Wave: Alternative ROCm backend

Ascend NPU

Intel XPU

Other Backends

Torch Native (SDPA): PyTorch’s scaled dot-product attention
FlexAttention: PyTorch’s FlexAttention API
Dual Chunk FlashAttention: For long-context models

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 (e.g., Qwen 3.5, Qwen 3 Next, Jet Nemotron, Jet VLM). GDN is not selected via --attention-backend; it is automatically activated when the model architecture requires it. The GDN linear attention layers have their own kernel backends, selected via --linear-attn-backend (default: triton).
Platform Constraints for GDN Models:
  • Blackwell (B200): triton, trtllm_mha, or fa4 only
  • NPU (Ascend): ascend only
  • AMD (ROCm): triton recommended
  • Other CUDA (Hopper, Ampere): auto-selection works; no special constraints

Hybrid Attention (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.

Speculative Decoding with Hybrid Attention

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
Constraints:
  • If any attention backend is trtllm_mha, speculative decoding supports only --speculative-eagle-topk 1
  • For paged MHA backends with --page-size > 1 and --speculative-eagle-topk > 1, only flashinfer is supported
  • CUDA Graph: the decode backend is always captured; the prefill backend is captured only when --speculative-attention-mode prefill
If you set only one of --prefill-attention-backend or --decode-attention-backend, the unspecified phase inherits --attention-backend. If both are specified and differ, SGLang automatically enables a hybrid wrapper.

Backend Selection Guide

Hopper GPUs (H100/H200)

Use FA3 for both MHA and MLA models. Best overall performance on SM90 architecture.

Blackwell GPUs (B200)

Use TRTLLM MLA for MLA models and TRTLLM MHA for MHA models. Optimized for SM100 architecture.

Ampere/Ada GPUs (A100/A40)

Use FlashInfer for best compatibility and performance on older architectures.

FP4 KV Cache

Use FA4 on Blackwell, FlashMLA on Hopper for MLA, or Triton as fallback.

FP8 KV Cache

Use FlashMLA or FA3 on Hopper, TRTLLM on Blackwell, FlashInfer on Ampere/Ada.

Long Context

Use Dual Chunk FlashAttention for million-token contexts, or FA3/FlashInfer with sliding window.

Best Practices

  1. Let SGLang auto-select: Unless you have specific requirements, let SGLang automatically choose the backend
  2. Match page size to backend: Check backend requirements for page size (e.g., FA4 requires 128 on Hopper)
  3. Consider KV cache format: Choose backends that support your desired KV cache dtype (FP8/FP4/BF16)
  4. Test on your workload: Different backends may perform differently depending on batch size, sequence length, and model size
  5. Monitor for graph breaks: Some backends work better with CUDA graphs than others

See Also