Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions benchmark/test_attention_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,26 @@ def set_more_shapes(self):
flag_gems.device == "musa" or vendor_name == "hygon", reason="RuntimeError"
)
@pytest.mark.scaled_dot_product_attention
@pytest.mark.parametrize("dropout_p", [0.0, 0.25])
@pytest.mark.parametrize("dropout_p", [0.0])
@pytest.mark.parametrize("is_causal", [True, False])
def test_perf_scaled_dot_product_attention(dropout_p, is_causal):
def scaled_dot_product_attention_kwargs(shape, dtype, device):
query = torch.randn(shape, device=device, dtype=dtype)
key = torch.randn(shape, device=device, dtype=dtype)
value = torch.randn(shape, device=device, dtype=dtype)
yield query, key, value, dropout_p, is_causal
yield query, key, value, None, dropout_p, is_causal

def sdpa_flash(query, key, value, dropout_p=dropout_p, is_causal=is_causal):
def sdpa_flash(
query, key, value, attn_mask=None, dropout_p=dropout_p, is_causal=is_causal
):
from torch.nn.attention import SDPBackend, sdpa_kernel

with sdpa_kernel(backends=[SDPBackend.FLASH_ATTENTION]):
torch.nn.functional.scaled_dot_product_attention(
query,
key,
value,
attn_mask=None,
attn_mask=attn_mask,
dropout_p=dropout_p,
is_causal=is_causal,
)
Expand All @@ -59,6 +61,7 @@ def sdpa_flash(query, key, value, dropout_p=dropout_p, is_causal=is_causal):
torch.bfloat16,
],
)
bench.set_gems(flag_gems.scaled_dot_product_attention)
bench.run()


Expand Down
4 changes: 4 additions & 0 deletions src/flag_gems/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
from flag_gems.ops.argmax import argmax
from flag_gems.ops.argmin import argmin
from flag_gems.ops.attention import (
ScaleDotProductAttention,
flash_attention_forward,
flash_attn_varlen_func,
scaled_dot_product_attention,
scaled_dot_product_attention_backward,
)
from flag_gems.ops.batch_norm import batch_norm, batch_norm_backward
from flag_gems.ops.bitwise_and import (
Expand Down Expand Up @@ -391,6 +393,8 @@
"rsqrt",
"rsqrt_",
"scaled_dot_product_attention",
"scaled_dot_product_attention_backward",
"ScaleDotProductAttention",
"scatter",
"scatter_",
"select_scatter",
Expand Down
Loading
Loading