vllm.v1.attention.backends.mla.prefill
¶
Modules:
-
aiter_flash_attn–AITER FlashAttention backend for MLA prefill (ROCm).
-
aiter_flydsl_fp8–AITER FlyDSL FP8 backend for MLA prefill (ROCm gfx950).
-
base–Abstract base class for MLA prefill backends.
-
cpu_sdpa–CPU MLA prefill backend implemented with dense per-request attention.
-
flash_attn–FlashAttention backend for MLA prefill.
-
flashinfer–FlashInfer backend for MLA prefill.
-
registry–Registry for MLA prefill backends.
-
selector–Selector for MLA prefill backends.
-
tokenspeed_mla–TokenSpeed CuTe DSL backend for MLA prefill.
-
trtllm_ragged–TRT-LLM Ragged backend for MLA prefill.
-
zen_cpu_sdpa–CPU MLA prefill backend using zentorch SDPA on AMD Zen CPUs.
Classes:
-
MLAPrefillBackend–Abstract base class for MLA prefill backends.
-
MLAPrefillBackendEnum–Enumeration of all supported MLA prefill backends.
Functions:
-
get_mla_prefill_backend–Select the MLA prefill backend based on configuration and device.
-
register_mla_prefill_backend–Register or override an MLA prefill backend implementation.
MLAPrefillBackend
¶
Bases: ABC
Abstract base class for MLA prefill backends.
Methods:
-
prepare_metadata–Prepare backend-specific metadata before the forward pass.
-
supports_out–Whether
run_prefill_new_tokensandrun_prefill_context_chunkhonor -
supports_quant_output–Whether
run_prefill_new_tokenscan write quantized output
prepare_metadata(prefill_metadata)
¶
Prepare backend-specific metadata before the forward pass.
Called by the metadata builder after constructing the prefill metadata.
supports_out()
¶
Whether run_prefill_new_tokens and run_prefill_context_chunk honor
a caller-provided out tensor of shape
[num_tokens, num_heads, v_head_dim], writing the result into it in place
and returning it.
When True, callers may pass out and skip the post-hoc
slice/flatten/copy -- and, for context chunks, size the accumulating
partial before running any chunk. False for backends that ignore out or
emit a padded (qk_head_dim) output. Overridden by backends that support
it.
supports_quant_output(quant_key)
¶
Whether run_prefill_new_tokens can write quantized output
directly (fused) for the given quant key, skipping the post-quant
pass. Overridden by backends that support it.
MLAPrefillBackendEnum
¶
Bases: Enum
Enumeration of all supported MLA prefill backends.
Methods:
-
clear_override–Clear any override for this backend, reverting to the default.
-
get_class–Get the backend class (respects overrides).
-
get_path–Get the class path for this backend (respects overrides).
-
is_overridden–Check if this backend has been overridden.
-
register–Dynamically register a new MLA prefill backend enum member.
clear_override()
¶
Clear any override for this backend, reverting to the default.
get_class()
¶
Get the backend class (respects overrides).
Returns:
-
type[MLAPrefillBackend]–The backend class
Raises:
-
ImportError–If the backend class cannot be imported
-
ValueError–If CUSTOM is used without being registered
get_path()
¶
Get the class path for this backend (respects overrides).
Returns:
-
str–The fully qualified class path string
Raises:
-
ValueError–If Backend.CUSTOM is used without being registered
is_overridden()
¶
Check if this backend has been overridden.
get_mla_prefill_backend(vllm_config)
¶
Select the MLA prefill backend based on configuration and device.
This function first checks for explicit user preferences via mla_prefill_backend in AttentionConfig, then falls back to automatic priority-based selection.
Parameters:
-
(vllm_config¶VllmConfig | None) –The vLLM configuration. May be None before model resolution, in which case defaults are used.
Returns:
-
type[MLAPrefillBackend]–The selected prefill backend class.
register_mla_prefill_backend(backend, class_path=None)
¶
Register or override an MLA prefill backend implementation.
Parameters:
-
(backend¶MLAPrefillBackendEnum | str) –The MLAPrefillBackendEnum member to register, or a string name for a new custom backend (e.g., "CUSTOM_MLA_PREFILL").
-
(class_path¶str | None, default:None) –Optional class path. If not provided and used as decorator, will be auto-generated from the class.
Returns:
Examples:
Override an existing MLA prefill backend¶
@register_mla_prefill_backend(MLAPrefillBackendEnum.FLASH_ATTN) class MyCustomFlashAttn(MLAPrefillBackend): ...
Register a custom third-party MLA prefill backend¶
@register_mla_prefill_backend(MLAPrefillBackendEnum.CUSTOM) class MyCustomPrefillBackend(MLAPrefillBackend): ...
Register a new custom MLA prefill backend with a dynamic enum name¶
@register_mla_prefill_backend("CUSTOM_MLA_PREFILL") class CustomMLAPrefillBackend(MLAPrefillBackend): ...
Direct registration¶
register_mla_prefill_backend( MLAPrefillBackendEnum.CUSTOM, "my.module.MyCustomPrefillBackend" )
Direct registration with string name¶
register_mla_prefill_backend( "CUSTOM_MLA_PREFILL", "custom.attention.mla_prefill.CustomMLAPrefillBackend" )