@@ -22,17 +22,33 @@ def set_more_shapes(self):
2222 flag_gems .device == "musa" or vendor_name == "hygon" , reason = "RuntimeError"
2323)
2424@pytest .mark .attention
25- def test_perf_scaled_dot_product_attention ():
25+ @pytest .mark .parametrize ("dropout_p" , [0.0 , 0.25 ])
26+ @pytest .mark .parametrize ("is_causal" , [True , False ])
27+ def test_perf_scaled_dot_product_attention (dropout_p , is_causal ):
2628 def scaled_dot_product_attention_kwargs (shape , dtype , device ):
2729 query = torch .randn (shape , device = device , dtype = dtype )
2830 key = torch .randn (shape , device = device , dtype = dtype )
2931 value = torch .randn (shape , device = device , dtype = dtype )
30- yield query , key , value , None , 0.0 , True
32+ yield query , key , value , dropout_p , is_causal
33+
34+ def sdpa_flash (query , key , value , dropout_p = dropout_p , is_causal = is_causal ):
35+ from torch .nn .attention import SDPBackend , sdpa_kernel
36+
37+ with sdpa_kernel (backends = [SDPBackend .FLASH_ATTENTION ]):
38+ torch .nn .functional .scaled_dot_product_attention (
39+ query ,
40+ key ,
41+ value ,
42+ attn_mask = None ,
43+ dropout_p = dropout_p ,
44+ is_causal = is_causal ,
45+ )
3146
3247 bench = AttentionBenchmark (
3348 op_name = "scaled_dot_product_attention" ,
3449 input_fn = scaled_dot_product_attention_kwargs ,
35- torch_op = torch .nn .functional .scaled_dot_product_attention ,
50+ # torch_op=torch.nn.functional.scaled_dot_product_attention,
51+ torch_op = sdpa_flash ,
3652 dtypes = [
3753 torch .float16 ,
3854 torch .bfloat16 ,
0 commit comments