Skip to content

vllm.v1.attention.backends.registry

Attention backend registry.

Classes:

Functions:

AttentionBackendEnum

Bases: Enum

Enumeration of all supported attention backends.

The enum value is the default class path, but this can be overridden at runtime using register_backend().

To get the actual backend class (respecting overrides), use: backend.get_class()

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 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 Backend.CUSTOM is used without being registered

get_path(include_classname=True)

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.

Returns:

  • bool –

    True if the backend has a registered override

register(name, value) classmethod

Dynamically register a new backend enum member.

Parameters:

  • name

    (str) –

    The name for the new enum member

  • value

    (str) –

    The fully qualified class path string

Returns:

MambaAttentionBackendEnum

Bases: Enum

Enumeration of all supported mamba attention backends.

The enum value is the default class path, but this can be overridden at runtime using register_backend().

To get the actual backend class (respecting overrides), use: backend.get_class()

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 mamba 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 Backend.CUSTOM is used without being registered

get_path(include_classname=True)

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.

Returns:

  • bool –

    True if the backend has a registered override

register(name, value) classmethod

Dynamically register a new mamba backend enum member.

Parameters:

  • name

    (str) –

    The name for the new enum member

  • value

    (str) –

    The fully qualified class path string

Returns:

_AttentionBackendEnumMeta

Bases: EnumMeta

Metaclass for AttentionBackendEnum to provide better error messages.

Methods:

  • __getitem__ –

    Get backend by name with helpful error messages.

__getitem__(name)

Get backend by name with helpful error messages.

register_backend(backend, class_path=None, is_mamba=False)

Register or override a backend implementation.

Parameters:

  • backend

    (AttentionBackendEnum | MambaAttentionBackendEnum | str) –

    The AttentionBackendEnum/MambaAttentionBackendEnum member to register, or a string name for a new custom backend (e.g., "CUSTOM_MLA").

  • class_path

    (str | None, default: None ) –

    Optional class path. If not provided and used as decorator, will be auto-generated from the class.

  • is_mamba

    (bool, default: False ) –

    Whether the backend is a Mamba attention backend.

Returns:

  • Callable[[type], type] –

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

Examples:

Override an existing attention backend

@register_backend(AttentionBackendEnum.FLASH_ATTN) class MyCustomFlashAttn: ...

Override an existing mamba attention backend

@register_backend(MambaAttentionBackendEnum.LINEAR, is_mamba=True) class MyCustomMambaAttn: ...

Register a custom third-party attention backend

@register_backend(AttentionBackendEnum.CUSTOM) class MyCustomBackend: ...

Register a new custom attention backend with a dynamic enum name

@register_backend("CUSTOM_MLA") class CustomMLABackend: ...

Direct registration

register_backend( AttentionBackendEnum.CUSTOM, "my.module.MyCustomBackend" )

Direct registration with string name

register_backend( "CUSTOM_MLA", "custom.attention.mla_v1.CustomMLAABackend" )