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

support grouped query attention(MQA & GQA) for flash_attn #22

Merged
merged 2 commits into from
May 27, 2024

Conversation

iclementine
Copy link
Collaborator

@iclementine iclementine commented May 16, 2024

support grouped query attention(GQA) for flash_attn(related kernels: fwd, bwd, split_kv, total_attention)

The MQA paper

Shazeer, Noam. “Fast Transformer Decoding: One Write-Head Is All You Need.” arXiv, November 5, 2019. https://doi.org/10.48550/arXiv.1911.02150.

The GQA paper

Ainslie, Joshua, James Lee-Thorp, Michiel de Jong, Yury Zemlyanskiy, Federico Lebrón, and Sumit Sanghai. “GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints.” arXiv, December 23, 2023.

Mind the layout of the heads in the query.

Copy link
Collaborator

@tongxin tongxin left a comment

Choose a reason for hiding this comment

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

LG

# --------------------------- public API ---------------------------
class FlashAttention(torch.autograd.Function):
@staticmethod
def forward(ctx, q, k, v, causal, sm_scale, return_log_normalizer, return_total_attention):
# size, stride, dtype checking
Dq, Dk, Dv = q.shape[-1], k.shape[-1], v.shape[-1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could first run an all equal test over the input shapes, using iterator, as a fast path, to avoid interpreter overhead.

@iclementine iclementine changed the title support grouped query attention(GQA) for flash_attn support grouped query attention(MQA & GQA) for flash_attn May 27, 2024
@iclementine iclementine merged commit 13664fc into FlagOpen:main May 27, 2024
1 check passed
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.

2 participants