Support HuggingFace kernels package for native diffusion attention backends (#4926)
Signed-off-by: samithuang <285365963@qq.com> Signed-off-by: Samit <285365963@qq.com>
This commit is contained in:
1 parent
4908b85731
commit
b96bc5ac87
9 files changed
+601
No files matched your search
@@ -121,6 +121,31 @@ class CudaOmniPlatform(OmniPlatform, CudaPlatformBase):
|
||||
|
||||
if selected_backend is not None:
|
||||
backend_upper = selected_backend.upper()
|
||||
if backend_upper in ("FLASH_ATTN_HUB", "FLASH_ATTN_3_HUB"):
|
||||
try:
|
||||
importlib.import_module("kernels")
|
||||
logger.info("Using HuggingFace kernels-backed attention backend '%s'", backend_upper)
|
||||
except ImportError:
|
||||
if backend_upper == "FLASH_ATTN_HUB":
|
||||
logger.warning(
|
||||
"HuggingFace `kernels` library is not available. Falling back to local FLASH_ATTN."
|
||||
)
|
||||
backend_upper = "FLASH_ATTN"
|
||||
elif backend_upper == "FLASH_ATTN_3_HUB":
|
||||
logger.warning(
|
||||
"HuggingFace `kernels` library is not available. Falling back to local FLASH_ATTN."
|
||||
)
|
||||
backend_upper = "FLASH_ATTN"
|
||||
|
||||
if backend_upper == "FLASH_ATTN_3_HUB":
|
||||
fa3_hub_supported = compute_capability is not None and compute_capability.major >= 9
|
||||
if not fa3_hub_supported:
|
||||
logger.warning(
|
||||
"FLASH_ATTN_3_HUB requires a Hopper-class GPU with compute capability >= 9.0. "
|
||||
"Falling back to FLASH_ATTN_HUB."
|
||||
)
|
||||
backend_upper = "FLASH_ATTN_HUB"
|
||||
|
||||
if backend_upper == "FLASH_ATTN" and not flash_attn_supported:
|
||||
if not compute_supported:
|
||||
logger.warning(
|
||||
|
||||
@@ -78,6 +78,14 @@ class MUSAOmniPlatform(OmniPlatform, MUSAPlatformBase):
|
||||
|
||||
if selected_backend is not None:
|
||||
backend_upper = selected_backend.upper()
|
||||
if backend_upper in ("FLASH_ATTN_HUB", "FLASH_ATTN_3_HUB"):
|
||||
logger.warning(
|
||||
"HuggingFace kernels-backed FlashAttention is "
|
||||
"not supported on MUSA. Falling back to local "
|
||||
"FLASH_ATTN."
|
||||
)
|
||||
backend_upper = "FLASH_ATTN"
|
||||
|
||||
if backend_upper == "FLASH_ATTN" and not flash_attn_supported:
|
||||
if not compute_supported:
|
||||
logger.warning(
|
||||
|
||||
@@ -107,6 +107,14 @@ class NPUOmniPlatform(OmniPlatform, NPUPlatform):
|
||||
|
||||
if selected_backend is not None:
|
||||
backend_upper = selected_backend.upper()
|
||||
if backend_upper in ("FLASH_ATTN_HUB", "FLASH_ATTN_3_HUB"):
|
||||
logger.warning(
|
||||
"HuggingFace kernels-backed FlashAttention is "
|
||||
"not supported on NPU. Falling back to local "
|
||||
"FLASH_ATTN."
|
||||
)
|
||||
backend_upper = "FLASH_ATTN"
|
||||
|
||||
backend = DiffusionAttentionBackendEnum[backend_upper]
|
||||
logger.debug("Using diffusion attention backend '%s'", backend_upper)
|
||||
return backend.get_path()
|
||||
|
||||
@@ -88,6 +88,14 @@ class RocmOmniPlatform(OmniPlatform, RocmPlatform):
|
||||
|
||||
if selected_backend is not None:
|
||||
backend_upper = selected_backend.upper()
|
||||
if backend_upper in ("FLASH_ATTN_HUB", "FLASH_ATTN_3_HUB"):
|
||||
logger.warning(
|
||||
"HuggingFace kernels-backed FlashAttention is "
|
||||
"not supported on ROCm. Falling back to local "
|
||||
"FLASH_ATTN."
|
||||
)
|
||||
backend_upper = "FLASH_ATTN"
|
||||
|
||||
if backend_upper == "FLASH_ATTN" and not aiter_supported:
|
||||
logger.warning(
|
||||
"Flash Attention requires `aiter` library which is only supported "
|
||||
|
||||
@@ -42,6 +42,14 @@ class XPUOmniPlatform(OmniPlatform, XPUPlatform):
|
||||
|
||||
if selected_backend is not None:
|
||||
backend_upper = selected_backend.upper()
|
||||
if backend_upper in ("FLASH_ATTN_HUB", "FLASH_ATTN_3_HUB"):
|
||||
logger.warning(
|
||||
"HuggingFace kernels-backed FlashAttention is "
|
||||
"not supported on XPU. Falling back to local "
|
||||
"FLASH_ATTN."
|
||||
)
|
||||
backend_upper = "FLASH_ATTN"
|
||||
|
||||
backend = DiffusionAttentionBackendEnum[backend_upper]
|
||||
logger.debug("Using diffusion attention backend '%s'", backend_upper)
|
||||
return backend.get_path()
|
||||
|
||||
Reference in new issue
Block a user