Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash Attention doesn't support attention mask #109

Closed
clownrat6 opened this issue Mar 10, 2024 · 2 comments
Closed

Flash Attention doesn't support attention mask #109

clownrat6 opened this issue Mar 10, 2024 · 2 comments

Comments

@clownrat6
Copy link
Contributor

clownrat6 commented Mar 10, 2024

Test code from this:

import time
import torch
import torch.nn.functional as F


N = 32
L = 2048
dims = 64
n_heads = 8
q = torch.randn(N, n_heads, L, dims, dtype=torch.float16).cuda()
k = torch.randn(N, n_heads, L, dims, dtype=torch.float16).cuda()
v = torch.randn(N, n_heads, L, dims, dtype=torch.float16).cuda()

dropout_rate = 0.2
num_trials = 10

with torch.backends.cuda.sdp_kernel(
    enable_flash=True, enable_math=False, enable_mem_efficient=False
):

    attn_bias = torch.zeros(N, n_heads, L, L, dtype=q.dtype).to(q.device)
    torch.cuda.synchronize()
    start = time.time()
    for i in range(num_trials):
        out = F.scaled_dot_product_attention(q, k, v, attn_mask=attn_bias, dropout_p=dropout_rate)
    torch.cuda.synchronize()
    end = time.time()
    print('Flash attention took {} seconds for {} trials'.format(end - start, num_trials))

Errors:


Dingtalk_20240310101951

Related issues:
Dao-AILab/flash-attention#352

@LinB203
Copy link
Member

LinB203 commented Mar 10, 2024

@clownrat6
Copy link
Contributor Author

Bin God 🙏🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants