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

ALiBi for the non-flash code path #858

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Markus28
Copy link
Contributor

Currently, ALiBi is only implemented for the flash code-path. This PR implements ALiBi also for the non-flash code path.

Here is a short script to verify that the behaviour matches the behaviour of the implementation with flash attention. To run this, one needs to merge the changes from #846

import torch
from flash_attn.modules.mha import get_alibi_slopes , FlashSelfAttention, SelfAttention

CAUSAL = False
qkv = torch.randn((16, 55, 3, 4, 32)).to('cuda', torch.float16)

module = SelfAttention(alibi_slopes=torch.tensor(get_alibi_slopes(4)), causal=CAUSAL).to('cuda', torch.float16)
module_flash = FlashSelfAttention(alibi_slopes=torch.tensor(get_alibi_slopes(4)), causal=CAUSAL).to('cuda', torch.float16)
result = module(qkv)
result_flash = module_flash(qkv)
print((result - result_flash) / result_flash * 100)

@Markus28 Markus28 changed the title feat: ALiBi for the non-flash code path ALiBi for the non-flash code path Feb 29, 2024
@Markus28 Markus28 marked this pull request as ready for review February 29, 2024 16:32
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

Successfully merging this pull request may close these issues.

1 participant