Skip to content

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:

Functions:

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_tokens and run_prefill_context_chunk honor

  • supports_quant_output –

    Whether run_prefill_new_tokens can 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:

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.

register(name, value) classmethod

Dynamically register a new MLA prefill backend enum member.

Parameters:

  • name

    (str) –

    The name for the new enum member

  • value

    (str) –

    The fully qualified class path string

Returns:

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:

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:

  • Callable[[type], type] –

    Decorator function if class_path is None, otherwise a no-op.

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" )