Attention Backend Feature Support¶
本文件由 tools/pre_commit/generate_attention_backend_docs.py 自动生成。 它展示了每个已注册的 attention backend 的功能支持情况, 基于 AttentionBackend.validate_configuration() 中的检查。
请勿手动编辑此文件。 运行以下命令以重新生成:
设置 Attention Backend¶
命令行¶
有两种方式可以从命令行指定 backend:
选项 1:使用 --attention-backend(简单)
选项 2:使用 --attention-config.backend / -ac.backend(结构化配置)
# 点号表示法
vllm serve <model> --attention-config.backend FLASH_ATTN
vllm serve <model> -ac.backend FLASH_ATTN
# JSON 格式
vllm serve <model> --attention-config '{"backend": "FLASH_ATTN"}'
vllm serve <model> -ac '{"backend": "FLASH_ATTN"}'
注意:
--attention-backend和--attention-config.backend是互斥的。 请使用其中之一,不要同时使用。
Python API¶
在 LLM 类中使用 AttentionConfig:
from vllm import LLM
from vllm.config import AttentionConfig
from vllm.v1.attention.backends.registry import AttentionBackendEnum
# 方法 1:使用 AttentionConfig 和枚举
llm = LLM(
model="Qwen/Qwen3-0.6B",
attention_config=AttentionConfig(backend=AttentionBackendEnum.FLASH_ATTN),
)
# 方法 2:使用 attention_backend 参数和字符串
llm = LLM(
model="Qwen/Qwen3-0.6B",
attention_backend="FLASH_ATTN",
)
Backend 选择行为¶
手动选择¶
当您通过 --attention-backend 或 AttentionConfig 显式设置 backend 时:
- 该 backend 会根据您的配置(模型 dtype、head size、compute capability 等)进行验证
- 如果该 backend 不支持您的配置,则会抛出错误并附带具体原因
- 如果有效,则使用该 backend
选择不兼容 backend 时的错误示例:
ValueError: Selected backend FLASHMLA is not valid for this configuration.
Reason: ['compute capability not supported']
自动选择¶
当未指定 backend 时(默认情况):
- vLLM 按优先级顺序遍历 backend(参见下表)
- 每个 backend 都会根据您的配置进行验证
- 选择第一个兼容的 backend
- 如果没有兼容的 backend,则会抛出错误,列出所有 backend 及其不兼容原因
Backend 优先级(CUDA)¶
当未显式选择 backend 时,vLLM 会从这些按优先级排序的列表中选择第一个兼容的 backend。
优先级 1 = 最高(最先尝试)。
标准 Attention(MHA、MQA、GQA)¶
优先级表由构建脚本自动生成:
Blackwell (SM 10.x):
| Priority | Backend |
|---|---|
| 1 | FLASHINFER |
| 2 | FLASH_ATTN |
| 3 | TRITON_ATTN |
| 4 | FLEX_ATTENTION |
| 5 | TURBOQUANT |
Ampere/Hopper (SM 8.x-9.x):
| Priority | Backend |
|---|---|
| 1 | FLASH_ATTN |
| 2 | FLASHINFER |
| 3 | TRITON_ATTN |
| 4 | FLEX_ATTENTION |
| 5 | TURBOQUANT |
MLA Attention(DeepSeek 风格)¶
优先级表由构建脚本自动生成:
Blackwell (SM 10.x):
| Priority | Backend |
|---|---|
| 1 | FLASHINFER_MLA |
| 2 | TOKENSPEED_MLA |
| 3 | CUTLASS_MLA |
| 4 | FLASH_ATTN_MLA |
| 5 | FLASHMLA |
| 6 | TRITON_MLA |
| 7 | FLASHINFER_MLA_SPARSE* |
| 8 | FLASHMLA_SPARSE |
注意: ROCm 和 CPU 平台有各自的选择逻辑。有关详细信息,请参阅特定平台的文档。
图例¶
| 列 | 描述 |
|---|---|
| Dtypes | 支持的模型数据类型(fp16、bf16、fp32) |
| KV Dtypes | 支持的 KV cache 数据类型(auto、fp8、fp8_e4m3 等) |
| Block Sizes | 支持的 KV cache block 大小(%N 表示 N 的倍数) |
| Head Sizes | 支持的 attention head 大小 |
| Sink | Attention sink 支持(用于 StreamingLLM) |
| Sparse | Sparse attention 支持(仅 MLA) |
| MM Prefix | Multimodal prefix full attention 支持 |
| Attention Types | 支持的 attention 模式(Decoder、Encoder、Enc-Dec) |
| Compute Cap. | 所需的 CUDA compute capability(非 CUDA backend 为 N/A) |
符号: ✅ = 支持,❌ = 不支持
标准 Attention(MHA、MQA、GQA)Backend¶
| Backend | Version | Dtypes | KV Dtypes | Block Sizes | Head Sizes | Sink | Non-Causal | MM Prefix | DCP | Attention Types | Compute Cap. |
|---|---|---|---|---|---|---|---|---|---|---|---|
CPU_ATTN | fp16, bf16, fp32 | auto, fp8, fp8_e4m3, fp8_e5m2 | %16 | 32, 64, 80, 96, 112, 128, 160, 192, 224, 256, 512 | ❌ | ✅ | ❌ | ❌ | All | N/A | |
CUTLASS_MSA | fp16, bf16 | auto | Any | Any | ❌ | ❌ | ❌ | ❌ | Decoder | Any | |
FLASHINFER | Native† | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3, fp8_e5m2, nvfp4_4over6 | 16, 32, 64, 128, 256, 512, 1024 | 64, 128, 256, 512 | ❌ | ✅ | ❌ | ✅ | Decoder | 8.x-9.x |
FLASHINFER | XQA† | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3, fp8_e5m2, nvfp4_4over6 | 16, 32, 64, 128, 256, 512, 1024 | 64, 128, 256, 512 | ❌ | ❌ | ❌ | ✅ | Decoder | 9.0 |
FLASHINFER | trtllm-gen† | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3, fp8_e5m2, nvfp4, nvfp4_4over6 | 16, 32, 64, 128, 256, 512, 1024 | 64, 128, 256, 512 | ✅ | ✅ | ❌ | ✅ | Decoder | 10.x |
FLASH_ATTN | FA2* | fp16, bf16 | auto, float16, bfloat16 | %16 | Any | ❌ | ✅ | ❌ | ✅ | All | ≥8.0 |
FLASH_ATTN | FA3* | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3 | %16 | Any | ✅ | ✅ | ❌ | ✅ | All | 9.x |
FLASH_ATTN | FA4* | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3 | %16 | Any | ✅ | ✅ | ❌ | ✅ | All | ≥10.0 |
FLASH_ATTN_DIFFKV | fp16, bf16 | auto | Any | Any | ❌ | ❌ | ❌ | ✅ | Decoder | Any | |
FLEX_ATTENTION | fp16, bf16, fp32 | auto, float16, bfloat16 | %16 | Any | ❌ | ✅ | ✅ | ❌ | Decoder, Encoder Only | Any | |
HPC_ATTN | fp16, bf16 | auto, bfloat16, fp8_e4m3 | 64 | 128 | ❌ | ❌ | ❌ | ❌ | Decoder | Any | |
ROCM_AITER_FA | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3, fp8_e5m2 | 16, 32 | 64, 128, 256 | ✅ | ✅ | ❌ | ❌ | Decoder | N/A | |
ROCM_AITER_UNIFIED_ATTN | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3, fp8_e5m2 | %16 | Any | ✅ | ❌ | ✅ | ❌ | All | N/A | |
ROCM_ATTN | fp16, bf16, fp32 | auto, float16, bfloat16, fp8, fp8_e4m3, fp8_e5m2 | %16 | 32, 64, 80, 96, 128, 160, 192, 224, 256 | ❌ | ✅ | ✅ | ❌ | Decoder, Encoder, Encoder Only | N/A | |
TRITON_ATTN | fp16, bf16, fp32 | auto, float16, bfloat16, fp8, fp8_e4m3, fp8_e5m2, int4_per_token_head, int8_per_token_head, fp8_per_token_head | %16 | Any | ✅ | ✅ | ✅ | ❌ | All | Any | |
TRITON_ATTN_DIFFKV | fp16, bf16 | auto, bfloat16 | Any | Any | ❌ | ❌ | ❌ | ❌ | Decoder | Any | |
TRITON_MSA | fp16, bf16 | auto | Any | Any | ❌ | ❌ | ❌ | ❌ | Decoder | Any | |
TURBOQUANT | fp16, bf16 | turboquant_k8v4, turboquant_4bit_nc, turboquant_k3v4_nc, turboquant_3bit_nc | 16, 32, 64, 128 | Any | ❌ | ❌ | ❌ | ❌ | Decoder | Any |
| Backend | Dtypes | KV Dtypes | Block Sizes | Head Sizes | Sink | Non-Causal | MM Prefix | DCP | Attention Types | Compute Cap. |
|---|---|---|---|---|---|---|---|---|---|---|
MINIMAX_M3_SPARSE | bf16, fp16 | bfloat16, fp8, fp8_e4m3, fp8_e5m2 | 128 | 128 | ❌ | ❌ | ❌ | ❌ | Decoder | Any |
† FlashInfer 在 Blackwell(SM100)上使用 TRTLLM attention,支持 sinks。通过
--attention-config.use_trtllm_attention=0禁用。* 通过
--attention-config.flash_attn_version=2或3指定 FlashAttention 版本。SM90 上默认为 FA3,其他情况为 FA2。
MLA(Multi-head Latent Attention)Backend¶
MLA 对 prefill 和 decode 阶段使用不同的 backend。
Prefill Backend¶
Prefill backend 在运行时根据硬件和配置选择。
| Backend | Description | Dtypes | Compute Cap. | Notes |
|---|---|---|---|---|
FLASH_ATTN‡ | FlashAttention varlen (FA2/FA3/FA4) | fp16, bf16 | Any | (qk_nope_head_dim=128, qk_rope_head_dim=64, v_head_dim=128) or (qk_nope_head_dim=192, qk_rope_head_dim=64, v_head_dim=256) or (qk_nope_head_dim=64, qk_rope_head_dim=64, v_head_dim=128) only |
TRTLLM_RAGGED | TensorRT-LLM ragged attention | fp16, bf16 | 10.x | (qk_nope_head_dim=128, qk_rope_head_dim=64, v_head_dim=128) or (qk_nope_head_dim=192, qk_rope_head_dim=64, v_head_dim=256) only |
FLASHINFER | FlashInfer CUTLASS backend | fp16, bf16 | 10.x | (qk_nope_head_dim=128, qk_rope_head_dim=64, v_head_dim=128) only |
TOKENSPEED_MLA | fp16, bf16 | 10.x | (qk_nope_head_dim=128, qk_rope_head_dim=64, v_head_dim=128) only |
Decode Backend¶
| Backend | Dtypes | KV Dtypes | Block Sizes | Head Sizes | Sink | Non-Causal | Sparse | MM Prefix | DCP | Attention Types | Compute Cap. |
|---|---|---|---|---|---|---|---|---|---|---|---|
CPU_MLA | fp16, bf16, fp32 | auto | 16 | 576 | ❌ | ❌ | ❌ | ❌ | ❌ | Decoder | N/A |
CUTLASS_MLA | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3 | 128 | Any | ❌ | ❌ | ❌ | ❌ | ✅ | Decoder | 10.x |
FLASHINFER_MLA | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3 | 32, 64 | Any | ❌ | ✅ | ❌ | ❌ | ✅ | Decoder | 10.x |
FLASHINFER_MLA_SPARSE | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3 | 32, 64 | Any | ❌ | ❌ | ❌ | ❌ | ✅ | Decoder | 10.x |
FLASHINFER_MLA_SPARSE_SM120 | bf16 | auto, fp8, fp8_e4m3, fp8_ds_mla | 64, 256 | Any | ❌ | ❌ | ❌ | ❌ | ❌ | Decoder | 12.x |
FLASHMLA | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3 | 64 | Any | ❌ | ❌ | ❌ | ❌ | ✅ | Decoder | 9.x-10.x |
FLASHMLA_SPARSE | bf16 | auto, bfloat16, fp8_ds_mla | 64 | 576 | ❌ | ❌ | ✅ | ❌ | ❌ | Decoder | 9.x-10.x |
FLASH_ATTN_MLA | fp16, bf16 | auto, float16, bfloat16 | %16 | Any | ❌ | ❌ | ❌ | ❌ | ✅ | Decoder | 9.x |
FLASH_ATTN_MLA_SPARSE | fp16, bf16 | auto, float16, bfloat16 | 64 | Any | ❌ | ❌ | ✅ | ❌ | ❌ | Decoder | 9.x |
ROCM_AITER_MLA | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3, fp8_e5m2 | %1 | Any | ❌ | ❌ | ❌ | ❌ | ❌ | Decoder | N/A |
ROCM_AITER_MLA_SPARSE | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3 | 1, 64 | Any | ❌ | ❌ | ✅ | ❌ | ❌ | Decoder | N/A |
ROCM_AITER_TRITON_MLA | fp16, bf16 | auto | Any | Any | ❌ | ❌ | ❌ | ❌ | ❌ | Decoder | N/A |
TOKENSPEED_MLA | fp16, bf16 | fp8, fp8_e4m3 | 32, 64 | Any | ❌ | ✅ | ❌ | ❌ | ✅ | Decoder | 10.x |
TRITON_MLA | fp16, bf16 | auto, float16, bfloat16, fp8, fp8_e4m3 | %16 | Any | ❌ | ✅ | ❌ | ❌ | ✅ | Decoder | Any |
XPU_MLA_SPARSE | fp16, bf16 | auto, float16, bfloat16 | Any | 576 | ❌ | ❌ | ✅ | ❌ | ❌ | Decoder | Any |
| Backend | Dtypes | KV Dtypes | Block Sizes | Head Sizes | Sink | Non-Causal | Sparse | MM Prefix | DCP | Attention Types | Compute Cap. |
|---|---|---|---|---|---|---|---|---|---|---|---|
FLASHINFER_MLA_SPARSE_DSV4 | bf16 | auto, bfloat16, fp8, fp8_e4m3, fp8_ds_mla | 256 | 512 | ✅ | ❌ | ✅ | ❌ | ❌ | Decoder | 10.x, 12.x |
FLASHMLA_SPARSE_DSV4 | bf16 | auto, fp8_ds_mla, fp8 | 256 | 512 | ✅ | ❌ | ✅ | ❌ | ❌ | Decoder | 9.x-10.x |
ROCM_FLASHMLA_SPARSE_DSV4 | fp16, bf16 | auto | Any | Any | ❌ | ❌ | ❌ | ❌ | ❌ | Decoder | N/A |