vllm.v1.attention.backends.registry
¶
Attention backend registry.
Classes:
-
AttentionBackendEnum–Enumeration of all supported attention backends.
-
MambaAttentionBackendEnum–Enumeration of all supported mamba attention backends.
Functions:
-
register_backend–Register or override a backend implementation.
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:
-
type[AttentionBackend]–The backend class
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
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:
-
type[AttentionBackend]–The backend class
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
_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:
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" )