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

How could I use a query to calculate the attention with multiple k-v #1350

Open
DongyuXu77 opened this issue Nov 21, 2024 · 1 comment
Open

Comments

@DongyuXu77
Copy link

DongyuXu77 commented Nov 21, 2024

In this situation:

Query shape is [batch_size, num_heads_q, seq_length, hidden_size]
Key/Value shape is [batch_size, num_heads_kv, seq_length, top_k, hidden_size]

which means each query vector in a specific position select top_k k-v pairs, how could I use flash-attn to calculate it?

@tridao
Copy link
Contributor

tridao commented Nov 21, 2024

You can expand the query top_k times and combine into the batch dimension, so that QKV have batch dimension batch_size * top_k

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