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:
Samit authored and GitHub committed 2026-07-08 14:34:36 +08:00
1 parent 4908b85731
commit b96bc5ac87
9 files changed
+601

No files matched your search

+25
View File
@@ -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(
+8
View File
@@ -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(
+8
View File
@@ -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()
+8
View File
@@ -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 "
+8
View File
@@ -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()