[Attention] FlashAttention ViT support, make default backend (#28763)
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
This commit is contained in:
@@ -267,24 +267,21 @@ class CudaPlatformBase(Platform):
|
||||
) -> "AttentionBackendEnum":
|
||||
from vllm.attention.backends.registry import AttentionBackendEnum
|
||||
|
||||
# For Blackwell GPUs, force TORCH_SDPA for now.
|
||||
# See https://github.com/facebookresearch/xformers/issues/1317#issuecomment-3199392579 # noqa: E501
|
||||
if cls.has_device_capability(100):
|
||||
return AttentionBackendEnum.TORCH_SDPA
|
||||
|
||||
if dtype not in (torch.float16, torch.bfloat16):
|
||||
return AttentionBackendEnum.XFORMERS
|
||||
|
||||
if cls.has_device_capability(80):
|
||||
# Try FlashAttention first
|
||||
try:
|
||||
backend_class = AttentionBackendEnum.FLASH_ATTN.get_class()
|
||||
if backend_class.supports_head_size(
|
||||
head_size
|
||||
) and backend_class.supports_dtype(dtype):
|
||||
return AttentionBackendEnum.FLASH_ATTN
|
||||
else:
|
||||
return AttentionBackendEnum.XFORMERS
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
if cls.has_device_capability(100):
|
||||
# xFormers doesn't support Blackwell, fall back to SDPA
|
||||
# See https://github.com/facebookresearch/xformers/issues/1317#issuecomment-3199392579 # noqa: E501
|
||||
return AttentionBackendEnum.TORCH_SDPA
|
||||
else:
|
||||
# Fallback for Volta/Turing GPUs or FA not supported
|
||||
return AttentionBackendEnum.XFORMERS
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -119,8 +119,8 @@ class FlashAttentionBackend(AttentionBackend):
|
||||
raise ValueError(f"Unrecognized FP8 dtype: {kv_cache_dtype}")
|
||||
|
||||
@classmethod
|
||||
def get_supported_head_sizes(cls) -> list[int]:
|
||||
return [32, 64, 96, 128, 160, 192, 224, 256]
|
||||
def supports_head_size(cls, head_size: int) -> bool:
|
||||
return head_size % 8 == 0 and head_size <= 256
|
||||
|
||||
@classmethod
|
||||
def supports_kv_cache_dtype(cls, kv_cache_dtype: CacheDType | None) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user