[Misc] Replace mamba_type string literals with MambaAttentionBackendEnum (#41188)

Signed-off-by: wangxiyuan <wangxiyuan1007@gmail.com>
This commit is contained in:
wangxiyuan
2026-05-11 03:59:36 +00:00
committed by GitHub
parent 7f95e66a11
commit 5536fc0c01
18 changed files with 64 additions and 58 deletions
-10
View File
@@ -193,16 +193,6 @@ class MambaAttentionBackendEnum(Enum, metaclass=_AttentionBackendEnumMeta):
_MAMBA_ATTN_OVERRIDES.pop(self, None)
MAMBA_TYPE_TO_BACKEND_MAP = {
"mamba1": MambaAttentionBackendEnum.MAMBA1.name,
"mamba2": MambaAttentionBackendEnum.MAMBA2.name,
"short_conv": MambaAttentionBackendEnum.SHORT_CONV.name,
"linear_attention": MambaAttentionBackendEnum.LINEAR.name,
"gdn_attention": MambaAttentionBackendEnum.GDN_ATTN.name,
"custom": MambaAttentionBackendEnum.CUSTOM.name,
}
_ATTN_OVERRIDES: dict[AttentionBackendEnum, str] = {}
_MAMBA_ATTN_OVERRIDES: dict[MambaAttentionBackendEnum, str] = {}
+4 -15
View File
@@ -12,7 +12,6 @@ from vllm.logger import init_logger
from vllm.utils.import_utils import resolve_obj_by_qualname
from vllm.v1.attention.backend import AttentionBackend, AttentionType
from vllm.v1.attention.backends.registry import (
MAMBA_TYPE_TO_BACKEND_MAP,
MambaAttentionBackendEnum,
)
@@ -138,7 +137,7 @@ def _cached_get_attn_backend(
def get_mamba_attn_backend(
mamba_type: str,
mamba_type: MambaAttentionBackendEnum,
) -> type[AttentionBackend]:
"""Select which mamba attention backend to use and lazily import it."""
return _cached_get_mamba_attn_backend(mamba_type)
@@ -146,21 +145,11 @@ def get_mamba_attn_backend(
@cache
def _cached_get_mamba_attn_backend(
mamba_type: str,
mamba_type: MambaAttentionBackendEnum,
) -> type[AttentionBackend]:
assert mamba_type and isinstance(mamba_type, str)
assert mamba_type and isinstance(mamba_type, MambaAttentionBackendEnum)
selected_backend = None
try:
backend_name = MAMBA_TYPE_TO_BACKEND_MAP[mamba_type]
selected_backend = MambaAttentionBackendEnum[backend_name]
except KeyError as e:
raise ValueError(
f"Invalid mamba attention backend type: '{mamba_type}'. Valid "
f"types are: {list(MAMBA_TYPE_TO_BACKEND_MAP.keys())}"
) from e
mamba_attn_backend = selected_backend.get_class()
mamba_attn_backend = mamba_type.get_class()
if envs.VLLM_BATCH_INVARIANT and not mamba_attn_backend.supports_batch_invariance():
raise RuntimeError(
"VLLM batch_invariant mode is not supported for "
+2 -1
View File
@@ -16,6 +16,7 @@ from typing_extensions import Self
from vllm.logger import init_logger
from vllm.utils.math_utils import cdiv, round_up
from vllm.utils.torch_utils import get_dtype_size, nvfp4_kv_cache_full_dim
from vllm.v1.attention.backends.registry import MambaAttentionBackendEnum
if TYPE_CHECKING:
from vllm.config import VllmConfig
@@ -532,7 +533,7 @@ class MambaSpec(KVCacheSpec):
shapes: tuple[tuple[int, ...], ...]
dtypes: tuple[torch.dtype]
page_size_padded: int | None = None
mamba_type: str = "mamba2"
mamba_type: MambaAttentionBackendEnum = MambaAttentionBackendEnum.MAMBA2
mamba_cache_mode: str = "none"
num_speculative_blocks: int = 0