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.
Source code in vllm/v1/attention/backends/registry.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
clear_override() ¶
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
Source code in vllm/v1/attention/backends/registry.py
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
Source code in vllm/v1/attention/backends/registry.py
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.
Source code in vllm/v1/attention/backends/registry.py
clear_override() ¶
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
Source code in vllm/v1/attention/backends/registry.py
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
Source code in vllm/v1/attention/backends/registry.py
_AttentionBackendEnumMeta ¶
Bases: EnumMeta
Metaclass for AttentionBackendEnum to provide better error messages.
Methods:
-
__getitem__–Get backend by name with helpful error messages.
Source code in vllm/v1/attention/backends/registry.py
__getitem__(name) ¶
Get backend by name with helpful error messages.
Source code in vllm/v1/attention/backends/registry.py
register_backend(backend, class_path=None, is_mamba=False) ¶
Register or override a backend implementation.
Parameters:
-
(backend¶AttentionBackendEnum | MambaAttentionBackendEnum) –The AttentionBackendEnum member to register
-
(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 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: ...
Direct registration¶
register_backend( AttentionBackendEnum.CUSTOM, "my.module.MyCustomBackend" )