[Feature] Add FlashAttention3 as a backend for VisionAttention (#5764)

Co-authored-by: othame <chenzhu_912@zju.edu.cn>
Co-authored-by: Mick <mickjagger19@icloud.com>
Co-authored-by: Yi Zhang <1109276519@qq.com>
This commit is contained in:
Zhu Chen
2025-05-08 10:01:19 -07:00
committed by GitHub
co-authored by othame Mick Yi Zhang
parent f1ff736d68
commit fa7d7fd9e5
11 changed files with 328 additions and 186 deletions
+4 -4
View File
@@ -151,20 +151,20 @@ class CLIPEncoderLayer(nn.Module):
self.layer_norm1 = norm_layer(config.hidden_size)
self.layer_norm2 = norm_layer(config.hidden_size)
if attn_implementation == "sdpa":
use_context_forward = False
qkv_backend = "sdpa"
softmax_in_single_precision = False
elif attn_implementation == "flash_attention_2":
qkv_backend = "triton_attn"
softmax_in_single_precision = False
use_context_forward = True
elif attn_implementation == "eager":
qkv_backend = "sdpa"
softmax_in_single_precision = True
use_context_forward = False
self.self_attn = VisionAttention(
embed_dim=config.hidden_size,
num_heads=config.num_attention_heads,
projection_size=config.hidden_size,
use_qkv_parallel=True,
use_context_forward=use_context_forward,
qkv_backend=qkv_backend,
softmax_in_single_precision=softmax_in_single_precision,
flatten_batch=True,
quant_config=quant_config,