[Refactor] Extract has_flash_attn_pkg in OmniPlatform (#3068)

Signed-off-by: Xiaodong Ye <yeahdongcn@gmail.com>
Co-authored-by: Canlin Guo <canlinguosdu@gmail.com>
This commit is contained in:
R0CKSTARandCanlin Guo authored and GitHub committed 2026-04-27 04:07:34 +00:00
1 parent afa2b09684
commit 52f17bf292
6 files changed
+94 -58

No files matched your search

+31 -6
View File
@@ -8,7 +8,6 @@ from vllm.logger import init_logger
from vllm_musa.platform import MUSAPlatformBase
from vllm_omni.diffusion.attention.backends.registry import DiffusionAttentionBackendEnum
from vllm_omni.diffusion.attention.backends.utils.fa import is_mate_available
from vllm_omni.platforms.interface import OmniPlatform, OmniPlatformEnum
logger = init_logger(__name__)
@@ -47,6 +46,12 @@ class MUSAOmniPlatform(OmniPlatform, MUSAPlatformBase):
# MUSA uses default runtime preparation
return None
@classmethod
def has_flash_attn_package(cls) -> bool:
from vllm_omni.diffusion.attention.backends.utils.fa import is_flash_attn_installed
return is_flash_attn_installed()
@classmethod
def get_diffusion_attn_backend_cls(
cls,
@@ -65,21 +70,41 @@ class MUSAOmniPlatform(OmniPlatform, MUSAPlatformBase):
Returns:
Fully qualified class path of the selected backend.
"""
from vllm_omni.diffusion.envs import PACKAGES_CHECKER
flash_attn_available = is_mate_available()
# Check compute capability for Flash Attention support
# Flash Attention requires compute capability >= 3.1
compute_capability = cls.get_device_capability()
compute_supported = False
if compute_capability is not None:
major, minor = compute_capability
capability = major * 10 + minor
compute_supported = capability >= 31
# Check if FA packages are available
packages_info = PACKAGES_CHECKER.get_packages_info()
packages_available = packages_info.get("has_flash_attn", False)
# Both compute capability and packages must be available for FA
flash_attn_supported = compute_supported and packages_available
if selected_backend is not None:
backend_upper = selected_backend.upper()
if backend_upper == "FLASH_ATTN" and not flash_attn_available:
logger.warning("Flash Attention (mate package) not available. Falling back to TORCH_SDPA backend.")
if backend_upper == "FLASH_ATTN" and not flash_attn_supported:
if not compute_supported:
logger.warning(
"Flash Attention requires MUSA GPU with compute capability >= 3.1. "
"Falling back to TORCH_SDPA backend."
)
elif not packages_available:
logger.warning("Flash Attention (mate package) not available. Falling back to TORCH_SDPA backend.")
logger.info("Defaulting to diffusion attention backend SDPA")
return DiffusionAttentionBackendEnum.TORCH_SDPA.get_path()
backend = DiffusionAttentionBackendEnum[backend_upper]
logger.info("Using diffusion attention backend '%s'", backend_upper)
return backend.get_path()
# Default to FLASH_ATTN if mate is available, otherwise SDPA
if flash_attn_available:
if flash_attn_supported:
logger.info("Defaulting to diffusion attention backend FLASH_ATTN")
return DiffusionAttentionBackendEnum.FLASH_ATTN.get_path()