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
2 changes: 1 addition & 1 deletion src/flag_gems/ops/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ def flash_attention_forward(
else:
non_null_window_right = -1

out = torch.empty_like(query)
out = torch.empty(query.shape, device=query.device, dtype=query.dtype)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why using torch.empty instead of torch.empty_like

if cumulative_sequence_length_q is not None:
out, q, k, v, lse, philox_seed, philox_offset, p = mha_varlan_fwd(
query,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_attention_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def attention_ref(
else:
attention_drop = attention
output = torch.einsum("bhts,bshd->bthd", attention_drop, v * dropout_scaling)
output = output.contiguous()
if query_padding_mask is not None:
output.masked_fill_((~query_padding_mask)[:, :, None, None], 0.0)
return output.to(dtype=dtype_og), attention.to(dtype=dtype_og)
Expand Down Expand Up @@ -662,7 +663,7 @@ def test_flash_fwd_gqa_alibi_softcap(
@pytest.mark.flash_attention_forward
@pytest.mark.parametrize(
["batch", "num_head", "num_head_k", "q_seq_len", "kv_seq_len"],
[(1, 4, 1, 1, 1024), (4, 4, 4, 1, 519)],
[(1, 4, 1, 1, 1024), (4, 4, 4, 1, 519), (1, 4, 1, 2, 16)],
)
@pytest.mark.parametrize("head_size", [128, 192])
@pytest.mark.parametrize("is_causal", [False, True])
Expand Down
Loading