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

can mask be supported? #30

Open
unwritten opened this issue Jan 2, 2024 · 1 comment
Open

can mask be supported? #30

unwritten opened this issue Jan 2, 2024 · 1 comment

Comments

@unwritten
Copy link

in
flash_attn_func(q, k, v, dropout_p=0.0, softmax_scale=None, causal=False):

can mask be supported before going into softmax like:

        att = att.masked_fill(mask[:, None, :, :], min_value)
        att = F.softmax(att, dim=-1, dtype=torch.float32).to(rdtype).masked_fill(mask[:, None, :, :], 0.0)
@adityas-amd
Copy link

Hi @unwritten,
I think it is supported on main branch,

def _flash_attn_forward(
q: torch.Tensor,
k: torch.Tensor,
v: torch.Tensor,
dropout_p: float,
softmax_scale: float,
causal: bool,
window_size_left: int,
window_size_right: int,
softcap: float,
alibi_slopes: Optional[torch.Tensor],
return_softmax: bool
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
out, softmax_lse, S_dmask, rng_state = flash_attn_cuda.fwd(
q,
k,
v,
None,
alibi_slopes,
dropout_p,
softmax_scale,
causal,
window_size_left,
window_size_right,
softcap,
return_softmax,
None,
)
return out, softmax_lse, S_dmask, rng_state

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

No branches or pull requests

4 participants