[Blackwell] Add CUDNN_ATTN and FLASHINFER_ATTN backends for diffusion (auto-route) (#3079)

Signed-off-by: lishunyang <lishunyang12@163.com>
Signed-off-by: Zhang <jianmusings@gmail.com>
Signed-off-by: Zhang Jian <jianmusings@gmail.com>
Co-authored-by: frauttauteffasu <247219357+frauttauteffasu@users.noreply.github.com>
Co-authored-by: Zhang Jian <jianmusings@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-05-28 11:09:25 +08:00
1 parent 1903cee56a
commit 373d3c7476
11 files changed
+859 -41

No files matched your search

+71 -5
View File
@@ -58,14 +58,32 @@ class CudaOmniPlatform(OmniPlatform, CudaPlatformBase):
) -> str:
from vllm_omni.diffusion.envs import PACKAGES_CHECKER
# Check compute capability for Flash Attention support
# Flash Attention requires compute capability >= 8.0 and < 10.0
# Check compute capability for Flash Attention support.
# FA requires sm_80+. Blackwell (sm_10x/sm_12x) only works with FA builds
# that include the Blackwell CUTE kernel — plain FA2 will crash there.
#
# Known Blackwell SKUs:
# sm_100 = B200 / GB200 (datacenter)
# sm_103 = B300 / GB300 (Blackwell Ultra)
# sm_120 = RTX Pro 6000, RTX 50-series (consumer)
# sm_121 = consumer Blackwell refresh
_known_blackwell_sms = {(10, 0), (10, 3), (12, 0), (12, 1)}
compute_capability = cls.get_device_capability()
compute_supported = False
is_blackwell = False
sm_str = ""
if compute_capability is not None:
major, minor = compute_capability
capability = major * 10 + minor
compute_supported = 80 <= capability < 100
compute_supported = capability >= 80
sm_str = f"sm_{major}{minor}"
# Accept major in {10, 11, 12} to cover future Blackwell refreshes.
is_blackwell = major in (10, 11, 12)
if is_blackwell and (major, minor) not in _known_blackwell_sms:
logger.info(
"Detected Blackwell-class GPU %s (untested variant); routing to CUDNN_ATTN with SDPA fallback.",
sm_str,
)
# Check if FA packages are available
packages_info = PACKAGES_CHECKER.get_packages_info()
@@ -74,13 +92,38 @@ class CudaOmniPlatform(OmniPlatform, CudaPlatformBase):
# Both compute capability and packages must be available for FA
flash_attn_supported = compute_supported and packages_available
# cuDNN 9.5+ ships Blackwell FMHA kernels. If the runtime is older,
# the CUDNN_ATTN default would still work via internal fallback but
# without the tuned Blackwell path, so we skip routing there.
cudnn_version = torch.backends.cudnn.version() or 0
cudnn_blackwell_ready = cudnn_version >= 90500
# FlashInfer edges cuDNN by ~4% at the kernel level on sm_120 but
# regresses ~2x at e2e on HV-1.5 because its dense-prefill path can't
# take 2D attn_masks and the SDPA fallback dispatches to
# EFFICIENT_ATTENTION (~25 ms) instead of the cuDNN mask path (~11 ms).
# CUDNN_ATTN pins sdpa_kernel([CUDNN_ATTENTION]) directly so masked
# calls keep the cuDNN path. Blackwell default prefers CUDNN_ATTN;
# users can opt into FLASHINFER_ATTN explicitly for no-mask workloads.
flashinfer_available = False
try:
import flashinfer # noqa: F401
flashinfer_available = True
except Exception as e:
# A partially installed / ABI-mismatched wheel can raise OSError or
# RuntimeError from extension loading, not just ImportError. This
# runs during default backend selection, so a probe failure must
# not abort startup — just treat FlashInfer as unavailable.
logger.debug("FlashInfer probe failed (%s); treating as unavailable", e)
if selected_backend is not None:
backend_upper = selected_backend.upper()
if backend_upper == "FLASH_ATTN" and not flash_attn_supported:
if not compute_supported:
logger.warning(
"Flash Attention requires GPU with compute capability >= 8.0 "
"and < 10.0. Falling back to TORCH_SDPA backend."
"Flash Attention requires GPU with compute capability >= 8.0. "
"Falling back to TORCH_SDPA backend."
)
elif not packages_available:
logger.warning("Flash Attention packages not available. Falling back to TORCH_SDPA backend.")
@@ -90,6 +133,29 @@ class CudaOmniPlatform(OmniPlatform, CudaPlatformBase):
logger.debug("Using diffusion attention backend '%s'", backend_upper)
return backend.get_path()
if is_blackwell and cudnn_blackwell_ready:
logger.info(
"Defaulting to diffusion attention backend CUDNN_ATTN (Blackwell %s, cuDNN %d)",
sm_str,
cudnn_version,
)
return DiffusionAttentionBackendEnum.CUDNN_ATTN.get_path()
if is_blackwell and flashinfer_available:
logger.info(
"Defaulting to diffusion attention backend FLASHINFER_ATTN (Blackwell %s, cuDNN unavailable)",
sm_str,
)
return DiffusionAttentionBackendEnum.FLASHINFER_ATTN.get_path()
if is_blackwell and not cudnn_blackwell_ready:
logger.warning(
"Detected Blackwell %s but cuDNN %d < 9.5 — no tuned Blackwell FMHA. "
"Falling through to FLASH_ATTN / SDPA.",
sm_str,
cudnn_version,
)
if flash_attn_supported:
logger.debug("Defaulting to diffusion attention backend FLASH_ATTN")
return DiffusionAttentionBackendEnum.FLASH_ATTN.get_path()