[Attention] Move FA3→FA4 upgrade into get_flash_attn_version() (#40815)
Signed-off-by: gcanlin <canlinguosdu@gmail.com>
This commit is contained in:
@@ -115,22 +115,29 @@ def get_flash_attn_version(
|
|||||||
)
|
)
|
||||||
fa_version = 2
|
fa_version = 2
|
||||||
|
|
||||||
# The FA3 kernel rejects s_aux (sinks) when hdim != hdim_v; upgrade to
|
# Some FA3 unsupported SM90 cases can use FA4 when available.
|
||||||
# FA4 on SM90 when available.
|
|
||||||
if (
|
if (
|
||||||
fa_version == 3
|
fa_version == 3
|
||||||
and has_sinks
|
|
||||||
and head_size is not None
|
|
||||||
and head_size_v is not None
|
|
||||||
and head_size != head_size_v
|
|
||||||
and device_capability.major == 9
|
and device_capability.major == 9
|
||||||
and is_fa_version_supported(4)
|
and is_fa_version_supported(4)
|
||||||
):
|
):
|
||||||
logger.info_once(
|
upgrade_reason = None
|
||||||
"Diff-KV with sinks: upgrading FlashAttention 3 -> 4",
|
if head_size is not None and head_size > 256:
|
||||||
scope="local",
|
upgrade_reason = f"FA3 does not support head_size={head_size} on SM90"
|
||||||
)
|
elif (
|
||||||
fa_version = 4
|
has_sinks
|
||||||
|
and head_size is not None
|
||||||
|
and head_size_v is not None
|
||||||
|
and head_size != head_size_v
|
||||||
|
):
|
||||||
|
upgrade_reason = "Diff-KV with sinks"
|
||||||
|
if upgrade_reason:
|
||||||
|
logger.info_once(
|
||||||
|
"%s: upgrading FlashAttention 3 -> 4",
|
||||||
|
upgrade_reason,
|
||||||
|
scope="local",
|
||||||
|
)
|
||||||
|
fa_version = 4
|
||||||
|
|
||||||
# FA4 currently uses batch-shape-dependent scheduling
|
# FA4 currently uses batch-shape-dependent scheduling
|
||||||
# heuristics on SM100+, which breaks batch invariance.
|
# heuristics on SM100+, which breaks batch invariance.
|
||||||
|
|||||||
@@ -638,14 +638,6 @@ class FlashAttentionImpl(AttentionImpl):
|
|||||||
requires_alibi=alibi_slopes is not None,
|
requires_alibi=alibi_slopes is not None,
|
||||||
head_size=head_size,
|
head_size=head_size,
|
||||||
)
|
)
|
||||||
# head_size > 256 requires FA4 on SM90+; force upgrade from FA3
|
|
||||||
if (
|
|
||||||
head_size > 256
|
|
||||||
and self.vllm_flash_attn_version == 3
|
|
||||||
and current_platform.is_cuda()
|
|
||||||
and current_platform.is_device_capability_family(90)
|
|
||||||
):
|
|
||||||
self.vllm_flash_attn_version = 4
|
|
||||||
logger.info_once(
|
logger.info_once(
|
||||||
"Using FlashAttention version %s",
|
"Using FlashAttention version %s",
|
||||||
self.vllm_flash_attn_version,
|
self.vllm_flash_attn_version,
|
||||||
|
|||||||
Reference in New Issue
Block a user