[Model] Add MiniMax H3 diffusion support (#5691)

This commit is contained in:
Isotr0py authored and GitHub committed 2026-08-03 14:10:40 +08:00
1 parent 727f90958e
commit 24741961eb
45 files changed
+7356 -31

No files matched your search

@@ -23,6 +23,19 @@ HAS_FA3 = False
fa3_fwd_func = None # Low-level forward function (_flash_attn_forward)
fa3_attn_func = None # High-level attention function (flash_attn_func)
# FA4 detection. The CuTe API returns LSE directly, so it can participate in
# Ring Attention's numerically stable block-wise output accumulation.
HAS_FA4 = False
fa4_attn_func = None
try:
from flash_attn.cute import flash_attn_func as fa4_attn_func # noqa: F401
HAS_FA4 = True
except Exception:
# Optional CuTe/CUTLASS/Quack components can be importable but
# ABI-incompatible. Treat the whole optional backend as unavailable.
pass
# Try flash_attn_interface first (from flash-attention source build)
try:
from flash_attn_interface import _flash_attn_forward as fa3_fwd_func # noqa: F401
@@ -9,9 +9,11 @@ import torch
from .ring_globals import (
HAS_AITER,
HAS_FA3,
HAS_FA4,
HAS_FLASH_ATTN,
HAS_FLASHINFER,
fa3_fwd_func,
fa4_attn_func,
)
_scaled_dot_product_flash_attention = torch.ops.aten._scaled_dot_product_flash_attention
@@ -190,6 +192,40 @@ def fa3_forward(q, k, v, dropout_p, softmax_scale, causal, window_size, softcap,
flash_attn3_func_forward = fa3_forward
def flash_attn4_func_forward(
q,
k,
v,
dropout_p=0.0,
softmax_scale=None,
causal=False,
window_size=(-1, -1),
softcap=None,
alibi_slopes=None,
return_softmax=False,
):
"""FA4 forward pass returning the LSE required by Ring Attention."""
del dropout_p, alibi_slopes, return_softmax
assert HAS_FA4, "FA4 is not available"
assert fa4_attn_func is not None, "FA4 high-level API is not available"
left, right = window_size if window_size else (-1, -1)
out, softmax_lse = fa4_attn_func(
q,
k,
v,
softmax_scale=softmax_scale,
causal=causal,
window_size=(
None if left == -1 else left,
None if right == -1 else right,
),
softcap=softcap or 0.0,
return_lse=True,
)
return out, softmax_lse
def flash_attn_forward_aiter(
q,
k,
@@ -15,6 +15,7 @@ from .ring_globals import (
)
from .ring_kernels import (
flash_attn3_func_forward,
flash_attn4_func_forward,
flash_attn_forward,
flash_attn_forward_aiter,
flashinfer_attn_forward,
@@ -32,6 +33,7 @@ class AttnType(Enum):
AITER = "aiter"
FA = "fa"
FA3 = "fa3"
FA4 = "fa4"
FLASHINFER = "flashinfer"
TORCH = "torch"
SAGE_AUTO = "sage_auto"
@@ -77,6 +79,9 @@ def select_flash_attn_impl(
elif impl_type == AttnType.FA3:
return flash_attn3_func_forward
elif impl_type == AttnType.FA4:
return flash_attn4_func_forward
elif impl_type == AttnType.FLASHINFER:
return flashinfer_attn_forward