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.
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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
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
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:
-
AttentionBackendEnum–The newly created enum member
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.
-
register–Dynamically register a new mamba backend enum member.
Source code in vllm/v1/attention/backends/registry.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
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
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:
-
MambaAttentionBackendEnum–The newly created enum member
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 | 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" )